Пример #1
1
 private void FiddlerApplication_ResponseHeaderAvailable(Fiddler.Session oSession)
 {
     #if DEBUG
     Logger.Push(String.Format("{0}:HTTP {1} for {2}", oSession.id, oSession.responseCode, oSession.fullUrl),0);
     #endif
     Parallel.ForEach<string>(Value_downloader.VideoMimelist, (string pattern) => { if (rslib_StringEvaluator.Evaltool.Evaluation(oSession.oResponse.MIMEType, pattern)) { FiddlerCaughtNormalMedia(oSession); } });
 }
Пример #2
0
        public static Session FiddlerSessionToSession(Fiddler.Session fSession)
        {
            Session s = new Session();
            //Set the host.
            s.Host = fSession.host;
            //Setup the request.
            s.Request.HttpMethod = fSession.oRequest.headers.HTTPMethod;
            s.UriScheme = fSession.oRequest.headers.UriScheme;
            s.Request.Path = fSession.oRequest.headers.RequestPath;
            s.Id = fSession.id;
            foreach (Fiddler.HTTPHeaderItem header in fSession.oRequest.headers) {
                s.Request.Headers.Add(header.Name, header.Value);
            }
            s.Request.BodyBytes = fSession.requestBodyBytes;

            //Setup up the resposne.
            if (fSession.oResponse != null && fSession.oResponse.headers != null && fSession.responseBodyBytes != null && fSession.responseBodyBytes.Length > 0) {
                foreach (Fiddler.HTTPHeaderItem header in fSession.oResponse.headers) {
                    s.Response.Headers.Add(header.Name, header.Value);
                }
                fSession.utilDecodeResponse();
                s.Response.BodyBytes = fSession.responseBodyBytes;
            }

            if (fSession.oFlags[UASettings.casabaFlag] != null && fSession.oFlags[UASettings.casabaFlag].Length > 0)
            {
                s.ContainsCodePoint = true;
                s.Chr = new UAUnicodeChar(fSession.oFlags[UASettings.casabaFlag][0]);
                s.Flags[UASettings.casabaFlag] = fSession.oFlags[UASettings.casabaFlag];
            }
            //MessageBox.Show(fSession.fullUrl);
            //s.Fsession= fSession;
            return s;
        }
 internal ValidateServerCertificateEventArgs(Fiddler.Session inSession, string inExpectedCN, X509Certificate inServerCertificate, X509Chain inServerCertificateChain, SslPolicyErrors inSslPolicyErrors)
 {
     this._oSession = inSession;
     this._sExpectedCN = inExpectedCN;
     this._oServerCertificate = inServerCertificate;
     this._ServerCertificateChain = inServerCertificateChain;
     this._sslPolicyErrors = inSslPolicyErrors;
 }
Пример #4
0
 private void FiddlerApplication_BeforeRequest(Fiddler.Session oSession)
 {
     oSession.bBufferResponse = false;
     if (HostList.Contains(oSession.host))
         oSession["X-OverrideGateway"] = "localhost:" + MFGPort;
     else
         oSession["X-OverrideGateway"] = "localhost:" + UpstreamPort;
     System.Diagnostics.Debug.WriteLine(oSession.host);
 }
Пример #5
0
 public Session(Fiddler.Session _FiddlerSession)
 {
     this.FiddlerSession = _FiddlerSession;
     this.Request = new Request(this.FiddlerSession);
     if (this.FiddlerSession.bHasResponse)
     {
         this.Response = new Response(this.FiddlerSession);
     }
 }
Пример #6
0
        /// <summary>
        /// リクエスト前に処理する
        /// </summary>
        /// <param name="oSession">セッション情報</param>
        public static void BeforeRequest(Fiddler.Session oSession)
        {
            // ★キャストエラーのチェックテスト
            //object obj = (Int32)32;
            //float f = (float)obj;

            // モンラインのみを対象にする
            if (!oSession.hostname.StartsWith("monmusugame"))
            {
                oSession.Ignore();
                return;
            }

        }
