0

我正在尝试使用 pwntools 来控制 python3 会话。这是我的代码:

from pwn import process
r = process(['python3'])
r.interactive()

但是,我进入后r.interactive(),在终端输入时,python3子进程有奇怪的反应。至少我大部分时间都没有看到我的命令得到回应。

我也试图打电话给python3一个bash会话,但同样的事情发生了。

$ 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 中的错误,还是我忽略了一些配置?

4

1 回答 1

2

您需要在 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
>>> 
于 2021-07-24T01:43:03.890 回答