private void Arrange()
        {
            var random = new Random();

            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _channelSessionAMock = new Mock<IChannelSession>(MockBehavior.Strict);
            _channelSessionBMock = new Mock<IChannelSession>(MockBehavior.Strict);
            _commandText = random.Next().ToString(CultureInfo.InvariantCulture);
            _encoding = Encoding.UTF8;
            _asyncResultA = null;
            _asyncResultB = null;

            var seq = new MockSequence();
            _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionAMock.Object);
            _channelSessionAMock.InSequence(seq).Setup(p => p.Open());
            _channelSessionAMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText))
                .Returns(true)
                .Raises(c => c.Closed += null, new ChannelEventArgs(5));
            _channelSessionAMock.InSequence(seq).Setup(p => p.Dispose());

            _sshCommand = new SshCommand(_sessionMock.Object, _commandText, _encoding);
            _asyncResultA = _sshCommand.BeginExecute();
            _sshCommand.EndExecute(_asyncResultA);

            _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionBMock.Object);
            _channelSessionBMock.InSequence(seq).Setup(p => p.Open());
            _channelSessionBMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText)).Returns(true);
        }
Ejemplo n.º 2
0
        // ---------------- Properties ----------------

        // ---------------- Functions ----------------

        /// <summary>
        /// Runs the SSH process.
        /// </summary>
        /// <returns>The exit code of the process.</returns>
        public int RunSsh(CancellationToken cancelToken)
        {
            this.config.Validate();

            this.lockFileManager.CreateLockFile();
            using (SshClient client = new SshClient(this.config.Server, this.config.Port, this.config.UserName, this.config.Password))
            {
                client.Connect();
                this.logger.WarningWriteLine(2, "Client Version: " + client.ConnectionInfo.ClientVersion);
                this.logger.WarningWriteLine(2, "Server Version: " + client.ConnectionInfo.ServerVersion);

                using (SshCommand command = client.CreateCommand(this.config.Command))
                {
                    IAsyncResult task = command.BeginExecute();

                    // Using tasks seems to print things to the console better; it doesn't all just bunch up at the end.
                    Task stdOutTask = AsyncWriteToStream(Console.OpenStandardOutput, command.OutputStream, task, "STDOUT", cancelToken);
                    Task stdErrTask = AsyncWriteToStream(Console.OpenStandardError, command.ExtendedOutputStream, task, "STDERR", cancelToken);

                    try
                    {
                        Task[] tasks = new Task[] { stdOutTask, stdErrTask };
                        Task.WaitAll(tasks, cancelToken);
                    }
                    catch (OperationCanceledException)
                    {
                        this.logger.WarningWriteLine(1, "Cancelling Task...");
                        command.CancelAsync();
                        this.logger.WarningWriteLine(1, "Task Cancelled");
                        this.lockFileManager.DeleteLockFile();
                        throw;
                    }

                    command.EndExecute(task);

                    int exitStatus = command.ExitStatus;

                    this.logger.WarningWriteLine(1, "Process exited with exit code: " + exitStatus);

                    this.lockFileManager.DeleteLockFile();
                    return(exitStatus);
                }
            }
        }
Ejemplo n.º 3
0
        public override Dictionary <AuditFileInfo, string> ReadFilesAsText(List <AuditFileInfo> files)
        {
            CallerInformation here = this.Here();
            Dictionary <AuditFileInfo, string> results = new Dictionary <AuditFileInfo, string>(files.Count);
            object    results_lock = new object();
            Stopwatch sw           = new Stopwatch();

            sw.Start();
            Parallel.ForEach(files, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 20
            }, (_f, state) =>
            {
                SshCommand cmd = this.SshClient.CreateCommand("cat " + _f.FullName);
                Stopwatch cs   = new Stopwatch();
                cs.Start();
                CommandAsyncResult result = cmd.BeginExecute(new AsyncCallback(SshCommandAsyncCallback), new KeyValuePair <SshCommand, Stopwatch> (cmd, cs)) as CommandAsyncResult;
                cmd.EndExecute(result);
                KeyValuePair <SshCommand, Stopwatch> s = (KeyValuePair <SshCommand, Stopwatch>)result.AsyncState;
                if (s.Key.Result != string.Empty)
                {
                    lock (results_lock)
                    {
                        results.Add(_f, s.Key.Result);
                    }
                    if (s.Value.IsRunning)
                    {
                        s.Value.Stop();
                    }
                    Debug(here, "Read {0} chars from {1}.", s.Key.Result.Length, _f.FullName);
                    Progress("Read environment files", files.Count, 3, s.Value.Elapsed);
                }
                else
                {
                    Error(here, "Could not read {0} as text. Command returned: {1}", _f.FullName, s.Key.Error);
                }
                s.Key.Dispose();
                cs = null;
            });
            sw.Stop();
            Success("Read text for {0} out of {1} files in {2} ms.", results.Count(r => r.Value.Length > 0), results.Count(), sw.ElapsedMilliseconds);
            return(results);
        }
