Ejemplo n.º 1
0
 // evil clones?
 public dSocks(dSocks mommy, Socket daddy)
 {
     xUser  = mommy.xUser;
     xPass  = mommy.xPass;
     xHost  = mommy.xHost;
     xPort  = mommy.xPort;
     socket = daddy;
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var listenAddr    = "0.0.0.0";
            var listenPort    = 1080;
            var socketTimeout = 5000;

            var chain = new dChain(socketTimeout);

            if (!ParseArgs(args, ref chain))
            {
                PrintHelp();
                return;
            }


            Console.WriteLine("Starting TCP listener..");
            TcpListener listener = new TcpListener(IPAddress.Parse(listenAddr), listenPort);

            listener.Start(100);

            while (true)
            {
                Console.WriteLine("Accepting connection");
                var client      = listener.AcceptSocket();
                var clientSocks = new dSocks(client);

                new Thread(() =>
                {
                    if (clientSocks.ServerInit() && clientSocks.ParseRequest() && clientSocks.ServerReply(0))
                    {
                        Console.WriteLine("Target {0} {1}", clientSocks.domain, clientSocks.port);

                        Console.WriteLine("Connecting...");
                        var server = chain.Connect();

                        if (!server.Connected)
                        {
                            Console.WriteLine("Couldn't connect to server");
                            client.Close();
                        }
                        else
                        {
                            Console.WriteLine("OK");
                            Task.Factory.StartNew(() =>
                            {
                                chain.Push(server);
                                chain.PushRaw(server, clientSocks.lastRequest);
                                Pipe(client, server);
                            });
                            Task.Factory.StartNew(() =>
                            {
                                chain.Pull(server);
                                Pipe(server, client);
                            });
                        }
                    }
                    else
                    {
                        client.Close();
                    }
                }).Start();
            }
        }