Example #1
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;
 }
Example #2
0
 public DataEventArgs(Client client, byte[] buffer, int count, SocksRequest req = null)
 {
     Client = client;
     Buffer = buffer;
     Count = count;
     Offset = 0;
     Request = req;
 }
Example #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;
 }
Example #4
0
        public void Begin(int PacketSize, int Timeout)
        {
            Client.onClientDisconnected += Client_onClientDisconnected;
            List <AuthTypes> authtypes = Socks5.RequestAuth(this);

            if (authtypes.Count <= 0)
            {
                Client.Send(new byte[] { 0x00, 0xFF });
                Client.Disconnect();
                return;
            }
            else if (Authentication && this.OnClientAuthenticating != null)
            {
                //request login.
                User user = Socks5.RequestLogin(this);
                if (user == null)
                {
                    Client.Disconnect();
                    return;
                }
                LoginStatus status = this.OnClientAuthenticating(this, new SocksAuthenticationEventArgs(user));
                Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)status });
                if (status == LoginStatus.Denied)
                {
                    Client.Disconnect();
                    return;
                }
                else if (status == LoginStatus.Correct)
                {
                    Authenticated = true;
                }
                //read password and invoke.
                //this.OnClientAuthenticating(this, new SocksAuthenticationEventArgs(..));
            }
            else
            {//no username/password required?
                Authenticated = true;
                Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Zero });
            }
            SocksRequest req = Socks5.RequestTunnel(this);

            if (req == null)
            {
                Client.Disconnect(); return;
            }
            SocksTunnel x = new SocksTunnel(this, req, PacketSize, Timeout);

            x.Open();
        }
Example #5
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;
 }
Example #6
0
        public void Begin(IPAddress outboundInterface, int PacketSize, int Timeout)
        {
            Client.onClientDisconnected += Client_onClientDisconnected;
            List<AuthTypes> authtypes = Socks5.RequestAuth(this);
            if (authtypes.Count <= 0)
            {
                Client.Send(new byte[] { 0x00, 0xFF });
                Client.Disconnect();
                return;
            }
            this.Authenticated = 0;
            SocksEncryption w = null;
            List<object> lhandlers = PluginLoader.LoadPlugin(typeof(LoginHandler));
            //check out different auth types, none will have no authentication, the rest do.
            if (lhandlers.Count > 0 && (authtypes.Contains(AuthTypes.SocksBoth) || authtypes.Contains(AuthTypes.SocksEncrypt) || authtypes.Contains(AuthTypes.SocksCompress) || authtypes.Contains(AuthTypes.Login)))
            {
                //this is the preferred method.
                w = Socks5.RequestSpecialMode(authtypes, Client);
                foreach (LoginHandler lh in lhandlers)
                {
					//request login.
					User user = Socks5.RequestLogin(this);
					if (user == null)
					{
						Client.Disconnect();
						return;
					}
					LoginStatus status = lh.HandleLogin(user);
					Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)status });
					if (status == LoginStatus.Denied)
					{
						Client.Disconnect();
						return;
					}
					else if (status == LoginStatus.Correct)
					{
						Authenticated = (w.GetAuthType() == AuthTypes.Login ? 1 : 2);
						break;
					}
                }
            }
            else if (authtypes.Contains(AuthTypes.None))
            {
                //no authentication.
                if (lhandlers.Count <= 0)
                {
                    //unsupported methods y0
                    Authenticated = 1;
                    Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Zero });
                }
                else
                {
                    //unsupported.
                    Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.Unsupported });
                    Client.Disconnect();
                    return;
                }
            }
            else
            {
                //unsupported.
                Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.Unsupported });
                Client.Disconnect();
                return;
            }
            //Request Site Data.
            if (Authenticated == 1)
            {
                w = new SocksEncryption();
                w.SetType(AuthTypes.Login);
                SocksRequest req = Socks5.RequestTunnel(this, w);
                if (req == null) { Client.Disconnect(); return; }
                req1 = new SocksRequest(req.StreamType, req.Type, req.Address, req.Port);
                //call on plugins for connect callbacks.
                foreach (ConnectHandler conn in PluginLoader.LoadPlugin(typeof(ConnectHandler)))
					if (conn.OnConnect(req1) == false)
					{
						req.Error = SocksError.Failure;
						Client.Send(req.GetData(true));
						Client.Disconnect();
						return;
					}  
                //Send Tunnel Data back.
                SocksTunnel x = new SocksTunnel(this, req, req1, PacketSize, Timeout);
                x.Open(outboundInterface);
            }
            else if (Authenticated == 2)
            {
                SocksRequest req = Socks5.RequestTunnel(this, w);
                if (req == null) { Client.Disconnect(); return; }
                req1 = new SocksRequest(req.StreamType, req.Type, req.Address, req.Port);
                foreach (ConnectHandler conn in PluginLoader.LoadPlugin(typeof(ConnectHandler)))
					if (conn.OnConnect(req1) == false)
					{
						req.Error = SocksError.Failure;
						Client.Send(req.GetData(true));
						Client.Disconnect();
						return;
					}  
                //Send Tunnel Data back.
                SocksSpecialTunnel x = new SocksSpecialTunnel(this, w, req, req1, PacketSize, Timeout);
                x.Open(outboundInterface);
            }
        }
