//Test script injection
        //Insert script to read the Browser URL and send it back to proxy
        public void OnResponse(object sender, SessionEventArgs e)
        {
            ////read response headers
            //var responseHeaders = e.ResponseHeaders;

            //if (e.ResponseStatusCode == HttpStatusCode.OK)
            //{
            //    if (e.ResponseContentType.Trim().ToLower().Contains("text/html"))
            //    {
            //        //Get/Set response body bytes
            //        byte[] responseBodyBytes = e.GetResponseBody();
            //        e.SetResponseBody(responseBodyBytes);

            //        //Get response body as string
            //        string responseBody = e.GetResponseBodyAsString();

            //        //Modify e.ServerResponse
            //        Regex rex = new Regex("</body>", RegexOptions.RightToLeft | RegexOptions.IgnoreCase | RegexOptions.Multiline);
            //        string modified = rex.Replace(responseBody, "<script type =\"text/javascript\">alert('Response was modified by this script!');</script></body>", 1);

            //        //Set modifed response Html Body
            //        e.SetResponseBodyString(modified);
            //    }
            //}
        }
Exemplo n.º 2
0
        public async Task ProxyServer_BeforeRequest(object sender, Titanium.Web.Proxy.EventArguments.SessionEventArgs e)
        {
            SessionListItem item = addSession(e);

            if (e.HttpClient.Request.HasBody)
            {
                e.HttpClient.Request.KeepBody = true;
                byte[] data = await e.GetRequestBody();

                //if (e.HttpClient.Request.Url.Contains("vk.com"))
                //{
                //    var str = Encoding.UTF8.GetString(data);
                //    if (str.Contains("привет"))
                //    {
                //        str = str.Replace("привет", "пока");
                //        data = Encoding.UTF8.GetBytes(str);
                //        e.SetRequestBody(data);
                //    }
                //}

                item.Update(e);

                if (item == SelectedSession)
                {
                    selectedSessionChanged();
                }
            }
        }
        //Test On Request, intecept requests
        //Read browser URL send back to proxy by the injection script in OnResponse event
        public void OnRequest(object sender, SessionEventArgs e)
        {
            Console.WriteLine(e.RequestUrl);

            ////read request headers
            //var requestHeaders = e.RequestHeaders;

            //if ((e.RequestMethod.ToUpper() == "POST" || e.RequestMethod.ToUpper() == "PUT"))
            //{
            //    //Get/Set request body bytes
            //    byte[] bodyBytes = e.GetRequestBody();
            //    e.SetRequestBody(bodyBytes);

            //    //Get/Set request body as string
            //    string bodyString = e.GetRequestBodyAsString();
            //    e.SetRequestBodyString(bodyString);

            //}

            ////To cancel a request with a custom HTML content
            ////Filter URL

            //if (e.RequestURL.Contains("google.com"))
            //{
            //    e.Ok("<!DOCTYPE html><html><body><h1>Website Blocked</h1><p>Blocked by titanium web proxy.</p></body></html>");
            //}
        }
        private async Task MyProxy_BeforeRequest(object sender, Titanium.Web.Proxy.EventArguments.SessionEventArgs e)
        {
            if (e.HttpClient.Request.Url.Contains("q.smart.360.cn/clean/cmd/send"))
            {
                var requestHeaders = e.HttpClient.Request.Headers;
                var method         = e.HttpClient.Request.Method.ToUpper();

                var header = e.HttpClient.Request.Headers.Where(c => c.Name == "Cookie").FirstOrDefault();
                if (header != null)
                {
                    if (string.IsNullOrEmpty(cmdModel.Cookie))
                    {
                        Console.WriteLine("Cookie: {0}", header.Value);
                        cmdModel.Cookie = header.Value.ToString();
                        CookieLoaded(this, null);
                    }
                }

                var body = Encoding.UTF8.GetString(await e.GetRequestBody());
                if (body.Contains("infoType=21005"))
                {
                    if (string.IsNullOrEmpty(cmdModel.StartCleaningCommand))
                    {
                        cmdModel.StartCleaningCommand = body;
                        StartCommandLoaded(this, null);
                    }
                }
                else if (body.Contains("infoType=21017"))
                {
                    if (string.IsNullOrEmpty(cmdModel.StopCleaningCommand))
                    {
                        cmdModel.StopCleaningCommand = body;
                        StopCommandLoaded(this, null);
                    }
                }
                else if (body.Contains("infoType=21012"))
                {
                    if (string.IsNullOrEmpty(cmdModel.ChargeCleaningCommand))
                    {
                        cmdModel.ChargeCleaningCommand = body;
                        ChargeCommandLoaded(this, null);
                    }
                }
                else
                {
                    UnknownCommandReceived(this, new UnknownCommandEventArgs {
                        command = body
                    });
                }
            }
            // return Task.FromResult(0);
            if (cmdModel.CmdFlags == CommandModel.CommandsFlags.Complete)
            {
                cmdModel.CmdFlags = CommandModel.CommandsFlags.None;
                CompleteHandler(this, null);
            }
        }
