Esempio n. 1
0
        private void TunnelDirectly()
        {
            string str;

            this._mySession.SetBitFlag(SessionFlags.SentToGateway, false);
            int    iPort     = 0x1bb;
            string sHostPort = this._mySession.oFlags["x-overrideHost"];

            if (sHostPort == null)
            {
                sHostPort = this._mySession.PathAndQuery;
            }
            Utilities.CrackHostAndPort(sHostPort, out str, ref iPort);
            try
            {
                IPAddress[] arrDestIPs = DNSResolver.GetIPAddressList(str, true, this._mySession.Timers);
                this.socketRemote = ServerChatter.CreateConnectedSocket(arrDestIPs, iPort, this._mySession);
            }
            catch (Exception exception)
            {
                this._indicateTunnelFailure(0x1f8, exception.Message);
                return;
            }
            try
            {
                this._mySession.oResponse.headers                    = new HTTPResponseHeaders();
                this._mySession.oResponse.headers.HTTPVersion        = this._mySession.oRequest.headers.HTTPVersion;
                this._mySession.oResponse.headers.HTTPResponseCode   = 200;
                this._mySession.oResponse.headers.HTTPResponseStatus = "200 Blind-Connection Established";
                this._mySession.oResponse.headers.Add("FiddlerGateway", "Direct");
                this._mySession.oResponse.headers.Add("StartTime", DateTime.Now.ToString("HH:mm:ss.fff"));
                this.socketClient.Send(this._mySession.oResponse.headers.ToByteArray(true, true));
                this._mySession.oFlags["x-EgressPort"] = (this.socketRemote.LocalEndPoint as IPEndPoint).Port.ToString();
                this.socketClient.BeginReceive(this.arrRequestBytes, 0, this.arrRequestBytes.Length, SocketFlags.None, new AsyncCallback(this.OnClientReceive), this.socketClient);
                this.socketRemote.BeginReceive(this.arrResponseBytes, 0, this.arrResponseBytes.Length, SocketFlags.None, new AsyncCallback(this.OnRemoteReceive), this.socketRemote);
                FiddlerApplication._frmMain.BeginInvoke(new updateUIDelegate(FiddlerApplication._frmMain.finishSession), new object[] { this._mySession });
                this.WaitForCompletion();
            }
            catch (Exception)
            {
                try
                {
                    this.socketRemote.Close();
                    this.socketClient.Close();
                }
                catch (Exception)
                {
                }
            }
        }
Esempio n. 2
0
 private void TunnelToGateway(IPEndPoint ipepForwardHTTPS)
 {
     try
     {
         this._mySession.oResponse._bWasForwarded = true;
         this._mySession.SetBitFlag(SessionFlags.SentToGateway, true);
         IPAddress[] arrDestIPs = new IPAddress[] { ipepForwardHTTPS.Address };
         this.socketRemote = ServerChatter.CreateConnectedSocket(arrDestIPs, ipepForwardHTTPS.Port, this._mySession);
         this.socketRemote.Send(this._mySession.oRequest.headers.ToByteArray(true, true, false));
         this._mySession.oFlags["x-EgressPort"] = (this.socketRemote.LocalEndPoint as IPEndPoint).Port.ToString();
         this.socketClient.BeginReceive(this.arrRequestBytes, 0, this.arrRequestBytes.Length, SocketFlags.None, new AsyncCallback(this.OnClientReceive), this.socketClient);
         this.socketRemote.BeginReceive(this.arrResponseBytes, 0, this.arrResponseBytes.Length, SocketFlags.None, new AsyncCallback(this.OnRemoteReceive), this.socketRemote);
         this._mySession.oResponse.headers = new HTTPResponseHeaders();
         this._mySession.oResponse.headers.HTTPResponseCode   = 0;
         this._mySession.oResponse.headers.HTTPResponseStatus = "0 Connection passed to Gateway - Result unknown";
         FiddlerApplication._frmMain.BeginInvoke(new updateUIDelegate(FiddlerApplication._frmMain.finishSession), new object[] { this._mySession });
         this.WaitForCompletion();
     }
     catch (Exception exception)
     {
         this._indicateTunnelFailure(0x1f6, exception.Message);
     }
 }