Пример #7
0
 internal Response(Fiddler.Session Sess)
 {
     this.headers = new ResponseHeaderParameters(this);
     try
     {
         this.ID = Int32.Parse(Sess.oFlags["IronFlag-ID"]);
     }
     catch
     {
         this.ID = 0;
     }
     if (Sess.oFlags.ContainsKey("IronFlag-TTL"))
     {
         this.TTL = Int32.Parse(Sess.oFlags["IronFlag-TTL"]);
     }
     if (Sess.oFlags.ContainsKey("IronFlag-SslError"))
     {
         this.isSSlValid = false;
     }
     this.httpVersion = Sess.oResponse.headers.HTTPVersion;
     this.code = Sess.oResponse.headers.HTTPResponseCode;
     try
     {
         if (Sess.oResponse.headers.HTTPResponseStatus.IndexOf(' ') > -1)
             this.status = Sess.oResponse.headers.HTTPResponseStatus.Substring(Sess.oResponse.headers.HTTPResponseStatus.IndexOf(' ')).Trim();
         else
             this.status = "";
     }
     catch(Exception Exp)
     {
         Tools.Trace("Response.cs", "Invalid Fiddler Session Response Status - " + Sess.oResponse.headers.HTTPResponseStatus);
         throw (Exp);
     }
     Fiddler.HTTPResponseHeaders ResHeaders = new Fiddler.HTTPResponseHeaders();
     foreach (Fiddler.HTTPHeaderItem HHI in Sess.oResponse.headers)
     {
         this.Headers.Add(HHI.Name, HHI.Value);
     }
     if (Sess.responseBodyBytes.Length > 0)
     {
         this.SetBody(Sess.responseBodyBytes);
     }
 }
Пример #8
0
 private void fiddlerCtrl1_FiddlerCaughtNormalMedia( Fiddler.Session oSession)
 {
     // Index, Scheme, Request, MIME, Cookie
     var MIMEtype = oSession.oResponse.MIMEType;
     Invoke(new Action(() =>
     {
         ListViewItem item = listView1.Items.Add(new ListViewItem(new string[] {
         Convert.ToString(listView1.Items.Count),
         oSession.oRequest.headers.UriScheme,
         oSession.oRequest.headers.RequestPath,
         MIMEtype,
         oSession.oResponse.headers.HTTPResponseCode.ToString()
         })
         {
             ForeColor = Color.Green,
             Tag = oSession
         });
         item.EnsureVisible();
     }));
     return;
 }
        public PassiveCheckResult RunCheck(Fiddler.Session fiddlerSession)
        {
            if (fiddlerSession.isHTTPS && fiddlerSession.oResponse.headers.Exists("set-cookie"))
            {
                string cookie = fiddlerSession.oResponse.headers["set-cookie"];

                if (cookie != null && cookie.Length > 0)
                {
                    string[] parts = cookie.Split(';');
                    string cookiename = parts[0];
                    cookiename = cookiename.Split('=')[0];

                    if (parts != null && parts.Length > 0)
                    {
                        bool isSecured = false;
                        bool isDomainSet = false;

                        parts.ForEach(v =>
                            {
                                if (v.Trim().ToLower() == "secure")
                                {
                                    isSecured = true;
                                }

                                if (v.Trim().ToLower().StartsWith("domain"))
                                {
                                    isDomainSet = true;
                                }
                            });

                        if (!isSecured)
                        {
                            return PassiveCheckResult.CreateFailure(this, fiddlerSession.fullUrl, "Cookie not marked as secure");
                        }
                    }
                }
            }

            return PassiveCheckResult.CreatePass(this, fiddlerSession.fullUrl);
        }
