Esempio n. 1
0
        public void RunOnDeviceWithAuthentication(string device, string commandline, CredToken creds)
        {
            // For whatever reason, making everything a string literal fixed a problem with making this work correctly
            var loggableArguments = $@"\\{device} -u {creds.Domain}\{creds.User} -p [REDACTED] " + commandline;
            _logger.LogMessage($"Beginning PsExec attempt on {device} with following command line options: {loggableArguments}");

            RunPsExec(device, commandline, creds);
        }
Esempio n. 2
0
        private void RunPsExec(string device, string arguments, CredToken creds = null)
        {
            ForceCleanRemotePsExeSvc(device);

            var process = GeneratePsExecProcess();

            try
            {
                if (creds != null)
                {
                    process.StartInfo.Arguments = $@"\\{device} -u {creds.Domain}\{creds.User} -p {SecureStringHelper.GetInsecureString(creds.SecurePassword)} {arguments}";
                }
                else
                {
                    process.StartInfo.Arguments = $@"\\{device} {arguments}";
                }

                process.Start();
                _logger.LogMessage($"PSExec process started with start ID: {process.Id}");
                process.WaitForExit(60000);

                if (!process.HasExited)
                {
                    process.Kill();
                    _logger.LogMessage($"Killed process {process.Id}");
                }

                var stdOutput = process.StandardOutput.ReadToEnd();
                var errOutput = process.StandardError.ReadToEnd();

                var stdResult = RemoveEmptyLines(stdOutput);
                var errResult = RemoveEmptyLines(errOutput);

                if (string.IsNullOrWhiteSpace(stdOutput) && string.IsNullOrWhiteSpace(errResult))
                {
                    throw new Exception($"Device did not return a value. Please run the command on the device manually. \n PsExec command line: {process.StartInfo.Arguments}");
                }

                ResultConsole.Instance.AddConsoleLine(errResult);
                ResultConsole.Instance.AddConsoleLine(stdResult);
                _logger.LogMessage(errResult);
            }
            catch (Exception ex)
            {
                var exceptionResult = $"Exception running command on device {device}. {ex.Message}";
                ResultConsole.Instance.AddConsoleLine(exceptionResult);
            }

            Thread.Sleep(1000);
        }
Esempio n. 3
0
 private void UpdateCredentials(string domain, string user, string pass)
 {
     _creds = new CredToken(domain, user, BuildSecureString(pass));
 }
Esempio n. 4
0
 public void SetCredentials(string domain, string user, SecureString pass)
 {
     _creds = new CredToken(domain, user, pass);
 }
Esempio n. 5
0
 public CredentialManager()
 {
     CredentialsChangedHandler += UpdateCredentials;
     _creds = null;
     _instance = this;
 }