示例#1
0
        internal static void BeforeResponse(Fiddler.Session Sess)
        {
            if (Sess.HTTPMethodIs("Connect")) return;
            if (Sess.oFlags.ContainsKey("IronFlag-BuiltBy"))
            {
                if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Stealth")) return;
            }
            Session IrSe;
            try
            {
                Sess.utilDecodeResponse();
                IrSe = new Session(Sess);
            }
            catch(Exception Exp)
            {
                IronException.Report("Error reading Response", Exp.Message, Exp.StackTrace);
                return;
            }
            if (IrSe == null)
            {
                IronException.Report("Error reading Response", "", "");
                return;
            }
            if (IrSe.Response == null)
            {
                IronException.Report("Error reading Response", "", "");
                return;
            }
            if (IrSe.FiddlerSession == null)
            {
                IronException.Report("Error reading Response", "", "");
                return;
            }
            long TTL = DateTime.Now.Ticks - IrSe.Request.TimeObject.Ticks;
            IrSe.Response.TTL = (int)(TTL / 10000);
            if (Sess.oFlags.ContainsKey("IronFlag-TTL"))
            {
                IrSe.FiddlerSession.oFlags["IronFlag-TTL"] = IrSe.Response.TTL.ToString();
            }
            else
            {
                IrSe.FiddlerSession.oFlags.Add("IronFlag-TTL", IrSe.Response.TTL.ToString());
            }
            try
            {
                Session ClonedIronSessionWithResponse = IrSe.GetClone();
                if (ClonedIronSessionWithResponse != null && ClonedIronSessionWithResponse.Response != null)
                {
                    PassiveChecker.AddToCheckResponse(ClonedIronSessionWithResponse);
                }
                else
                    IronException.Report("IronSession with Response Couldn't be cloned at ID - " + IrSe.ID.ToString(), "", "");
            }
            catch (Exception Exp)
            {
                IronException.Report("Error Cloning IronSession in BeforeRequest", Exp.Message, Exp.StackTrace);
            }

            if (!IrSe.FiddlerSession.isFlagSet(Fiddler.SessionFlags.RequestGeneratedByFiddler))
            {
                //IronUpdater.AddProxyResponse(IrSe.Response);
            }

            if (!IrSe.FiddlerSession.isFlagSet(Fiddler.SessionFlags.RequestGeneratedByFiddler))
            {
                IrSe.Response.Host = IrSe.Request.Host;
                IrSe.OriginalResponse = IrSe.Response.GetClone(true);
                if(CanInterceptResponse(IrSe))
                {
                    IrSe.MSR = new ManualResetEvent(false);
                    IrSe.FiddlerSession.state = Fiddler.SessionStates.HandTamperResponse;
                    InterceptedSessions.Add(IrSe.ID + "-Response", IrSe);
                    IronUI.SendSessionToProxy(IrSe);
                    InterceptedSessions[IrSe.ID + "-Response"].MSR.WaitOne();
                    InterceptedSessions.Remove(IrSe.ID + "-Response");

                    IrSe.UpdateFiddlerSessionFromIronSession();
                }
                else if (ScriptedInterceptionEnabled)
                {
                    IrSe.UpdateFiddlerSessionFromIronSession();
                }
                else
                {
                    IrSe.FiddlerSession.state = Fiddler.SessionStates.AutoTamperResponseBefore;
                }

                if (ScriptedInterceptionEnabled && ScInt.CallAfterInterception)
                {
                    try
                    {
                        ScInt.AfterInterception = true;
                        ScInt.ShouldIntercept(IrSe);
                    }
                    catch (Exception Exp)
                    {
                        IronUI.ShowProxyException("Error in Scripted Interception Script");
                        IronException.Report("Error in Scripted Interception Script", Exp);
                    }
                    ScInt.AfterInterception = false;
                    IrSe.UpdateFiddlerSessionFromIronSession();
                }

                if (IronProxy.WasResponseChanged(IrSe))
                {
                    Response ClonedResponse = IrSe.Response.GetClone(true);
                    //IronUpdater.AddProxyResponsesAfterEdit(IrSe.OriginalResponse.GetClone(true), ClonedResponse);
                    //IronUI.UpdateEditedProxyLogResponseEntry(ClonedResponse);
                    IronUpdater.AddProxyResponses(new Response[] { IrSe.OriginalResponse, IrSe.Response });
                }
                else
                {
                    IronUpdater.AddProxyResponses(new Response[] { null, IrSe.Response });
                }
            }

            if (PluginEngine.ShouldRunResponseBasedPassivePlugins())
            {
                try
                {
                    PluginEngine.RunAllResponseBasedInlinePassivePlugins(IrSe);
                    IrSe.UpdateFiddlerSessionFromIronSession();
                }
                catch (Exception Exp)
                {
                    IronException.Report("Error running 'BeforeInterception' Passive plugins on Response", Exp.Message, Exp.StackTrace);
                }
            }
        }