Пример #10
0
        private void FiddlerApplication_AfterSessionComplete(Fiddler.Session oSession)
        {
            logger.Trace("{0} {1} {2}\n{3} {4} {5}\n\n", oSession.id, oSession.oRequest.headers.HTTPMethod, Ellipsize(oSession.fullUrl, 60), oSession.responseCode, oSession.GetResponseContentType(), oSession.ResponseBody.Length);

            checkList.ForEach(v =>
                {
                    try
                    {
                        logger.Trace("Running audit: " + v.Name);
                        PassiveCheckResult result = v.RunCheck(oSession);
                        if (!result.Passed)
                        {
                            logger.Warn("{0} failed for {1}", v.Name, oSession.fullUrl);
                        }

                        resultList.Add(result);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                    }
                });
        }
        public PassiveCheckResult RunCheck(Fiddler.Session fiddlerSession)
        {
            if (fiddlerSession.isHTTPS)
            {
                if (fiddlerSession.oResponse.headers.Exists("cache-control"))
                {
                    string cc = fiddlerSession.oResponse.headers["cache-control"].Trim().ToLower();
                    if (!cc.Contains("no-store"))
                    {
                        return PassiveCheckResult.CreateFailure(this, fiddlerSession.url, "Cache-Control header does not contain 'no-store'");
                    }
                    else if (!cc.Contains("no-cache"))
                    {
                        return PassiveCheckResult.CreateFailure(this, fiddlerSession.url, "Cache-Control header does not contain 'no-cache'");
                    }
                }
                else
                {
                    return PassiveCheckResult.CreateFailure(this, fiddlerSession.url, "No Cache-Control header found");
                }
            }

            return PassiveCheckResult.CreatePass(this, fiddlerSession.url);
        }
Пример #12
0
        private static void setUpstreamProxyHandler(Fiddler.Session requestingSession)
        {
            if (requestingSession.isHTTPS || requestingSession.port == 443)
            {
                if(useHttpsGateway)
                    requestingSession["X-OverrideGateway"] = httpsGateway;
                return;
            }

            if(useHttpGateway)
            {
                requestingSession["X-OverrideGateway"] = httpGateway;
            }
        }
Пример #13
0
 private static void raiseAfterSessionComplete(Fiddler.Session session)
 {
     InvokeAfterSessionComplete(session.ToNekoxySession());
 }
Пример #14
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);
            }

            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);
            }
        }
Пример #15
0
 public bool BeforeRequest(Fiddler.Session session, Rule rule)
 {
     return _requestActions.All(action => action.BeforeRequest(session, rule));
 }
Пример #16
0
 private void Log_OnLogString(object sender, Fiddler.LogEventArgs e)
 {
     logger.Trace("Fiddler says: {0}", e.LogString);
 }
Пример #17
0
 private static void raiseResponseHeadersAvailable(Fiddler.Session session)
 {
     InvokeAfterReadResponseHeaders(new HttpResponse(session.GenerateStatusLine(), session.ResponseHeaders.GenerateHeaders(), null));
 }
Пример #18
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]);
                }
            }
        }
Пример #19
0
		private void FiddlerApplication_BeforeRequest( Fiddler.Session oSession ) {

			Utility.Configuration.ConfigurationData.ConfigConnection c = Utility.Configuration.Config.Connection;


			// 上流プロキシ設定
			if ( c.UseUpstreamProxy ) {
				oSession["X-OverrideGateway"] = string.Format( "{0}:{1}", c.UpstreamProxyAddress, c.UpstreamProxyPort );
			}


			if ( oSession.fullUrl.Contains( "/kcsapi/" ) ) {

				string url = oSession.fullUrl;
				string body = oSession.GetRequestBodyAsString();

				//保存
				{
					if ( c.SaveReceivedData && c.SaveRequest ) {

						Task.Run( (Action)( () => {
							SaveRequest( url, body );
						} ) );
					}
				}

				UIControl.BeginInvoke( (Action)( () => { LoadRequest( url, body ); } ) );
			}

			// flash wmode & quality
			{
				if ( oSession.fullUrl.Contains( "/gadget/js/kcs_flash.js" ) ) {

					oSession.bBufferResponse = true;
				}
			}

		}
