首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用pwntools进程交互方式控制python3

使用pwntools进程交互方式控制python3
EN

Stack Overflow用户
提问于 2021-06-26 05:52:33
回答 1查看 365关注 0票数 0

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

代码语言:javascript
复制
from pwn import process
r = process(['python3'])
r.interactive()

但是,在我进入r.interactive()之后,当我在终端中输入时,python3子进程会有奇怪的反应。至少在大多数情况下,我没有看到我的命令被回放。

我还试图在bash会话中调用python3,但同样的事情也发生了。

代码语言:javascript
复制
$ 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,还是我忽略了一些配置?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-24 09:43:04

您需要在shell中指定PTY,如下所示:

代码语言:javascript
复制
$ 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
>>> 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68137400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档