protected void Arrange()
        {
            _closingRegister = new List<EventArgs>();
            _exceptionRegister = new List<ExceptionEventArgs>();
            _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);

            _connectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);
            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _channelMock = new Mock<IChannelDirectTcpip>(MockBehavior.Strict);

            _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
            _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
            _channelMock.Setup(p => p.Close());
            _channelMock.Setup(p => p.Dispose());

            _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port);
            _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            _forwardedPort.Session = _sessionMock.Object;
            _forwardedPort.Start();

            _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
                {
                    ReceiveTimeout = 500,
                    SendTimeout = 500,
                    SendBufferSize = 0
                };
            _client.Connect(_endpoint);

            // allow for client socket to establish connection
            Thread.Sleep(50);
        }
Exemplo n.º 2
0
        private void Arrange()
        {
            _closingRegister   = new List <EventArgs>();
            _exceptionRegister = new List <ExceptionEventArgs>();

            _sessionMock        = new Mock <ISession>(MockBehavior.Strict);
            _channelMock        = new Mock <IChannelDirectTcpip>(MockBehavior.Strict);
            _connectionInfoMock = new Mock <IConnectionInfo>(MockBehavior.Strict);

            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
            _channelMock.Setup(p => p.Close());
            _channelMock.Setup(p => p.Dispose());

            _forwardedPort            = new ForwardedPortDynamic(8122);
            _forwardedPort.Closing   += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            _forwardedPort.Session    = _sessionMock.Object;
            _forwardedPort.Start();

            var endPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            _client = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _client.Connect(endPoint);
        }
        private void Arrange()
        {
            _closingRegister = new List<EventArgs>();
            _exceptionRegister = new List<ExceptionEventArgs>();

            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _channelMock = new Mock<IChannelDirectTcpip>(MockBehavior.Strict);
            _connectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);

            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
            _channelMock.Setup(p => p.Close());
            _channelMock.Setup(p => p.Dispose());

            _forwardedPort = new ForwardedPortDynamic(8122);
            _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            _forwardedPort.Session = _sessionMock.Object;
            _forwardedPort.Start();

            var endPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            _client = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _client.Connect(endPoint);
        }
Exemplo n.º 4
0
        public void ForwardSsh(ref SshClient client, ref ForwardedPortDynamic port)
        {
            var random = new Random();

            do
            {
                try
                {
                    var randomSshClient = sshClients[random.Next(sshClients.Length)];
                    var sshClientInfo   = randomSshClient.Split('|');
                    client = new SshClient(sshClientInfo[0], sshClientInfo[1], sshClientInfo[2]);
                    client.KeepAliveInterval      = new TimeSpan(0, 0, config.IP_Alive_Interval);
                    client.ConnectionInfo.Timeout = new TimeSpan(0, 0, config.IP_Timeout);
                    client.Connect();
                    if (client.IsConnected)
                    {
                        port = new ForwardedPortDynamic("127.0.0.1", 1080);
                        client.AddForwardedPort(port);
                        port.Start();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    File.AppendAllText("Error.txt", ex.ToString());
                }
            } while (true);
        }
Exemplo n.º 5
0
 // Token: 0x0600054A RID: 1354 RVA: 0x00032898 File Offset: 0x00030A98
 public static bool SSHForwardToPort(string host, string username, string password, string ipforward, string portforward)
 {
     try
     {
         SshClient sshClient = new SshClient(host, username, password);
         sshClient.KeepAliveInterval      = new TimeSpan(0, 0, 30);
         sshClient.ConnectionInfo.Timeout = new TimeSpan(0, 0, 30);
         sshClient.Connect();
         ForwardedPortDynamic forwardedPortDynamic = new ForwardedPortDynamic(ipforward, Convert.ToUInt32(portforward));
         sshClient.AddForwardedPort(forwardedPortDynamic);
         forwardedPortDynamic.Exception += delegate(object sender1, ExceptionEventArgs e1)
         {
             Console.WriteLine(e1.Exception.ToString());
         };
         forwardedPortDynamic.Start();
     }
     catch (Exception ex)
     {
         bool flag = ex.Message == "Only one usage of each socket address (protocol/network address/port) is normally permitted";
         if (flag)
         {
             throw ex;
         }
         return(false);
     }
     Thread.Sleep(10000000);
     return(true);
 }
Exemplo n.º 6
0
        protected void Arrange()
        {
            _closingRegister   = new List <EventArgs>();
            _exceptionRegister = new List <ExceptionEventArgs>();
            _endpoint          = new IPEndPoint(IPAddress.Loopback, 8122);

            _connectionInfoMock = new Mock <IConnectionInfo>(MockBehavior.Strict);
            _sessionMock        = new Mock <ISession>(MockBehavior.Strict);
            _channelMock        = new Mock <IChannelDirectTcpip>(MockBehavior.Strict);

            _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
            _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
            _channelMock.Setup(p => p.Dispose());

            _forwardedPort            = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port);
            _forwardedPort.Closing   += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            _forwardedPort.Session    = _sessionMock.Object;
            _forwardedPort.Start();

            _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
            {
                ReceiveTimeout = 500,
                SendTimeout    = 500,
                SendBufferSize = 0
            };
            _client.Connect(_endpoint);

            // allow for client socket to establish connection
            Thread.Sleep(50);
        }
