Skip to content

Commit

Permalink
Prefer Python3 for the remotely-executed Python script
Browse files Browse the repository at this point in the history
This should be done as part of our general transition to Python3,
but should also be done because some systems with e.g. Python2.6
do not support OrderedDict, but DO have a Python3 version that works.
  • Loading branch information
heapcrash committed Dec 18, 2020
1 parent 9de7438 commit 631096d
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 631096d

Please sign in to comment.