Esempio n. 1
0
 private Socks4Request(Socks4Command cmd, int remotePort, IPAddress remoteHostIP, string userID, string remoteHost)
 {
     this.ProxyType  = string.IsNullOrEmpty(remoteHost) ? SocksProxyType.Socks4 : SocksProxyType.Socks4a;
     this.Command    = cmd;
     this.RemotePort = remotePort;
     this.RemoteIP   = remoteHostIP;
     this.UserID     = userID;
     this.RemoteHost = remoteHost;
 }
Esempio n. 2
0
        static bool TryParse(byte[] request, int requestLength, out Socks4Command cmd, out int port, out IPAddress addr, out string user)
        {
            // +----+-----+----------+----------+----------+-------+--------------+-------+
            // |VER | CMD | DST.PORT | DST.ADDR |  USERID  | NULL  |  DST.DOMAIN  | NULL  |
            // +----+-----+----------+----------+----------+-------+--------------+-------+
            // | 1  |  1  |    2     |    4     | VARIABLE | X'00' |   VARIABLE   | X'00' |
            // +----+-----+----------+----------+----------+-------+--------------+-------+
            int n = 0;

            cmd  = Socks4Command.Connect;
            addr = null;
            user = null;
            port = 0;

            if (requestLength < 9 || request[n++] != (byte)4)
            {
                return(false);
            }

            cmd = (Socks4Command)request[n++];
            if (cmd != Socks4Command.Connect && cmd != Socks4Command.Bind)
            {
                return(false);
            }

            port = (request[n++] << 8) | request[n++];

            var ip = new byte[4];

            Buffer.BlockCopy(request, n, ip, 0, 4);
            n += 4;

            if (!IsInvalidIPAddress(ip))
            {
                addr = new IPAddress(ip);
            }

            var buffer = new byte[256];
            int index  = 0;

            while (n < requestLength && index < buffer.Length && request[n] != 0)
            {
                buffer[index++] = request[n++];
            }

            if (n >= requestLength || index >= buffer.Length)
            {
                return(false);
            }

            user = Encoding.UTF8.GetString(buffer, 0, index);
            n++;

            return(addr != null);
        }
Esempio n. 3
0
 public Socks4Request(Socks4Command cmd, DnsEndPoint remoteEndPoint, string userID = null)
     : this(cmd, remoteEndPoint.Port, new IPAddress(new byte[] { 0, 0, 0, 1 }), userID ?? string.Empty, remoteEndPoint.Host)
 {
 }
Esempio n. 4
0
 public Socks4Request(Socks4Command cmd, IPEndPoint remoteEndPoint, string userID = null)
     : this(cmd, remoteEndPoint.Port, remoteEndPoint.Address, userID ?? string.Empty, string.Empty)
 {
 }