Exemplo n.º 7
0
        public void Connect(string IP, string usernameIP, string passwordIP, string port)
        {
            using (var _client = new SshClient(IP, 22, usernameIP, passwordIP))
            {
                // timeout 30s
                _client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(25);
                _client.ErrorOccurred         += (se, ev) => { };
                _client.KeepAliveInterval      = TimeSpan.FromSeconds(60);
                _client.Connect();

                if (_client.IsConnected)
                {
                    var forwarder = new ForwardedPortDynamic("127.0.0.1", Convert.ToUInt32(port));
                    forwarder.Exception += (se, ev) => { };
                    _client.AddForwardedPort(forwarder);

                    forwarder.Start();



                    // ko dung nua thi stop
                    //forwarder.Stop();
                    //client.Disconnect
                    //MessageBox.Show("forwarded");
                    //Thread.Sleep(10 * 60 * 1000);
                }
            }
        }
Exemplo n.º 8
0
        public void StartTest()
        {
            uint port = 0;                                                // TODO: Initialize to an appropriate value
            ForwardedPortDynamic target = new ForwardedPortDynamic(port); // TODO: Initialize to an appropriate value

            target.Start();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Exemplo n.º 9
0
        private void Arrange()
        {
            CreateMocks();
            SetupData();
            SetupMocks();

            _forwardedPort.Start();

            _client.Connect(_forwardedPortEndPoint);
        }
Exemplo n.º 10
0
        protected void Arrange()
        {
            CreateMocks();
            SetupData();
            SetupMocks();

            _forwardedPort.Start();

            EstablishSocks4Connection(_client);
        }
 protected void Act()
 {
     try
     {
         _forwardedPort.Start();
         Assert.Fail();
     }
     catch (ObjectDisposedException ex)
     {
         _actualException = ex;
     }
 }
 protected void Act()
 {
     try
     {
         _forwardedPort.Start();
         Assert.Fail();
     }
     catch (InvalidOperationException ex)
     {
         _actualException = ex;
     }
 }
Exemplo n.º 13
0
 protected void Act()
 {
     try
     {
         _forwardedPort.Start();
         Assert.Fail();
     }
     catch (SshConnectionException ex)
     {
         _actualException = ex;
     }
 }
        protected void Arrange()
        {
            CreateMocks();
            SetupData();
            SetupMocks();

            // start port
            _forwardedPort.Start();
            // connect to port
            EstablishSocks4Connection(_client);
            // wait until SOCKS client is bound to channel
            Assert.IsTrue(_channelBindStarted.WaitOne(TimeSpan.FromMilliseconds(200)));
        }
Exemplo n.º 15
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            btnConnect.Enabled = false;

            _client = new SshClient(txip.Text.Trim(), txusername.Text.Trim(), txpwd.Text.Trim());
            _client.Connect();
            ForwardedPortDynamic port = new ForwardedPortDynamic("127.0.0.1", 1080);

            _client.AddForwardedPort(port);
            if (_client.IsConnected)
            {
                port.Start();
            }
        }
        protected void Arrange()
        {
            var random = new Random();

            _closingRegister     = new List <EventArgs>();
            _exceptionRegister   = new List <ExceptionEventArgs>();
            _endpoint            = new IPEndPoint(IPAddress.Loopback, 8122);
            _remoteEndpoint      = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort));
            _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500));
            _userName            = random.Next().ToString(CultureInfo.InvariantCulture);

            _connectionInfoMock = new Mock <IConnectionInfo>(MockBehavior.Strict);
            _sessionMock        = new Mock <ISession>(MockBehavior.Strict);
            _channelMock        = new Mock <IChannelDirectTcpip>(MockBehavior.Strict);

            _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port);

            Socket handlerSocket = null;

            _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
            _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
            _channelMock.Setup(p => p.Open(_remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port, _forwardedPort, It.IsAny <Socket>())).Callback <string, uint, IForwardedPort, Socket>((address, port, forwardedPort, socket) => handlerSocket = socket);
            _channelMock.Setup(p => p.IsOpen).Returns(true);
            _channelMock.Setup(p => p.Bind()).Callback(() =>
            {
                Thread.Sleep(_expectedElapsedTime);
                if (handlerSocket != null && handlerSocket.Connected)
                {
                    handlerSocket.Shutdown(SocketShutdown.Both);
                }
            });
            _channelMock.Setup(p => p.Close());
            _channelMock.Setup(p => p.Dispose());

            _forwardedPort.Closing   += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            _forwardedPort.Session    = _sessionMock.Object;
            _forwardedPort.Start();

            _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
            {
                ReceiveTimeout = 500,
                SendTimeout    = 500,
                SendBufferSize = 0
            };
            EstablishSocks4Connection(_client);
        }
