Exemple #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("BrowserProxyGateway", "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);
                this.WaitForCompletion();
            }
            catch (Exception)
            {
                try
                {
                    this.socketRemote.Close();
                    this.socketClient.Close();
                }
                catch (Exception)
                {
                }
            }
        }
Exemple #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.WaitForCompletion();
     }
     catch (Exception exception)
     {
         this._indicateTunnelFailure(0x1f6, exception.Message);
     }
 }