Skip to content

Commit 1b47ae1

Browse files
Add RETURN_CONST as an allowed _const_code in safeeval (#2352)
* better error message when process creation fails in ssh.process * add RETURN_CONST as an allowed _const_code in safeeval * fix lint * add to changelog * fix changelog * add couldn't find python warning * Deduplicate error message code --------- Co-authored-by: Peace-Maker <[email protected]>
1 parent 2114692 commit 1b47ae1

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ The table below shows which release corresponds to each branch, and what date th
9292

9393
## 4.11.2
9494
- [#2349][2349] Fix term.readline omitting a trailing \n
95+
- [#2352][2352] add `RETURN_CONST` as an allowed `_const_code` in safeeval
9596

9697
[2349]: https://github.com/Gallopsled/pwntools/pull/2349
98+
[2352]: https://github.com/Gallopsled/pwntools/pull/2352
9799

98100
## 4.11.1 (`stable`)
99101

pwnlib/tubes/ssh.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1074,15 +1074,19 @@ def is_exe(path):
10741074
python = ssh_process(self, script, tty=True, cwd=cwd, raw=True, level=self.level, timeout=timeout)
10751075

10761076
try:
1077-
python.recvline_contains(b'PWNTOOLS') # Magic flag so that any sh/bash initialization errors are swallowed
1078-
python.recvline() # Python interpreter that was selected
1077+
python.recvline_contains(b'PWNTOOLS') # Magic flag so that any sh/bash initialization errors are swallowed
1078+
try:
1079+
if b'python' not in python.recvline(): # Python interpreter that was selected
1080+
raise ValueError("Python not found on remote host")
1081+
except (EOFError, ValueError):
1082+
self.warn_once('Could not find a Python interpreter on %s\n' % self.host
1083+
+ "Use ssh.system() instead of ssh.process()\n")
1084+
h.failure("Process creation failed")
1085+
return None
1086+
10791087
result = safeeval.const(python.recvline()) # Status flag from the Python script
10801088
except (EOFError, ValueError):
10811089
h.failure("Process creation failed")
1082-
self.warn_once('Could not find a Python interpreter on %s\n' % self.host
1083-
+ "Use ssh.run() instead of ssh.process()\n"
1084-
"The original error message:\n"
1085-
+ python.recvall().decode())
10861090
return None
10871091

10881092
# If an error occurred, try to grab as much output

pwnlib/util/safeeval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'BUILD_CONST_KEY_MAP', 'BUILD_STRING',
77
'LOAD_CONST','RETURN_VALUE','STORE_SUBSCR', 'STORE_MAP',
88
'LIST_TO_TUPLE', 'LIST_EXTEND', 'SET_UPDATE', 'DICT_UPDATE', 'DICT_MERGE',
9-
'COPY', 'RESUME',
9+
'COPY', 'RESUME', 'RETURN_CONST'
1010
]
1111

1212
_expr_codes = _const_codes + [

0 commit comments

Comments
 (0)