Beispiel #1
0
        public void Open()
        {
            if (ModifiedReq.Address == null || ModifiedReq.Port <= -1 || ModifiedReq.IP == null) { Client.Client.Disconnect(); return; }

            Console.WriteLine("Client: {0}:{1}({2})", ModifiedReq.Address, ModifiedReq.Port, ModifiedReq.IP);
            foreach (ConnectSocketOverrideHandler conn in PluginLoader.LoadPlugin(typeof(ConnectSocketOverrideHandler)))
                if (conn.Enabled)
                {
                    Client pm = conn.OnConnectOverride(ModifiedReq);
                    if (pm != null)
                    {
                        //check if it's connected.
                        if (pm.Sock.Connected)
                        {
                            RemoteClient = pm;
                            //send request right here.
                            byte[] shit = Req.GetData(true);
                            shit[1] = 0x00;
                            //gucci let's go.
                            Client.Client.Send(shit);
                            ConnectHandler(null);
                            return;
                        }
                    }
                }
            var socketArgs = new SocketAsyncEventArgs { RemoteEndPoint = new IPEndPoint(ModifiedReq.IP, ModifiedReq.Port) };
            socketArgs.Completed += socketArgs_Completed;
            RemoteClient.Sock = new Socket(SocketType.Stream, ProtocolType.Tcp);
            RemoteClient.Sock.ReceiveTimeout = 10000;
            RemoteClient.Sock.SendTimeout = 10000;

            if (!RemoteClient.Sock.ConnectAsync(socketArgs))
                ConnectHandler(socketArgs);
        }
Beispiel #2
0
        // private ManualResetEventSlim signal = new ManualResetEventSlim(false);

        private async void AcceptConnections()
        {
            while (accept)
            {
                try
                {
                    Socket x = await p.AcceptSocketAsync();

                    if (x == null)
                    {
                        break;
                    }
                    Client f = new Client(x, PacketSize);
                    f.ClientDisconnecting += ClientDisconnecting;
                    f.onDataReceived += onDataReceived;
                    f.onDataSent += onDataSent;
                    ClientConnected(this, new ClientEventArgs(f));
                }
                catch (ObjectDisposedException ex)
                {
                    Console.WriteLine(ex.Message);
                    break;
                }
            }
        }
Beispiel #3
0
 public void Start()
 {
     if (ModifiedReq.Address == null || ModifiedReq.Port <= -1) { Client.Client.Disconnect(); return; }
     #if DEBUG
     Console.WriteLine("{0}:{1}", ModifiedReq.Address, ModifiedReq.Port);
     #endif
     foreach (ConnectSocketOverrideHandler conn in PluginLoader.LoadPlugin(typeof(ConnectSocketOverrideHandler)))
         if (conn.Enabled)
         {
             Client pm = conn.OnConnectOverride(ModifiedReq);
             if (pm != null)
             {
                 //check if it's connected.
                 if (pm.Sock.Connected)
                 {
                     RemoteClient = pm;
                     //send request right here.
                     byte[] shit = Req.GetData(true);
                     shit[1] = 0x00;
                     //process packet.
                     byte[] output = se.ProcessOutputData(shit, 0, shit.Length);
                     //gucci let's go.
                     Client.Client.Send(output);
                     ConnectHandler(null);
                     return;
                 }
             }
         }
     var socketArgs = new SocketAsyncEventArgs { RemoteEndPoint = new IPEndPoint(ModifiedReq.IP, ModifiedReq.Port) };
     socketArgs.Completed += socketArgs_Completed;
     RemoteClient.Sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     if (!RemoteClient.Sock.ConnectAsync(socketArgs))
         ConnectHandler(socketArgs);
 }
Beispiel #4
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;
 }
Beispiel #5
0
        public void ConnectAsync()
        {
            //
            p = new Socket(SocketType.Stream, ProtocolType.Tcp);

            Client = new Client(p, 2048);
            Client.ClientDisconnecting += ClientClientDisconnecting;
            Client.Sock.BeginConnect(new IPEndPoint(ipAddress, Port), new AsyncCallback(onConnected), Client);
            //return status?
        }
Beispiel #6
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;
 }
Beispiel #7
0
 public void Dispose()
 {
     if (isDisposing)
     {
         return;
     }
     isDisposing = true;
     disconnected = true;
     this.Client = null;
     this.RemoteClient = null;
     this.ModifiedReq = null;
     this.Req = null;
 }
Beispiel #8
0
 public ClientEventArgs(Client client)
 {
     Client = client;
 }
Beispiel #9
0
        public static SocksError SendRequest(Client cli, SocksEncryption enc, 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;
            //process data.
            cli.Send(enc.ProcessOutputData(p, 0, p.Length));
            byte[] buffer = new byte[512];
            //process input data.
            int recv = cli.Receive(buffer, 0, buffer.Length);
            if(recv == -1)
            {
                return SocksError.Failure;
            }
            byte[] buff = enc.ProcessInputData(buffer, 0, recv);

            return (SocksError)buff[1];
        }