示例#2
0
        internal static void BeforeRequest(Fiddler.Session Sess)
        {
            if (Sess.HTTPMethodIs("Connect"))
            {
                if (IronProxy.UseUpstreamProxy)
                {
                    string UpstreamProxyString = string.Format("{0}:{1}", IronProxy.UpstreamProxyIP, IronProxy.UpstreamProxyPort.ToString());
                    Sess.oFlags.Add("x-overrideGateway", UpstreamProxyString);
                }
                if (Config.HasFiddlerFlags)
                {
                    string[,] Flags = Config.GetFiddlerFlags();
                    for (int i = 0; i < Flags.GetLength(0); i++)
                    {
                        Sess.oFlags.Add(Flags[i, 0], Flags[i, 1]);
                    }
                }
                return;
            }
            if(Sess.oFlags.ContainsKey("IronFlag-BuiltBy"))
            {
                if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Stealth"))
                {
                    if (IronProxy.UseUpstreamProxy)
                    {
                        string UpstreamProxyString = string.Format("{0}:{1}", IronProxy.UpstreamProxyIP, IronProxy.UpstreamProxyPort.ToString());
                        Sess.oFlags.Add("x-overrideGateway", UpstreamProxyString);
                    }
                    if (Config.HasFiddlerFlags)
                    {
                        string[,] Flags = Config.GetFiddlerFlags();
                        for (int i = 0; i < Flags.GetLength(0); i++)
                        {
                            Sess.oFlags.Add(Flags[i, 0], Flags[i, 1]);
                        }
                    }
                    return;
                }
            }
            Session IrSe;
            try
            {
                IrSe = new Session(Sess);
            }
            catch(Exception Exp)
            {
                IronException.Report("Error reading Request", Exp.Message, Exp.StackTrace);
                return;
            }
            if (IrSe == null)
            {
                IronException.Report("Error reading Request", "", "");
                return;
            }
            if (IrSe.Request == null)
            {
                IronException.Report("Error reading Request", "", "");
                return;
            }
            if (IrSe.FiddlerSession == null)
            {
                IronException.Report("Error reading Request", "", "");
                return;
            }

            //Needs to be turned on to read the response body
            IrSe.FiddlerSession.bBufferResponse = true;

            IrSe.Request.TimeObject = DateTime.Now;
            if (Sess.oFlags.ContainsKey("IronFlag-Ticks"))
            {
                IrSe.FiddlerSession.oFlags["IronFlag-Ticks"] = IrSe.Request.TimeObject.Ticks.ToString();
            }
            else
            {
                IrSe.FiddlerSession.oFlags.Add("IronFlag-Ticks", IrSe.Request.TimeObject.Ticks.ToString());
            }

            //try
            //{
            //    Session ClonedIronSessionWithRequest = IrSe.GetClone();
            //    if (ClonedIronSessionWithRequest != null && ClonedIronSessionWithRequest.Request != null)
            //        PassiveChecker.AddToCheckRequest(ClonedIronSessionWithRequest);
            //    else
            //        IronException.Report("IronSession Request Couldn't be cloned at ID - " + IrSe.ID.ToString(),"","");
            //}
            //catch(Exception Exp)
            //{
            //    IronException.Report("Error Cloning IronSession in BeforeRequest", Exp.Message, Exp.StackTrace);
            //}

            if (PluginEngine.ShouldRunRequestBasedPassivePlugins())
            {
                try
                {
                    PluginEngine.RunAllRequestBasedInlinePassivePlugins(IrSe);
                    IrSe.UpdateFiddlerSessionFromIronSession();
                }
                catch (Exception Exp)
                {
                    IronException.Report("Error running 'Inline' Passive plugins on Request", Exp.Message, Exp.StackTrace);
                }
            }

            if (!IrSe.FiddlerSession.isFlagSet(Fiddler.SessionFlags.RequestGeneratedByFiddler))
            {
                IrSe.ID = Interlocked.Increment(ref Config.ProxyRequestsCount);
                IrSe.OriginalRequest = IrSe.Request.GetClone(true);
                //IronUpdater.AddProxyRequest(IrSe.Request);
                if(CanInterceptRequest(IrSe))
                {
                    IrSe.MSR = new ManualResetEvent(false);
                    InterceptedSessions.Add(IrSe.ID + "-Request", IrSe);
                    IrSe.FiddlerSession.state = Fiddler.SessionStates.HandTamperRequest;
                    IronUI.SendSessionToProxy(IrSe);
                    InterceptedSessions[IrSe.ID + "-Request"].MSR.WaitOne();
                    InterceptedSessions.Remove(IrSe.ID + "-Request");

                    IrSe.UpdateFiddlerSessionFromIronSession();
                }
                else if (ScriptedInterceptionEnabled)
                {
                    IrSe.UpdateFiddlerSessionFromIronSession();
                }
                else
                {
                    IrSe.FiddlerSession.state = Fiddler.SessionStates.AutoTamperRequestBefore;
                }

                if (ScriptedInterceptionEnabled && ScInt.CallAfterInterception)
                {
                    try
                    {
                        ScInt.AfterInterception = true;
                        ScInt.ShouldIntercept(IrSe);
                    }
                    catch (Exception Exp)
                    {
                        IronUI.ShowProxyException("Error in Scripted Interception Script");
                        IronException.Report("Error in Scripted Interception Script", Exp);
                    }
                    ScInt.AfterInterception = false;
                    IrSe.UpdateFiddlerSessionFromIronSession();
                }

                if (IronProxy.WasRequestChanged(IrSe))
                {
                    Request ClonedRequest = IrSe.Request.GetClone(true);
                    //IronUpdater.AddProxyRequestsAfterEdit(IrSe.OriginalRequest.GetClone(true), ClonedRequest);
                    //IronUI.UpdateEditedProxyLogRequestEntry(ClonedRequest);
                    IronUpdater.AddProxyRequests(new Request[] { IrSe.OriginalRequest, IrSe.Request });
                }
                else
                {
                    IronUpdater.AddProxyRequests(new Request[] { null, IrSe.Request });
                }
            }
            else
            {
                if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Shell"))
                {
                    IronUpdater.AddShellRequest(IrSe.Request);
                }
                else if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Scan"))
                {
                    IronUpdater.AddScanRequest(IrSe.Request);
                }
                else if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Probe"))
                {
                    IronUpdater.AddProbeRequest(IrSe.Request);
                }
                else if (Config.IsSourcePresent(Sess.oFlags["IronFlag-BuiltBy"]))
                {
                    IronUpdater.AddOtherSourceRequest(IrSe.Request);
                }
            }

            //try
            //{
            //    PluginStore.RunAllPassivePluginsAfterRequestInterception(IrSe);
            //}
            //catch (Exception Exp)
            //{
            //    IronException.Report("Error running 'AfterInterception' Passive plugins on Request", Exp.Message, Exp.StackTrace);
            //}

            if (IronProxy.UseUpstreamProxy)
            {
                string UpstreamProxyString = string.Format("{0}:{1}", IronProxy.UpstreamProxyIP, IronProxy.UpstreamProxyPort.ToString());
                IrSe.FiddlerSession.oFlags.Add("x-overrideGateway", UpstreamProxyString);
            }
            if (Config.HasFiddlerFlags)
            {
                string[,] Flags = Config.GetFiddlerFlags();
                for (int i = 0; i < Flags.GetLength(0); i++)
                {
                    IrSe.FiddlerSession.oFlags.Add(Flags[i, 0], Flags[i, 1]);
                }
            }
        }