Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'shell' option for ssh.process to pass to "sh -c" #800

Merged
merged 1 commit into from
Nov 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pwnlib/tubes/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ def shell(self, shell = None, tty = True, timeout = Timeout.default):
return self.run(shell, tty, timeout = timeout)

def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, timeout=Timeout.default, run=True,
stdin=0, stdout=1, stderr=2, preexec_fn=None, preexec_args=[], raw=True, aslr=None, setuid=None):
stdin=0, stdout=1, stderr=2, preexec_fn=None, preexec_args=[], raw=True, aslr=None, setuid=None,
shell=False):
r"""
Executes a process on the remote server, in the same fashion
as pwnlib.tubes.process.process.
Expand Down Expand Up @@ -680,6 +681,8 @@ def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, time
See ``pwnlib.tubes.process.process`` for more information.
setuid(bool):
See ``pwnlib.tubes.process.process`` for more information.
shell(bool):
Pass the command-line arguments to the shell.

Returns:
A new SSH channel, or a path to a script if ``run=False``.
Expand Down Expand Up @@ -737,6 +740,9 @@ def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, time
Traceback (most recent call last):
...
NameError: global name 'bar' is not defined

>>> s.process('echo hello', shell=True).recvall()
'hello\n'
"""
if not argv and not executable:
self.error("Must specify argv or executable")
Expand All @@ -750,6 +756,11 @@ def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, time
if not isinstance(argv, (list, tuple)):
self.error('argv must be a list or tuple')

if shell:
if len(argv) != 1:
self.error('Cannot provide more than 1 argument if shell=True')
argv = ['/bin/sh', '-c'] + argv

# Python doesn't like when an arg in argv contains '\x00'
# -> execve() arg 2 must contain only strings
for i, arg in enumerate(argv):
Expand Down