Example #7
0
        public void Begin(IPAddress outboundInterface, int PacketSize, int Timeout)
        {
            Client.onClientDisconnected += Client_onClientDisconnected;
            List <AuthTypes> authtypes = Socks5.RequestAuth(this);

            if (authtypes.Count <= 0)
            {
                Client.Send(new byte[] { 0x00, 0xFF });
                Client.Disconnect();
                return;
            }
            this.Authenticated = 0;
            SocksEncryption w         = null;
            List <object>   lhandlers = PluginLoader.LoadPlugin(typeof(LoginHandler));

            //check out different auth types, none will have no authentication, the rest do.
            if (lhandlers.Count > 0 &&
                (authtypes.Contains(AuthTypes.SocksBoth) ||
                 authtypes.Contains(AuthTypes.SocksEncrypt) ||
                 authtypes.Contains(AuthTypes.SocksCompress) ||
                 authtypes.Contains(AuthTypes.Login)))
            {
                //this is the preferred method.
                w = Socks5.RequestSpecialMode(authtypes, Client);
                foreach (LoginHandler lh in lhandlers)
                {
                    //request login.
                    User user = Socks5.RequestLogin(this);
                    if (user == null)
                    {
                        Client.Disconnect();
                        return;
                    }
                    LoginStatus status = lh.HandleLogin(user);
                    Client.Send(new byte[] { user.AuthTypeVersion, (byte)status });
                    if (status == LoginStatus.Denied)
                    {
                        Client.Disconnect();
                        return;
                    }
                    else if (status == LoginStatus.Correct)
                    {
                        Authenticated = (w.GetAuthType() == AuthTypes.Login ? 1 : 2);
                        break;
                    }
                }
            }
            else if (authtypes.Contains(AuthTypes.None))
            {
                //no authentication.
                if (lhandlers.Count <= 0)
                {
                    //unsupported methods y0
                    Authenticated = 1;
                    Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Zero });
                }
                else
                {
                    //unsupported.
                    Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.Unsupported });
                    Client.Disconnect();
                    return;
                }
            }
            else
            {
                //unsupported.
                Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.Unsupported });
                Client.Disconnect();
                return;
            }
            //Request Site Data.
            if (Authenticated == 1)
            {
                w = new SocksEncryption();
                w.SetType(AuthTypes.Login);
                SocksRequest req = Socks5.RequestTunnel(this, w);
                if (req == null)
                {
                    Client.Disconnect(); return;
                }
                req1 = new SocksRequest(req.StreamType, req.Type, req.Address, req.Port);
                //call on plugins for connect callbacks.
                foreach (ConnectHandler conn in PluginLoader.LoadPlugin(typeof(ConnectHandler)))
                {
                    if (conn.OnConnect(req1) == false)
                    {
                        req.Error = SocksError.Failure;
                        Client.Send(req.GetData(true));
                        Client.Disconnect();
                        return;
                    }
                }
                //Send Tunnel Data back.
                SocksTunnel x = new SocksTunnel(this, req, req1, PacketSize, Timeout);
                x.Open(outboundInterface);
            }
            else if (Authenticated == 2)
            {
                SocksRequest req = Socks5.RequestTunnel(this, w);
                if (req == null)
                {
                    Client.Disconnect(); return;
                }
                req1 = new SocksRequest(req.StreamType, req.Type, req.Address, req.Port);
                foreach (ConnectHandler conn in PluginLoader.LoadPlugin(typeof(ConnectHandler)))
                {
                    if (conn.OnConnect(req1) == false)
                    {
                        req.Error = SocksError.Failure;
                        Client.Send(req.GetData(true));
                        Client.Disconnect();
                        return;
                    }
                }
                //Send Tunnel Data back.
                SocksSpecialTunnel x = new SocksSpecialTunnel(this, w, req, req1, PacketSize, Timeout);
                x.Open(outboundInterface);
            }
        }
