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); } } }
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]); } } }
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); } try { PluginStore.RunAllPassivePluginsBeforeResponseInterception(IrSe); } catch(Exception Exp) { IronException.Report("Error running 'BeforeInterception' Passive plugins on Response", Exp.Message, Exp.StackTrace); } if (!IrSe.FiddlerSession.isFlagSet(Fiddler.SessionFlags.RequestGeneratedByFiddler)) { IrSe.Response.Host = IrSe.Request.Host; if(CanIntercept(IrSe.Response, IrSe.Request)) { 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"); } else { IrSe.FiddlerSession.state = Fiddler.SessionStates.AutoTamperResponseBefore; } } try { PluginStore.RunAllPassivePluginsAfterResponseInterception(IrSe); } catch(Exception Exp) { IronException.Report("Error running 'AfterInterception' Passive plugins on Response", Exp.Message, Exp.StackTrace); } }
internal static void AfterSessionComplete(Fiddler.Session Sess) { if (Sess.HTTPMethodIs("Connect")) return; if (Sess.isFlagSet(Fiddler.SessionFlags.RequestGeneratedByFiddler)) { Session IrSe; try { IrSe = new Session(Sess); } catch(Exception Exp) { IronException.Report("Error handling Response", Exp.Message, Exp.StackTrace); return; } if (IrSe == null) { IronException.Report("Error handling Response", "", ""); return; } if (IrSe.FiddlerSession == null) { IronException.Report("Error handling Response", "", ""); return; } if (IrSe.Response == null) { IronException.Report("Error handling Response", "", ""); return; } if (Sess.oFlags["IronFlag-BuiltBy"] == "ManualTestingSection") { try { ManualTesting.HandleResponse(IrSe); } catch(Exception Exp) { IronException.Report("Error handling 'Manual Testing' Response", Exp.Message, Exp.StackTrace); } } else if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Shell") || Sess.oFlags["IronFlag-BuiltBy"].Equals("Scan") || Sess.oFlags["IronFlag-BuiltBy"].Equals("Probe") || Sess.oFlags["IronFlag-BuiltBy"].Equals("Stealth") || Config.IsSourcePresent(Sess.oFlags["IronFlag-BuiltBy"])) { try { string DictID = ""; if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Shell")) { try { IronUpdater.AddShellResponse(IrSe.Response); DictID = Sess.oFlags["IronFlag-ID"] + "-Shell"; } catch (Exception Exp) { IronException.Report("Error handling 'Scripting Shell' Response", Exp.Message, Exp.StackTrace); } } else if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Probe")) { try { IronUpdater.AddProbeResponse(IrSe.Response); DictID = Sess.oFlags["IronFlag-ID"] + "-Probe"; } catch (Exception Exp) { IronException.Report("Error handling 'Probe' Response", Exp.Message, Exp.StackTrace); } } else if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Stealth")) { try { DictID = Sess.oFlags["IronFlag-ID"] + "-Stealth"; } catch (Exception Exp) { IronException.Report("Error handling 'Stealth' Response", Exp.Message, Exp.StackTrace); } } else if (Sess.oFlags["IronFlag-BuiltBy"].Equals("Scan")) { try { IronUpdater.AddScanResponse(IrSe.Response); DictID = Sess.oFlags["IronFlag-ID"] + "-Scan"; } catch (Exception Exp) { IronException.Report("Error handling 'Automated Scanning' Response", Exp.Message, Exp.StackTrace); } } else { try { IronUpdater.AddOtherSourceResponse(IrSe.Response); DictID = string.Format("{0}-{1}", Sess.oFlags["IronFlag-ID"], Sess.oFlags["IronFlag-BuiltBy"]); } catch (Exception Exp) { IronException.Report(string.Format("Error handling '{0}' Response", Sess.oFlags["IronFlag-BuiltBy"]), Exp.Message, Exp.StackTrace); } } Config.APIResponseDict[DictID].SetResponse(IrSe.Response); Config.APIResponseDict[DictID].MSR.Set(); } catch (Exception MainExp) { IronException.Report("Error handling 'Scripting Shell/Automated Scanning/Probe' Response", MainExp.Message, MainExp.StackTrace); } } } }
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); } try { PluginStore.RunAllPassivePluginsBeforeRequestInterception(IrSe); } catch (Exception Exp) { IronException.Report("Error running 'BeforeInterception' Passive plugins on Request", Exp.Message, Exp.StackTrace); } if (!IrSe.FiddlerSession.isFlagSet(Fiddler.SessionFlags.RequestGeneratedByFiddler)) { IrSe.ID = Interlocked.Increment(ref Config.ProxyRequestsCount); IronUpdater.AddProxyRequest(IrSe.Request); if(CanIntercept(IrSe.Request)) { 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"); } else { IrSe.FiddlerSession.state = Fiddler.SessionStates.AutoTamperRequestBefore; } } 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); } } 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]); } } }