private async Task OnRequest(object arg1, Titanium.Web.Proxy.EventArguments.SessionEventArgs e) { Console.WriteLine(e.WebSession.Request.Url + " REQ"); ////read request headers var requestHeaders = e.WebSession.Request.RequestHeaders; var method = e.WebSession.Request.Method.ToUpper(); if ((method == "POST" || method == "PUT" || method == "PATCH")) { //Get/Set request body bytes byte[] bodyBytes = await e.GetRequestBody(); await e.SetRequestBody(bodyBytes); //Get/Set request body as string /* * string bodyString = await e.GetRequestBodyAsString(); * await e.SetRequestBodyString(bodyString);*/ } //To cancel a request with a custom HTML content //Filter URL if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("tenrys.isgay")) { await e.Ok("<!DOCTYPE html>" + "<html><body><h1>" + "XAOTI CMAKES MEMES XDDD" + "</h1>" + "<p>FUCCC.</p>" + "</body>" + "</html>"); } //Redirect example if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("wikipedia.org")) { await e.Redirect("https://www.paypal.com"); } }
private async Task Proxyserver_BeforeRequest(object sender, Titanium.Web.Proxy.EventArguments.SessionEventArgs e) { try { string reqeustURL = e.HttpClient.Request.Url; if (reqeustURL.Contains("query.hicloud.com") || reqeustURL.Contains("/TDS/data/files")) { this.Invoke(new Action(() => { textBox3.AppendText(e.HttpClient.Request.Url + Environment.NewLine); })); if (checkBox2.Checked) { string debug = e.HttpClient.Request.Url + " : " + Environment.NewLine; List <HttpHeader> clientheaders = e.HttpClient.Request.Headers.GetAllHeaders(); for (int i = 0, j = clientheaders.Count; i < j; i++) { debug += clientheaders[i].Name + ": " + clientheaders[i].Value + Environment.NewLine; } if (e.HttpClient.Request.HasBody) { debug += Environment.NewLine + await e.GetRequestBodyAsString(); } debug += Environment.NewLine + Environment.NewLine; File.AppendAllText("logs.txt", debug); } } if (reqeustURL.Contains("query.hicloud.com")) { if (reqeustURL.Contains("CheckNewVersion.aspx")) { Dictionary <string, HttpHeader> Headers = new Dictionary <string, HttpHeader>(); Headers.Add("Content-Type", new HttpHeader("Content-Type", "application/xml;charset=UTF-8")); e.Ok("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><status>1</status></root>", Headers, true); } else if (reqeustURL.Contains("CouplingReport.action")) { string resbody = await e.GetRequestBodyAsString(); int where = resbody.IndexOf("descinfo"); if (where != -1) { where += 13; int finish = resbody.IndexOf("\",", where); new Thread(() => { MessageBox.Show(resbody.Substring(where, finish - where), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }).Start(); } } else if (reqeustURL.Contains("authorize.action")) { WebClient client = new WebClient(); client.Headers.Set(HttpRequestHeader.Accept, "*/*"); client.Headers.Set(HttpRequestHeader.ContentType, "application/json;charset=UTF-8"); string updata = await e.GetRequestBodyAsString(); string respons = client.UploadString("https://query.hicloud.com:443/sp_ard_common/v1/authorize.action", updata); Dictionary <string, HttpHeader> Headers = new Dictionary <string, HttpHeader>(); Headers.Add("Date", new HttpHeader("Date", client.ResponseHeaders[HttpResponseHeader.Date])); Headers.Add("Content-Type", new HttpHeader("Content-Type", "text/plain;charset=UTF-8")); Headers.Add("Server", new HttpHeader("Server", "elb")); Headers.Add("X-XSS-Protection", new HttpHeader("X-XSS-Protection", "1; mode=block")); Headers.Add("X-frame-options", new HttpHeader("X-frame-options", "SAMEORIGIN")); Headers.Add("X-Content-Type-Options", new HttpHeader("X-Content-Type-Options", "nosniff")); string manipulatedresponse = ManipulateData(respons); e.Ok(manipulatedresponse, Headers); } else if (e.HttpClient.Request.HasBody) { string bodydata = await e.GetRequestBodyAsString(); int whereisit = bodydata.IndexOf("PackageType"); if (whereisit != -1) { whereisit += 16; int finish = bodydata.IndexOf('"', whereisit); string pacakgetype = bodydata.Substring(whereisit, finish - whereisit); string opscheck = "full"; if (radioButton2.Checked) { opscheck = "hfull_switch"; } else if (radioButton3.Checked) { opscheck = "full_back"; } else if (radioButton4.Checked) { opscheck = "full_recovery"; } if (pacakgetype == opscheck) { string responsedata = Encoding.UTF8.GetString(Properties.Resources.responsedata).Replace("\r\n", ""); bool Iveabase = (GetURLVersion(textBox1.Text) != "Unknown"); if (Iveabase) { responsedata = responsedata.Replace("hasfullpackage", "0"); if (_customData.CustomBase) { responsedata = responsedata.Replace("WriteVerionID", _customData.CustomBaseID); } else { responsedata = responsedata.Replace("WriteVerionID", GetURLVersion(textBox1.Text)); } if (checkBox4.Checked) { responsedata = responsedata.Replace("pointbase", "1"); } else { responsedata = responsedata.Replace("pointbase", "0"); } responsedata = responsedata.Replace("basetype", textBox8.Text); responsedata = responsedata.Replace("VersionURL", textBox1.Text); responsedata = responsedata.Replace("Unknown1", textBox2.Text); } else { responsedata = responsedata.Replace("hasfullpackage", "1"); } if (checkBox1.Checked) { if (_customData.CustomPreload) { responsedata = responsedata.Replace("WiteVerionID", _customData.CustomPreloadID); } else { responsedata = responsedata.Replace("WiteVerionID", GetURLVersion(textBox4.Text)); } if (checkBox6.Checked) { if (Iveabase) { responsedata = responsedata.Replace("pointpreload", "2"); } else { responsedata = responsedata.Replace("pointpreload", "1"); } } else { responsedata = responsedata.Replace("pointpreload", "0"); } responsedata = responsedata.Replace("VrsionURL", textBox4.Text); responsedata = responsedata.Replace("Unknown2", textBox5.Text); responsedata = responsedata.Replace("hasreloadedpackage", "0"); } else { responsedata = responsedata.Replace("hasreloadedpackage", "1"); } if (checkBox3.Checked) { if (_customData.CustomCust) { responsedata = responsedata.Replace("WteVerionID", _customData.CustomCustID); } else { responsedata = responsedata.Replace("WteVerionID", GetURLVersion(textBox7.Text)); } if (checkBox5.Checked) { if (Iveabase) { responsedata = responsedata.Replace("pointcust", "2"); } else { responsedata = responsedata.Replace("pointcust", "1"); } } else { responsedata = responsedata.Replace("pointcust", "0"); } responsedata = responsedata.Replace("VrionURL", textBox7.Text); responsedata = responsedata.Replace("Unknown3", textBox6.Text); responsedata = responsedata.Replace("hascustpackage", "0"); } else { responsedata = responsedata.Replace("hascustpackage", "1"); } Dictionary <string, HttpHeader> Headers = new Dictionary <string, HttpHeader>(); Headers.Add("Content-Type", new HttpHeader("Content-Type", "application/json;charset=utf8")); e.Ok(responsedata, Headers, true); } else { string responsedata = Encoding.UTF8.GetString(Properties.Resources.emptyresponse).Replace("\r\n", ""); Dictionary <string, HttpHeader> Headers = new Dictionary <string, HttpHeader>(); Headers.Add("Content-Type", new HttpHeader("Content-Type", "application/json;charset=utf8")); e.Ok(responsedata, Headers, true); } } } } } catch (Exception ex) { this.Invoke(new Action(() => { textBox3.AppendText(ex.StackTrace + Environment.NewLine); })); MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }