Exemple #1
0
 public void Open()
 {
     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)))
     {
         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);
 }
Exemple #2
0
 public DataEventArgs(Client client, byte[] buffer, int count)
 {
     Client = client;
     Buffer = buffer;
     Count = count;
     Offset = 0;
 }
Exemple #3
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;
 }
Exemple #4
0
 public DataEventArgs(Client client, byte[] buffer, int count, SocksRequest req = null)
 {
     Client = client;
     Buffer = buffer;
     Count = count;
     Offset = 0;
     Request = req;
 }
Exemple #5
0
 public void ConnectAsync()
 {
     //
     p = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     Client = new Client(p, 2048);
     Client.onClientDisconnected += Client_onClientDisconnected;
     Client.Sock.BeginConnect(new IPEndPoint(ipAddress, Port), new AsyncCallback(onConnected), Client);
     //return status?
 }
Exemple #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;
 }
Exemple #7
0
        public override socks5.TCP.Client OnConnectOverride(socks5.Socks.SocksRequest sr)
        {
            if (!IsGfwFucked(sr.Address))
                return null;
            var proxysock = new Socket(SocketType.Stream, ProtocolType.Tcp);
            HttpWebRequest httpreq = HttpWebRequest.CreateHttp(sr.Address);
            WebProxy wp = httpreq.Proxy as WebProxy;
            wp.Address=new Uri(proxyurl);
            var response = httpreq.GetResponse();

            var client = new Client(new Socket(SocketType.Stream, ProtocolType.Tcp), 65535);

            return client;
        }
Exemple #8
0
 void AcceptClient(IAsyncResult res)
 {
     try
     {
         TcpListener px = (TcpListener)res.AsyncState;
         Socket x = px.EndAcceptSocket(res);
         Task.Set();
         Client f = new Client(x, PacketSize);
         f.onClientDisconnected += onClientDisconnected;
         onClientConnected(this, new ClientEventArgs(f));
     }
     catch(Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
  }
Exemple #9
0
 void AcceptClient(IAsyncResult res)
 {
     try
     {
         TcpListener px = (TcpListener)res.AsyncState;
         Socket x = px.EndAcceptSocket(res);
         Task.Set();
         Client f = new Client(x, PacketSize);
         //f.onClientDisconnected += onClientDisconnected;
         //f.onDataReceived += onDataReceived;
         //f.onDataSent += onDataSent;
         onClientConnected(this, new ClientEventArgs(f));
     }
     catch(Exception ex)
     {
         Console.WriteLine(ex.ToString());
         //server stopped or client errored?
     }
  }
Exemple #10
0
 public bool Connect()
 {
     try
     {
         p = new Socket(AddressFamily.InterNetwork, 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;
     }
 }
Exemple #11
0
 public ClientEventArgs(Client client)
 {
     Client = client;
 }
Exemple #12
0
 public SocksClient(Client cli)
 {
     Client = cli;
 }
Exemple #13
0
 public static byte[] Receive(Client client)
 {
     byte[] buffer = new byte[2048];
     int received = client.Receive(buffer, 0, buffer.Length);
     if (received != -1)
     {
         return buffer;
     }
     else
         return null;
 }
Exemple #14
0
        public static AuthTypes Greet(Client client, IList<AuthTypes> supportedAuthTypes = null)
        {
            if (supportedAuthTypes == null)
                supportedAuthTypes = new[] { AuthTypes.None, AuthTypes.Login, AuthTypes.SocksEncrypt };

            // https://www.ietf.org/rfc/rfc1928.txt [Page 3]
            var bytes = new byte[supportedAuthTypes.Count + 2];
            bytes[0] = 0x05; // protocol version - socks5
            bytes[1] = (byte)supportedAuthTypes.Count;
            for (var i = 0; i < supportedAuthTypes.Count; i++)
            {
                bytes[i + 2] = (byte)supportedAuthTypes[i];
            }
            client.Send(bytes);

            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;
        }
Exemple #15
0
 public static AuthTypes Greet(Client client)
 {
     client.Send(new byte[] { 0x05, Convert.ToByte(3), (byte)AuthTypes.None, (byte)AuthTypes.Login, (byte)AuthTypes.SocksEncrypt });//(byte)AuthTypes.SocksBoth });//(byte)AuthTypes.SocksCompress
     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;
 }
Exemple #16
0
        public static socks5.Socks.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];
        }
Exemple #17
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;
 }
Exemple #18
0
 private void onConnected(IAsyncResult res)
 {
     Client = (Client)res.AsyncState;
     try
     {
         Client.Sock.EndConnect(res);
     }
     catch
     {
         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));
 }
Exemple #19
0
 public static int Receive(Client client, out byte[] buffer)
 {
     buffer = new byte[65535];
     return client.Receive(buffer, 0, buffer.Length);
 }
Exemple #20
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;
        }