Ejemplo n.º 4
0
        public int Execute(string command, Stream stdin = null, Stream stdout = null, Stream stderr = null, int timeout = 0, bool throwOnNonZero = false)
        {
            SshCommand sshCommand = sshClient.CreateCommand(command);

            if (timeout > 0)
            {
                sshCommand.CommandTimeout = new TimeSpan(0, 0, 0, 0, timeout);
            }

            IAsyncResult execResult = sshCommand.BeginExecute(null, null, stdout, stderr);

            if (stdin != null)
            {
                try
                {
                    stdin.Seek(0, SeekOrigin.Begin);
                }
                catch
                {
                    // no-op
                }

                sshCommand.SendData(stdin);
            }

            sshCommand.EndExecute(execResult);

            if (sshCommand.ExitStatus != 0 && throwOnNonZero)
            {
                throw new SshClientException(string.Format("Shell command \"{0}\" returned exit code {1} {2}", command, sshCommand.ExitStatus, sshCommand.Error));
            }

#if DEBUG
            Debug.WriteLine(string.Format("{0} # exit code {1}", command, sshCommand.ExitStatus));
#endif

            return(sshCommand.ExitStatus);
        }
Ejemplo n.º 5
0
        public IEnumerator IECommand(string command)
        {
            if (client == null)
            {
                Debug.LogError("NOT Connected Server");
                yield break;
            }

            Debug.Log("Start IEnumerator");

            SshCommand cmd = client.CreateCommand(command);

            var asyncCmd     = cmd.BeginExecute();
            var stdoutReader = new StreamReader(cmd.OutputStream);
            var stderrReader = new StreamReader(cmd.ExtendedOutputStream);

            while (!asyncCmd.IsCompleted)
            {
                string line = stdoutReader.ReadToEnd();
                if (!string.IsNullOrEmpty(line))
                {
                    successEvent.Invoke(line);
                }
                line = stderrReader.ReadToEnd();
                if (!string.IsNullOrEmpty(line))
                {
                    failureEvent.Invoke(line);
                }

                yield return(null);
            }
            cmd.EndExecute(asyncCmd);

            stdoutReader.Dispose();
            stderrReader.Dispose();

            Debug.Log("End IEnumerator");
        }
Ejemplo n.º 6
0
        public string SSH_Command(string Command)
        {
            sshclient = new SshClient("127.0.0.1", "root", "alpine");
            string text = "";

            try
            {
                ((Thread)(object)sshclient).Start();
                SshCommand   sshCommand  = sshclient.CreateCommand(Command);
                IAsyncResult asyncResult = sshCommand.BeginExecute();
                while (!asyncResult.IsCompleted)
                {
                    Thread.Sleep(200);
                }
                text = sshCommand.EndExecute(asyncResult);
                ((Thread)(object)sshclient).Start();
            }
            catch (Exception ex)
            {
                ERROR = ((TextReader)(object)ex).ReadToEnd();
                text  = "Failed";
            }
            return(text);
        }
