Example #1
1
 static void Main(string[] args)
 {
     Socks5Server x = new Socks5Server(IPAddress.Any, 1080);
     PluginLoader.ChangePluginStatus(false, typeof(Auth));
     x.Start();
     Socks5Client m = new Socks5Client("localhost", 1080, "portquiz.net", 65532);
     m.OnConnected += M_OnConnected;
     m.OnDataReceived += M_OnDataReceived;
     m.ConnectAsync();
     while (true)
     {
         /*Console.Clear();
         Console.Write("Total Clients: \t{0}\nTotal Recvd: \t{1:0.00##}MB\nTotal Sent: \t{2:0.00##}MB\n", x.Stats.TotalClients, ((x.Stats.NetworkReceived / 1024f) / 1024f), ((x.Stats.NetworkSent / 1024f) / 1024f));
         Console.Write("Receiving/sec: \t{0}\nSending/sec: \t{1}", x.Stats.BytesReceivedPerSec, x.Stats.BytesSentPerSec);*/
         Thread.Sleep(1000);
     }
 }
Example #2
0
 public Socks5ClientDataArgs(Socks5Client client, byte[] buff, int count, int offset)
 {
     cli = client;
     Buffer = buff;
     Count = count;
     Offset = offset;
 }
Example #3
0
 public Socks5ClientDataArgs(Socks5Client client, byte[] buff, int count, int offset)
 {
     cli    = client;
     Buffer = buff;
     Count  = count;
     Offset = offset;
 }
Example #4
0
        public static bool SendLogin(Socks5Client cli, string Username, string Password)
        {
            byte[] x     = new byte[Username.Length + Password.Length + 3];
            int    total = 0;

            x[total++] = 0x01;
            x[total++] = Convert.ToByte(Username.Length);
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Username), 0, x, 2, Username.Length);
            total     += Username.Length;
            x[total++] = Convert.ToByte(Password.Length);
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Password), 0, x, total, Password.Length);
            //send request.
            cli.Client.Send(x);
            byte[] buffer = new byte[512];
            cli.Client.Receive(buffer, 0, buffer.Length);
            switch (buffer[1])
            {
            case 0x00:
                //success.
                return(true);

            default:
                return(false);
            }
        }
Example #5
0
 static void Main(string[] args)
 {
     Socks5Server x = new Socks5Server(IPAddress.Any, 1084);
     x.Start();
     PluginLoader.ChangePluginStatus(false, typeof(socks5.ExamplePlugins.DataHandlerExample));
     //enable plugin.
     /*foreach (object p in PluginLoader.GetPlugins)
     {
         if (p.GetType() == typeof(LoginHandlerExample))
         {
             //enable it.
             PluginLoader.ChangePluginStatus(true, p.GetType());
             Console.WriteLine("Enabled {0}.", p.GetType().ToString());
         }
     }*/
     //Start showing network stats.
     Socks5Client p = new Socks5Client("localhost", 1084, "your.ip.goes.here or domain", 9000, "yolo", "swag");
     p.OnConnected += p_OnConnected;
     p.ConnectAsync();
     while (true)
     {
         /*Console.Clear();
         Console.Write("Total Clients: \t{0}\nTotal Recvd: \t{1:0.00##}MB\nTotal Sent: \t{2:0.00##}MB\n", x.Stats.TotalClients, ((x.Stats.NetworkReceived / 1024f) / 1024f), ((x.Stats.NetworkSent / 1024f) / 1024f));
         Console.Write("Receiving/sec: \t{0}\nSending/sec: \t{1}", x.Stats.BytesReceivedPerSec, x.Stats.BytesSentPerSec);*/
         Thread.Sleep(1000);
     }
 }
Example #6
0
 public override socks5.TCP.Client OnConnectOverride(socks5.Socks.SocksRequest sr)
 {
     //use a socks5client to connect to it and passthru the data.
     //port 9050 is where torsocks is running (linux & windows)
     Socks5Client s = new Socks5Client ("localhost", 9050, sr.Address, sr.Port, "un", "pw");
     if (s.Connect ()) {
         //connect synchronously to block the thread.
         return s.Client;
     } else {
         Console.WriteLine ("Failed!");
         return null;
     }
 }
Example #7
0
        public static socks5.Socks.SocksError SendRequest(Socks5Client cli, string ipOrDomain, int port)
        {
            AddressType type;
            IPAddress   ipAddress;

            if (!IPAddress.TryParse(ipOrDomain, out ipAddress))
            {
                //it's a domain. :D (hopefully).
                type = AddressType.Domain;
            }
            else
            {
                type = AddressType.IP;
            }
            SocksRequest sr = new SocksRequest(StreamTypes.Stream, type, ipOrDomain, port);

            //send data.
            byte[] p = sr.GetData(false);
            p[1] = 0x01;
            cli.Client.Send(p);
            byte[] buffer = new byte[512];
            cli.Client.Receive(buffer, 0, buffer.Length);
            return((SocksError)buffer[1]);
        }