Exemplo n.º 17
0
        private void Arrange()
        {
            SetupData();
            CreateMocks();
            SetupMocks();

            _forwardedPort            = new ForwardedPortDynamic(8122);
            _forwardedPort.Closing   += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            _forwardedPort.Session    = _sessionMock.Object;
            _forwardedPort.Start();

            var endPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            _client = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _client.Connect(endPoint);
        }
Exemplo n.º 18
0
        // Token: 0x0600054B RID: 1355 RVA: 0x00032964 File Offset: 0x00030B64
        //public static bool SetSSH2(string host, string username, string password, string ipforward, string portforward, ref SshTunnel tunnel)
        //{
        //	try
        //	{
        //		tunnel.StopAccepting(true);
        //		tunnel.CloseTunnel(true);
        //		tunnel = null;
        //		GC.Collect();
        //	}
        //	catch (Exception)
        //	{
        //	}
        //	tunnel = new SshTunnel();
        //	int port = 22;
        //	bool flag = tunnel.Connect(host, port);
        //	bool flag2 = !flag;
        //	bool result;
        //	if (flag2)
        //	{
        //		Console.WriteLine(tunnel.LastErrorText);
        //		result = false;
        //	}
        //	else
        //	{
        //		flag = tunnel.AuthenticatePw(username, password);
        //		bool flag3 = !flag;
        //		if (flag3)
        //		{
        //			Console.WriteLine(tunnel.LastErrorText);
        //			result = false;
        //		}
        //		else
        //		{
        //			tunnel.DynamicPortForwarding = true;
        //			flag = tunnel.BeginAccepting(Convert.ToInt32(portforward));
        //			bool flag4 = !flag;
        //			if (flag4)
        //			{
        //				Console.WriteLine(tunnel.LastErrorText);
        //				result = false;
        //			}
        //			else
        //			{
        //				result = true;
        //			}
        //		}
        //	}
        //	return result;
        //}

        // Token: 0x0600054C RID: 1356 RVA: 0x00032A40 File Offset: 0x00030C40
        public static bool SetSSH1(string host, string username, string password, string ipforward, string portforward, ref SshClient cursshclient)
        {
            SshClient sshClient = null;

            try
            {
                bool flag = cursshclient != null;
                if (flag)
                {
                    foreach (ForwardedPort forwardedPort in cursshclient.ForwardedPorts)
                    {
                        forwardedPort.Stop();
                    }
                    cursshclient.Disconnect();
                }
                sshClient = new SshClient(host, username, password);
                sshClient.KeepAliveInterval      = new TimeSpan(0, 0, 30);
                sshClient.ConnectionInfo.Timeout = new TimeSpan(0, 0, 30);
                sshClient.Connect();
                ForwardedPortDynamic forwardedPortDynamic = new ForwardedPortDynamic(ipforward, Convert.ToUInt32(portforward));
                sshClient.AddForwardedPort(forwardedPortDynamic);
                forwardedPortDynamic.Exception += delegate(object sender1, ExceptionEventArgs e1)
                {
                    Console.WriteLine(e1.Exception.ToString());
                };
                forwardedPortDynamic.Start();
            }
            catch (Exception ex)
            {
                cursshclient = sshClient;
                bool flag2 = ex.Message == "Only one usage of each socket address (protocol/network address/port) is normally permitted";
                if (flag2)
                {
                    MessageBox.Show("Port " + portforward + " đã được sử dụng, hãy đổi sang port khác", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(true);
                }
                return(false);
            }
            cursshclient = sshClient;
            return(true);
        }
Exemplo n.º 19
0
        protected void Arrange()
        {
            _closingRegister   = new List <EventArgs>();
            _exceptionRegister = new List <ExceptionEventArgs>();
            _endpoint          = new IPEndPoint(IPAddress.Loopback, 8122);

            _connectionInfoMock = new Mock <IConnectionInfo>(MockBehavior.Strict);
            _sessionMock        = new Mock <ISession>(MockBehavior.Strict);
            _channelMock        = new Mock <IChannelDirectTcpip>(MockBehavior.Strict);

            _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
            _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);

            _forwardedPort            = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port);
            _forwardedPort.Closing   += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            _forwardedPort.Session    = _sessionMock.Object;
            _forwardedPort.Start();
        }
        protected void Arrange()
        {
            _closingRegister = new List<EventArgs>();
            _exceptionRegister = new List<ExceptionEventArgs>();
            _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);

            _connectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);
            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _channelMock = new Mock<IChannelDirectTcpip>(MockBehavior.Strict);

            _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
            _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);

            _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port);
            _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            _forwardedPort.Session = _sessionMock.Object;
            _forwardedPort.Start();
        }