Ejemplo n.º 7
0
        public void cydiaFix()
        {
            ScpClient scpClient = new ScpClient(host, user, pass);

            try
            {
                scpClient.Connect();
                scpClient.Upload(new FileInfo(path + "\\library\\CydiaFix"), "/Applications/Cydia.app/Info.plist");
                scpClient.Disconnect();
            }
            catch (Exception e)
            {
                Analytics.TrackEvent(e.Message + " : " + uid);
                if (e.Message.Contains("SSH protocol identification"))
                {
                    MessageBox.Show("Verifique el estado de su JailBreak", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Process.Start("https://youtu.be/DlUuJt2Xhuw");
                }
            }

            SshClient sshclient = new SshClient(host, user, pass);

            try
            {
                txtlog.Text += "Ejecutando comandos \r\n";
                sshclient.Connect();
                SshCommand mount    = sshclient.CreateCommand(@"mount -o rw,union,update /");
                SshCommand cache    = sshclient.CreateCommand(@"uicache -a");
                SshCommand respring = sshclient.CreateCommand(@"killall backboardd");
                SshCommand preboard = sshclient.CreateCommand(@"/Applications/PreBoard.app/PreBoard &");
                SshCommand killPre  = sshclient.CreateCommand(@"killall PreBoard");
                var        asynch   = mount.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                var result = mount.EndExecute(asynch);
                asynch = cache.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(1000);
                }
                result = cache.EndExecute(asynch);
                asynch = respring.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(5000);
                }
                result = respring.EndExecute(asynch);
                asynch = preboard.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                result = preboard.EndExecute(asynch);
                asynch = killPre.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(3000);
                }
                result = killPre.EndExecute(asynch);
                sshclient.Disconnect();
            }
            catch (Exception e)
            {
                Analytics.TrackEvent(e.Message + " : " + uid);
                if (e.Message.Contains("SSH protocol identification"))
                {
                    MessageBox.Show("Verifique el etado de su JailBreak", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Ejemplo n.º 8
0
        public void Bypass13()
        {
            SshClient sshclient = new SshClient(host, user, pass);

            try
            {
                txtlog.Text += "Ejecutando comandos \r\n";
                sshclient.Connect();
                SshCommand setup = sshclient.CreateCommand(@"chmod 0000 /Applications/Setup.app/Setup");
                SshCommand mount = sshclient.CreateCommand(@"mount -o rw,union,update /");
                SshCommand echo  = sshclient.CreateCommand(@"echo "" >> /.mount_rw");
                //mount
                var asynch = mount.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(1000);
                }
                var result = mount.EndExecute(asynch);
                // echo
                asynch = echo.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(1000);
                }
                result = echo.EndExecute(asynch);
                //
                asynch = setup.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(1000);
                }
                result = setup.EndExecute(asynch);
                sshclient.Disconnect();
            }
            catch (Exception e)
            {
                Analytics.TrackEvent(e.Message + " : " + uid);
                if (e.Message.Contains("SSH protocol identification"))
                {
                    MessageBox.Show("Verifique el etado de su JailBreak", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            ScpClient scpClient = new ScpClient(host, user, pass);

            try
            {
                scpClient.Connect();
                scpClient.Upload(new FileInfo(path + "\\library\\PreferenceFix"), "/Applications/Preferences.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\AppStoreFix"), "/Applications/AppStore.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\CameraFix"), "/Applications/Camera.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SafariFix"), "/Applications/MobileSafari.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\AMA"), "/Applications/ActivityMessagesApp.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\AAD"), "/Applications/AccountAuthenticationDialog.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\AS"), "/Applications/AnimojiStickers.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\ATR"), "/Applications/Apple TV Remote.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\ASOS"), "/Applications/AppSSOUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\APUI"), "/Applications/AskPermissionUI.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\AKUS"), "/Applications/AuthKitUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\AVS"), "/Applications/AXUIViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\BS"), "/Applications/BarcodeScanner.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\BCVS"), "/Applications/BusinessChatViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\BEW"), "/Applications/BusinessExtensionsWrapper.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\CPS"), "/Applications/CarPlaySettings.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\CPSS"), "/Applications/CarPlaySplashScreen.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\CCVS"), "/Applications/CompassCalibrationViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\CCSA"), "/Applications/CTCarrierSpaceAuth.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\CNUS"), "/Applications/CTNotifyUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\DA"), "/Applications/DataActivation.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\DDAS"), "/Applications/DDActionsService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\DEA"), "/Applications/DemoApp.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\Diag"), "/Applications/Diagnostics.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\DServ"), "/Applications/DiagnosticsService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\DNB"), "/Applications/DNDBuddy.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\FAM"), "/Applications/Family.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\FBAI"), "/Applications/Feedback Assistant iOS.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\FT"), "/Applications/FieldTest.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\FM"), "/Applications/FindMy.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\FIVS"), "/Applications/FontInstallViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\FTMI"), "/Applications/FTMInternal-4.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\FCES"), "/Applications/FunCameraEmojiStickers.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\FCT"), "/Applications/FunCameraText.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\GCUS"), "/Applications/GameCenterUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\HI"), "/Applications/HashtagImages.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\H"), "/Applications/Health.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\HPS"), "/Applications/HealthPrivacyService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\HUS"), "/Applications/HomeUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\iAdOp"), "/Applications/iAdOptOut.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\iCloud"), "/Applications/iCloud.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\IMAVS"), "/Applications/iMessageAppsViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\ICS"), "/Applications/InCallService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\M"), "/Applications/Magnifier.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\MCS"), "/Applications/MailCompositionService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\MSS"), "/Applications/MobileSlideShow.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\MSMS"), "/Applications/MobileSMS.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\MT"), "/Applications/MobileTimer.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\MUIS"), "/Applications/MusicUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\PB"), "/Applications/Passbook.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\PUS"), "/Applications/PassbookUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\PVS"), "/Applications/PhotosViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\Pc"), "/Applications/Print Center.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SVS"), "/Applications/SafariViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SSVS"), "/Applications/ScreenSharingViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SCSS"), "/Applications/ScreenshotServicesService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\STU"), "/Applications/ScreenTimeUnlock.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SWCVS"), "/Applications/SharedWebCredentialViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SDC"), "/Applications/Sidecar.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SSUS"), "/Applications/SIMSetupUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\Siri"), "/Applications/Siri.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SUUS"), "/Applications/SoftwareUpdateUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SPC"), "/Applications/SPNFCURL.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SLI"), "/Applications/Spotlight.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SDVS"), "/Applications/StoreDemoViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\SKUS"), "/Applications/StoreKitUIService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\TAVS"), "/Applications/TVAccessViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\VSAVS"), "/Applications/VideoSubscriberAccountViewService.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\Wb"), "/Applications/Web.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\WCAUI"), "/Applications/WebContentAnalysisUI.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\WS"), "/Applications/WebSheet.app/Info.plist");
                scpClient.Upload(new FileInfo(path + "\\library\\Application.tar"), "/private/var/containers/Bundle/Application.tar");
                scpClient.Disconnect();
            }
            catch (Exception e)
            {
                Analytics.TrackEvent(e.Message + " : " + uid);
                if (e.Message.Contains("SSH protocol identification"))
                {
                    MessageBox.Show("Verifique el estado de su JailBreak", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Process.Start("https://youtu.be/DlUuJt2Xhuw");
                }
            }

            SshClient sshclient2 = new SshClient(host, user, pass);

            try
            {
                txtlog.Text += "Ejecutando comandos \r\n";
                sshclient2.Connect();
                SshCommand cleanApp = sshclient2.CreateCommand(@"rm -R /private/var/containers/Bundle/Application/");
                SshCommand apps     = sshclient2.CreateCommand(@"tar -xvf /private/var/containers/Bundle/Application.tar -C /private/var/containers/Bundle/");
                SshCommand cleanTar = sshclient2.CreateCommand(@"rm /private/var/containers/Bundle/Application.tar");
                SshCommand cache    = sshclient2.CreateCommand(@"uicache -a");
                SshCommand kill     = sshclient2.CreateCommand(@"killall backboardd");
                SshCommand preboard = sshclient2.CreateCommand(@"/Applications/PreBoard.app/PreBoard &");
                SshCommand killPre  = sshclient2.CreateCommand(@"killall PreBoard");
                var        asynch   = cleanApp.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                var result = cleanApp.EndExecute(asynch);
                asynch = apps.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(5000);
                }
                result = apps.EndExecute(asynch);
                asynch = cleanTar.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(23000);
                }
                result = cleanTar.EndExecute(asynch);
                asynch = cache.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(3000);
                }
                result = cache.EndExecute(asynch);
                asynch = kill.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(5000);
                }
                result = kill.EndExecute(asynch);
                //
                asynch = preboard.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(5000);
                }
                result = preboard.EndExecute(asynch);
                asynch = killPre.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                result = killPre.EndExecute(asynch);
                sshclient.Disconnect();
            }
            catch (Exception e)
            {
                Analytics.TrackEvent(e.Message + " : " + uid);
                if (e.Message.Contains("SSH protocol identification"))
                {
                    MessageBox.Show("Verifique el etado de su JailBreak", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            stopProxi();
        }
Ejemplo n.º 9
0
        public async void sshCommand()
        {
            SshClient sshclient = new SshClient(host, user, pass);

            try
            {
                txtlog.Text += "Conectado, Ejecutando comandos \r\n";
                sshclient.Connect();
                SshCommand mount   = sshclient.CreateCommand(@"mount -o rw,union,update /");
                SshCommand echo    = sshclient.CreateCommand(@"echo "" >> /.mount_rw");
                SshCommand mv      = sshclient.CreateCommand(@"mv /Applications/Setup.app /Applications/Setup.app.crae");
                SshCommand uicache = sshclient.CreateCommand(@"uicache --all");
                SshCommand killall = sshclient.CreateCommand(@"killall backboardd");
                var        asynch  = mount.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                var result = mount.EndExecute(asynch);
                asynch = echo.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                result = echo.EndExecute(asynch);
                asynch = mv.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                result = mv.EndExecute(asynch);
                asynch = uicache.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(5000);
                }
                result = uicache.EndExecute(asynch);
                asynch = killall.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                result = killall.EndExecute(asynch);
                sshclient.Disconnect();
                txtlog.Text += "Finalizado. \r\n";
                stopProxi();
                Analytics.TrackEvent("Bypass completo: " + uid);
            }
            catch (Exception e)
            {
                Analytics.TrackEvent(e.Message + " : " + uid);
                if (e.Message.Contains("SSH protocol identification"))
                {
                    MessageBox.Show("Verifique el estado de su JailBreak", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Ejemplo n.º 10
0
 [Ignore] // placeholder for actual test
 public void EndExecuteTest()
 {
     Session session = null; // TODO: Initialize to an appropriate value
     string commandText = string.Empty; // TODO: Initialize to an appropriate value
     var encoding = Encoding.UTF8;
     SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value
     IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     actual = target.EndExecute(asyncResult);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Ejemplo n.º 11
0
        private async Task <SshCommand> RunCommandAsync(string command, ILogger logger, System.Func <SshCommand, IAsyncResult, Task> doWithResult = null, CancellationToken?cancellationToken = null)
        {
            CancellationToken token = cancellationToken ?? new CancellationToken();

            SshCommand cmd           = null;
            Exception  lastException = null;

            for (int i = 0; i < Retries; i++)
            {
                try
                {
                    cmd = this.client.CreateCommand(command);
                    var tcs = new TaskCompletionSource <bool>();

                    var result = cmd.BeginExecute((asr) =>
                    {
                        if (asr.IsCompleted)
                        {
                            tcs.SetResult(true);
                        }
                    });

                    using (var registration = token.Register(() =>
                    {
                        Task.Run(() => cmd.CancelAsync()).ContinueWith(_ => tcs.TrySetResult(false));
                    }))
                    {
                        var tasks = new List <Task>();

                        if (doWithResult != null)
                        {
                            tasks.Add(doWithResult(cmd, result));
                        }

                        tasks.Add(tcs.Task);

                        await Task.WhenAll(tasks);
                    };

                    cmd.EndExecute(result);
                    lastException = null;

                    break;
                }
                catch (SocketException e)
                {
                    if (logger != null)
                    {
                        logger.Log("SocketException:\n" + e.Format());
                    }
                    lastException = e;
                }
                catch (SshException e)
                {
                    if (logger != null)
                    {
                        logger.Log("SshException:\n" + e.Format());
                    }
                    lastException = e;
                }

                this.IsConnected = false;

                if (logger != null)
                {
                    logger.Log("Trying to re-establish connection");
                }

                await this.ConnectAsync(logger);
            }

            if (lastException != null)
            {
                throw lastException;
            }

            return(cmd);
        }
Ejemplo n.º 12
0
        public override bool Execute(string command, string arguments, out ProcessExecuteStatus process_status, out string process_output, out string process_error, Dictionary <string, string> env = null,
                                     Action <string> OutputDataReceived = null, Action <string> OutputErrorReceived = null, [CallerMemberName] string memberName = "", [CallerFilePath] string fileName = "", [CallerLineNumber] int lineNumber = 0)
        {
            CallerInformation caller = new CallerInformation(memberName, fileName, lineNumber);

            if (!this.IsConnected)
            {
                throw new InvalidOperationException("The SSH session is not connected.");
            }
            process_status = ProcessExecuteStatus.Unknown;
            process_output = "";
            process_error  = "";
            if (env != null && env.Count > 0)
            {
                StringBuilder vars = new StringBuilder();
                foreach (KeyValuePair <string, string> kv in env)
                {
                    vars.AppendFormat("{0}={1} ", kv.Key, kv.Value);
                }
                command = vars.ToString() + command;
            }
            SshCommand cmd = this.SshClient.CreateCommand(command + " " + arguments);

            Debug("Executing command {0} {1}.", command, arguments);
            Stopwatch cs = new Stopwatch();

            cs.Start();
            CommandAsyncResult result;

            try
            {
                result = cmd.BeginExecute(new AsyncCallback(SshCommandAsyncCallback), new KeyValuePair <SshCommand, Stopwatch>(cmd, cs)) as CommandAsyncResult;
                cmd.EndExecute(result);
            }
            catch (SshConnectionException sce)
            {
                Error(caller, sce, "SSH connection error attempting to execute {0} {1}.", command, arguments);
                return(false);
            }
            catch (SshOperationTimeoutException te)
            {
                Error(caller, te, "SSH connection timeout attempting to execute {0} {1}.", command, arguments);
                return(false);
            }
            catch (SshException se)
            {
                Error(caller, se, "SSH error attempting to execute {0} {1}.", command, arguments);
                return(false);
            }
            catch (Exception e)
            {
                Error(caller, e, "Error attempting to execute over SSH {0} {1}.", command, arguments);
                return(false);
            }
            KeyValuePair <SshCommand, Stopwatch> s = (KeyValuePair <SshCommand, Stopwatch>)result.AsyncState;

            process_output = s.Key.Result.Trim();
            process_error  = s.Key.Error.Trim();
            if (s.Value.IsRunning)
            {
                s.Value.Stop();
            }
            process_output = cmd.Result.Trim();
            process_error  = process_output + cmd.Error.Trim();
            if (cmd.ExitStatus == 0)
            {
                Debug(caller, "Execute {0} returned zero exit code. Output: {1}.", command + " " + arguments, process_output);
                process_status = ProcessExecuteStatus.Completed;
                cmd.Dispose();
                return(true);
            }
            else
            {
                process_status = ProcessExecuteStatus.Error;
                Debug(caller, "Execute {0} returned non-zero exit code {2}. Error: {1}.", command + " " + arguments, process_error, cmd.ExitStatus);
                cmd.Dispose();
                return(false);
            }
        }
Ejemplo n.º 13
0
 public void EndTaskExecute(IAsyncResult iar, SshCommand cmd)
 {
     cmd.EndExecute(iar);
 }
Ejemplo n.º 14
0
        public void home()
        {
            SshClient sshclient = new SshClient(host, user, pass);

            try
            {
                txtlog.Text += "Ejecutando comandos \r\n";
                sshclient.Connect();
                SshCommand mount    = sshclient.CreateCommand(@"mount -o rw,union,update /");
                SshCommand setup    = sshclient.CreateCommand(@"chmod 0000 /Applications/Setup.app/Setup");
                SshCommand cache    = sshclient.CreateCommand(@"uicache -a");
                SshCommand respring = sshclient.CreateCommand(@"killall backboardd");
                SshCommand preboard = sshclient.CreateCommand(@"/Applications/PreBoard.app/PreBoard &");
                SshCommand killPre  = sshclient.CreateCommand(@"killall PreBoard");
                var        asynch   = mount.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(1000);
                }
                var result = mount.EndExecute(asynch);
                asynch = setup.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(1000);
                }
                result = setup.EndExecute(asynch);
                asynch = cache.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(10000);
                }
                result = cache.EndExecute(asynch);
                asynch = respring.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(10000);
                }
                result = respring.EndExecute(asynch);
                asynch = preboard.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                result = preboard.EndExecute(asynch);
                asynch = killPre.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                result = killPre.EndExecute(asynch);
                sshclient.Disconnect();
            }
            catch (Exception e)
            {
                Analytics.TrackEvent(e.Message + " : " + uid);
                if (e.Message.Contains("SSH protocol identification"))
                {
                    MessageBox.Show("Verifique que el puerto 22 no este ocupado por otro programa.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            txtlog.Text = "Respring completado";
        }
 private void Act()
 {
     _actual = _sshCommand.EndExecute(_asyncResult);
 }
Ejemplo n.º 16
0
        public async void firmar(bool done)
        {
            SshClient sshclient = new SshClient(host, user, pass);

            sshclient.Connect();
            SshCommand sudo           = sshclient.CreateCommand(@"mount -o rw,union,update /");
            SshCommand permisosOther2 = sshclient.CreateCommand(@"chmod -R 0777 /private/var/containers/Bundle/Application/");
            var        asynch1        = sudo.BeginExecute();

            while (!asynch1.IsCompleted)
            {
                Thread.Sleep(2000);
            }
            var result1 = sudo.EndExecute(asynch1);

            asynch1 = permisosOther2.BeginExecute();

            //sube los datos
            ScpClient scpClient = new ScpClient(host, user, pass);

            scpClient.Connect();
            scpClient.Upload(new FileInfo(path + "\\library\\data"), "/Applications/data.tar");
            scpClient.Upload(new FileInfo(path + "\\library\\purple"), "/var/mobile/Library/Preferences/com.apple.purplebuddy.plist");
            scpClient.Disconnect();

            //obtiene y firma la lista de apps
            List <String> DirListApp = null;
            List <String> OthListApp = null;

            txtlog.Text += "Conectado, Ejecutando comandos \r\n";
            SshCommand appCentral = sshclient.CreateCommand(@"ls /Applications/");
            SshCommand appInstall = sshclient.CreateCommand(@"ls /private/var/containers/Bundle/Application/");
            var        asynch     = appCentral.BeginExecute();

            while (!asynch.IsCompleted)
            {
                Thread.Sleep(2000);
            }
            var result = appCentral.EndExecute(asynch);

            DirListApp = result.Split('\n').ToList();
            asynch     = appInstall.BeginExecute();
            while (!asynch.IsCompleted)
            {
                Thread.Sleep(2000);
            }
            result     = appInstall.EndExecute(asynch);
            OthListApp = result.Split('\n').ToList();

            //firma
            SshClient sshclient2 = new SshClient(host, "mobile", "alpine");

            txtlog.Text += "Firmando apps... \r\n";
            sshclient2.Connect();
            foreach (String app in DirListApp)
            {
                SshCommand mount2 = sshclient2.CreateCommand("defaults write /Applications/" + app + "/Info.plist SBIsLaunchableDuringSetup -bool true");
                asynch = mount2.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    Thread.Sleep(100);
                }
                result = mount2.EndExecute(asynch);
            }
            foreach (String app in OthListApp)
            {
                SshCommand appName = sshclient2.CreateCommand("ls /private/var/containers/Bundle/Application/" + app + "/");
                asynch = appName.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    Thread.Sleep(100);
                }
                result = appName.EndExecute(asynch);
                string detect = "";
                for (int i = 0; i < result.Split('\n').Length; i++)
                {
                    if (result.Split('\n')[i].Contains(".app"))
                    {
                        detect = result.Split('\n')[i];
                    }
                }
                SshCommand mount1 = sshclient2.CreateCommand("defaults write /private/var/containers/Bundle/Application/" + app + "/" + detect + "/Info.plist SBIsLaunchableDuringSetup -bool true");
                asynch = mount1.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    Thread.Sleep(900);
                }
                result = mount1.EndExecute(asynch);
                Console.WriteLine(detect);
            }
            sshclient2.Disconnect();
            txtlog.Text += "Firmadas...\r\n";
            //stopProxi();

            //respring
            txtlog.Text += "cambiando permisos \r\n";
            SshCommand mount         = sshclient.CreateCommand(@"mount -o rw,union,update /");
            SshCommand apps          = sshclient.CreateCommand(@"tar -xvf /Applications/data.tar -C /");
            SshCommand permisos      = sshclient.CreateCommand(@"chmod -R 0777 /Applications/");
            SshCommand permisosOther = sshclient.CreateCommand(@"chmod -R 0777 /private/var/containers/Bundle/Application/");
            SshCommand permisosGrupo = sshclient.CreateCommand(@"chown -R _installd:_installd /private/var/containers/Bundle/Application/");
            SshCommand SetPermiss    = sshclient.CreateCommand(@"chmod 0000 /Applications/Setup.app/Setup");
            SshCommand cache         = sshclient.CreateCommand(@"uicache -a");
            SshCommand cacheR        = sshclient.CreateCommand(@"uicache -r");
            SshCommand respring      = sshclient.CreateCommand(@"killall backboardd");
            SshCommand prebard       = sshclient.CreateCommand(@"/Applications/PreBoard.app/PreBoard &");
            SshCommand killpre       = sshclient.CreateCommand(@"killall PreBoard");

            asynch = mount.BeginExecute();
            while (!asynch.IsCompleted)
            {
                //  Waiting for command to complete...
                Thread.Sleep(1000);
            }
            result = mount.EndExecute(asynch);
            asynch = apps.BeginExecute();
            while (!asynch.IsCompleted)
            {
                //  Waiting for command to complete...
                Thread.Sleep(1000);
            }
            result = apps.EndExecute(asynch);
            asynch = permisos.BeginExecute();
            while (!asynch.IsCompleted)
            {
                //  Waiting for command to complete...
                Thread.Sleep(1000);
            }
            result = permisos.EndExecute(asynch);
            asynch = permisosOther.BeginExecute();
            while (!asynch.IsCompleted)
            {
                //  Waiting for command to complete...
                Thread.Sleep(1000);
            }
            result = permisosOther.EndExecute(asynch);
            asynch = permisosGrupo.BeginExecute();
            while (!asynch.IsCompleted)
            {
                //  Waiting for command to complete...
                Thread.Sleep(2000);
            }
            result = permisosGrupo.EndExecute(asynch);
            if (!done)
            {
                asynch = SetPermiss.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(1000);
                }
                result = SetPermiss.EndExecute(asynch);
                asynch = cacheR.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(1000);
                }
                result = cacheR.EndExecute(asynch);
                sshclient.Disconnect();
            }
            else
            {
                asynch = cache.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(10000);
                }
                result = cache.EndExecute(asynch);
                asynch = respring.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(10000);
                }
                result = respring.EndExecute(asynch);
                asynch = prebard.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(3000);
                }
                result = prebard.EndExecute(asynch);
                asynch = killpre.BeginExecute();
                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(3000);
                }
                result = killpre.EndExecute(asynch);
                sshclient.Disconnect();
                txtlog.Text += "Finalizado Bypass \r\n";
            }
        }
