有一个netcat
CTF 任务需要通过 RCE 获取标志(对我来说最简单和最明显的变体是exec()
)
Python 2.7.18 (default, Apr 28 2021, 17:39:59)
[GCC 10.2.1 20210110] on linux2
>>> print input()
pow(2, 3) # No problems with functions
8
>>> print input()
None # Can print None values
None
>>> print input()
eval('1 + 1')
2
>>> print input()
eval('1 + 1') # eval() works
2
>>> x = 1
>>> print input()
eval('x + 1') # eval() with local variables involved also works
2
>>> print input()
exec('') # Even empty exec() causes an error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
exec('') # Even empty exec() causes an error
^
SyntaxError: invalid syntax
>>> print input()
exec('import os') # exec() call causes an error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
exec('import os') # exec() call causes an error
^
SyntaxError: invalid syntax
是否可以在 Python 2.7中推送一个exec()
with调用?(无法input()
切换 Python 版本或更改可执行文件)print input()
UPD
我需要这样的东西:
>>> print input()
exec('import os\nprint os.name') # I need a similar RCE in this CTF task, so eval() is not suitable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
exec('import os\nprint os.name') # I need a similar RCE in this CTF task, so eval() is not suitable
^
SyntaxError: invalid syntax