コード例 #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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
ファイル: Socks.cs プロジェクト: ZeDingo/Socks5
        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];
        }
コード例 #4
0
        public void Start(int PacketSize, int Timeout)
        {
            Client.ClientDisconnecting += ClientClientDisconnecting;

            SocksEncryption w = null;

            if (Client == null)
            {
                this.Dispose();
                return;
            }

            Authenticated = AuthenticateConnection(ref w);
            //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.Enabled)
                    {
                        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.TunnelDisposing += x_TunnelDisposing;
                x.Open();
            }
            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);
                if (PluginLoader.LoadPlugin(typeof(ConnectHandler)).Cast <ConnectHandler>().Where(conn => conn.Enabled).Any(conn => 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.TunnelDisposing += x_TunnelDisposing;
                x.Start();
            }
        }