Exemple #1
0
 public SocksTunnel(SocksClient p, SocksRequest req, SocksRequest req1, int packetSize, int timeout)
 {
     RemoteClient = new Client(new Socket(SocketType.Stream, ProtocolType.Tcp), PacketSize);
     Client = p;
     Req = req;
     ModifiedReq = req1;
     PacketSize = packetSize;
     Timeout = timeout;
 }
Exemple #2
0
 public SocksTunnel(SocksClient p, SocksRequest req, SocksRequest req1, int packetSize, int timeout)
 {
     RemoteClient = new Client(new Socket(SocketType.Stream, ProtocolType.Tcp), PacketSize);
     Client       = p;
     Req          = req;
     ModifiedReq  = req1;
     PacketSize   = packetSize;
     Timeout      = timeout;
 }
Exemple #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;
     PacketSize   = packetSize;
     Timeout      = timeout;
     se           = ph;
     isDisposing  = false;
 }
Exemple #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;
     isDisposing = false;
 }
Exemple #5
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;
                StringBuilder address = new StringBuilder();
                switch ((AddressType)buff[3])
                {
                case AddressType.IP:
                {
                    for (int i = 4; i < 8; i++)
                    {
                        //grab IP.
                        address.Append(Convert.ToInt32(buff[i]).ToString() + (i != 7 ? "." : ""));
                    }
                    fwd += 4;
                }
                break;

                case AddressType.Domain:
                {
                    int domainlen = Convert.ToInt32(buff[4]);
                    address.Append(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.ToString(), port));
            }

            default:
                //not supported.
                return(null);
            }
        }
Exemple #6
0
 public void Dispose()
 {
     if (isDisposing)
     {
         return;
     }
     isDisposing       = true;
     disconnected      = true;
     this.Client       = null;
     this.RemoteClient = null;
     this.ModifiedReq  = null;
     this.Req          = null;
 }
Exemple #7
0
 public void Dispose()
 {
     if (isDisposing)
     {
         return;
     }
     isDisposing = true;
     disconnected = true;
     this.Client = null;
     this.RemoteClient = null;
     this.ModifiedReq = null;
     this.Req = null;
 }
Exemple #8
0
        public static User RequestLogin(SocksClient client)
        {
            //request authentication.
            client.Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.Login });
            byte[] buff;
            int    recv = Receive(client.Client, out 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(username, password, (IPEndPoint)client.Client.Sock.RemoteEndPoint));
        }
Exemple #9
0
        public static List <AuthTypes> RequestAuth(SocksClient client)
        {
            byte[] buff;
            int    recv = Receive(client.Client, out buff);

            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;

                case AuthTypes.SocksBoth:
                    types.Add(AuthTypes.SocksBoth);
                    break;

                case AuthTypes.SocksEncrypt:
                    types.Add(AuthTypes.SocksEncrypt);
                    break;

                case AuthTypes.SocksCompress:
                    types.Add(AuthTypes.SocksCompress);
                    break;
                }
            }
            return(types);
        }
Exemple #10
0
        void ServerClientConnected(object sender, ClientEventArgs e)
        {
            #if DEBUG
            Console.WriteLine("New Client :");
            #endif
            //call plugins related to ClientConnectedHandler.
            foreach (ClientConnectedHandler cch in PluginLoader.LoadPlugin(typeof(ClientConnectedHandler)))
                if (cch.Enabled)
                {
                    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);
            try
            {
                client.Start(this.PacketSize, this.Timeout);
            }
            catch (ObjectDisposedException ex)
            {
                Console.WriteLine(ex.Message);
                Clients.Remove(client);
                client.Dispose();
                client = null;
            }
        }
Exemple #11
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;
                        StringBuilder address = new StringBuilder();
                        switch ((AddressType)buff[3])
                        {
                            case AddressType.IP:
                                {
                                    for (int i = 4; i < 8; i++)
                                    {
                                        //grab IP.
                                        address.Append(Convert.ToInt32(buff[i]).ToString() + (i != 7 ? "." : ""));
                                    }
                                    fwd += 4;
                                }
                                break;
                            case AddressType.Domain:
                                {
                                    int domainlen = Convert.ToInt32(buff[4]);
                                    address.Append(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.ToString(), port);
                    }
                default:
                    //not supported.
                    return null;

            }
        }
Exemple #12
0
        public static User RequestLogin(SocksClient client)
        {
            //request authentication.
            client.Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.Login });
            byte[] buff;
            int recv = Receive(client.Client, out 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(username, password, (IPEndPoint)client.Client.Sock.RemoteEndPoint);
        }
Exemple #13
0
        public static List<AuthTypes> RequestAuth(SocksClient client)
        {
            byte[] buff;
            int recv = Receive(client.Client, out buff);

            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;
                    case AuthTypes.SocksBoth:
                        types.Add(AuthTypes.SocksBoth);
                        break;
                    case AuthTypes.SocksEncrypt:
                        types.Add(AuthTypes.SocksEncrypt);
                        break;
                    case AuthTypes.SocksCompress:
                        types.Add(AuthTypes.SocksCompress);
                        break;
                }
            }
            return types;
        }
Exemple #14
0
 public SocksClientEventArgs(SocksClient client)
 {
     Client = client;
 }