예제 #1
0
        private static async void ProxyBeforeRequest(RawContext rawContext, SessionEventArgs e)
        {
            try
            {
                if (await HandleGoogleLogin(rawContext, e))
                {
                    Logger.Info("Fixed app signature for Google");
                    return;
                }
                if (!AppConfig.HostsToDump.Contains(rawContext.RequestUri.Host))
                {
                    return;
                }

                var requestContext = RequestContext.GetInstance(rawContext);
                requestContext.ModifyRequest();
                if (requestContext.RequestModified)
                {
                    await e.SetRequestBody(requestContext.ModifiedRequestData.RequestBody);
                }

                Logger.Info(rawContext.RequestUri.AbsoluteUri + " Request Sent.");
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
예제 #2
0
        public static RequestContextListItemViewModel FromRawContext(RawContext context)
        {
            var model = new RequestContextListItemViewModel();

            model.Guid        = context.Guid.ToString();
            model.RequestTime = context.RequestTime;
            model.Host        = context.RequestUri.Host;


            var requestContext = RequestContext.GetInstance(context);

            try
            {
                var lsMethods = new List <string>();

                foreach (var request in requestContext.RequestData.Requests)
                {
                    lsMethods.Add(request.Key.ToString());
                }

                model.Methods = string.Join(", ", lsMethods);
            }
            catch (Exception)
            {
                model.Methods = "n/a";
            }

            return(model);
        }
예제 #3
0
 private void OnBeforeRequest(RawContext context, SessionEventArgs e)
 {
     if (context == null)
     {
         return;
     }
     BeforeRequest?.Invoke(context, e);
 }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    RawContext.Dispose();
                }

                disposedValue = true;
            }
        }
예제 #5
0
        private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e)
        {
            try
            {
                _logger.Debug($"{e.WebSession.Request.RequestUri.AbsoluteUri} Request Initialized");


                var uid     = Guid.NewGuid();
                var context = new RawContext()
                {
                    RequestHeaders = e.WebSession.Request.RequestHeaders.Values.ToList(),
                    Guid           = uid,
                    RequestUri     = e.WebSession.Request.RequestUri,
                    RequestTime    = DateTime.UtcNow,
                    ClientIp       = e.ClientEndPoint.Address.ToString()
                };
                _contexts.Add(uid.ToString(), context);
                e.WebSession.Response.ResponseHeaders.Add("POGO_UID", new HttpHeader("POGO_UID", uid.ToString()));


                try
                {
                    context.RequestBody = await e.GetRequestBody();
                }
                catch (BodyNotFoundException)
                {
                }
                //if (e.WebSession.Request.RequestUri.Host == "pgorelease.nianticlabs.com")
                //{
                //    var codedRequest = new CodedInputStream(context.RequestBody);
                //    var requestEnvelope = RequestEnvelope.Parser.ParseFrom(codedRequest);
                //    for (int i = 0; i < requestEnvelope.Requests.Count; i++)
                //    {
                //        var request = requestEnvelope.Requests[i];
                //        if (request.RequestType == RequestType.CheckChallenge)
                //        {
                //            var message = CheckChallengeMessage.Parser.ParseFrom(request.RequestMessage);
                //            message.DebugRequest = true;
                //            request.RequestMessage = message.ToByteString();
                //            var newEnvelope = PrepareRequestEnvelope(requestEnvelope);
                //            context.RequestBody = await newEnvelope.ReadAsByteArrayAsync();
                //            await e.SetRequestBody(context.RequestBody);
                //        }
                //    }
                //}
                OnBeforeRequest(context, e);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
            }
        }
예제 #6
0
        private static async void ProxyBeforeResponse(RawContext rawContext, SessionEventArgs e)
        {
            try
            {
                if (!AppConfig.HostsToDump.Contains(rawContext.RequestUri.Host))
                {
                    return;
                }
                rawContext.IsLive = true;
                ContextCache.RawContexts.TryAdd(rawContext.Guid, rawContext);

                var requestContext = RequestContext.GetInstance(rawContext);

                if (requestContext?.ResponseData == null)
                {
                    Logger.Error("Could not find the request context in cache or there is no response data, it shouldn't happen.");
                    return;
                }
                requestContext.CopyResponseData(rawContext);
                requestContext.ModifyResponse();
                if (requestContext.ResponseModified)
                {
                    await e.SetResponseBody(requestContext.ModifiedResponseData.ResponseBody);
                }

                NotificationHub.SendRawContext(RequestContextListModel.FromRawContext(rawContext));


                Logger.Info(rawContext.RequestUri.AbsoluteUri + " Request Completed.");

                if (AppConfig.DumpRaw)
                {
                    foreach (var dumper in AppConfig.DataDumpers)
                    {
                        await dumper.Dump(rawContext);
                    }
                }
                if (AppConfig.DumpProcessed)
                {
                    foreach (var dumper in AppConfig.DataDumpers)
                    {
                        await dumper.Dump(requestContext);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
예제 #7
0
        private static async Task <bool> HandleGoogleLogin(RawContext rawContext, SessionEventArgs e)
        {
            if (e.WebSession.Request.RequestUri.AbsoluteUri != "https://android.clients.google.com/auth")
            {
                return(false);
            }
            if (rawContext.RequestBody == null || rawContext.RequestBody.Length == 0)
            {
                return(false);
            }
            var data = Encoding.UTF8.GetString(rawContext.RequestBody);

            if (!data.Contains("com.nianticlabs.pokemongo"))
            {
                return(false);
            }
            var dataArr     = data.Split('&');
            var newDataList = new List <string>();
            var changed     = false;

            foreach (var currentData in dataArr)
            {
                if (currentData.StartsWith("callerSig="))
                {
                    newDataList.Add("callerSig=321187995bc7cdc2b5fc91b11a96e2baa8602c62");
                    changed = true;
                }
                else if (currentData.StartsWith("client_sig="))
                {
                    newDataList.Add("client_sig=321187995bc7cdc2b5fc91b11a96e2baa8602c62");
                    changed = true;
                }
                else
                {
                    newDataList.Add(currentData);
                }
            }
            if (!changed)
            {
                return(false);
            }
            var newData = string.Join("&", newDataList);
            await e.SetRequestBody(Encoding.UTF8.GetBytes(newData));

            return(true);
        }
예제 #8
0
 protected override void OnClose()
 {
     base.OnClose();
     RawContext.Close();
     PythonView.Close();
 }