protected override CommandResult ProcessXmppMessage(string message) { InfoInstruction infoResult; try { infoResult = InfoInstruction.Parse(message); } catch (Exception e) { return(CreateError($"Can't parse {CmdName} instruction output: got exception \n{e}")); } if (!string.IsNullOrEmpty(infoResult.Error)) { return(CreateError(infoResult.Error)); } TextOutput updateResult; try { updateResult = SyncSoftwareInfo(infoResult.Software); } catch (Exception e) { return(CreateError($"Command {CmdName} failed. Can't sync command {infoResult.Code} to lib: \n{e}")); } //todo: sync soft effect info CommandResult result = CreateOutput(new TextOutput(Verbosity, message), CommandState.Finished); result.Output.Add(updateResult); return(result); }
public void SendMessage(string message) { if (message.StartsWith("target")) { if (message.Split(' ').Length > 1) { _target = message.Split(' ')[1]; string netPath = $"Server//Data//{_target}.xml"; _network = Serializer.DeserializeNet(netPath); } EmulateResponse("ok"); //404 target system:2739100 not found } else if (message.StartsWith("status")) { EmulateResponse(StatusInstruction.Assemble($"{_user}@{_domain}", string.IsNullOrEmpty(_target)?"none":_target, _admSystem, _proxyLevel, _visibleAs)); } else if (message.StartsWith("info")) { string codeStr = message.Replace("info #", ""); long softCode; string incorrectProgMessage = @"-------------------- incorrect program #{0} END----------------"; if (!long.TryParse(codeStr, out softCode)) { EmulateResponse(string.Format(incorrectProgMessage, codeStr)); } else { Structure.Software libSoft; if (!_softwareLib.All.TryGetValue(softCode, out libSoft)) { EmulateResponse(string.Format(incorrectProgMessage, codeStr)); return; } //soft found EmulateResponse(InfoInstruction.Assemble(libSoft)); } } else if (message.StartsWith("look")) { //todo: check errors string nodeName = message.Replace("look ", ""); Node node; if (_network == null) { EmulateResponse("network not found"); } if (!_network.Nodes.TryGetValue(nodeName, out node)) { EmulateResponse($@"-------------------- {_network.Name} / {nodeName}: not available END----------------"); } else { string response = LookInstruction.AssembleAccessible(_network.Name, node); EmulateResponse(response); } } else if (message.StartsWith("#")) { EmulateResponse("Not implemented"); } else { EmulateResponse("command no found"); } }
public void TestInfo() { string hack = @"-------------------- #180 programm info: Effect: disable Allowed node types: -Firewall -Antivirus -VPN -Brandmauer -Router -Traffic monitor -Cyptographic system Duration: 600sec. END ----------------"; var infoResponse = InfoInstruction.Parse(hack); Assert.NotNull(hack, "Parsed not successfully"); Assert.IsTrue(string.IsNullOrEmpty(infoResponse.Error), "Should be a success"); Assert.AreEqual(180, infoResponse.Code, "Code"); Assert.AreEqual(600, infoResponse.Duration, "Duration"); Assert.AreEqual("disable", infoResponse.Effect, "Effect"); Assert.AreEqual("", infoResponse.InevitableEffect, "InevitableEffect"); Assert.AreEqual("[Firewall,Antivirus,VPN,Brandmauer,Router,Traffic monitor,Cyptographic system]", infoResponse.SupportedNodes, "SupportedNodes"); Assert.AreEqual("exploit", infoResponse.Software.SoftwareType, "SoftwareType"); hack = @"-------------------- #180 programm info: Effect: disable Inevitable effect: logname Allowed node types: -Firewall -Antivirus -VPN -Brandmauer -Router -Traffic monitor -Cyptographic system Duration: 600sec. END ----------------"; infoResponse = InfoInstruction.Parse(hack); Assert.NotNull(hack, "Parsed not successfully"); Assert.IsTrue(string.IsNullOrEmpty(infoResponse.Error), "Should be a success"); Assert.AreEqual("logname", infoResponse.InevitableEffect, "InevitableEffect"); string soft = @"-------------------- #2294523 programm info: Effect: trace Inevitable effect: logname Allowed node types: -Firewall -Antivirus -VPN -Brandmauer -Router -Traffic monitor -Cyptographic system END ----------------"; infoResponse = InfoInstruction.Parse(soft); Assert.NotNull(soft, "Parsed not successfully"); Assert.IsTrue(string.IsNullOrEmpty(infoResponse.Error), "Should be a success"); Assert.AreEqual(2294523, infoResponse.Code, "Code"); Assert.AreEqual(0, infoResponse.Duration, "Duration"); Assert.AreEqual("trace", infoResponse.Effect, "Effect"); Assert.AreEqual("logname", infoResponse.InevitableEffect, "InevitableEffect"); Assert.AreEqual("[Firewall,Antivirus,VPN,Brandmauer,Router,Traffic monitor,Cyptographic system]", infoResponse.SupportedNodes, "SupportedNodes"); Assert.AreEqual("protection", infoResponse.Software.SoftwareType, "SoftwareType"); soft = @"-------------------- #2294523 programm info: Allowed node types: -Firewall END ----------------"; infoResponse = InfoInstruction.Parse(soft); Assert.NotNull(soft, "Parsed not successfully"); Assert.IsTrue(string.IsNullOrEmpty(infoResponse.Error), "Should be a success"); Assert.AreEqual(2294523, infoResponse.Code, "2294523"); Assert.AreEqual(0, infoResponse.Duration, "Duration"); Assert.AreEqual("", infoResponse.Effect, ""); Assert.AreEqual("", infoResponse.InevitableEffect, ""); Assert.AreEqual("[Firewall]", infoResponse.SupportedNodes, "SupportedNodes"); Assert.AreEqual("protection", infoResponse.Software.SoftwareType, "SoftwareType"); }