Beispiel #1
0
        public void Cleanup()
        {
            if (_forwardedPort != null && _forwardedPort.IsStarted)
            {
                _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
                _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(5));
                _forwardedPort.Stop();
            }

            if (_client != null)
            {
                if (_client.Connected)
                {
                    _client.Shutdown(SocketShutdown.Both);
                    _client.Close();
                    _client = null;
                }
            }

            if (_channelDisposed != null)
            {
                _channelDisposed.Dispose();
                _channelDisposed = null;
            }
        }
Beispiel #2
0
 public void Dispose()
 {
     ForwardedPort.Stop();
     ForwardedPort.Dispose();
     Ssh.Disconnect();
     Ssh?.Dispose();
 }
Beispiel #3
0
        public void StopTest()
        {
            uint port = 0;                                                // TODO: Initialize to an appropriate value
            ForwardedPortDynamic target = new ForwardedPortDynamic(port); // TODO: Initialize to an appropriate value

            target.Stop();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
        protected void Act()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            _forwardedPort.Stop();

            stopwatch.Stop();
            _elapsedTimeOfStop = stopwatch.Elapsed;
        }
 protected void Act()
 {
     try
     {
         _forwardedPort.Stop();
         Assert.Fail();
     }
     catch (ObjectDisposedException ex)
     {
         _actualException = ex;
     }
 }
        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);

            _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.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();
            _forwardedPort.Stop();

            _closingRegister.Clear();
        }
        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);

            _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.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();
            _forwardedPort.Stop();

            _closingRegister.Clear();
        }
 protected void Act()
 {
     _forwardedPort.Stop();
 }
Beispiel #9
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";
            }
        }
Beispiel #10
0
        public bool LoginByCookieFakeIP(string profile, string allCookies)
        {
            var                  status = false;
            ChromeDriver         driver = null;
            var                  email  = string.Empty;
            ForwardedPortDynamic port   = null;
            SshClient            client = null;

            ForwardSsh(ref client, ref port);
            try
            {
                string profile_path = Path.GetDirectoryName(profile);
                string profile_name = Path.GetFileName(profile);
                var    service      = ChromeDriverService.CreateDefaultService();
                service.HideCommandPromptWindow = true;
                var options = new ChromeOptions();
                options.AddArguments("--user-data-dir=" + profile_path);
                options.AddArguments("--profile-directory=" + profile_name);
                options.AddArguments("--proxy-server=socks5://127.0.0.1:1080");
                options.AddArguments("disable-infobars");
                options.AddArguments("start-maximized");
                driver = new ChromeDriver(service, options);

                driver.Navigate().GoToUrl("https://www.youtube.com");
                var cookies = allCookies.Split(';');
                foreach (var cookie in cookies)
                {
                    var pair = cookie.Split('=');
                    if (pair.Count() == 2)
                    {
                        driver.Manage().Cookies.AddCookie(new OpenQA.Selenium.Cookie(pair[0].Trim(), pair[1].Trim()));
                    }
                }
                driver.Navigate().Refresh();

                Thread.Sleep(config.Page_Load);

                status = true;
            }
            catch (Exception e)
            {
                using (StreamWriter writer = new StreamWriter("Error.txt", true))
                {
                    writer.WriteLine("Profile: " + Path.GetFileName(profile) + "|Email: " + email + "|" + e.ToString());
                }
            }

            if (driver != null)
            {
                driver.Close();
                driver.Quit();
            }

            if (port != null)
            {
                port.Stop();
            }

            if (client != null)
            {
                client.Disconnect();
            }

            return(status);
        }
