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

Prefer Python3 for the remotely-executed Python script #1746

Merged
Merged
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions pwnlib/tubes/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,14 @@ def func(): pass

func_src = inspect.getsource(func).strip()
setuid = True if setuid is None else bool(setuid)

# executable may be a unicode string on Python2 and will get a u-prefix
# when passed to repr() in the script below.
#
# This breaks things if a Python3 interpreter is selected.
executable = six.ensure_str(executable)
argv = [bytes(a) for a in argv]
env = None if not env else { six.ensure_str(k): six.ensure_str(v) for k,v in env}

script = r"""
#!/usr/bin/env python
Expand All @@ -942,7 +950,7 @@ def func(): pass
except NameError:
integer_types = int,
exe = %(executable)r
argv = [bytes(a) for a in %(argv)r]
argv = %(argv)r
env = %(env)r

os.chdir(%(cwd)r)
Expand Down Expand Up @@ -1076,7 +1084,7 @@ def is_exe(path):

with self.progress(msg) as h:

script = 'for py in python2.7 python2 python; do test -x "$(which $py 2>&1)" && exec $py -c %s check; done; echo 2' % sh_string(script)
script = 'for py in python3 python2.7 python2 python; do test -x "$(which $py 2>&1)" && exec $py -c %s check; done; echo 2' % sh_string(script)
with context.quiet:
python = ssh_process(self, script, tty=True, raw=True, level=self.level, timeout=timeout)

Expand Down