-2

我正在创建一个脚本,它将启动一些线程,并在二进制文件上运行输入。用法是python3 script.py binary input.txt。这是遇到此错误的可重现段:

from pwn import *
import threading

inputFile = ""
try:
    inputFile = open(sys.argv[2], 'r')
    inputStr = inputFile.read().strip()
    inputFile.close()
except OSError:
    sys.exit()

def run(testStr) :
    p = process("./"+sys.argv[1])
    p.sendline(testStr)
    p.shutdown()
    return p.poll(block = True)

def opens() :
    while True:
        run(inputStr)
        
for i in range(0,10):
    thread = threading.Thread(target = opens)
    thread.start()

运行 5 秒左右后,我遇到了这个错误,以及错误:out of pty devices. 我在 ubuntu 20.04 上运行。

4

1 回答 1

0

事实证明 pwntools 进程 API 不会关闭 stderr 或 stdout,因此在从运行返回之前关闭它们可以解决问题。

于 2020-07-16T05:44:05.617 回答