尝试插入 python 3

Trying to thread in python 3

我一直在进行一项渗透测试学院挑战,以对暴力摘要验证进行挑战,该挑战现在正在运行,但我现在想对其进行线程化,以便更快地进行。但是,这不起作用并产生以下错误。

错误信息

    self.__target(*self.__args, **self.__kwargs)
    TypeError: attempt_user() takes exactly 1 argument (5 given)

我不明白为什么它在我只给出一个参数的情况下需要 5 个参数,我们将不胜感激。我的代码在下面。

代码

import hashlib
import requests
import re
from threading import *
from requests.auth import HTTPDigestAuth

URL =  'http://pentesteracademylab.appspot.com/lab/webapp/digest/1'


lines = [line.rstrip('\n') for line in open('wordl2.txt')]




def attempt_user(i):
try:
    r = requests.get(URL, auth=HTTPDigestAuth('admin', i))
    test = r.status_code
    print ('status code for {} is {}'.format(i, test))
    print (r.headers)
except:
    print ('fail')

# Loop ports informed by parameter
for i in lines:
    # Create a thread by calling the connect function and passing the host and port as a parameter
    t = Thread(target=attempt_user, args=(i))
    # start a thread
    t.start()

这不起作用的原因是 args 应该是一个包含参数的可迭代对象。你给它的不是(正如你所想的那样)一个元组,而是一个单一的值(在你的例子中是一个字符串(!))。

这不是一个元组:

("foo")

这是一个元组:

("foo",)

因此,当您执行 t = Thread(target=attempt_user, args=(i)) 时,Thread.__init__ 获取 i 中的每个元素(在本例中为五个字符)并将它们作为单独的参数传递给 attempt_user .

如我的评论所述,解决方法是实际交出一个元组:

# Loop ports informed by parameter
for i in lines:
    # Create a thread by calling the connect function and passing the host and port as a parameter
    t = Thread(target=attempt_user, args=(i,))
    # start a thread
    t.start()