Exemplo n.º 1
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();
                }
            }
        }
        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.º 3
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.º 4
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);
            }


        }