Beispiel #11
0
        public bool LoginFakeIP(string profile, string mail)
        {
            var                  status = false;
            ChromeDriver         driver = null;
            ForwardedPortDynamic port   = null;
            SshClient            client = null;

            ForwardSsh(ref client, ref port);
            var email = string.Empty;

            try
            {
                var mails = mail.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                if (mails.Length < 3)
                {
                    throw new Exception("Wrong email, password, email recovery format");
                }
                email = mails[0];
                string password      = mails[1];
                string recoveryEmail = mails[2];

                string profile_path = Path.GetDirectoryName(profile);
                string profile_name = Path.GetFileName(profile);
                var    service      = ChromeDriverService.CreateDefaultService();
                service.HideCommandPromptWindow = true;
                var options = new ChromeOptions();
                options.AddArguments("--user-data-dir=" + profile_path);
                options.AddArguments("--profile-directory=" + profile_name);
                options.AddArguments("--proxy-server=socks5://127.0.0.1:1080");
                options.AddArguments("disable-infobars");
                options.AddArguments("start-maximized");

                driver = new ChromeDriver(service, options);
                driver.Navigate().GoToUrl("https://accounts.google.com/signin/v2/identifier");
                Thread.Sleep(config.Page_Load);

                var elements = driver.FindElements(By.XPath("//*/div[@id='profileIdentifier']")).Where(x => x.Displayed);
                if (elements.Count() == 0)
                {
                    var mailInput = driver.FindElement(By.XPath("//*/input[@id='identifierId']"));
                    mailInput.SendKeys(Keys.Control + "a");
                    mailInput.SendKeys(email);
                    Thread.Sleep(config.Wait_Enter);
                    mailInput.SendKeys(Keys.Enter);
                    Thread.Sleep(config.Page_Load);
                }

                var passwordInput = driver.FindElementsByTagName("input").First(x => x.GetAttribute("name") == "password");
                passwordInput.SendKeys(Keys.Control + "a");
                passwordInput.SendKeys(password);
                Thread.Sleep(config.Wait_Enter);
                passwordInput.SendKeys(Keys.Enter);
                Thread.Sleep(config.Page_Load);

                var confirmRecoveryEmailOptionButtons = driver.FindElementsByClassName("vdE7Oc").Where(x => x.Displayed).ToArray();
                var numOptions = confirmRecoveryEmailOptionButtons.Length;

                if (numOptions > 0)
                {
                    IWebElement confirmRecoveryEmailOptionButton = null;
                    if (numOptions == 1)
                    {
                        confirmRecoveryEmailOptionButton = confirmRecoveryEmailOptionButtons[0];
                        confirmRecoveryEmailOptionButton.Click();
                        Thread.Sleep(config.Page_Load);
                    }
                    else
                    {
                        try
                        {
                            confirmRecoveryEmailOptionButton = confirmRecoveryEmailOptionButtons[numOptions - 2];
                            confirmRecoveryEmailOptionButton.Click();
                            Thread.Sleep(config.Page_Load);
                            var secretQuestionResponses = driver.FindElementsByTagName("input").Where(x => x.GetAttribute("name") == "knowledgePreregisteredEmailResponse").Where(x => x.Displayed);
                            if (secretQuestionResponses.Count() == 0)
                            {
                                var otherMethodButton = driver.FindElement(By.XPath("//*/div[@class='daaWTb']/div[@class='U26fgb O0WRkf oG5Srb HQ8yf C0oVfc nDKKZc NpwL8d NaOGkc']/content[@class='CwaK9']/span[@class='RveJvd snByac']"));
                                otherMethodButton.Click();
                                Thread.Sleep(config.Page_Load);
                                confirmRecoveryEmailOptionButtons = driver.FindElementsByClassName("vdE7Oc").Where(x => x.Displayed).ToArray();
                                confirmRecoveryEmailOptionButton  = confirmRecoveryEmailOptionButtons[numOptions - 3];
                                confirmRecoveryEmailOptionButton.Click();
                                Thread.Sleep(config.Page_Load);
                            }
                        }
                        catch (Exception ex)
                        {
                            using (StreamWriter writer = new StreamWriter("Error.txt", true))
                            {
                                writer.WriteLine("Email: " + email + "|" + ex.ToString());
                            }
                        }
                    }
                }

                var recoveryMailInputs = driver.FindElementsByTagName("input").Where(x => x.GetAttribute("name") == "knowledgePreregisteredEmailResponse");
                if (recoveryMailInputs.Count() > 0)
                {
                    var recoveryMailInput = recoveryMailInputs.First();
                    recoveryMailInput.SendKeys(Keys.Control + "a");
                    recoveryMailInput.SendKeys(recoveryEmail);
                    Thread.Sleep(config.Wait_Enter);
                    recoveryMailInput.SendKeys(Keys.Enter);
                    Thread.Sleep(config.Page_Load);
                }
                driver.Navigate().GoToUrl("https://mail.google.com/mail/u/0/#inbox");
                Thread.Sleep(config.Page_Load);

                status = true;
            }
            catch (Exception e)
            {
                using (StreamWriter writer = new StreamWriter("Error.txt", true))
                {
                    writer.WriteLine("Profile: " + Path.GetFileName(profile) + "|Email: " + email + "|" + e.ToString());
                }
            }

            if (driver != null)
            {
                driver.Close();
                driver.Quit();
            }

            if (port != null)
            {
                port.Stop();
            }

            if (client != null)
            {
                client.Disconnect();
            }

            return(status);
        }
