예제 #1
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;
 }
예제 #2
0
 void _server_onClientConnected(object sender, ClientEventArgs e)
 {
     Console.WriteLine("Client connected.");
     SocksClient client = new SocksClient(e.Client);
     client.onClientDisconnected += client_onClientDisconnected;
     client.OnClientAuthenticating += client_OnClientAuthenticating;
     Clients.Add(client);
     client.Authentication = this.Authentication;
     client.Begin(this.PacketSize, this.Timeout);
 }
예제 #3
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);
        }
예제 #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 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;
        }
예제 #6
0
 public SocksClientEventArgs(SocksClient client)
 {
     Client = client;
 }