コード例 #1
0
        public static List <AuthTypes> RequestAuth(SocksClient client)
        {
            byte[] buff = Receive(client.Client);

            if (buff == null || (HeaderTypes)buff[0] != HeaderTypes.Socks5)
            {
                return(new List <AuthTypes>());
            }

            int methods            = Convert.ToInt32(buff[1]);
            List <AuthTypes> types = new List <AuthTypes>();

            for (int i = 2; i < methods + 2; i++)
            {
                switch ((AuthTypes)buff[i])
                {
                case AuthTypes.Login:
                    types.Add(AuthTypes.Login);
                    break;

                case AuthTypes.None:
                    types.Add(AuthTypes.None);
                    break;
                }
            }
            return(types);
        }
コード例 #2
0
ファイル: SocksTunnel.cs プロジェクト: ZeDingo/Socks5
 public SocksTunnel(SocksClient p, SocksRequest req, int packetSize, int timeout)
 {
     RemoteClient = new Client(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), PacketSize);
     Client = p;
     Req = req;
     PacketSize = packetSize;
     Timeout = timeout;
 }
コード例 #3
0
 public SocksTunnel(SocksClient p, SocksRequest req, int packetSize, int timeout)
 {
     RemoteClient = new Client(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), PacketSize);
     Client       = p;
     Req          = req;
     PacketSize   = packetSize;
     Timeout      = timeout;
 }
コード例 #4
0
        public static SocksRequest RequestTunnel(SocksClient client)
        {
            byte[] buff = Receive(client.Client);
            if (buff == null || (HeaderTypes)buff[0] != HeaderTypes.Socks5)
            {
                return(null);
            }
            switch ((StreamTypes)buff[1])
            {
            case StreamTypes.Stream:
            {
                int    fwd     = 4;
                string address = "";
                switch ((AddressType)buff[3])
                {
                case AddressType.IP:
                {
                    for (int i = 4; i < 8; i++)
                    {
                        //grab IP.
                        address += Convert.ToInt32(buff[i]).ToString() + (i != 7 ? "." : "");
                    }
                    fwd += 4;
                }
                break;

                case AddressType.Domain:
                {
                    int domainlen = Convert.ToInt32(buff[4]);
                    address += Encoding.ASCII.GetString(buff, 5, domainlen);
                    fwd     += domainlen + 1;
                }
                break;

                case AddressType.IPv6:
                    //can't handle IPV6 traffic just yet.
                    return(null);
                }
                byte[] po = new byte[2];
                Array.Copy(buff, fwd, po, 0, 2);
                Int16 x    = BitConverter.ToInt16(po, 0);
                int   port = Convert.ToInt32(IPAddress.NetworkToHostOrder(x));
                port = (port < 1 ? port + 65536 : port);
                return(new SocksRequest(StreamTypes.Stream, (AddressType)buff[3], address, port));
            }

            default:
                //not supported.
                return(null);
            }
        }
コード例 #5
0
        public static User RequestLogin(SocksClient client)
        {
            //request authentication.
            client.Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Authentication });
            byte[] buff = Receive(client.Client);

            if (buff == null || buff[0] != 0x01)
            {
                return(null);
            }

            int    numusername = Convert.ToInt32(buff[1]);
            int    numpassword = Convert.ToInt32(buff[(numusername + 2)]);
            string username    = Encoding.ASCII.GetString(buff, 2, numusername);
            string password    = Encoding.ASCII.GetString(buff, numusername + 3, numpassword);

            return(new User(username, password, (IPEndPoint)client.Client.Sock.RemoteEndPoint));
        }
コード例 #6
0
ファイル: ClientEventArgs.cs プロジェクト: ZeDingo/Socks5
 public SocksClientEventArgs(SocksClient client)
 {
     Client = client;
 }
コード例 #7
0
ファイル: Socks.cs プロジェクト: ZeDingo/Socks5
        public static SocksRequest RequestTunnel(SocksClient client)
        {
            byte[] buff = Receive(client.Client);
            if (buff == null || (HeaderTypes)buff[0] != HeaderTypes.Socks5) return null;
            switch ((StreamTypes)buff[1])
            {
                case StreamTypes.Stream:
                    {
                        int fwd = 4;
                        string address = "";
                        switch ((AddressType)buff[3])
                        {
                            case AddressType.IP:
                                {
                                    for (int i = 4; i < 8; i++)
                                    {
                                        //grab IP.
                                        address += Convert.ToInt32(buff[i]).ToString() + (i != 7 ? "." : "");
                                    }
                                    fwd += 4;
                                }
                                break;
                            case AddressType.Domain:
                                {
                                    int domainlen = Convert.ToInt32(buff[4]);
                                    address += Encoding.ASCII.GetString(buff, 5, domainlen);
                                    fwd += domainlen + 1;
                                }
                                break;
                            case AddressType.IPv6:
                                //can't handle IPV6 traffic just yet.
                                return null;
                        }
                        byte[] po = new byte[2];
                        Array.Copy(buff, fwd, po, 0, 2);
                        Int16 x = BitConverter.ToInt16(po, 0);
                        int port = Convert.ToInt32(IPAddress.NetworkToHostOrder(x));
                        port = (port < 1 ? port + 65536 : port);
                        return new SocksRequest(StreamTypes.Stream, (AddressType)buff[3], address, port);
                    }
                default:
                    //not supported.
                    return null;

            }
        }
コード例 #8
0
ファイル: Socks.cs プロジェクト: ZeDingo/Socks5
        public static User RequestLogin(SocksClient client)
        {
            //request authentication.
            client.Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Authentication });
            byte[] buff = Receive(client.Client);

            if (buff == null || buff[0] != 0x01) return null;

            int numusername = Convert.ToInt32(buff[1]);
            int numpassword = Convert.ToInt32(buff[(numusername + 2)]);
            string username = Encoding.ASCII.GetString(buff, 2, numusername);
            string password = Encoding.ASCII.GetString(buff, numusername + 3, numpassword);

            return new User(username, password, (IPEndPoint)client.Client.Sock.RemoteEndPoint);
        }
コード例 #9
0
ファイル: Socks.cs プロジェクト: ZeDingo/Socks5
        public static List<AuthTypes> RequestAuth(SocksClient client)
        {
            byte[] buff = Receive(client.Client);

            if (buff == null || (HeaderTypes)buff[0] != HeaderTypes.Socks5) return new List<AuthTypes>();

            int methods = Convert.ToInt32(buff[1]);
            List<AuthTypes> types = new List<AuthTypes>();
            for (int i = 2; i < methods + 2; i++)
            {
                switch ((AuthTypes)buff[i])
                {
                    case AuthTypes.Login:
                        types.Add(AuthTypes.Login);
                        break;
                    case AuthTypes.None:
                        types.Add(AuthTypes.None);
                        break;
                }
            }
            return types;
        }