Exemplo n.º 1
0
 public Socks5ClientDataArgs(Socks5Client client, byte[] buff, int count, int offset)
 {
     cli    = client;
     Buffer = buff;
     Count  = count;
     Offset = offset;
 }
Exemplo n.º 2
0
        private Socks5Client EstablishConnection(Iq stanza, string sid, IEnumerable <Streamhost> hosts)
        {
            bool flag = false;

            foreach (Streamhost streamhost in hosts)
            {
                try
                {
                    Socks5Client client = new Socks5Client(streamhost.Host, streamhost.Port, null, null);
                    flag = true;
                    string domain = this.Sha1(sid + stanza.From + stanza.To);
                    if (client.Request(SocksCommand.Connect, domain, 0).Status != ReplyStatus.Succeeded)
                    {
                        throw new Socks5Exception("SOCKS5 Connect request failed.");
                    }
                    base.im.IqResult(stanza, Xml.Element("query", "http://jabber.org/protocol/bytestreams").Attr("sid", sid).Child(Xml.Element("streamhost-used", null).Attr("jid", streamhost.Jid.ToString())));
                    return(client);
                }
                catch
                {
                    if (flag)
                    {
                        break;
                    }
                }
            }
            base.im.IqError(stanza, ErrorType.Cancel, ErrorCondition.ItemNotFound, null, new XmlElement[0]);
            throw new XmppException("Couldn't connect to streamhost.");
        }
Exemplo n.º 3
0
 public Socks5ClientDataArgs(Socks5Client client, byte[] buff, int count, int offset)
 {
     cli = client;
     Buffer = buff;
     Count = count;
     Offset = offset;
 }
