コード例 #1
0
ファイル: Sniffer.cs プロジェクト: vaginessa/sniffer-1
        /// <summary>
        /// Gets triggered before the request has been made
        /// </summary>
        /// <param name="objSession"></param>
        private void FiddlerApplication_BeforeRequest(Session objSession)
        {
            try
            {
                //Declarations
                Utility   objUtility   = new Utility();
                DBUtility objDBUtility = new DBUtility();


                //Declarations
                String strContentType = String.Empty;

                //Uncomment this if tampering of response is required
                //objSession.bBufferResponse = true;

                //Get the content type
                strContentType = objSession.oRequest.headers["Accept"];

                //If its an HTML request or else the configuration has been set to capture all the requests
                if (strContentType.Contains("text/html") || _enConfiguration == Config.CaptureAll)
                {
                    //Get the request headers
                    HTTPRequestHeaders objRequestHeaders = objSession.oRequest.headers;

                    //Construct the network data
                    NetworkData objNetworkData = new NetworkData
                    {
                        ClientIP    = objSession.clientIP,
                        HostName    = objSession.hostname,
                        URLFullPath = objSession.fullUrl,
                        IsHTTPS     = objSession.isHTTPS,
                        RequestedAt = objSession.Timers.ClientBeginRequest.ToString(),
                        RequestType = objRequestHeaders.HTTPMethod
                    };


                    //Get the request body
                    String strRequestBody = objSession.GetRequestBodyAsString();


                    //If its a POST request
                    if (objNetworkData.RequestType == "POST")
                    {
                        //Get the request parameters
                        objNetworkData.RequestParameters = objUtility.GetRequestParameters(strRequestBody);
                    }
                    else if (objNetworkData.RequestType == "GET")
                    {
                        String [] arrQueryString = objNetworkData.URLFullPath.Split(new Char[] { '?' });

                        if (arrQueryString.Length > 1)
                        {
                            objNetworkData.RequestParameters = objUtility.GetRequestParameters(arrQueryString[1]);
                        }
                    }


                    //Update the capture to Mongo DB
                    if (_enConfiguration != Config.CaptureOnlyWithRequestParameters || objNetworkData.RequestParameters.Count > 0)
                    {
                        objDBUtility.AddData("NetworkData", "NetworkData", objNetworkData);
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.DisplayException("FiddlerApplication_BeforeRequest", ex);
            }
        }