Exemplo n.º 21
0
        /// <summary>
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="socksPort"></param>
        /// <param name="user"></param>
        /// <param name="pass"></param>
        /// <param name="keyFile"></param>
        public Ssh2Socks(IPAddress ip, uint port, uint socksPort, string user, string pass, string keyFile)
        {
            Ip      = ip;
            Port    = port <= 0 ? 22 : port;
            User    = user;
            Pass    = pass;
            KeyFile = keyFile;

            Ssh = KeyFile == null
                ? new SshClient(Ip.ToString(), (int)Port, User, Pass)
                : new SshClient(Ip.ToString(), (int)Port, User, new PrivateKeyFile(KeyFile));
            Ssh.Connect();

            SocksPort = socksPort;
            if (SocksPort <= 0)
            {
                SocksPort = (uint)Helper.GetFreeTcpPort();
            }

            ForwardedPort = new ForwardedPortDynamic("127.0.0.1", SocksPort);
            Ssh.AddForwardedPort(ForwardedPort);
            ForwardedPort.Start();
        }
Exemplo n.º 22
0
 private bool Connect_SSH()
 {
     try {
         sshClient   = new SshClient("sol.edu.cc.uec.ac.jp", ID, PW);
         portDynamic = new ForwardedPortDynamic("127.0.0.1", 8080);
         sshClient.Connect();
         sshClient.AddForwardedPort(portDynamic);
         portDynamic.Start();
     } catch (SshConnectionException e) {
         MessageBox.Show($"SSHコネクションが切断されました。\n{e.Message}");
         return(false);
     } catch (SshAuthenticationException e) {
         MessageBox.Show($"SSH認証に失敗しました。\n{e.Message}");
         return(false);
     } catch (SocketException e) {
         MessageBox.Show($"ソケットエラーです。\n多重起動していないか確認してください。\n{e.Message}");
         return(false);
     } catch (Exception e) {
         MessageBox.Show($"不明なSSH接続時のエラーです。\n{e.Message}");
         return(false);
     }
     return(true);
 }
Exemplo n.º 23
0
        private void btn_Q2_Click(object sender, EventArgs e)
        {
            sshC = new SshClient("192.168.10.131", "root", "123123");

            sshC.KeepAliveInterval      = new TimeSpan(0, 0, 30);
            sshC.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
            sshC.Connect();

            // 动态链接
            ForwardedPortDynamic port = new ForwardedPortDynamic("127.0.0.1", 22);

            sshC.AddForwardedPort(port);
            port.Start();

            ////var fport = new ForwardedPortRemote("192.168.10.131", 22, "127.0.0.1", 22);
            ////sshC.AddForwardedPort(fport);
            ////fport.Start();

            ////string x = sshC.RunCommand("pwd").Result;
            ;
            string x = sshC.RunCommand("pwd").Result;

            ;
        }
