Ejemplo n.º 1
0
        void TestServer()
        {
            if (testing == false)
            {
                this.Dispatcher.Invoke(() =>
                {
                    txtStatus.Text       = "TEST";
                    txtStatus.Background = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0x00));
                });

                testing = true;
                try
                {
                    Socks5Client.Socks5Client p = new Socks5Client.Socks5Client("localhost", 80, "www.baidu.com", 80, "lemur", "bison");
                    // p.OnConnected += p_OnConnected;
                    if (p.Connect())
                    {
                        DoLog("====       TEST OK       ====");
                        this.Dispatcher.Invoke(() =>
                        {
                            txtStatus.Text       = "OK";
                            txtStatus.Background = new SolidColorBrush(Color.FromRgb(0x00, 0xff, 0x00));
                        });
                        p.Disconnect();
                    }
                    else
                    {
                        DoLog("====        CHK NET        ====");
                        this.Dispatcher.Invoke(() =>
                        {
                            txtStatus.Text       = "LOCAL";
                            txtStatus.Background = new SolidColorBrush(Color.FromRgb(0xff, 0x88, 0x00));
                        });
                    }


                    //p.Send(new byte[] {0x11, 0x21});
                }
                catch (Exception ex)
                {
                    DoLog("####     TEST FAIL    ####");
                    this.Dispatcher.Invoke(() =>
                    {
                        txtStatus.Text       = "OFF";
                        txtStatus.Background = new SolidColorBrush(Color.FromRgb(0xff, 0x00, 0x00));
                    });
                    btnResetSrv_Click(null, null);
                }
                finally
                {
                    testing = false;
                }
            }
        }
Ejemplo n.º 2
0
        private void btnResetSrv_Click(object sender, RoutedEventArgs e)
        {
            var thread = new Thread(() =>
            {
                if (x != null)
                {
                    DoLog("SERVER STOPPING!");
                    try
                    {
                        x.Stop();
                    }
                    catch (Exception ex)
                    {
                        DoLog(ex.Message);
                    }
                    x = null;

                    DoLog("\tSERVER STOPPED!");
                }
                DoLog("SERVER RESTARTING!");
                x = new Socks5Server(IPAddress.Any, port);
                x.Start();
                PluginLoader.ChangePluginStatus(false, typeof(DataHandlerExample));
                //enable plugin.
                foreach (object pl in PluginLoader.GetPlugins)
                {
                    //if (pl.GetType() == typeof(LoginHandlerExample))
                    //{
                    //    //enable it.
                    //    PluginLoader.ChangePluginStatus(true, pl.GetType());
                    //    Console.WriteLine("Enabled {0}.", pl.GetType().ToString());
                    //}
                }

                //Start showing network stats.
                Socks5Client.Socks5Client p = new Socks5Client.Socks5Client("localhost", 80, "127.0.0.1", 80, "lemur", "bison");
                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);
                //}
                DoLog("\tSERVER RESTARTED!");
            });

            thread.Start();
        }
Ejemplo n.º 3
0
        public static bool DoSocksAuth(Socks5Client p, string Username, string Password)
        {
            AuthTypes auth = Socks.Greet(p.Client);

            if (auth == AuthTypes.Unsupported)
            {
                p.Client.Disconnect();
                return(false);
            }
            if (auth != AuthTypes.None)
            {
                p.enc = new Encryption.SocksEncryption();
                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);
                    //let them know we got it
                    p.Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Zero });
                    //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));
                    //wait for server to confirm we got it.
                    p.Client.Receive(buffer, 0, buffer.Length);
                    //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);
        }
Ejemplo n.º 4
0
        public static bool DoSocksAuth(Socks5Client p, string Username, string Password)
        {
            AuthTypes auth = Socks.Greet(p.Client);
            if (auth == AuthTypes.Unsupported)
            {
                p.Client.Disconnect();
                return false;
            }
            if (auth != AuthTypes.None)
            {
                p.enc = new Encryption.SocksEncryption();
                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);
                        //let them know we got it
                        p.Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Zero });
                        //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));
                        //wait for server to confirm we got it.
                        p.Client.Receive(buffer, 0, buffer.Length);
                        //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;
        }
Ejemplo n.º 5
0
        private void btnResetSrv_Click(object sender, RoutedEventArgs e)
        {
            var thread = new Thread(() =>
            {
                if (x != null)
                {

                    DoLog("SERVER STOPPING!");
                    try
                    {
                        x.Stop();
                    }
                    catch (Exception ex)
                    {
                        DoLog(ex.Message);
                    }
                    x = null;

                    DoLog("\tSERVER STOPPED!");
                }
                DoLog("SERVER RESTARTING!");
                x = new Socks5Server(IPAddress.Any, port);
                x.Start();
                PluginLoader.ChangePluginStatus(false, typeof(DataHandlerExample));
                //enable plugin.
                foreach (object pl in PluginLoader.GetPlugins)
                {
                    //if (pl.GetType() == typeof(LoginHandlerExample))
                    //{
                    //    //enable it.
                    //    PluginLoader.ChangePluginStatus(true, pl.GetType());
                    //    Console.WriteLine("Enabled {0}.", pl.GetType().ToString());
                    //}
                }

                //Start showing network stats.
                Socks5Client.Socks5Client p = new Socks5Client.Socks5Client("localhost", 80, "127.0.0.1", 80, "lemur", "bison");
                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);
                //}
                DoLog("\tSERVER RESTARTED!");
            });
            thread.Start();
        }
Ejemplo n.º 6
0
        void TestServer()
        {
            if (testing == false)
            {
                this.Dispatcher.Invoke(() =>
                {
                    txtStatus.Text = "TEST";
                    txtStatus.Background = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0x00));
                });

                testing = true;
                try
                {

                    Socks5Client.Socks5Client p = new Socks5Client.Socks5Client("localhost", 80, "www.baidu.com", 80, "lemur", "bison");
                    // p.OnConnected += p_OnConnected;
                    if (p.Connect())
                    {
                        DoLog("====       TEST OK       ====");
                        this.Dispatcher.Invoke(() =>
                        {
                            txtStatus.Text = "OK";
                            txtStatus.Background = new SolidColorBrush(Color.FromRgb(0x00, 0xff, 0x00));
                        });
                        p.Disconnect();
                    }
                    else
                    {
                        DoLog("====        CHK NET        ====");
                        this.Dispatcher.Invoke(() =>
                        {
                            txtStatus.Text = "LOCAL";
                            txtStatus.Background = new SolidColorBrush(Color.FromRgb(0xff, 0x88, 0x00));
                        });
                    }

                    //p.Send(new byte[] {0x11, 0x21});

                }
                catch (Exception ex)
                {
                    DoLog("####     TEST FAIL    ####");
                    this.Dispatcher.Invoke(() =>
                    {
                        txtStatus.Text = "OFF";
                        txtStatus.Background = new SolidColorBrush(Color.FromRgb(0xff, 0x00, 0x00));
                    });
                    btnResetSrv_Click(null, null);
                }
                finally
                {
                    testing = false;
                }
            }
        }