Ejemplo n.º 1
0
        // Token: 0x06000941 RID: 2369 RVA: 0x0001F410 File Offset: 0x0001D610
        private void OnGetFullResponse(Socks5Connector.SocksContext context)
        {
            List <byte> receivedData = context.ReceivedData;

            if (receivedData[0] != 5)
            {
                base.OnException("invalid protocol version");
                return;
            }
            byte b = receivedData[1];

            if (b == 0)
            {
                base.OnCompleted(new ProxyEventArgs(context.Socket));
                return;
            }
            string exception = string.Empty;

            switch (b)
            {
            case 2:
                exception = "connection not allowed by ruleset";
                break;

            case 3:
                exception = "network unreachable";
                break;

            case 4:
                exception = "host unreachable";
                break;

            case 5:
                exception = "connection refused by destination host";
                break;

            case 6:
                exception = "TTL expired";
                break;

            case 7:
                exception = "command not supported / protocol error";
                break;

            case 8:
                exception = "address type not supported";
                break;

            default:
                exception = "general failure";
                break;
            }
            base.OnException(exception);
        }
Ejemplo n.º 2
0
        // Token: 0x06000942 RID: 2370 RVA: 0x0001F4C8 File Offset: 0x0001D6C8
        private void SendHandshake(SocketAsyncEventArgs e)
        {
            Socks5Connector.SocksContext socksContext = e.UserToken as Socks5Connector.SocksContext;
            EndPoint targetEndPoint = socksContext.TargetEndPoint;
            int      port;

            byte[] array;
            int    num;

            if (targetEndPoint is IPEndPoint)
            {
                IPEndPoint ipendPoint = targetEndPoint as IPEndPoint;
                port = ipendPoint.Port;
                if (ipendPoint.AddressFamily == AddressFamily.InterNetwork)
                {
                    array    = new byte[10];
                    array[3] = 1;
                    Buffer.BlockCopy(ipendPoint.Address.GetAddressBytes(), 0, array, 4, 4);
                }
                else
                {
                    if (ipendPoint.AddressFamily != AddressFamily.InterNetworkV6)
                    {
                        base.OnException("unknown address family");
                        return;
                    }
                    array    = new byte[22];
                    array[3] = 4;
                    Buffer.BlockCopy(ipendPoint.Address.GetAddressBytes(), 0, array, 4, 16);
                }
                num = array.Length;
            }
            else
            {
                DnsEndPoint dnsEndPoint = targetEndPoint as DnsEndPoint;
                port     = dnsEndPoint.Port;
                array    = new byte[7 + ProxyConnectorBase.ASCIIEncoding.GetMaxByteCount(dnsEndPoint.Host.Length)];
                array[3] = 3;
                num      = 5;
                num     += ProxyConnectorBase.ASCIIEncoding.GetBytes(dnsEndPoint.Host, 0, dnsEndPoint.Host.Length, array, num);
                num     += 2;
            }
            array[0]       = 5;
            array[1]       = 1;
            array[2]       = 0;
            array[num - 2] = (byte)(port / 256);
            array[num - 1] = (byte)(port % 256);
            e.SetBuffer(array, 0, num);
            socksContext.ReceivedData   = new List <byte>(num + 5);
            socksContext.ExpectedLength = 5;
            base.StartSend(socksContext.Socket, e);
        }
Ejemplo n.º 3
0
 // Token: 0x0600093E RID: 2366 RVA: 0x0001F170 File Offset: 0x0001D370
 protected override void ProcessSend(SocketAsyncEventArgs e)
 {
     if (!base.ValidateAsyncResult(e))
     {
         return;
     }
     Socks5Connector.SocksContext socksContext = e.UserToken as Socks5Connector.SocksContext;
     if (socksContext.State == Socks5Connector.SocksState.NotAuthenticated)
     {
         e.SetBuffer(0, 2);
         this.StartReceive(socksContext.Socket, e);
         return;
     }
     if (socksContext.State == Socks5Connector.SocksState.Authenticating)
     {
         e.SetBuffer(0, 2);
         this.StartReceive(socksContext.Socket, e);
         return;
     }
     e.SetBuffer(0, e.Buffer.Length);
     this.StartReceive(socksContext.Socket, e);
 }
Ejemplo n.º 4
0
 // Token: 0x06000940 RID: 2368 RVA: 0x0001F24C File Offset: 0x0001D44C
 protected override void ProcessReceive(SocketAsyncEventArgs e)
 {
     if (!base.ValidateAsyncResult(e))
     {
         return;
     }
     Socks5Connector.SocksContext socksContext = (Socks5Connector.SocksContext)e.UserToken;
     if (socksContext.State == Socks5Connector.SocksState.NotAuthenticated)
     {
         if (!this.ProcessAuthenticationResponse(socksContext.Socket, e))
         {
             return;
         }
         byte b = e.Buffer[1];
         if (b == 0)
         {
             socksContext.State = Socks5Connector.SocksState.Authenticated;
             this.SendHandshake(e);
             return;
         }
         if (b == 2)
         {
             socksContext.State = Socks5Connector.SocksState.Authenticating;
             this.AutheticateWithUserNamePassword(e);
             return;
         }
         if (b == 255)
         {
             base.OnException("no acceptable methods were offered");
             return;
         }
         base.OnException("protocol error");
         return;
     }
     else if (socksContext.State == Socks5Connector.SocksState.Authenticating)
     {
         if (!this.ProcessAuthenticationResponse(socksContext.Socket, e))
         {
             return;
         }
         if (e.Buffer[1] == 0)
         {
             socksContext.State = Socks5Connector.SocksState.Authenticated;
             this.SendHandshake(e);
             return;
         }
         base.OnException("authentication failure");
         return;
     }
     else
     {
         byte[] array = new byte[e.BytesTransferred];
         Buffer.BlockCopy(e.Buffer, e.Offset, array, 0, e.BytesTransferred);
         socksContext.ReceivedData.AddRange(array);
         if (socksContext.ExpectedLength > socksContext.ReceivedData.Count)
         {
             this.StartReceive(socksContext.Socket, e);
             return;
         }
         if (socksContext.State != Socks5Connector.SocksState.FoundLength)
         {
             byte b2 = socksContext.ReceivedData[3];
             int  num;
             if (b2 == 1)
             {
                 num = 10;
             }
             else if (b2 == 3)
             {
                 num = (int)(7 + socksContext.ReceivedData[4]);
             }
             else
             {
                 num = 22;
             }
             if (socksContext.ReceivedData.Count < num)
             {
                 socksContext.ExpectedLength = num;
                 this.StartReceive(socksContext.Socket, e);
                 return;
             }
             if (socksContext.ReceivedData.Count > num)
             {
                 base.OnException("response length exceeded");
                 return;
             }
             this.OnGetFullResponse(socksContext);
             return;
         }
         else
         {
             if (socksContext.ReceivedData.Count > socksContext.ExpectedLength)
             {
                 base.OnException("response length exceeded");
                 return;
             }
             this.OnGetFullResponse(socksContext);
             return;
         }
     }
 }