Exemplo n.º 5
0
 public async Task ProxyServer_AfterResponse(object sender, Titanium.Web.Proxy.EventArguments.SessionEventArgs e)
 {
     await Task.Run(() =>
     {
         if (sessionDictionary.TryGetValue(e.HttpClient, out var item))
         {
             item.Exception = e.Exception;
         }
     });
 }
 //Test script injection
 //Insert script to read the Browser URL and send it back to proxy
 public void OnResponse(object sender, SessionEventArgs e)
 {
     
     ////read response headers
    // var responseHeaders = e.ProxySession.Response.ResponseHeaders;
   
     //if (!e.ProxySession.Request.Hostname.Equals("medeczane.sgk.gov.tr")) return;
     //if (e.RequestMethod == "GET" || e.RequestMethod == "POST")
     //{
     //    if (e.ProxySession.Response.ResponseStatusCode == "200")
     //    {
     //        if (e.ProxySession.Response.ContentType.Trim().ToLower().Contains("text/html"))
     //        {
     //            string body = e.GetResponseBodyAsString(); 
     //        }
     //    }
     //}
 }
Exemplo n.º 7
0
        public async Task ProxyServer_BeforeResponse(object sender, Titanium.Web.Proxy.EventArguments.SessionEventArgs e)
        {
            SessionListItem item = null;

            if (sessionDictionary.TryGetValue(e.HttpClient, out item))
            {
                item.Update(e);
            }
            if (item != null)
            {
                if (e.HttpClient.Request.HasBody)
                {
                    e.HttpClient.Response.KeepBody = true;
                    await e.GetResponseBody();

                    item.Update(e);

                    if (item == SelectedSession)
                    {
                        selectedSessionChanged();
                    }
                }
            }
        }
 private Task MyProxy_BeforeResponse(object sender, Titanium.Web.Proxy.EventArguments.SessionEventArgs e)
 {
     return(Task.FromResult(0));
 }
