Example #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);
        }
Example #2
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;
 }
Example #3
0
 public SocksSpecialTunnel(SocksClient p, SocksEncryption ph, SocksRequest req, SocksRequest req1, int packetSize, int timeout)
 {
     RemoteClient = new Client(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), packetSize);
     Client       = p;
     Req          = req;
     ModifiedReq  = req1;
     Timeout      = timeout;
     se           = ph;
 }
Example #4
0
 public SocksSpecialTunnel(SocksClient p, SocksEncryption ph, SocksRequest req, SocksRequest req1, int packetSize, int timeout)
 {
     RemoteClient = new Client(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), PacketSize);
     Client = p;
     Req = req;
     ModifiedReq = req1;
     PacketSize = packetSize;
     Timeout = timeout;
     se = ph;
 }
Example #5
0
        void _server_onClientConnected(object sender, ClientEventArgs e)
        {
            //Console.WriteLine("Client connected.");
            SocksClient client = new SocksClient(e.Client);
	    client.onClientConnected += client_onClientConnected;
            client.onClientDisconnected += client_onClientDisconnected;
            client.OnClientAuthenticating += client_OnClientAuthenticating;
            Clients.Add(client);
            client.Authentication = this.Authentication;
            client.Begin(this.PacketSize, this.Timeout);
        }
Example #6
0
        public static SocksRequest RequestTunnel(SocksClient client, SocksEncryption ph)
        {
            byte[] data;
            int    recv = Receive(client.Client, out data);

            byte[] buff = ph.ProcessInputData(data, 0, recv);
            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);
            }
        }
Example #7
0
        public static User RequestLogin(SocksClient client)
        {
            ////request authentication.
            client.Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.Login });
            int recv = Receive(client.Client, out var buff);

            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(buff[0], username, password, (IPEndPoint)client.Client.Sock.RemoteEndPoint));
        }
Example #8
0
 public SocksClientEventArgs(SocksClient client)
 {
     Client = client;
 }
Example #9
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;

            }
        }
Example #10
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);
        }
Example #11
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;
        }
Example #12
0
 void _server_onClientConnected(object sender, ClientEventArgs e)
 {
     //Console.WriteLine("Client connected.");
     //call plugins related to ClientConnectedHandler.
     foreach (ClientConnectedHandler cch in PluginLoader.LoadPlugin(typeof(ClientConnectedHandler)))
     {
         try
         {
             if (!cch.OnConnect(e.Client, (IPEndPoint)e.Client.Sock.RemoteEndPoint))
             {
                 e.Client.Disconnect();
                 return;
             }
         }
         catch
         {
         }
     }
     SocksClient client = new SocksClient(e.Client);
     e.Client.onDataReceived += Client_onDataReceived;
     e.Client.onDataSent += Client_onDataSent;
     client.onClientDisconnected += client_onClientDisconnected;
     Clients.Add(client);
     client.Begin(this.OutboundIPAddress, this.PacketSize, this.Timeout);
 }
Example #13
0
        public static SocksRequest RequestTunnel(SocksClient client, SocksEncryption ph)
        {
            byte[] data;
            int recv = Receive(client.Client, out data);
            byte[] buff = ph.ProcessInputData(data, 0, recv);
            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);
                    UInt16 port = BitConverter.ToUInt16(new byte[] { po[1], po[0] }, 0);
                    return new SocksRequest(StreamTypes.Stream, (AddressType)buff[3], address, port);
                }
            default:
                //not supported.
                return null;

            }
        }