我正在尝试使用pwntools来控制python3会话。下面是我的代码:
from pwn import process
r = process(['python3'])
r.interactive()但是,在我进入r.interactive()之后,当我在终端中输入时,python3子进程会有奇怪的反应。至少在大多数情况下,我没有看到我的命令被回放。
我还试图在bash会话中调用python3,但同样的事情也发生了。
$ python3
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import process
>>> r = process(['bash'])
[x] Starting local process '/usr/bin/bash'
[+] Starting local process '/usr/bin/bash': pid 119080
>>> r.interactive()
[*] Switching to interactive mode
echo hello
hello
echo this is bash
this is bash
python3
print(1)
print(2)
print(3)
exit
echo hello
File "<stdin>", line 5
echo hello
^
SyntaxError: invalid syntax为什么会发生这种情况?是pwntools中的bug,还是我忽略了一些配置?
发布于 2021-07-24 09:43:04
您需要在shell中指定PTY,如下所示:
$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *; r = process(['python3'], stdin=PTY, raw=False); r.interactive()
[x] Starting local process '/usr/bin/python3'
[+] Starting local process '/usr/bin/python3': pid 2984281
[*] Switching to interactive mode
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1+1
1+1
2
>>> https://stackoverflow.com/questions/68137400
复制相似问题