Пример #20
0
		private void FiddlerApplication_AfterSessionComplete( Fiddler.Session oSession ) {

			//保存
			{
				Utility.Configuration.ConfigurationData.ConfigConnection c = Utility.Configuration.Config.Connection;

				if ( c.SaveReceivedData ) {

					try {

						if ( !Directory.Exists( c.SaveDataPath ) )
							Directory.CreateDirectory( c.SaveDataPath );


						if ( c.SaveResponse && oSession.fullUrl.Contains( "/kcsapi/" ) ) {

							// 非同期で書き出し処理するので取っておく
							// stringはイミュータブルなのでOK
							string url = oSession.fullUrl;
							string body = oSession.GetResponseBodyAsString();

							Task.Run( (Action)( () => {
								SaveResponse( url, body );
							} ) );

						} else if ( oSession.fullUrl.Contains( "/kcs/" ) &&
							( ( c.SaveSWF && oSession.oResponse.MIMEType == "application/x-shockwave-flash" ) || c.SaveOtherFile ) ) {

							string saveDataPath = c.SaveDataPath; // スレッド間の競合を避けるため取っておく
							string tpath = string.Format( "{0}\\{1}", saveDataPath, oSession.fullUrl.Substring( oSession.fullUrl.IndexOf( "/kcs/" ) + 5 ).Replace( "/", "\\" ) );
							{
								int index = tpath.IndexOf( "?" );
								if ( index != -1 ) {
									if ( Utility.Configuration.Config.Connection.ApplyVersion ) {
										string over = tpath.Substring( index + 1 );
										int vindex = over.LastIndexOf( "VERSION=", StringComparison.CurrentCultureIgnoreCase );
										if ( vindex != -1 ) {
											string version = over.Substring( vindex + 8 ).Replace( '.', '_' );
											tpath = tpath.Insert( tpath.LastIndexOf( '.', index ), "_v" + version );
											index += version.Length + 2;
										}

									}

									tpath = tpath.Remove( index );
								}
							}

							// 非同期で書き出し処理するので取っておく
							byte[] responseCopy = new byte[oSession.ResponseBody.Length];
							Array.Copy( oSession.ResponseBody, responseCopy, oSession.ResponseBody.Length );

							Task.Run( (Action)( () => {
								try {
									lock ( this ) {
										// 同時に書き込みが走るとアレなのでロックしておく

										Directory.CreateDirectory( Path.GetDirectoryName( tpath ) );

										//System.Diagnostics.Debug.WriteLine( oSession.fullUrl + " => " + tpath );
										using ( var sw = new System.IO.BinaryWriter( System.IO.File.OpenWrite( tpath ) ) ) {
											sw.Write( responseCopy );
										}
									}

									Utility.Logger.Add( 1, string.Format( "通信からファイル {0} を保存しました。", tpath.Remove( 0, saveDataPath.Length + 1 ) ) );

								} catch ( IOException ex ) {	//ファイルがロックされている; 頻繁に出るのでエラーレポートを残さない

									Utility.Logger.Add( 3, "通信内容の保存に失敗しました。 " + ex.Message );
								}
							} ) );

						}

					} catch ( Exception ex ) {

						Utility.ErrorReporter.SendErrorReport( ex, "通信内容の保存に失敗しました。" );
					}

				}

			}


			if ( oSession.fullUrl.Contains( "/kcsapi/" ) && oSession.oResponse.MIMEType == "text/plain" ) {

				// 非同期でGUIスレッドに渡すので取っておく
				// stringはイミュータブルなのでOK
				string url = oSession.fullUrl;
				string body = oSession.GetResponseBodyAsString();
				UIControl.BeginInvoke( (Action)( () => { LoadResponse( url, body ); } ) );

				// kancolle-db.netに送信する
				if ( Utility.Configuration.Config.Connection.SendDataToKancolleDB ) {
					Task.Run( (Action)( () => DBSender.ExecuteSession( oSession ) ) );
				}

			}



			if ( ServerAddress == null ) {
				string url = oSession.fullUrl;

				int idxb = url.IndexOf( "/kcsapi/" );

				if ( idxb != -1 ) {
					int idxa = url.LastIndexOf( "/", idxb - 1 );

					ServerAddress = url.Substring( idxa + 1, idxb - idxa - 1 );
				}
			}

		}