Esempio n. 3
0
 public Session(HTTPRequestHeaders oRequestHeaders, byte[] arrRequestBody)
 {
     EventHandler<StateChangeEventArgs> handler = null;
     this.bBufferResponse = FiddlerApplication.Prefs.GetBoolPref("fiddler.ui.rules.bufferresponses", false);
     this.Timers = new SessionTimers();
     this._bAllowClientPipeReuse = true;
     this.oFlags = new StringDictionary();
     if (oRequestHeaders == null)
     {
         throw new ArgumentNullException("oRequestHeaders", "oRequestHeaders must not be null when creating a new Session.");
     }
     if (arrRequestBody == null)
     {
         arrRequestBody = Utilities.emptyByteArray;
     }
     if (CONFIG.bDebugSpew)
     {
         if (handler == null)
         {
             handler = (s, ea) => FiddlerApplication.DebugSpew(string.Format("onstatechange>#{0} moving from state '{1}' to '{2}' {3}", new object[] { this.id.ToString(), ea.oldState, ea.newState, Environment.StackTrace }));
         }
         this.OnStateChanged += handler;
     }
     this.Timers.ClientConnected = this.Timers.ClientBeginRequest = this.Timers.FiddlerGotRequestHeaders = DateTime.Now;
     this.m_clientIP = null;
     this.m_clientPort = 0;
     this.oFlags["x-clientIP"] = this.m_clientIP;
     this.oFlags["x-clientport"] = this.m_clientPort.ToString();
     this.oResponse = new ServerChatter(this);
     this.oRequest = new ClientChatter(this);
     this.oRequest.pipeClient = null;
     this.oResponse.pipeServer = null;
     this.oRequest.headers = oRequestHeaders;
     this.requestBodyBytes = arrRequestBody;
     this.m_state = SessionStates.AutoTamperRequestBefore;
 }