Exemplo n.º 24
0
 private void materialRaisedButton1_Click(object sender, EventArgs e)
 {
     if (!status)
     {
         statusLabel.Text = "Connecting...";
         IPGlobalProperties         ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
         TcpConnectionInformation[] tcpConnInfoArray   = ipGlobalProperties.GetActiveTcpConnections();
         bool isAvailable        = true;
         bool internetconnection = false;
         foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
         {
             if (tcpi.LocalEndPoint.Port == int.Parse(Lport.Text))
             {
                 statusLabel.Text = "port is using by another proccess..!";
                 break;
             }
         }
         try
         {
             using (var client = new WebClient())
                 using (client.OpenRead("http://clients3.google.com/generate_204"))
                 {
                     internetconnection = true;
                 }
         }
         catch
         {
             MessageBox.Show("Failed.Check Your Internet connection!");
         }
         if (isAvailable && internetconnection)
         {
             client = new SshClient(sshHost.Text, sshUser.Text, sshPASS.Text);
             client.KeepAliveInterval      = new TimeSpan(0, 0, 30);
             client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
             client.Connect();
             port = new ForwardedPortDynamic(Lhost.Text, uint.Parse(Lport.Text));
             client.AddForwardedPort(port);
             try
             {
                 run = new Thread(() => port.Start());
                 run.Start();
                 statusLabel.Text = "Connected✅";
                 status           = true;
                 MessageBox.Show("listener is active!\nhost:" + Lhost.Text + "\nport:" + Lport.Text);
                 buttonConnect.Text = "DisConnect";
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.ToString());
             }
         }
     }
     else
     {
         port.Stop();
         run.Abort();
         status = false;
         client.Disconnect();
         statusLabel.Text   = "DisConnected❌";
         buttonConnect.Text = "Connect";
     }
 }