Пример #21
0
 internal Request(Fiddler.Session Sess)
 {
     this.InitiateParameters();
     if (Sess.oFlags.ContainsKey("IronFlag-ID"))
     {
         this.ID = Int32.Parse(Sess.oFlags["IronFlag-ID"]);
     }
     if (Sess.oFlags.ContainsKey("IronFlag-ScanID"))
     {
         this.ScanID = Int32.Parse(Sess.oFlags["IronFlag-ScanID"]);
     }
     if (Sess.oFlags.ContainsKey("IronFlag-Ticks"))
     {
         this.TimeObject = new DateTime(long.Parse(Sess.oFlags["IronFlag-Ticks"]));
     }
     if (Sess.oFlags.ContainsKey("IronFlag-BuiltBy"))
     {
         if (Sess.oFlags["IronFlag-BuiltBy"] == "ManualTestingSection")
             this.Source = RequestSource.Test;
     }
     this.AbsorbFullURL(Sess.fullUrl);
     this.Method = Sess.oRequest.headers.HTTPMethod;
     foreach (Fiddler.HTTPHeaderItem HHI in Sess.oRequest.headers)
     {
         this.Headers.Add(HHI.Name, HHI.Value);
     }
     this.SetBody(Sess.requestBodyBytes);
 }
Пример #22
0
 private void FiddlerApplication_OnNotification(object sender, Fiddler.NotificationEventArgs e)
 {
     logger.Warn("Fiddler says: {0}", e.NotifyString);
 }
Пример #23
0
		private void FiddlerApplication_BeforeResponse( Fiddler.Session oSession ) {

			//flash 品質設定
			if ( oSession.bBufferResponse && oSession.fullUrl.Contains( "/gadget/js/kcs_flash.js" ) ) {

				string js = oSession.GetResponseBodyAsString();
				bool flag = false;

				var wmode = _wmodeRegex.Match( js );
				if ( wmode.Success ) {
					js = js.Replace( wmode.Value, string.Format( @"""wmode"":""{0}""", Utility.Configuration.Config.FormBrowser.FlashWMode ) );
					flag = true;
				}

				var quality = _qualityRegex.Match( js );
				if ( quality.Success ) {
					js = js.Replace( quality.Value, string.Format( @"""quality"":""{0}""", Utility.Configuration.Config.FormBrowser.FlashQuality ) );
					flag = true;
				}

				if ( flag ) {
					oSession.utilSetResponseBody( js );

					Utility.Logger.Add( 1, "flashの品質設定を行いました。" );
				}
			}
		}
Пример #24
0
 internal Request(Fiddler.Session Sess)
 {
     this.InitiateParameters();
     if (Sess.oFlags.ContainsKey("IronFlag-ID"))
     {
         this.ID = Int32.Parse(Sess.oFlags["IronFlag-ID"]);
     }
     if (Sess.oFlags.ContainsKey("IronFlag-ScanID"))
     {
         this.ScanID = Int32.Parse(Sess.oFlags["IronFlag-ScanID"]);
     }
     if (Sess.oFlags.ContainsKey("IronFlag-Ticks"))
     {
         this.TimeObject = new DateTime(long.Parse(Sess.oFlags["IronFlag-Ticks"]));
     }
     if (Sess.oFlags.ContainsKey("IronFlag-BuiltBy"))
     {
         switch (Sess.oFlags["IronFlag-BuiltBy"])
         {
             case("ManualTestingSection"):
                 this.Source = RequestSource.Test;
                 break;
             case (RequestSource.Shell):
                 this.Source = RequestSource.Shell;
                 break;
             case (RequestSource.Probe):
                 this.Source = RequestSource.Probe;
                 break;
             case (RequestSource.Scan):
                 this.Source = RequestSource.Scan;
                 break;
             case (RequestSource.Stealth):
                 this.Source = RequestSource.Stealth;
                 break;
             default:
                 if (Config.IsSourcePresent(Sess.oFlags["IronFlag-BuiltBy"]))
                     this.Source = Sess.oFlags["IronFlag-BuiltBy"];
                 break;
         }
     }
     if (Sess.oFlags.ContainsKey("IronFlag-RunPassivePlugins"))
     {
         this.CanRunPassivePlugins = Sess.oFlags["IronFlag-RunPassivePlugins"].Equals("1");
     }
     this.AbsorbFullURL(Sess.fullUrl);
     this.Method = Sess.oRequest.headers.HTTPMethod;
     foreach (Fiddler.HTTPHeaderItem HHI in Sess.oRequest.headers)
     {
         this.Headers.Add(HHI.Name, HHI.Value);
     }
     this.SetBody(Sess.requestBodyBytes);
 }