Beispiel #12
0
        public bool Start_Download(DataTable csvTable)
        {
            Progress progress = new Progress();

            progress.Set_Max = csvTable.Rows.Count + 6;
            progress.Show();

            progress.Set_Text = "アカウント情報を取得しています...";
            progress.Add_ProgressBar();
            if (!Input_Account())
            {
                progress.Quit();
                return(false);
            }

            progress.Set_Text = "SSH接続を試行しています...";
            progress.Add_ProgressBar();
            if (!Connect_SSH())
            {
                portDynamic.Stop();
                portDynamic.Dispose();
                sshClient.Disconnect();
                sshClient.Dispose();
                progress.Quit();
                return(false);
            }

            progress.Set_Text = "Chromeの準備をしています...";
            progress.Add_ProgressBar();
            ChromeOptions options = Set_Options();

            driver = new ChromeDriver(options);
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

            progress.Set_Text = "UEC統合認証中...";
            progress.Add_ProgressBar();
            if (!UEC_Authorization())
            {
                Terminate_Chrome();
                progress.Quit();
                return(false);
            }

            progress.Set_Text = "シラバス検索ページへ遷移中...";
            progress.Add_ProgressBar();
            if (!Goto_SearchPage())
            {
                Terminate_Chrome();
                progress.Quit();
                return(false);
            }
            foreach (DataRow row in csvTable.Rows)
            {
                progress.Set_Text = $"{string.Join(",", row.ItemArray)}を取得中...";
                progress.Add_ProgressBar();
                if (!Search_Syllabus(row))
                {
                    MessageBox.Show($"次の行のシラバス取得に失敗しました。項目を見直してください。\n{string.Join(",", row.ItemArray)}");
                    if (!Goto_SearchPage())
                    {
                        Terminate_Chrome();
                        progress.Quit();
                        return(false);
                    }
                    continue;
                }
                if (!Download_and_Reference_Syllabus(row))
                {
                    MessageBox.Show($"次の行のシラバス取得に失敗しました。項目を見直してください。\n{string.Join(",", row.ItemArray)}");
                    if (!Goto_SearchPage())
                    {
                        Terminate_Chrome();
                        progress.Quit();
                        return(false);
                    }
                }
                if (!Goto_SearchPage())
                {
                    Terminate_Chrome();
                    progress.Quit();
                    return(false);
                }
            }
            progress.Set_Text = "Chromeの終了処理中...";
            progress.Add_ProgressBar();
            Terminate_Chrome();
            progress.Quit();
            return(true);
        }
Beispiel #13
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";
     }
 }