Example #8
0
        public void Begin(int PacketSize, int Timeout)
        {
            Client.onClientDisconnected += Client_onClientDisconnected;
            List <AuthTypes> authtypes = Socks5.RequestAuth(this);

            if (authtypes.Count <= 0)
            {
                Client.Send(new byte[] { 0x00, 0xFF });
                Client.Disconnect();
                return;
            }
            foreach (LoginHandler lh in PluginLoader.LoadPlugin(typeof(LoginHandler)))
            {
                if (lh.Enabled)
                {
                    if (!authtypes.Contains(AuthTypes.Login)) //disconnect.
                    {
                        Client.Send(new byte[] { (byte)HeaderTypes.Socks5, 0xFF });
                        Client.Disconnect();
                        return;
                    }
                    //request login.
                    User user = Socks5.RequestLogin(this);
                    if (user == null)
                    {
                        Client.Disconnect();
                        return;
                    }
                    LoginStatus status = lh.HandleLogin(user);
                    Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)status });
                    if (status == LoginStatus.Denied)
                    {
                        Client.Disconnect();
                        return;
                    }
                    else if (status == LoginStatus.Correct)
                    {
                        Authenticated = true;
                        break;
                    }
                }
            }
            //Request Site Data.
            if (!Authenticated)
            {//no username/password required?
                Authenticated = true;
                Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Zero });
            }

            SocksRequest req = Socks5.RequestTunnel(this);

            if (req == null)
            {
                Client.Disconnect(); return;
            }
            req1 = new SocksRequest(req.StreamType, req.Type, req.Address, req.Port);
            //call on plugins for connect callbacks.
            foreach (ConnectHandler conn in PluginLoader.LoadPlugin(typeof(ConnectHandler)))
            {
                if (conn.Enabled)
                {
                    if (conn.OnConnect(req1) == false)
                    {
                        req.Error = SocksError.Failure;
                        Client.Send(req.GetData());
                        Client.Disconnect();
                        return;
                    }
                }
            }

            //Send Tunnel Data back.
            SocksTunnel x = new SocksTunnel(this, req, req1, PacketSize, Timeout);

            x.Open();
        }
Example #9
0
 /// <summary>
 /// Handle request callback.
 /// </summary>
 /// <param name="Request"></param>
 /// <returns>Return true to allow the connection, return false to deny it.</returns>
 public abstract bool OnConnect(SocksRequest Request);
 /// <summary>
 /// Override the connection, to do whatever you want with it. Client is a wrapper around a socket.
 /// </summary>
 /// <param name="sr">The original request params.</param>
 /// <returns></returns>
 public abstract Client OnConnectOverride(SocksRequest sr);
Example #11
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];
        }