Exemplo n.º 4
0
        public async void TestConnectByIPv4Async()
        {
            var    socks  = new Socks5Client(Socks5ProxyList[1], Socks5ProxyPorts[1]);
            var    host   = "74.125.197.99";        // ResolveIPv4 ("www.google.com");
            Socket socket = null;

            if (host == null)
            {
                return;
            }

            try {
                socket = await socks.ConnectAsync(host, 80, 10 * 1000);

                socket.Disconnect(false);
            } catch (TimeoutException) {
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
Exemplo n.º 5
0
        public void Socks5_Test_03_ConnectStream()
        {
            this.ConnectClients();
            ManualResetEvent Error  = new ManualResetEvent(false);
            ManualResetEvent Done   = new ManualResetEvent(false);
            Socks5Client     Client = new Socks5Client("waher.se", 1080, "socks5.waher.se",
                                                       new TextWriterSniffer(Console.Out, BinaryPresentationMethod.Hexadecimal));

            Client.OnStateChange += (sender, e) =>
            {
                switch (Client.State)
                {
                case Socks5State.Authenticated:
                    Client.CONNECT("Stream0001", this.client1.FullJID, this.client2.FullJID);
                    break;

                case Socks5State.Connected:
                    Done.Set();
                    break;

                case Socks5State.Error:
                case Socks5State.Offline:
                    Error.Set();
                    break;
                }
            };

            Assert.AreEqual(0, WaitHandle.WaitAny(new WaitHandle[] { Done, Error }, 10000), "Unable to connect.");
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Socks5Server x = new Socks5Server(IPAddress.Any, 10084);

            x.Start();
            PluginLoader.ChangePluginStatus(false, typeof(DataHandlerExample));
            //enable plugin.
            foreach (object pl in PluginLoader.GetPlugins)
            {
                //if (pl.GetType() == typeof(LoginHandlerExample))
                //{
                //    //enable it.
                //    PluginLoader.ChangePluginStatus(true, pl.GetType());
                //    Console.WriteLine("Enabled {0}.", pl.GetType().ToString());
                //}
            }
            //Start showing network stats.
            Socks5Client p = new Socks5Client("localhost", 10084, "127.0.0.1", 10084, "yolo", "swag");

            p.OnConnected += p_OnConnected;
            p.ConnectAsync();
            //while (true)
            //{
            // //   Console.Clear();
            //    Console.Write("Total Clients: \t{0}\nTotal Recvd: \t{1:0.00##}MB\nTotal Sent: \t{2:0.00##}MB\n", x.Stats.TotalClients, ((x.Stats.NetworkReceived / 1024f) / 1024f), ((x.Stats.NetworkSent / 1024f) / 1024f));
            //    Console.Write("Receiving/sec: \t{0}\nSending/sec: \t{1}", x.Stats.BytesReceivedPerSec, x.Stats.BytesSentPerSec);
            //    Thread.Sleep(1000);
            //}
        }
Exemplo n.º 7
0
        public async void TestConnectWithBadCredentialsAsync()
        {
            using (var proxy = new Socks5ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

                var    credentials = new NetworkCredential("username", "bad");
                var    socks       = new Socks5Client(proxy.IPAddress.ToString(), proxy.Port, credentials);
                Socket socket      = null;

                try {
                    socket = await socks.ConnectAsync("www.google.com", 80, ConnectTimeout);

                    socket.Disconnect(false);
                    Assert.Fail("Expected AuthenticationException");
                } catch (AuthenticationException) {
                    // this is what we expect to get
                    Assert.Pass("Got an AuthenticationException just as expected");
                } catch (TimeoutException) {
                    Assert.Inconclusive("Timed out.");
                } catch (Exception ex) {
                    Assert.Fail(ex.Message);
                } finally {
                    if (socket != null)
                    {
                        socket.Dispose();
                    }
                }
            }
        }
Exemplo n.º 8
0
        public async void TestConnectByIPv6Async()
        {
            using (var proxy = new Socks5ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

                var    socks  = new Socks5Client(proxy.IPAddress.ToString(), proxy.Port);
                var    host   = "2607:f8b0:400e:c03::69";            // ResolveIPv6 ("www.google.com");
                Socket socket = null;

                if (host == null)
                {
                    return;
                }

                try {
                    socket = await socks.ConnectAsync(host, 80, ConnectTimeout);

                    socket.Disconnect(false);
                } catch (ProxyProtocolException ex) {
                    Assert.IsTrue(ex.Message.StartsWith($"Failed to connect to {host}:80: ", StringComparison.Ordinal), ex.Message);
                    Assert.Inconclusive(ex.Message);
                } catch (TimeoutException) {
                    Assert.Inconclusive("Timed out.");
                } catch (Exception ex) {
                    Assert.Fail(ex.Message);
                } finally {
                    if (socket != null)
                    {
                        socket.Dispose();
                    }
                }
            }
        }
Exemplo n.º 9
0
        public async void TestConnectByIPv4Async()
        {
            using (var proxy = new Socks5ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

                var    socks  = new Socks5Client(proxy.IPAddress.ToString(), proxy.Port);
                var    host   = "74.125.197.99";            // ResolveIPv4 ("www.google.com");
                Socket socket = null;

                if (host == null)
                {
                    return;
                }

                try {
                    socket = await socks.ConnectAsync(host, 80, ConnectTimeout);

                    socket.Disconnect(false);
                } catch (TimeoutException) {
                    Assert.Inconclusive("Timed out.");
                } catch (Exception ex) {
                    Assert.Fail(ex.Message);
                } finally {
                    if (socket != null)
                    {
                        socket.Dispose();
                    }
                }
            }
        }
Exemplo n.º 10
0
        public void TestArgumentExceptions()
        {
            var credentials = new NetworkCredential("user", "password");
            var socks       = new Socks5Client("socks5.proxy.com", 0, credentials);

            Assert.Throws <ArgumentNullException> (() => new Socks4Client(null, 1080));
            Assert.Throws <ArgumentException> (() => new Socks4Client(string.Empty, 1080));
            Assert.Throws <ArgumentOutOfRangeException> (() => new Socks4Client(socks.ProxyHost, -1));
            Assert.Throws <ArgumentNullException> (() => new Socks4Client(socks.ProxyHost, 1080, null));

            Assert.AreEqual(5, socks.SocksVersion);
            Assert.AreEqual(1080, socks.ProxyPort);
            Assert.AreEqual("socks5.proxy.com", socks.ProxyHost);
            Assert.AreEqual(credentials, socks.ProxyCredentials);

            Assert.Throws <ArgumentNullException> (() => socks.Connect(null, 80));
            Assert.Throws <ArgumentNullException> (() => socks.Connect(null, 80, ConnectTimeout));
            Assert.Throws <ArgumentNullException> (async() => await socks.ConnectAsync(null, 80));
            Assert.Throws <ArgumentNullException> (async() => await socks.ConnectAsync(null, 80, ConnectTimeout));

            Assert.Throws <ArgumentException> (() => socks.Connect(string.Empty, 80));
            Assert.Throws <ArgumentException> (() => socks.Connect(string.Empty, 80, 100000));
            Assert.Throws <ArgumentException> (async() => await socks.ConnectAsync(string.Empty, 80));
            Assert.Throws <ArgumentException> (async() => await socks.ConnectAsync(string.Empty, 80, ConnectTimeout));

            Assert.Throws <ArgumentOutOfRangeException> (() => socks.Connect("www.google.com", 0));
            Assert.Throws <ArgumentOutOfRangeException> (() => socks.Connect("www.google.com", 0, ConnectTimeout));
            Assert.Throws <ArgumentOutOfRangeException> (async() => await socks.ConnectAsync("www.google.com", 0));
            Assert.Throws <ArgumentOutOfRangeException> (async() => await socks.ConnectAsync("www.google.com", 0, ConnectTimeout));

            Assert.Throws <ArgumentOutOfRangeException> (() => socks.Connect("www.google.com", 80, -ConnectTimeout));
            Assert.Throws <ArgumentOutOfRangeException> (async() => await socks.ConnectAsync("www.google.com", 80, -ConnectTimeout));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Performs a mediated transfer, meaning we send the data over a proxy server.
        /// </summary>
        /// <param name="session">The SI session whose data to transfer.</param>
        /// <param name="proxies"></param>
        /// <exception cref="Socks5Exception">The SOCKS5 connection to the designated
        /// proxy server could not be established.</exception>
        /// <exception cref="XmppErrorException">The server returned an XMPP error code.
        /// Use the Error property of the XmppErrorException to obtain the specific
        /// error condition.</exception>
        /// <exception cref="XmppException">The server returned invalid data or another
        /// unspecified XMPP error occurred.</exception>
        void MediatedTransfer(SISession session, IEnumerable <Streamhost> proxies)
        {
            var proxy = NegotiateProxy(session, proxies);

            // Connect to the designated proxy.
            using (var client = new Socks5Client(proxy.Host, proxy.Port)) {
                // Send the SOCKS5 Connect command.
                string     hostname = Sha1(session.Sid + session.From + session.To);
                SocksReply reply    = client.Request(SocksCommand.Connect, hostname, 0);
                if (reply.Status != ReplyStatus.Succeeded)
                {
                    throw new Socks5Exception("SOCKS5 Connect request failed.");
                }
                // Activate the bytetream.
                var xml = Xml.Element("query", "http://jabber.org/protocol/bytestreams")
                          .Attr("sid", session.Sid).Child(
                    Xml.Element("activate").Text(session.To.ToString()));
                Iq iq = im.IqRequest(IqType.Set, proxy.Jid, im.Jid, xml);
                if (iq.Type == IqType.Error)
                {
                    throw Util.ExceptionFromError(iq, "Could not activate the bytestream.");
                }
                // Finally, go ahead and send the data to the proxy.
                SendData(session, client.GetStream());
            }
        }
Exemplo n.º 12
0
        private void SocketAccept(Socket socket, EndPoint proxy, EndPoint dest)
        {
            var dataSocket = socket.Accept();

            logger.Info($"socket accepted:{dataSocket.RemoteEndPoint as IPEndPoint}<->{dataSocket.LocalEndPoint as IPEndPoint}");
            Socks5Client client = new Socks5Client(proxy, dest, new Socks5ClientOptions()
            {
                KeepAlive = true
            });

            if (!client.ConnectWithEp())
            {
                throw new Exception("socks cannot connect");
            }

            TransferAdapter adapter = new TransferAdapter(dataSocket, client, logger);

            adapter.SocksClientConnected = true;
            adapter.OnCloseHandler      += (sender, args) =>
            {
                adapter.Stop();
                adapters.Remove(args.Adapter);
                logger.Info("remove adapter");
            };
            logger.Info($" adapter starting {adapter.GetHashCode()}");;

            if (!adapter.Start())
            {
                logger.Info("adapter start fail!");
            }
            ;

            Task.Run(() => SocketAccept(socket, proxy, dest)).ContinueWith(SocketAcceptContinueWith);
        }
Exemplo n.º 13
0
        public async void TestConnectByIPv6Async()
        {
            var    socks  = new Socks5Client(Socks5ProxyList[2], Socks5ProxyPorts[2]);
            var    host   = "2607:f8b0:400e:c03::69";        // ResolveIPv6 ("www.google.com");
            Socket socket = null;

            if (host == null)
            {
                return;
            }

            try {
                socket = await socks.ConnectAsync(host, 80, 10 * 1000);

                socket.Disconnect(false);
            } catch (ProxyProtocolException) {
                // This is the expected outcome since this Socks5 server does not support IPv6 address types
            } catch (TimeoutException) {
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
Exemplo n.º 14
0
        public void Socks5_Test_02_ConnectSOCKS5()
        {
            ManualResetEvent Error  = new ManualResetEvent(false);
            ManualResetEvent Done   = new ManualResetEvent(false);
            Socks5Client     Client = new Socks5Client("proxy.kode.im", 5000, "proxy.kode.im",
                                                       //Socks5Client Client = new Socks5Client("89.163.130.28", 7777, "proxy.draugr.de",
                                                       new TextWriterSniffer(Console.Out, BinaryPresentationMethod.Hexadecimal));

            Client.OnStateChange += (sender, e) =>
            {
                switch (Client.State)
                {
                case Socks5State.Authenticated:
                    Done.Set();
                    break;

                case Socks5State.Error:
                case Socks5State.Offline:
                    Error.Set();
                    break;
                }
            };

            Assert.AreEqual(0, WaitHandle.WaitAny(new WaitHandle[] { Done, Error }, 10000), "Unable to connect.");
        }
Exemplo n.º 15
0
 public void Should_take_data_from_test_server_via_proxy5_dns()
 {
     using (var socks = new Socks5Client())
     {
         socks.Connect(ProxyServerName, ProxyServerPort, "httpbin.org", 80, true);
         TestConnction(socks);
     }
 }
Exemplo n.º 16
0
        public TransferAdapter(Socket s, Socks5Client client, BaseLogger logger)
        {
            this.logger = logger;

            this.opendSocks5Client = client;
            this.opendSocket       = s;
            tmpArgs.Add(opendSocket);
            tmpArgs.Add(opendSocks5Client);
        }
Exemplo n.º 17
0
        public void TestGetAddressType()
        {
            const string host = "www.google.com";
            const string ipv6 = "2607:f8b0:400e:c03::69";
            const string ipv4 = "74.125.197.99";
            IPAddress    ip;

            Assert.AreEqual(Socks5Client.Socks5AddressType.Domain, Socks5Client.GetAddressType(host, out ip));
            Assert.AreEqual(Socks5Client.Socks5AddressType.IPv4, Socks5Client.GetAddressType(ipv4, out ip));
            Assert.AreEqual(Socks5Client.Socks5AddressType.IPv6, Socks5Client.GetAddressType(ipv6, out ip));
        }
Exemplo n.º 18
0
 public void Should_take_data_from_test_server_via_proxy5_on_river_socks_server()
 {
     using (var server = new SocksProxyServer(4548))
     {
         using (var socks = new Socks5Client())
         {
             socks.Connect("localhost", 4548, "httpbin.org", 80, true);
             TestConnction(socks);
         }
     }
 }
Exemplo n.º 19
0
        public void TestGetFailureReason()
        {
            for (byte i = 1; i < 10; i++)
            {
                var reason = Socks5Client.GetFailureReason(i);

                if (i > 8)
                {
                    Assert.IsTrue(reason.StartsWith("Unknown error", StringComparison.Ordinal));
                }
            }
        }
Exemplo n.º 20
0
 public Client(string address = "127.0.0.1", int socksPort = 9050)
 {
     Util.AssertPortOpen(address, socksPort);
     try
     {
         _socksEndPoint = new IPEndPoint(IPAddress.Parse(address), socksPort);
         _socks5Client  = new Socks5Client();
     }
     catch (Exception ex)
     {
         throw new TorException("SocksPort client initialization failed.", ex);
     }
 }
Exemplo n.º 21
0
        private static async Task HttpSocksExampleAsync()
        {
            var socksEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), SocksPort);
            var socks5Client  = new Socks5Client();
            var socket        = socks5Client.ConnectToServer(socksEndpoint);

            socket = socks5Client.ConnectToDestination(socket, "icanhazip.com", 443);

            using (var httpClient = new HttpClient(new NetworkHandler(socket)))
                using (var response = await httpClient.GetAsync("https://icanhazip.com/"))
                {
                    Console.WriteLine("{0} {1}", (int)response.StatusCode, response.ReasonPhrase);
                    Console.WriteLine((await response.Content.ReadAsStringAsync()).Trim());
                }
        }
        /// <summary>
        /// Establishes a SOCKS5 connection with one of the streamhosts in the
        /// specified collection of streamhosts.
        /// </summary>
        /// <param name="stanza">The original requesting IQ stanza.</param>
        /// <param name="sid">The session-id associated with this request.</param>
        /// <param name="hosts">An enumerable collection of Streamhost
        /// instances.</param>
        /// <returns>An initialized instance of the Socks5Client class
        /// representing the established SOCKS5 connection.</returns>
        /// <exception cref="Socks5Exception">An error occurred during SOCKS5
        /// negotiation.</exception>
        /// <exception cref="XmppException">No connection to any of the provided
        /// streamhosts could be established.</exception>
        private async Task <Socks5Client> EstablishConnection(Iq stanza, string sid, IEnumerable <Streamhost> hosts)
        {
            // Try to establish a SOCKS5 connection to any of the streamhosts in the
            // collection.
            bool connected = false;

            foreach (var host in hosts)
            {
                try
                {
                    var client = await Socks5Client.Create(host.Host, host.Port);

                    connected = true;
                    // Send the SOCKS5 Connect command.
                    string     hostname = Sha1(sid + stanza.From + stanza.To);
                    SocksReply reply    = await client.Request(SocksCommand.Connect, hostname, 0);

                    if (reply.Status != ReplyStatus.Succeeded)
                    {
                        throw new Socks5Exception("SOCKS5 Connect request failed.");
                    }
                    // Send acknowledging IQ-result.
                    await im.IqResult(stanza,
                                      Xml.Element("query", "http://jabber.org/protocol/bytestreams")
                                      .Attr("sid", sid).Child(Xml.Element("streamhost-used")
                                                              .Attr("jid", host.Jid.ToString()))
                                      );

                    return(client);
                }
                catch
                {
                    // Fall through and try the next streamhost.
                    if (connected)
                    {
                        break;
                    }
                }
            }
            // Still here means we couldn't connect to any of the streamhosts or
            // an error occurred during SOCKS5 negotiation.
            await im.IqError(stanza, ErrorType.Cancel, ErrorCondition.ItemNotFound);

            // Error out.
            throw new XmppException("Couldn't connect to streamhost.");
        }
Exemplo n.º 23
0
        public override socks5.TCP.Client OnConnectOverride(socks5.Socks.SocksRequest sr)
        {
            //use a socks5client to connect to it and passthru the data.
            //port 9050 is where torsocks is running (linux & windows)
            Socks5Client s = new Socks5Client(NKLISocksClient.Program.RemoteAddress_Socks, NKLISocksClient.Program.RemotePort_Socks, sr.Address, sr.Port, "un", "pw");

            if (s.Connect())
            {
                //connect synchronously to block the thread.
                return(s.Client);
            }
            else
            {
                Console.WriteLine("Failed!");
                return(null);
            }
        }
Exemplo n.º 24
0
        public void TestConnectAnonymous()
        {
            var    socks  = new Socks5Client("98.174.90.36", 1080);          // this is a socks 4 & 5 proxy server
            Socket socket = null;

            try {
                socket = socks.Connect("www.google.com", 80, 10 * 1000);
                socket.Disconnect(false);
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
Exemplo n.º 25
0
        public void TestConnectAnonymous()
        {
            var    socks  = new Socks5Client(Socks5ProxyList[0], Socks5ProxyPorts[0]);
            Socket socket = null;

            try {
                socket = socks.Connect("www.google.com", 80, 10 * 1000);
                socket.Disconnect(false);
            } catch (TimeoutException) {
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
Exemplo n.º 26
0
        public async Task TestConnectAnonymousAsync()
        {
            using (var proxy = new Socks5ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

                var    socks  = new Socks5Client(proxy.IPAddress.ToString(), proxy.Port);
                Stream stream = null;

                try {
                    stream = await socks.ConnectAsync("www.google.com", 80, ConnectTimeout);
                } catch (TimeoutException) {
                    Assert.Inconclusive("Timed out.");
                } catch (Exception ex) {
                    Assert.Fail(ex.Message);
                } finally {
                    stream?.Dispose();
                }
            }
        }
Exemplo n.º 27
0
        public async Task TestTimeoutException()
        {
            using (var proxy = new Socks5ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

                var    socks  = new Socks5Client(proxy.IPAddress.ToString(), proxy.Port);
                Stream stream = null;

                try {
                    stream = await socks.ConnectAsync("example.com", 25, 1000);
                } catch (TimeoutException) {
                    Assert.Pass();
                } catch (Exception ex) {
                    Assert.Fail(ex.Message);
                } finally {
                    stream?.Dispose();
                }
            }
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            Socks5Server x = new Socks5Server(IPAddress.Any, 1080);

            PluginLoader.ChangePluginStatus(false, typeof(Auth));
            x.Start();
            Socks5Client m = new Socks5Client("localhost", 1080, "portquiz.net", 65532);

            m.OnConnected    += M_OnConnected;
            m.OnDataReceived += M_OnDataReceived;
            m.ConnectAsync();
            while (true)
            {
                //Console.Clear();
                //Console.Write("Total Clients: \t{0}\nTotal Recvd: \t{1:0.00##}MB\nTotal Sent: \t{2:0.00##}MB\n", x.Stats.TotalClients, ((x.Stats.NetworkReceived / 1024f) / 1024f), ((x.Stats.NetworkSent / 1024f) / 1024f));
                //Console.Write("Receiving/sec: \t{0}\nSending/sec: \t{1}", x.Stats.SBytesReceivedPerSec, x.Stats.SBytesSentPerSec);
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 29
0
        private static async Task SocksExampleAsync()
        {
            var socksEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), SocksPort);
            var socks5Client  = new Socks5Client();
            var socket        = socks5Client.ConnectToServer(socksEndpoint);

            socket = socks5Client.ConnectToDestination(socket, "icanhazip.com", 80);

            using (var proxiedStream = new NetworkStream(socket))
                using (var writer = new StreamWriter(proxiedStream))
                    using (var reader = new StreamReader(proxiedStream))
                    {
                        writer.WriteLine("GET / HTTP/1.1");
                        writer.WriteLine("Host: icanhazip.com");
                        writer.WriteLine();
                        writer.Flush();

                        Console.WriteLine((await reader.ReadToEndAsync()).Trim());
                    }
        }
Exemplo n.º 30
0
        private void MediatedTransfer(SISession session, IEnumerable <Streamhost> proxies)
        {
            Streamhost streamhost = this.NegotiateProxy(session, proxies);

            using (Socks5Client client = new Socks5Client(streamhost.Host, streamhost.Port, null, null))
            {
                string domain = this.Sha1(session.Sid + session.From + session.To);
                if (client.Request(SocksCommand.Connect, domain, 0).Status != ReplyStatus.Succeeded)
                {
                    CommonConfig.Logger.WriteInfo("SOCKS5 Connect request failed.");
                    throw new Socks5Exception("SOCKS5 Connect request failed.");
                }
                CommonConfig.Logger.WriteInfo("SOCKS5 Connect successed.");
                XmlElement data    = Xml.Element("query", "http://jabber.org/protocol/bytestreams").Attr("sid", session.Sid).Child(Xml.Element("activate", null).Text(session.To.ToString()));
                Iq         errorIq = base.im.IqRequest(IqType.Set, streamhost.Jid, base.im.Jid, data, null, -1, "");
                if (errorIq.Type == IqType.Error)
                {
                    throw Util.ExceptionFromError(errorIq, "Could not activate the bytestream.");
                }
                this.SendData(session, client.GetStream());
            }
        }
Exemplo n.º 31
0
        public bool Input(Iq stanza)
        {
            if (stanza.Type != IqType.Set)
            {
                return(false);
            }
            XmlElement query = stanza.Data["query"];

            if ((query == null) || (query.NamespaceURI != "http://jabber.org/protocol/bytestreams"))
            {
                return(false);
            }
            string sid = query.GetAttribute("sid");

            if (!this.VerifySession(stanza, sid))
            {
                base.im.IqError(stanza, ErrorType.Modify, ErrorCondition.NotAcceptable, null, new XmlElement[0]);
                return(true);
            }
            if (query.GetAttribute("mode") == "udp")
            {
                base.im.IqError(stanza, ErrorType.Modify, ErrorCondition.FeatureNotImplemented, "UDP-mode is not supported.", new XmlElement[0]);
                return(true);
            }
            IEnumerable <Streamhost> hosts = this.ParseStreamhosts(query);

            if (hosts.Count <Streamhost>() == 0)
            {
                base.im.IqError(stanza, ErrorType.Modify, ErrorCondition.BadRequest, "No streamhosts advertised.", new XmlElement[0]);
                return(true);
            }
            Task.Factory.StartNew(delegate {
                using (Socks5Client client = this.EstablishConnection(stanza, sid, hosts))
                {
                    this.ReceiveData(stanza, sid, client.GetStream());
                }
            });
            return(true);
        }
Exemplo n.º 32
0
 public Socks5ClientArgs(Socks5Client p, SocksError x)
 {
     sock = p;
     status = x;
 }