Пример #25
0
        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);
                    }
                }
            }
        }
Пример #26
0
 private void FiddlerApplication_BeforeRequest(Fiddler.Session oSession)
 {
     FiddlerUtil.BeforeRequest(oSession);
 }
Пример #27
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);
                }
            }
        }
Пример #28
0
 private void FiddlerApplication_AfterSessionComplete(Fiddler.Session oSession)
 {
     FiddlerUtil.AfterSessionComplete(oSession, this);
 }
Пример #29
0
        private void FiddlerApplication_AfterSessionComplete(Fiddler.Session fiddler_session)
        {
            // Ignore HTTPS connect requests
            if (fiddler_session.RequestMethod == "CONNECT")
                return;

            if (fiddler_session == null || fiddler_session.oRequest == null || fiddler_session.oRequest.headers == null)
                return;

            var full_url = fiddler_session.fullUrl;
            Console.WriteLine("URL: " + full_url);

            HTTPRequestHeaders request_headers = fiddler_session.RequestHeaders;
            HTTPResponseHeaders response_headers = fiddler_session.ResponseHeaders;
            int http_response_code = response_headers.HTTPResponseCode;
            Console.WriteLine("HTTP Response: " + http_response_code.ToString());

            string referer = null;
            Dictionary<String, HTTPHeaderItem> request_headers_dictionary =
             request_headers.ToDictionary(p => p.Name);
            if (request_headers_dictionary.ContainsKey("Referer"))
            {
                referer = request_headers_dictionary["Referer"].Value;
            }

            //foreach (HTTPHeaderItem header_item in response_headers)
            //{
            //    Console.Error.WriteLine(header_item.Name + " " + header_item.Value);
            //}

            //foreach (HTTPHeaderItem header_item in request_headers)
            //{
            //    Console.Error.WriteLine(header_item.Name + " " + header_item.Value);
            //}

            Console.Error.WriteLine("Referer: " + referer);

            // http://fiddler.wikidot.com/timers
            var timers = fiddler_session.Timers;
            TimeSpan duration = (TimeSpan)(timers.ClientDoneResponse - timers.ClientBeginRequest);
            Console.Error.WriteLine(String.Format("Duration: {0:F10}", duration.Milliseconds));
            var dic = new Dictionary<string, object>(){
                    {"url" ,full_url}, {"status", http_response_code},
                    {"duration", duration.Milliseconds },
                    {"referer", referer }
                };
            insert(dic);

            // https://groups.google.com/forum/#!msg/httpfiddler/RuFf5VzKCg0/wcgq-WeUnCoJ
            //// the following code does not work as intended: request body is always blank
            //string request_body = fiddler_session.GetRequestBodyAsString();

            //if (!string.IsNullOrEmpty(request_body))
            //{
            //    // TODO: UrlDecode
            //    Console.Error.WriteLine(string.Join(Environment.NewLine, request_body.Split(new char[] { '&' })));
            //}
        }
Пример #30
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);
            }

            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]);
                }
            }
        }