Example #8
0
        public static int Greet(Socks5Client client)
        {
            if (client.reqPass)
            {
                client.Client.Send(new byte[] { 0x05, Convert.ToByte(2), 0x00, 0x02 });
            }
            else
            {
                client.Client.Send(new byte[] { 0x05, Convert.ToByte(1), 0x00 });
            }
            byte[] buffer   = new byte[512];
            int    received = client.Client.Receive(buffer, 0, buffer.Length);

            if (received > 0)
            {
                //check for server version.
                if (buffer[0] == 0x05)
                {
                    switch (buffer[1])
                    {
                    case 0x00:
                        //doesnt require a password.
                        return(1);

                    case 0x02:
                        //requires a password.
                        return(2);

                    case 0xFF:
                        //no supported login methods.
                        break;
                    }
                }
            }
            return(0);
        }
Example #9
0
 public Socks5ClientArgs(Socks5Client p, SocksError x)
 {
     sock   = p;
     status = x;
 }
Example #10
0
        public static bool DoSocksAuth(Socks5Client p, string Username, string Password)
        {
            AuthTypes auth = Socks.Greet(p.Client, p.UseAuthTypes);

            if (auth == AuthTypes.Unsupported)
            {
                p.Client.Disconnect();
                return(false);
            }
            p.enc = new Encryption.SocksEncryption();
            if (auth != AuthTypes.None)
            {
                switch (auth)
                {
                case AuthTypes.Login:
                    //logged in.
                    p.enc.SetType(AuthTypes.Login);
                    //just reqeust login?

                    break;

                case AuthTypes.SocksBoth:
                    //socksboth.
                    p.enc.SetType(AuthTypes.SocksBoth);
                    p.enc.GenerateKeys();
                    //send public key.
                    p.Client.Send(p.enc.GetPublicKey(), out var code1);
                    //now receive key.

                    byte[] buffer  = new byte[4096];
                    int    keysize = p.Client.Receive(buffer, 0, buffer.Length, out var error);
                    p.enc.SetKey(buffer, 0, keysize);
                    //let them know we got it
                    //now receive our encryption key.
                    int enckeysize = p.Client.Receive(buffer, 0, buffer.Length, out error);
                    //decrypt with our public key.
                    byte[] newkey = new byte[enckeysize];
                    Buffer.BlockCopy(buffer, 0, newkey, 0, enckeysize);
                    p.enc.SetEncKey(p.enc.key.Decrypt(newkey, false));
                    //now we share our encryption key.
                    p.Client.Send(p.enc.ShareEncryptionKey(), out var code2);

                    break;

                case AuthTypes.SocksEncrypt:
                    p.enc.SetType(AuthTypes.SocksEncrypt);
                    p.enc.GenerateKeys();
                    //send public key.
                    p.Client.Send(p.enc.GetPublicKey(), out var code3);
                    //now receive key.

                    buffer  = new byte[4096];
                    keysize = p.Client.Receive(buffer, 0, buffer.Length, out error);
                    p.enc.SetKey(buffer, 0, keysize);
                    //now receive our encryption key.
                    enckeysize = p.Client.Receive(buffer, 0, buffer.Length, out error);
                    //decrypt with our public key.
                    newkey = new byte[enckeysize];
                    Buffer.BlockCopy(buffer, 0, newkey, 0, enckeysize);
                    p.enc.SetEncKey(p.enc.key.Decrypt(newkey, false));
                    //now we share our encryption key.

                    p.Client.Send(p.enc.ShareEncryptionKey(), out var code);

                    //socksencrypt.
                    break;

                case AuthTypes.SocksCompress:
                    p.enc.SetType(AuthTypes.SocksCompress);
                    //sockscompress.
                    break;

                default:
                    p.Client.Disconnect();
                    return(false);
                }
                if (p.enc.GetAuthType() != AuthTypes.Login)
                {
                    //now receive login params.
                    byte[] buff = new byte[1024];
                    int    recv = p.Client.Receive(buff, 0, buff.Length, out var error);
                    //check for
                    if (recv > 0)
                    {
                        //check if socks5 version is 5
                        if (buff[0] == 0x05)
                        {
                            //good.
                            if (buff[1] == (byte)AuthTypes.Login)
                            {
                                if (Username == null || Password == null)
                                {
                                    p.Client.Sock.Close(); return(false);
                                }
                                int ret = Socks.SendLogin(p.Client, Username, Password);
                                if (ret != 1)
                                {
                                    p.Client.Sock.Close();
                                    return(false);
                                }
                            }
                            else
                            {
                                //idk? close for now.
                                p.Client.Disconnect();
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        p.Client.Disconnect();
                        return(false);
                    }
                }
                else
                {
                    if (Username == null || Password == null)
                    {
                        p.Client.Sock.Close(); return(false);
                    }
                    int ret = Socks.SendLogin(p.Client, Username, Password);
                    if (ret != 1)
                    {
                        p.Client.Sock.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #11
0
        public static bool DoSocksAuth(Socks5Client p, string Username, string Password)
        {
            AuthTypes auth = Socks.Greet(p.Client, p.UseAuthTypes);
            if (auth == AuthTypes.Unsupported)
            {
                p.Client.Disconnect();
                return false;
            }
            p.enc = new Encryption.SocksEncryption();
            if (auth != AuthTypes.None)
            {
                switch (auth)
                {
                    case AuthTypes.Login:
                        //logged in.
                        p.enc.SetType(AuthTypes.Login);
                        //just reqeust login?

                        break;
                    case AuthTypes.SocksBoth:
                        //socksboth.
                        p.enc.SetType(AuthTypes.SocksBoth);
                        p.enc.GenerateKeys();
                        //send public key.
                        p.Client.Send(p.enc.GetPublicKey());
                        //now receive key.

                        byte[] buffer = new byte[4096];
                        int keysize = p.Client.Receive(buffer, 0, buffer.Length);
                        p.enc.SetKey(buffer, 0, keysize);
                        //let them know we got it
                        //now receive our encryption key.
                        int enckeysize = p.Client.Receive(buffer, 0, buffer.Length);
                        //decrypt with our public key.
                        byte[] newkey = new byte[enckeysize];
                        Buffer.BlockCopy(buffer, 0, newkey, 0, enckeysize);
                        p.enc.SetEncKey(p.enc.key.Decrypt(newkey, false));
                        //now we share our encryption key.
                        p.Client.Send(p.enc.ShareEncryptionKey());

                        break;
                    case AuthTypes.SocksEncrypt:
                        p.enc.SetType(AuthTypes.SocksEncrypt);
                        p.enc.GenerateKeys();
                        //send public key.
                        p.Client.Send(p.enc.GetPublicKey());
                        //now receive key.

                        buffer = new byte[4096];
                        keysize = p.Client.Receive(buffer, 0, buffer.Length);
                        p.enc.SetKey(buffer, 0, keysize);
                        //now receive our encryption key.
                        enckeysize = p.Client.Receive(buffer, 0, buffer.Length);
                        //decrypt with our public key.
                        newkey = new byte[enckeysize];
                        Buffer.BlockCopy(buffer, 0, newkey, 0, enckeysize);
                        p.enc.SetEncKey(p.enc.key.Decrypt(newkey, false));
                        //now we share our encryption key.

                        p.Client.Send(p.enc.ShareEncryptionKey());

                        //socksencrypt.
                        break;
                    case AuthTypes.SocksCompress:
                        p.enc.SetType(AuthTypes.SocksCompress);
                        //sockscompress.
                        break;
                    default:
                        p.Client.Disconnect();
                        return false;
                }
                if (p.enc.GetAuthType() != AuthTypes.Login)
                {
                    //now receive login params.
                    byte[] buff = new byte[1024];
                    int recv = p.Client.Receive(buff, 0, buff.Length);
                    //check for
                    if (recv > 0)
                    {
                        //check if socks5 version is 5
                        if (buff[0] == 0x05)
                        {
                            //good.
                            if (buff[1] == (byte)AuthTypes.Login)
                            {
                                if (Username == null || Password == null) { p.Client.Sock.Close(); return false; }
                                int ret = Socks.SendLogin(p.Client, Username, Password);
                                if (ret != 1)
                                {
                                    p.Client.Sock.Close();
                                    return false;
                                }
                            }
                            else
                            {
                                //idk? close for now.
                                p.Client.Disconnect();
                                return false;
                            }
                        }
                    }
                    else
                    {
                        p.Client.Disconnect();
                        return false;
                    }
                }
                else
                {
                    if (Username == null || Password == null) { p.Client.Sock.Close(); return false; }
                    int ret = Socks.SendLogin(p.Client,Username, Password);
                    if (ret != 1)
                    {
                        p.Client.Sock.Close();
                        return false;
                    }
                }
            }
            return true;
        }
Example #12
0
 public Socks5ClientArgs(Socks5Client p, SocksError x)
 {
     sock = p;
     status = x;
 }