Skip to content

Commit

Permalink
Executing command with sudo no longer exposes the user password to th…
Browse files Browse the repository at this point in the history
…e root. (#393)

Closes #350
  • Loading branch information
URunDEAD authored Nov 5, 2021
1 parent 3d66b36 commit f9a5ff7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/SSHLibrary/javaclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,12 @@ def _execute(self):
self._shell.execCommand(command)

def _execute_with_sudo(self, sudo_password=None):
command = 'sudo ' + self._command.decode(self._encoding)
command = self._command.decode(self._encoding)
if sudo_password is None:
self._shell.execCommand(command)
self._shell.execCommand('sudo ' + command)
else:
self._shell.execCommand('echo %s | sudo --stdin --prompt "" %s' % (sudo_password, command))
self._shell.execCommand('sudo --stdin --prompt "" %s' % (command))
self._shell.write('\n\n' + sudo_password + '\n')

def _invoke(self):
command = self._command.decode(self._encoding)
Expand Down
7 changes: 4 additions & 3 deletions src/SSHLibrary/pythonclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,12 @@ def _execute(self):
self._shell.exec_command(self._command)

def _execute_with_sudo(self, sudo_password=None):
command = 'sudo ' + self._command.decode(self._encoding)
command = self._command.decode(self._encoding)
if sudo_password is None:
self._shell.exec_command(command)
self._shell.exec_command('sudo ' + command)
else:
self._shell.exec_command('echo %s | sudo --stdin --prompt "" %s' % (sudo_password, command))
self._shell.exec_command('sudo --stdin --prompt "" %s' % (command))
self._shell.sendall('\n\n' + sudo_password + '\n')

def _invoke(self):
self._shell.invoke_subsystem(self._command)

0 comments on commit f9a5ff7

Please sign in to comment.