Esempio n. 4
0
 private bool LoadResponse(Stream strmResponse, string sResponseFile, string sOptionalContentTypeHint)
 {
     bool flag2;
     bool flag = string.IsNullOrEmpty(sResponseFile);
     this.oResponse = new ServerChatter(this, "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
     this.responseBodyBytes = Utilities.emptyByteArray;
     this.bBufferResponse = true;
     this.BitFlags |= SessionFlags.ResponseGeneratedByFiddler;
     this.oFlags["x-Fiddler-Generated"] = flag ? "LoadResponseFromStream" : "LoadResponseFromFile";
     if (flag)
     {
         flag2 = this.oResponse.ReadResponseFromStream(strmResponse, sOptionalContentTypeHint);
     }
     else
     {
         flag2 = this.oResponse.ReadResponseFromFile(sResponseFile, sOptionalContentTypeHint);
     }
     if (this.HTTPMethodIs("HEAD"))
     {
         this.responseBodyBytes = Utilities.emptyByteArray;
     }
     if (this.m_state < SessionStates.AutoTamperResponseBefore)
     {
         this.state = SessionStates.AutoTamperResponseBefore;
     }
     return flag2;
 }
Esempio n. 5
0
 private void InnerExecute()
 {
     if ((this.oRequest == null) || (this.oResponse == null))
     {
         return;
     }
     if (!this._executeObtainRequest())
     {
         return;
     }
     if (this.HTTPMethodIs("CONNECT"))
     {
         this.isTunnel = true;
         if (this.oFlags.ContainsKey("x-replywithtunnel"))
         {
             this._ReturnSelfGeneratedCONNECTTunnel(this.hostname);
             return;
         }
     }
     if (this.m_state >= SessionStates.ReadingResponse)
     {
         if (this.isAnyFlagSet(SessionFlags.ResponseGeneratedByFiddler))
         {
             FiddlerApplication.DoResponseHeadersAvailable(this);
         }
         goto Label_057A;
     }
     if (this.oFlags.ContainsKey("x-replywithfile"))
     {
         this.oResponse = new ServerChatter(this, "HTTP/1.1 200 OK\r\nServer: Fiddler\r\n\r\n");
         if (this.LoadResponseFromFile(this.oFlags["x-replywithfile"]) && this.isAnyFlagSet(SessionFlags.ResponseGeneratedByFiddler))
         {
             FiddlerApplication.DoResponseHeadersAvailable(this);
         }
         this.oFlags["x-repliedwithfile"] = this.oFlags["x-replywithfile"];
         this.oFlags.Remove("x-replywithfile");
         goto Label_057A;
     }
     if ((this.port < 0) || (this.port > 0xffff))
     {
         FiddlerApplication.HandleHTTPError(this, SessionFlags.ProtocolViolationInRequest, true, false, "HTTP Request specified an invalid port number.");
     }
     if (this._isDirectRequestToFiddler())
     {
         if (this.oRequest.headers.RequestPath.OICEndsWith(".pac"))
         {
             if (CONFIG.bHookWithPAC && this.oRequest.headers.RequestPath.OICEndsWith("/proxy.pac"))
             {
                 this._returnPACFileResponse();
                 return;
             }
             if (this.oRequest.headers.RequestPath.OICEndsWith("/UpstreamProxy.pac"))
             {
                 this._returnUpstreamPACFileResponse();
                 return;
             }
         }
         if (this.oRequest.headers.RequestPath.OICEndsWith("/fiddlerroot.cer"))
         {
             _returnRootCert(this);
             return;
         }
         if (CONFIG.iReverseProxyForPort == 0)
         {
             this._returnEchoServiceResponse();
             return;
         }
         this.oFlags.Add("X-ReverseProxy", "1");
         this.host = string.Format("{0}:{1}", CONFIG.sReverseProxyHostname, CONFIG.iReverseProxyForPort);
     }
     Label_01F5:
     this.state = SessionStates.SendingRequest;
     if (!this.oResponse.ResendRequest())
     {
         this.CloseSessionPipes(true);
         this.state = SessionStates.Aborted;
         return;
     }
     if (this.isAnyFlagSet(SessionFlags.RequestStreamed))
     {
         bool bStreamResponse = false;
         GenericTunnel.CreateTunnel(this, bStreamResponse);
         if (bStreamResponse)
         {
             return;
         }
     }
     this.Timers.ServerGotRequest = DateTime.Now;
     this.state = SessionStates.ReadingResponse;
     if (this.HTTPMethodIs("CONNECT") && !this.oResponse._bWasForwarded)
     {
         this.SetBitFlag(SessionFlags.ResponseGeneratedByFiddler, true);
         this.oResponse.headers = new HTTPResponseHeaders();
         this.oResponse.headers.HTTPVersion = this.oRequest.headers.HTTPVersion;
         this.oResponse.headers.HTTPResponseCode = 200;
         this.oResponse.headers.HTTPResponseStatus = "200 Connection Established";
         this.oResponse.headers.Add("FiddlerGateway", "Direct");
         this.oResponse.headers.Add("StartTime", DateTime.Now.ToString("HH:mm:ss.fff"));
         this.oResponse.headers.Add("Connection", "close");
         this.responseBodyBytes = Utilities.emptyByteArray;
     }
     else
     {
         if (!this.oResponse.ReadResponse())
         {
             if (!this.oResponse.bServerSocketReused || (this.state == SessionStates.Aborted))
             {
                 FiddlerApplication.DebugSpew("Failed to read server response. Aborting.");
                 if (this.state != SessionStates.Aborted)
                 {
                     string str = string.Empty;
                     if (!Utilities.IsNullOrEmpty(this.responseBodyBytes))
                     {
                         str = Encoding.UTF8.GetString(this.responseBodyBytes);
                     }
                     str = string.Format("Server returned {0} bytes.{1}", this.oResponse.m_responseTotalDataCount, str);
                     this.oRequest.FailSession(0x1f8, "Fiddler - Receive Failure", string.Format("[Fiddler] ReadResponse() failed: The server did not return a response for this request.{0}", str));
                 }
                 this.CloseSessionPipes(true);
                 this.state = SessionStates.Aborted;
                 return;
             }
             FiddlerApplication.DebugSpew("[" + this.id.ToString() + "] ServerSocket Reuse failed. Restarting fresh.");
             this.oResponse.Initialize(true);
             goto Label_01F5;
         }
         if ((200 == this.responseCode) && this.isAnyFlagSet(SessionFlags.RequestStreamed))
         {
             this.responseBodyBytes = this.oResponse.TakeEntity();
             try
             {
                 this.oRequest.pipeClient.Send(this.oResponse.headers.ToByteArray(true, true));
                 this.oRequest.pipeClient.Send(this.responseBodyBytes);
                 (this.__oTunnel as GenericTunnel).BeginResponseStreaming();
             }
             catch (Exception exception)
             {
                 FiddlerApplication.Log.LogFormat("Failed to create RPC Tunnel {0}", new object[] { Utilities.DescribeException(exception) });
             }
             return;
         }
         if (this.isAnyFlagSet(SessionFlags.ResponseBodyDropped))
         {
             this.responseBodyBytes = Utilities.emptyByteArray;
             this.oResponse.FreeResponseDataBuffer();
         }
         else
         {
             long num;
             this.responseBodyBytes = this.oResponse.TakeEntity();
             if ((this.oResponse.headers.Exists("Content-Length") && !this.HTTPMethodIs("HEAD")) && (long.TryParse(this.oResponse.headers["Content-Length"], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out num) && (num != this.responseBodyBytes.LongLength)))
             {
                 FiddlerApplication.HandleHTTPError(this, SessionFlags.ProtocolViolationInResponse, true, true, string.Format("Content-Length mismatch: Response Header indicated {0:N0} bytes, but server sent {1:N0} bytes.", num, this.responseBodyBytes.LongLength));
             }
         }
     }
     Label_057A:
     this.oFlags["x-ResponseBodyTransferLength"] = (this.responseBodyBytes == null) ? "0" : this.responseBodyBytes.LongLength.ToString();
     this.state = SessionStates.AutoTamperResponseBefore;
     FiddlerApplication.DoBeforeResponse(this);
     if (!this._handledAsAutomaticRedirect() && !this._handledAsAutomaticAuth())
     {
         bool flag3 = false;
         if ((this.m_state >= SessionStates.Done) || this.isFlagSet(SessionFlags.ResponseStreamed))
         {
             this.FinishUISession(this.isFlagSet(SessionFlags.ResponseStreamed));
             if (this.isFlagSet(SessionFlags.ResponseStreamed) && this.oFlags.ContainsKey("log-drop-response-body"))
             {
                 this.SetBitFlag(SessionFlags.ResponseBodyDropped, true);
                 this.responseBodyBytes = Utilities.emptyByteArray;
             }
             flag3 = true;
         }
         if (flag3)
         {
             if (this.m_state < SessionStates.Done)
             {
                 this.m_state = SessionStates.Done;
             }
             FiddlerApplication.DoAfterSessionComplete(this);
         }
         else
         {
             if (this.oFlags.ContainsKey("x-replywithfile"))
             {
                 this.LoadResponseFromFile(this.oFlags["x-replywithfile"]);
                 this.oFlags["x-replacedwithfile"] = this.oFlags["x-replywithfile"];
                 this.oFlags.Remove("x-replywithfile");
             }
             this.state = SessionStates.AutoTamperResponseAfter;
         }
         bool bForceClientServerPipeAffinity = false;
         if (this._isResponseMultiStageAuthChallenge())
         {
             bForceClientServerPipeAffinity = this._isNTLMType2();
         }
         if (this.m_state >= SessionStates.Done)
         {
             this.FinishUISession();
             flag3 = true;
         }
         if (!flag3)
         {
             this.ReturnResponse(bForceClientServerPipeAffinity);
         }
         if (flag3 && (this.oRequest.pipeClient != null))
         {
             if (bForceClientServerPipeAffinity || this._MayReuseMyClientPipe())
             {
                 this._createNextSession(bForceClientServerPipeAffinity);
             }
             else
             {
                 this.oRequest.pipeClient.End();
             }
             this.oRequest.pipeClient = null;
         }
         this.oResponse.releaseServerPipe();
     }
 }
Esempio n. 6
0
 internal Session(ClientPipe clientPipe, ServerPipe serverPipe)
 {
     EventHandler<StateChangeEventArgs> handler = null;
     this.bBufferResponse = FiddlerApplication.Prefs.GetBoolPref("fiddler.ui.rules.bufferresponses", false);
     this.Timers = new SessionTimers();
     this._bAllowClientPipeReuse = true;
     this.oFlags = new StringDictionary();
     if (CONFIG.bDebugSpew)
     {
         if (handler == null)
         {
             handler = (s, ea) => FiddlerApplication.DebugSpew(string.Format("onstatechange>#{0} moving from state '{1}' to '{2}' {3}", new object[] { this.id.ToString(), ea.oldState, ea.newState, Environment.StackTrace }));
         }
         this.OnStateChanged += handler;
     }
     if (clientPipe != null)
     {
         this.Timers.ClientConnected = clientPipe.dtAccepted;
         this.m_clientIP = (clientPipe.Address == null) ? null : clientPipe.Address.ToString();
         this.m_clientPort = clientPipe.Port;
         this.oFlags["x-clientIP"] = this.m_clientIP;
         this.oFlags["x-clientport"] = this.m_clientPort.ToString();
         if (clientPipe.LocalProcessID != 0)
         {
             this._LocalProcessID = clientPipe.LocalProcessID;
             this.oFlags["x-ProcessInfo"] = string.Format("{0}:{1}", clientPipe.LocalProcessName, this._LocalProcessID);
         }
     }
     else
     {
         this.Timers.ClientConnected = DateTime.Now;
     }
     this.oResponse = new ServerChatter(this);
     this.oRequest = new ClientChatter(this);
     this.oRequest.pipeClient = clientPipe;
     this.oResponse.pipeServer = serverPipe;
 }
Esempio n. 7
0
 public void utilCreateResponseAndBypassServer()
 {
     if (this.state > SessionStates.SendingRequest)
     {
         throw new InvalidOperationException("Too late, we're already talking to the server.");
     }
     this.oResponse = new ServerChatter(this, "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
     this.responseBodyBytes = Utilities.emptyByteArray;
     this.oFlags["x-Fiddler-Generated"] = "utilCreateResponseAndBypassServer";
     this.BitFlags |= SessionFlags.ResponseGeneratedByFiddler;
     this.bBufferResponse = true;
     this.state = SessionStates.AutoTamperResponseBefore;
 }
Esempio n. 8
0
 public Session(byte[] arrRequest, byte[] arrResponse, SessionFlags oSF)
 {
     HTTPHeaderParseWarnings warnings;
     int num;
     int num2;
     int num3;
     int num4;
     this.bBufferResponse = FiddlerApplication.Prefs.GetBoolPref("fiddler.ui.rules.bufferresponses", false);
     this.Timers = new SessionTimers();
     this._bAllowClientPipeReuse = true;
     this.oFlags = new StringDictionary();
     if (Utilities.IsNullOrEmpty(arrRequest))
     {
         throw new ArgumentException("Missing request data for session");
     }
     if (Utilities.IsNullOrEmpty(arrResponse))
     {
         arrResponse = Encoding.ASCII.GetBytes("HTTP/1.1 0 FIDDLER GENERATED - RESPONSE DATA WAS MISSING\r\n\r\n");
     }
     this.state = SessionStates.Done;
     this.m_requestID = Interlocked.Increment(ref cRequests);
     this.BitFlags = oSF;
     if (!Parser.FindEntityBodyOffsetFromArray(arrRequest, out num, out num2, out warnings))
     {
         throw new InvalidDataException("Request corrupt, unable to find end of headers.");
     }
     if (!Parser.FindEntityBodyOffsetFromArray(arrResponse, out num3, out num4, out warnings))
     {
         throw new InvalidDataException("Response corrupt, unable to find end of headers.");
     }
     this.requestBodyBytes = new byte[arrRequest.Length - num2];
     this.responseBodyBytes = new byte[arrResponse.Length - num4];
     Buffer.BlockCopy(arrRequest, num2, this.requestBodyBytes, 0, this.requestBodyBytes.Length);
     Buffer.BlockCopy(arrResponse, num4, this.responseBodyBytes, 0, this.responseBodyBytes.Length);
     string sData = CONFIG.oHeaderEncoding.GetString(arrRequest, 0, num) + "\r\n\r\n";
     string sHeaders = CONFIG.oHeaderEncoding.GetString(arrResponse, 0, num3) + "\r\n\r\n";
     this.oRequest = new ClientChatter(this, sData);
     this.oResponse = new ServerChatter(this, sHeaders);
 }