Exemplo n.º 25
0
        void JobLikeProduct(Account account, string port, string userAgent)
        {
            HttpRequest request    = new HttpRequest();
            var         configXNet = new ConfigXNet();

            configXNet.AddUserAgent(ref request, userAgent);

            try
            {
                using (var client = new SshClient(account.IP, 22, account.UsernameIP, account.PasswordIP))
                {
                    // timeout 30s
                    client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(25);
                    client.ErrorOccurred         += (se, ev) => { };
                    client.KeepAliveInterval      = TimeSpan.FromSeconds(60);
                    client.Connect();

                    if (client.IsConnected)
                    {
                        var forwarder = new ForwardedPortDynamic("127.0.0.1", Convert.ToUInt32(port));
                        forwarder.Exception += (se, ev) => { };
                        client.AddForwardedPort(forwarder);

                        forwarder.Start();
                        request.Proxy = HttpProxyClient.Parse(ProxyType.Socks5, "127.0.0.1:" + port);

                        var login = new LoginAccount();

                        if (login.IsSuccessful(ref request, account))
                        {
                            if (_removeProduct)
                            {
                                var remove = new RemoveProduct();
                                remove.Remove(ref request);
                            }

                            lock (_fileResultObj)
                            {
                                _randomAccount--;
                                rtxtResult.Text += account.Email + " | " + account.Password + Environment.NewLine;
                            }

                            InteractProducts(ref request, account);
                        }
                        else
                        {
                            var export = new ExportResult();
                            lock (_fileErrorObj)
                            {
                                export.FileResult(_fileErrorPath, account);
                                rtxtResult.Text += account.Email + " | " + account.Password + " | Lỗi không đăng nhập được" + Environment.NewLine;
                            }
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
            catch
            {
                var export = new ExportResult();
                lock (_fileErrorObj)
                {
                    export.FileResult(_fileErrorPath, account);
                    rtxtResult.Text += account.Email + " | " + account.Password + " | Lỗi không đăng nhập được" + Environment.NewLine;
                }
                return;
            }
        }
        private void Arrange()
        {
            SetupData();
            CreateMocks();
            SetupMocks();

            _forwardedPort = new ForwardedPortDynamic(8122);
            _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) =>
                {
                    _exceptionRegister.Add(args);
                    _exceptionFired.Set();
                };
            _forwardedPort.Session = _sessionMock.Object;
            _forwardedPort.Start();

            var endPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            _client = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _client.Connect(endPoint);
        }
Exemplo n.º 27
0
        //bool Login(Account account, ref HttpRequest request, string port, string useAgent)
        //{

        //    SettingsRequest(ref request, useAgent);

        //    string html = request.Get("https://www.lazada.vn/customer/account/login/").ToString();
        //    var info = new ProductInfo(html);
        //    request.AddParam("FORM_TOKEN", info.FormToken());
        //    request.AddParam("referer", "https://www.lazada.vn/");
        //    request.AddParam("LoginForm[email]", account.Email);
        //    request.AddParam("LoginForm[password]", account.Password);
        //    Thread.Sleep(THREAD_SLEEP_FAST);
        //    html = request.Post("https://www.lazada.vn/customer/account/login/").ToString();
        //    html = request.Get("https://www.lazada.vn/customer/account/").ToString();
        //    if (html.Contains("Quản lý tài khoản"))
        //        return true;
        //    return false;

        //}

        void JobRegister(Account account, string port, string userAgent)
        {
            HttpRequest request    = new HttpRequest();
            var         configXNet = new ConfigXNet();

            configXNet.AddUserAgent(ref request, userAgent);

            try
            {
                using (var client = new SshClient(account.IP, 22, account.UsernameIP, account.PasswordIP))
                {
                    // timeout 30s
                    client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(25);
                    client.ErrorOccurred         += (se, ev) => { };
                    client.KeepAliveInterval      = TimeSpan.FromSeconds(60);
                    client.Connect();

                    if (client.IsConnected)
                    {
                        var forwarder = new ForwardedPortDynamic("127.0.0.1", Convert.ToUInt32(port));
                        forwarder.Exception += (se, ev) => { };
                        client.AddForwardedPort(forwarder);

                        forwarder.Start();
                        request.Proxy = HttpProxyClient.Parse(ProxyType.Socks5, "127.0.0.1:" + port);

                        var register = new RegisterAccount();

                        if (register.IsSuccessful(ref request, account))
                        {
                            lock (_randomAccountObj)
                            {
                                _randomAccount--;
                                var export = new ExportResult();
                                export.FileResult(_fileResultPath, account);
                                rtxtResult.Text += account.Email + " | " + account.Password + Environment.NewLine;
                            }

                            InteractProducts(ref request, account);

                            //Debug.WriteLine(account.Email, "Xong");
                        }
                        else
                        {
                            //Debug.WriteLine(account.Email, "Lỗi");
                            var export = new ExportResult();
                            lock (_fileErrorObj)
                                export.FileResult(_fileErrorPath, account);
                        }
                    }
                    else
                    {
                        //Debug.WriteLine(account.Email, "Lỗi SSH");
                        var export = new ExportResult();
                        lock (_fileErrorObj)
                            export.FileResult(_fileErrorPath, account);
                    }
                }
            }
            catch
            {
                //Debug.WriteLine(account.Email, "Lỗi SSH");
                var export = new ExportResult();
                lock (_fileErrorObj)
                    export.FileResult(_fileErrorPath, account);
            }
        }
 protected void Act()
 {
     _forwardedPort.Start();
 }
Exemplo n.º 29
0
        void SSHConnect(object sender, DoWorkEventArgs e)
        {
            if (_MainForm.textBox1.Text == string.Empty)
            {
                MessageBox.Show("No hostname specified"); return;
            }
            if (_MainForm.textBox2.Text == string.Empty)
            {
                MessageBox.Show("No username specified");
            }
            if (!_MainForm.radioButton1.Checked && !_MainForm.radioButton2.Checked)
            {
                MessageBox.Show("No authentication specified"); return;
            }
            try
            {
                using (var client = new SshClient(_MainForm.textBox1.Text, _MainForm.textBox2.Text, _MainForm.getAuth()))
                {
                    var ProxyPort = new ForwardedPortDynamic("127.0.0.1", 1080);
                    _MainForm.WriteLog("Attempting connection to " + _MainForm.textBox1.Text);
                    client.Connect();
                    if (client.IsConnected)
                    {
                        //Connect
                        isConnected = true;
                        _MainForm.WriteLog("Connected");
                        _MainForm.WriteLog("Adding SOCKS port: " + ProxyPort.BoundHost + ":" + ProxyPort.BoundPort);
                        client.AddForwardedPort(ProxyPort);
                        ProxyPort.Start();
                        _MainForm.WriteLog("Ready for connections");
                        _MainForm.ConnectionButton.Text = "Disconnect";
                        _MainForm.textBox1.ReadOnly     = true;
                        _MainForm.textBox2.ReadOnly     = true;
                        _MainForm.textBox3.ReadOnly     = true;
                        _MainForm.radioButton1.Enabled  = false;
                        _MainForm.radioButton2.Enabled  = false;
                        _MainForm.textBox4.ReadOnly     = true;
                        _MainForm.textBox5.ReadOnly     = true;
                        _MainForm.button3.Enabled       = false;
                        _MainForm.WriteLog("Setting windows proxy");
                        _MainForm.WriteLog("Connected");
                        RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
                        registry.SetValue("ProxyEnable", 1);
                        registry.SetValue("ProxyServer", "socks=127.0.0.1:1080");
                        settingsReturn           = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
                        refreshReturn            = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
                        ConnectionButton.Enabled = true;

                        while (isConnected)
                        {
                            Thread.Sleep(1000);
                        }
                        //Disconnect
                        _MainForm.WriteLog("Setting windows proxy to default values");
                        WriteLog("Disconnecting");
                        registry.SetValue("ProxyEnable", 0);
                        registry.DeleteValue("ProxyServer");
                        settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
                        refreshReturn  = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
                        ProxyPort.Stop();
                        client.RemoveForwardedPort(ProxyPort);
                        client.Disconnect();
                        Thread.Sleep(500);
                        WriteLog("Disconnected");
                        _MainForm.textBox1.ReadOnly     = false;
                        _MainForm.textBox2.ReadOnly     = false;
                        _MainForm.textBox3.ReadOnly     = false;
                        _MainForm.radioButton1.Enabled  = true;
                        _MainForm.radioButton2.Enabled  = true;
                        _MainForm.textBox4.ReadOnly     = false;
                        _MainForm.textBox5.ReadOnly     = false;
                        _MainForm.button3.Enabled       = true;
                        ConnectionButton.Enabled        = true;
                        _MainForm.ConnectionButton.Text = "Connect";
                    }
                }
            } catch (Exception ex)
            {
                _MainForm.WriteLog(ex.Message);
                MessageBox.Show(ex.Message);
                _MainForm.textBox1.ReadOnly     = false;
                _MainForm.textBox2.ReadOnly     = false;
                _MainForm.textBox3.ReadOnly     = false;
                _MainForm.radioButton1.Enabled  = true;
                _MainForm.radioButton2.Enabled  = true;
                _MainForm.textBox4.ReadOnly     = false;
                _MainForm.textBox5.ReadOnly     = false;
                _MainForm.button3.Enabled       = true;
                ConnectionButton.Enabled        = true;
                _MainForm.ConnectionButton.Text = "Connect";
            }
        }
        protected void Arrange()
        {
            var random = new Random();

            _closingRegister = new List<EventArgs>();
            _exceptionRegister = new List<ExceptionEventArgs>();
            _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
            _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort));
            _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500));
            _userName = random.Next().ToString(CultureInfo.InvariantCulture);
            _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port);

            _connectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);
            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _channelMock = new Mock<IChannelDirectTcpip>(MockBehavior.Strict);

            Socket handlerSocket = null;

            _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
            _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
            _channelMock.Setup(p => p.Open(_remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port, _forwardedPort, It.IsAny<Socket>())).Callback<string, uint, IForwardedPort, Socket>((address, port, forwardedPort, socket) => handlerSocket = socket);
            _channelMock.Setup(p => p.IsOpen).Returns(true);
            _channelMock.Setup(p => p.Bind()).Callback(() =>
                {
                    Thread.Sleep(_expectedElapsedTime);
                    if (handlerSocket != null && handlerSocket.Connected)
                        handlerSocket.Shutdown(SocketShutdown.Both);
                });
            _channelMock.Setup(p => p.Close());
            _channelMock.Setup(p => p.Dispose());

            _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            _forwardedPort.Session = _sessionMock.Object;
            _forwardedPort.Start();

            _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
                {
                    ReceiveTimeout = 500,
                    SendTimeout = 500,
                    SendBufferSize = 0
                };
            EstablishSocks4Connection(_client);
        }