Beispiel #10
0
 public static int SendLogin(Client 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.Send(x);
     byte[] buffer = new byte[512];
     cli.Receive(buffer, 0, buffer.Length);
     if (buffer[1] == 0x00)
     {
         return 1;
     }
     else if (buffer[1] == 0xFF)
     {
         return 0;
     }
     return 0;
 }
Beispiel #11
0
 public static AuthTypes Greet(Client client)
 {
     client.Send(new byte[] { 0x05, Convert.ToByte(5), (byte)AuthTypes.None, (byte)AuthTypes.Login, (byte)AuthTypes.SocksCompress, (byte)AuthTypes.SocksEncrypt, (byte)AuthTypes.SocksBoth });
     byte[] buffer = new byte[512];
     int received = client.Receive(buffer, 0, buffer.Length);
     if(received > 0)
     {
         //check for server version.
         if (buffer[0] == 0x05)
         {
             return (AuthTypes)buffer[1];
         }
     }
     return 0;
 }
 /// <summary>
 /// Handle client connected callback. Useful for IPblocking.
 /// </summary>
 /// <param name="Client"></param>
 /// <returns>Return true to allow the connection, return false to deny it.</returns>
 public abstract bool OnConnect(Client Client, IPEndPoint IP);
Beispiel #13
0
 public SocksClient(Client cli)
 {
     Client = cli;
 }
Beispiel #14
0
        public static SocksEncryption RequestSpecialMode(List<AuthTypes> auth, Client client)
        {
            //select mode, do key exchange if encryption, or start compression.
            if (auth.Contains(AuthTypes.SocksBoth))
            {
                //tell client that we chose socksboth.
                client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.SocksBoth });
                //wait for public key.
                SocksEncryption ph = new SocksEncryption();
                ph.GenerateKeys();
                //wait for public key.
                byte[] buffer = new byte[4096];
                int keysize = client.Receive(buffer, 0, buffer.Length);
                //store key in our encryption class.
                ph.SetKey(buffer, 0, keysize);
                //send key.
                client.Send(ph.GetPublicKey());
                //now we give them our key.
                client.Send(ph.ShareEncryptionKey());
                //send more.
                int enckeysize = client.Receive(buffer, 0, buffer.Length);
                //decrypt with our public key.
                byte[] newkey = new byte[enckeysize];
                Buffer.BlockCopy(buffer, 0, newkey, 0, enckeysize);
                ph.SetEncKey(ph.key.Decrypt(newkey, false));

                ph.SetType(AuthTypes.SocksBoth);
                //ready up our client.
                return ph;
            }
            else if (auth.Contains(AuthTypes.SocksEncrypt))
            {
                //tell client that we chose socksboth.
                client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.SocksEncrypt });
                //wait for public key.
                SocksEncryption ph = new SocksEncryption();
                ph.GenerateKeys();
                //wait for public key.
                byte[] buffer = new byte[4096];
                int keysize = client.Receive(buffer, 0, buffer.Length);
                //store key in our encryption class.
                ph.SetKey(buffer, 0, keysize);
                ph.SetType(AuthTypes.SocksBoth);
                //ready up our client.
                return ph;
            }
            else if (auth.Contains(AuthTypes.SocksCompress))
            {
                //start compression.
                client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.SocksCompress });
                SocksEncryption ph = new SocksEncryption();
                ph.SetType(AuthTypes.SocksCompress);
                //ready
            }
            else if (auth.Contains(AuthTypes.Login))
            {
                SocksEncryption ph = new SocksEncryption();
                ph.SetType(AuthTypes.Login);
                return ph;
            }
            return null;
        }
Beispiel #15
0
 public static int Receive(Client client, out byte[] buffer)
 {
     buffer = new byte[65535];
     return client.Receive(buffer, 0, buffer.Length);
 }
Beispiel #16
0
        private void onConnected(IAsyncResult res)
        {
            Client = (Client)res.AsyncState;
            try
            {
                Client.Sock.EndConnect(res);
            }
            catch (SocketException ex)
            {
                this.OnConnected(this, new Socks5ClientArgs(null, SocksError.Failure));
                return;
            }
            if (Socks.DoSocksAuth(this, Username, Password))
            {
                SocksError p = Socks.SendRequest(Client, enc, Dest, Destport);
                Client.onDataReceived += Client_onDataReceived;
                this.OnConnected(this, new Socks5ClientArgs(this, p));

            }
            else
                this.OnConnected(this, new Socks5ClientArgs(this, SocksError.Failure));
        }
Beispiel #17
0
 public bool Connect()
 {
     try
     {
         p = new Socket(SocketType.Stream, ProtocolType.Tcp);
         Client = new Client(p, 65535);
         Client.Sock.Connect(new IPEndPoint(ipAddress, Port));
         //try the greeting.
         //Client.onDataReceived += Client_onDataReceived;
         if (Socks.DoSocksAuth(this, Username, Password))
             if (Socks.SendRequest(Client, enc, Dest, Destport) == SocksError.Granted)
                 return true;
         return false;
     }
     catch
     {
         return false;
     }
 }