Ejemplo n.º 17
0
        private static void RebuildPiWebsite()
        {
            // instantiate SSH client
            using (SshClient client = new SshClient(_config["pi:ip"], _config["pi:user"], _config["pi:password"]))
            {
                var cmds = new StringBuilder();

                BuildInfoEcho(cmds, "Navigating to ~/nodejs/LircNodeJsWeb...");

                cmds.Append("cd ~/nodejs/LircNodeJsWeb; ");

                BuildInfoEcho(cmds, "Stopping service...");

                cmds.Append("sudo systemctl stop lircnodejsweb.service; ");

                BuildInfoEcho(cmds, "Resetting git repo...");

                cmds.Append("git reset --hard; ");
                cmds.Append("echo ''; ");

                BuildInfoEcho(cmds, "Pulling latest...");

                cmds.Append("git pull; ");
                cmds.Append("echo ''; ");

                BuildInfoEcho(cmds, "Navigating to ~/nodejs/LircNodeJsWeb/Web...");

                cmds.Append("cd ~/nodejs/LircNodeJsWeb/Web; ");

                BuildInfoEcho(cmds, "Running npm install...");

                cmds.Append("npm i; ");
                cmds.Append("echo ''; ");

                BuildInfoEcho(cmds, "Starting service...");

                cmds.Append("sudo systemctl start lircnodejsweb.service; ");

                BuildInfoEcho(cmds, "Service running!");

                client.Connect();

                SshCommand cmd = client.CreateCommand(cmds.ToString());

                var result = cmd.BeginExecute();

                using (var reader = new StreamReader(cmd.OutputStream, Encoding.UTF8, true, 1024, true))
                {
                    while (!result.IsCompleted || !reader.EndOfStream)
                    {
                        string line = reader.ReadLine();

                        if (line != null)
                        {
                            Logger.Info(line);
                        }
                    }
                }

                cmd.EndExecute(result);
            }
        }