Exemplo n.º 1
0
 protected void OnClientReceive(IAsyncResult ar)
 {
     try
     {
         int count = this.socketClient.EndReceive(ar);
         if (count > 0)
         {
             if ((this._mySession.requestBodyBytes == null) || (this._mySession.requestBodyBytes.LongLength == 0L))
             {
                 try
                 {
                     HTTPSClientHello hello = new HTTPSClientHello();
                     if (hello.LoadFromStream(new MemoryStream(this.arrRequestBytes, 0, count, false)))
                     {
                         this._mySession.requestBodyBytes          = Encoding.UTF8.GetBytes(hello.ToString() + "\n");
                         this._mySession["https-Client-SessionID"] = hello.SessionID;
                     }
                 }
                 catch (Exception exception)
                 {
                     this._mySession.requestBodyBytes = Encoding.UTF8.GetBytes("HTTPSParse Failed: " + exception.Message);
                 }
             }
             this.socketRemote.BeginSend(this.arrRequestBytes, 0, count, SocketFlags.None, new AsyncCallback(this.OnRemoteSent), this.socketRemote);
         }
         else
         {
             this.CloseTunnel();
         }
     }
     catch (Exception)
     {
         this.CloseTunnel();
     }
 }
Exemplo n.º 2
0
        protected void OnClientReceive(IAsyncResult iasyncResult_0)
        {
            try
            {
                int num = this.socketClient.EndReceive(iasyncResult_0);
                if (num > 0)
                {
                    this._lngEgressByteCount += (long)num;
                    FiddlerApplication.DoReadRequestBuffer(this._mySession, this.arrRequestBytes, num);
                    if (this._mySession.requestBodyBytes != null)
                    {
                        if (this._mySession.requestBodyBytes.LongLength != 0L)
                        {
                            goto IL_FF;
                        }
                    }
                    try
                    {
                        HTTPSClientHello hTTPSClientHello = new HTTPSClientHello();
                        if (hTTPSClientHello.LoadFromStream(new MemoryStream(this.arrRequestBytes, 0, num, false)))
                        {
                            this._mySession.requestBodyBytes          = Encoding.UTF8.GetBytes(hTTPSClientHello.ToString() + "\n");
                            this._mySession["https-Client-SessionID"] = hTTPSClientHello.SessionID;
                            if (!string.IsNullOrEmpty(hTTPSClientHello.ServerNameIndicator))
                            {
                                this._mySession["https-Client-SNIHostname"] = hTTPSClientHello.ServerNameIndicator;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        this._mySession.requestBodyBytes = Encoding.UTF8.GetBytes("Request HTTPSParse failed: " + ex.Message);
                    }
IL_FF:
                    this.socketRemote.BeginSend(this.arrRequestBytes, 0, num, SocketFlags.None, new AsyncCallback(this.OnRemoteSent), this.socketRemote);
                }
                else
                {
                    FiddlerApplication.DoReadRequestBuffer(this._mySession, this.arrRequestBytes, 0);
                    this.CloseTunnel();
                }
            }
            catch (Exception)
            {
                this.CloseTunnel();
            }
        }
Exemplo n.º 3
0
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder(512);

            if (this._HandshakeVersion == 2)
            {
                stringBuilder.Append("A SSLv2-compatible ClientHello handshake was found. Fiddler extracted the parameters below.\n\n");
            }
            else
            {
                stringBuilder.Append("A SSLv3-compatible ClientHello handshake was found. Fiddler extracted the parameters below.\n\n");
            }
            stringBuilder.AppendFormat("Version: {0}\n", HTTPSUtilities.HTTPSVersionToString(this._MajorVersion, this._MinorVersion));
            stringBuilder.AppendFormat("Random: {0}\n", Utilities.ByteArrayToString(this._Random));
            stringBuilder.AppendFormat("SessionID: {0}\n", Utilities.ByteArrayToString(this._SessionID));
            stringBuilder.AppendFormat("Extensions: \n{0}\n", HTTPSClientHello.ExtensionListToString(this._Extensions));
            stringBuilder.AppendFormat("Ciphers: \n{0}\n", HTTPSClientHello.CipherSuitesToString(this._CipherSuites));
            stringBuilder.AppendFormat("Compression: \n{0}\n", HTTPSClientHello.CompressionSuitesToString(this._CompressionSuites));
            return(stringBuilder.ToString());
        }
Exemplo n.º 4
0
 protected void OnClientReceive(IAsyncResult ar)
 {
     try
     {
         int cBytes = this.socketClient.EndReceive(ar);
         if (cBytes > 0)
         {
             this._lngEgressByteCount += cBytes;
             FiddlerApplication.DoReadRequestBuffer(this._mySession, this.arrRequestBytes, cBytes);
             if ((this._mySession.requestBodyBytes == null) || (this._mySession.requestBodyBytes.LongLength == 0L))
             {
                 try
                 {
                     HTTPSClientHello hello = new HTTPSClientHello();
                     if (hello.LoadFromStream(new MemoryStream(this.arrRequestBytes, 0, cBytes, false)))
                     {
                         this._mySession.requestBodyBytes = Encoding.UTF8.GetBytes(hello.ToString() + "\n");
                         this._mySession["https-Client-SessionID"] = hello.SessionID;
                         if (!string.IsNullOrEmpty(hello.ServerNameIndicator))
                         {
                             this._mySession["https-Client-SNIHostname"] = hello.ServerNameIndicator;
                         }
                     }
                 }
                 catch (Exception exception)
                 {
                     this._mySession.requestBodyBytes = Encoding.UTF8.GetBytes("Request HTTPSParse failed: " + exception.Message);
                 }
             }
             this.socketRemote.BeginSend(this.arrRequestBytes, 0, cBytes, SocketFlags.None, new AsyncCallback(this.OnRemoteSent), this.socketRemote);
         }
         else
         {
             FiddlerApplication.DoReadRequestBuffer(this._mySession, this.arrRequestBytes, 0);
             this.CloseTunnel();
         }
     }
     catch (Exception)
     {
         this.CloseTunnel();
     }
 }
Exemplo n.º 5
0
 private bool AcceptHTTPSRequest(X509Certificate2 oCert)
 {
     try
     {
         if (CONFIG.bUseSNIForCN)
         {
             byte[] buffer = new byte[0x400];
             int count = this.oRequest.pipeClient.GetRawSocket().Receive(buffer, SocketFlags.Peek);
             HTTPSClientHello hello = new HTTPSClientHello();
             if (hello.LoadFromStream(new MemoryStream(buffer, 0, count, false)))
             {
                 this.oFlags["https-Client-SessionID"] = hello.SessionID;
                 if (!string.IsNullOrEmpty(hello.ServerNameIndicator))
                 {
                     FiddlerApplication.Log.LogFormat("Secure Endpoint request with SNI of '{0}'", new object[] { hello.ServerNameIndicator });
                     this.oFlags["https-Client-SNIHostname"] = hello.ServerNameIndicator;
                     oCert = CertMaker.FindCert(hello.ServerNameIndicator);
                 }
             }
         }
         if (!this.oRequest.pipeClient.SecureClientPipeDirect(oCert))
         {
             FiddlerApplication.Log.LogString("Failed to secure client connection when acting as Secure Endpoint.");
             return false;
         }
     }
     catch (Exception exception)
     {
         FiddlerApplication.Log.LogFormat("Failed to secure client connection when acting as Secure Endpoint: {0}", new object[] { exception.ToString() });
     }
     return true;
 }
Exemplo n.º 6
0
 internal bool ReturnResponse(bool bForceClientServerPipeAffinity)
 {
     this.state = SessionStates.SendingResponse;
     bool flag = false;
     this.Timers.ClientBeginResponse = this.Timers.ClientDoneResponse = DateTime.Now;
     try
     {
         if ((this.oRequest.pipeClient != null) && this.oRequest.pipeClient.Connected)
         {
             if (this.oFlags.ContainsKey("response-trickle-delay"))
             {
                 int num = int.Parse(this.oFlags["response-trickle-delay"]);
                 this.oRequest.pipeClient.TransmitDelay = num;
             }
             this.oRequest.pipeClient.Send(this.oResponse.headers.ToByteArray(true, true));
             this.oRequest.pipeClient.Send(this.responseBodyBytes);
             this.Timers.ClientDoneResponse = DateTime.Now;
             if ((((this.responseCode == 0x65) && (this.oRequest != null)) && ((this.oResponse != null) && (this.oRequest.headers != null))) && ((this.oRequest.headers.ExistsAndContains("Upgrade", "WebSocket") && (this.oResponse.headers != null)) && this.oResponse.headers.ExistsAndContains("Upgrade", "WebSocket")))
             {
                 FiddlerApplication.Log.LogFormat("Upgrading Session #{0} to websocket", new object[] { this.id });
                 WebSocket.CreateTunnel(this);
                 this.state = SessionStates.Done;
                 this.FinishUISession(false);
                 return true;
             }
             if (((this.responseCode == 200) && this.HTTPMethodIs("CONNECT")) && (this.oRequest.pipeClient != null))
             {
                 bForceClientServerPipeAffinity = true;
                 Socket rawSocket = this.oRequest.pipeClient.GetRawSocket();
                 if (rawSocket != null)
                 {
                     byte[] buffer = new byte[0x400];
                     int iMaxByteCount = rawSocket.Receive(buffer, SocketFlags.Peek);
                     if (iMaxByteCount == 0)
                     {
                         this.oFlags["x-CONNECT-Peek"] = "After the client received notice of the established CONNECT, it failed to send any data.";
                         this.requestBodyBytes = Encoding.UTF8.GetBytes("After the client received notice of the established CONNECT, it failed to send any data.\n");
                         if (this.isFlagSet(SessionFlags.SentToGateway))
                         {
                             this.PoisonServerPipe();
                         }
                         this.PoisonClientPipe();
                         this.oRequest.pipeClient.End();
                         flag = true;
                         goto Label_0442;
                     }
                     if (CONFIG.bDebugSpew)
                     {
                         FiddlerApplication.Log.LogFormat("Peeking at the first bytes from CONNECT'd client session {0} yielded:\n{1}", new object[] { this.id, Utilities.ByteArrayToHexView(buffer, 0x20, iMaxByteCount) });
                     }
                     if ((buffer[0] == 0x16) || (buffer[0] == 0x80))
                     {
                         try
                         {
                             HTTPSClientHello hello = new HTTPSClientHello();
                             if (hello.LoadFromStream(new MemoryStream(buffer, 0, iMaxByteCount, false)))
                             {
                                 this.requestBodyBytes = Encoding.UTF8.GetBytes(hello.ToString() + "\n");
                                 this["https-Client-SessionID"] = hello.SessionID;
                                 if (!string.IsNullOrEmpty(hello.ServerNameIndicator))
                                 {
                                     this["https-Client-SNIHostname"] = hello.ServerNameIndicator;
                                 }
                             }
                         }
                         catch (Exception)
                         {
                         }
                         CONNECTTunnel.CreateTunnel(this);
                         flag = true;
                         goto Label_0442;
                     }
                     if ((((iMaxByteCount > 4) && (buffer[0] == 0x47)) && ((buffer[1] == 0x45) && (buffer[2] == 0x54))) && (buffer[3] == 0x20))
                     {
                         this.SetBitFlag(SessionFlags.IsWebSocketTunnel, true);
                     }
                     else
                     {
                         this.oFlags["x-CONNECT-Peek"] = BitConverter.ToString(buffer, 0, Math.Min(iMaxByteCount, 0x10));
                         this.oFlags["x-no-decrypt"] = "PeekYieldedUnknownProtocol";
                         CONNECTTunnel.CreateTunnel(this);
                         flag = true;
                         goto Label_0442;
                     }
                 }
             }
             if (bForceClientServerPipeAffinity || this._MayReuseMyClientPipe())
             {
                 FiddlerApplication.DebugSpew("Creating next session with pipes from {0}.", new object[] { this.id });
                 this._createNextSession(bForceClientServerPipeAffinity);
                 flag = true;
             }
             else
             {
                 if (CONFIG.bDebugSpew)
                 {
                     FiddlerApplication.DebugSpew(string.Format("fiddler.network.clientpipereuse> Closing client socket since bReuseClientSocket was false after returning [{0}]", this.url));
                 }
                 this.oRequest.pipeClient.End();
                 flag = true;
             }
         }
         else
         {
             flag = true;
         }
     }
     catch (Exception exception)
     {
         if (CONFIG.bDebugSpew)
         {
             FiddlerApplication.DebugSpew(string.Format("Write to client failed for Session #{0}; exception was {1}", this.id, exception.ToString()));
         }
         this.state = SessionStates.Aborted;
     }
     Label_0442:
     this.oRequest.pipeClient = null;
     if (flag)
     {
         this.state = SessionStates.Done;
         try
         {
             this.FinishUISession(false);
         }
         catch (Exception)
         {
         }
     }
     FiddlerApplication.DoAfterSessionComplete(this);
     if (this.oFlags.ContainsKey("log-drop-response-body"))
     {
         this.oFlags["x-ResponseBodyFinalLength"] = (this.responseBodyBytes != null) ? this.responseBodyBytes.LongLength.ToString() : "0";
         this.SetBitFlag(SessionFlags.ResponseBodyDropped, true);
         this.responseBodyBytes = Utilities.emptyByteArray;
     }
     return flag;
 }