Exemplo n.º 9
0
        public static async Task OnRequest(object sender, SessionEventArgs e)
        {
            try
            {

                Regex regex = new Regex("http://app.wcproject.so-net.tw/ajax/(.*)");

                var url = e.WebSession.Request.Url;

                if (!regex.IsMatch(url))
                    return;


                var method = regex.Match(url).Groups[1].Value;

                var reqLogPath = logPath + "requests\\" + method;

                var cookieId = "";

                foreach (var header in e.WebSession.Request.RequestHeaders)
                    if (header.Name.Equals("Cookie") && header.Value.Contains("wcatpt"))
                        cookieId = BodyToDict(header.Value)["wcatpt"].Split(new char[] { ':' })[0];


                Console.WriteLine(url);

                var body = Encoding.UTF8.GetString(await e.GetRequestBody());

                var fields = BodyToDict(body);

                CryptoDectectResult cryptInfo = CryptoDectect.isRequestCrypted(method);

                if (cryptInfo != null)
                {
                    string writed = body + Environment.NewLine + Environment.NewLine;

                    string key = Cipher.DEFAULT_NETWORKHASH;

                    if (!cryptInfo.isDefultKey && !cookieId.Equals("") && existsKeys.ContainsKey(cookieId))
                        key = existsKeys[cookieId];

                    string decryptedData = "";

                    if (fields.ContainsKey("data"))
                    {
                        decryptedData = WhiteCat.DecryptRequest(method, fields["data"], key);
                    }

                    switch (method)
                    {
                        case "regist/checkregister":
                            break;
                        case "regist/create":
                            break;
                        case "quest/complete":
                            QuestComplete response = WhiteCat.Parse<QuestComplete>(decryptedData);

                            response.gold *= 5;
                            response.soul *= 10;

                            int count = response.itemIds.Count;

                            for (var i = 0; i < count * 6; i++)
                            {
                                response.itemIds.Add(response.itemIds[i]);
                            }
                            string fixedData = JsonConvert.SerializeObject(response);
                            string fixedEncrypted = Cipher.EncryptRJ128(key, Cipher.DEFAULT_IV_128, fixedData);
                            fields["data"] = fixedEncrypted;
                            await  e.SetRequestBodyString(DictionaryToBody(fields));
                            break;
                    }

                }
                else
                {
                    Console.WriteLine("Detected unrecognized method: " + method);
                    Console.WriteLine("Content: " + body);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }


        }
Exemplo n.º 10
0
        //Modify response
        public static async Task OnResponse(object sender, SessionEventArgs e)
        {
            try
            {
                Regex regex = new Regex("http://app.wcproject.so-net.tw/ajax/(.*)");

                var url = e.WebSession.Request.Url;

                if (!regex.IsMatch(url))
                    return;

                var method = regex.Match(url).Groups[1].Value;

                var resLogPath = logPath + "response\\" + method;

                var body = Encoding.UTF8.GetString(await e.GetResponseBody());

                var cookieId = "";

                foreach (var header in e.WebSession.Response.ResponseHeaders)
                    if (header.Name.Equals("Set-Cookie") && header.Value.Contains("wcatpt"))
                        cookieId = CookiesToDict(header.Value)["wcatpt"].Split(new char[] { ':' })[0];

                if (cookieId.Equals(""))
                {
                    foreach (var header in e.WebSession.Request.RequestHeaders)
                        if (header.Name.Equals("Cookie") && header.Value.Contains("wcatpt"))
                            cookieId = CookiesToDict(header.Value)["wcatpt"].Split(new char[] { ':' })[0];
                }

                CryptoDectectResult cryptInfo = CryptoDectect.isResponseCrypted(method);

                string key = Cipher.DEFAULT_NETWORKHASH;

                if (!cryptInfo.isDefultKey && !cookieId.Equals("") && existsKeys.ContainsKey(cookieId))
                    key = existsKeys[cookieId];

                string decrypted = WhiteCat.DecryptResponse(method, body, key);

                switch (method)
                {
                    case "regist/checkregister":
                        break;
                    case "regist/create":
                        RegistCreate res = WhiteCat.Parse<RegistCreate>(decrypted);
                        SaveKey(cookieId, res.result.uh);
                        break;
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }
Exemplo n.º 11
0
 internal MultipartRequestPartSentEventArgs(SessionEventArgs session, string boundary, HeaderCollection headers) : base(session.ClientConnection)
 {
     Session  = session;
     Boundary = boundary;
     Headers  = headers;
 }
Exemplo n.º 12
0
        public static async Task OnRequest(object sender, SessionEventArgs e)
        {
            try
            {

                Regex regex = new Regex("http://app.wcproject.so-net.tw/ajax/(.*)");

                var url = e.WebSession.Request.Url;

                if (!regex.IsMatch(url))
                    return;


                var method = regex.Match(url).Groups[1].Value;

                var reqLogPath = logPath + "requests\\" + method;

                var cookieId = "";

                foreach (var header in e.WebSession.Request.RequestHeaders)
                    if (header.Name.Equals("Cookie") && header.Value.Contains("wcatpt"))
                        cookieId = BodyToDict(header.Value)["wcatpt"].Split(new char[] { ':' })[0];


                Console.WriteLine(url);

                var body = Encoding.UTF8.GetString(await e.GetRequestBody());

                var fields = BodyToDict(body);

                CryptoDectectResult cryptInfo = CryptoDectect.isRequestCrypted(method);

                if (cryptInfo != null)
                {
                    string writed = body + Environment.NewLine + Environment.NewLine;

                    string key = Cipher.DEFAULT_NETWORKHASH;

                    if (!cryptInfo.isDefultKey && !cookieId.Equals("") && existsKeys.ContainsKey(cookieId))
                        key = existsKeys[cookieId];

                    string decryptedData = "";

                    if (fields.ContainsKey("data"))
                    {
                        decryptedData = WhiteCat.DecryptRequest(method, fields["data"], key);

                        writed += "DATA:" + Environment.NewLine + decryptedData;
                    }

                    if (!Directory.Exists(reqLogPath))
                        Directory.CreateDirectory(reqLogPath);

                    File.WriteAllText(reqLogPath + "\\" + Environment.TickCount.ToString() + ".txt", writed);


                    switch (method)
                    {
                        case "regist/checkregister":
                            break;
                        case "regist/create":
                            break;
                    }

                }
                else
                {
                    Console.WriteLine("Detected unrecognized method: " + method);
                    Console.WriteLine("Content: " + body);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }


        }