我正在开发一个zip文件密码破解程序,我需要一个暴力破解选项。我已经写出了它的基本代码,但我不确定如何使用参数使其工作。我如何写一个论证来使这项工作?
import optparse
import zipfile
import argparse
from threading import Thread
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--brute")
def extract_zip(zFile, password):
try:
password_encoded = bytes(password.encode('utf-8'))
zFile.setpassword(password_encoded)
zFile.testzip()
print ("[+] Password Found: " + password + '\n')
except:
pass
def Main():
parser = optparse.OptionParser("useage &prog "+\
"-f <zipfile> -d <dictionary> / -b <brute force>")
parser.add_option('-f', dest='zname', type='string',\
help='specify zip file')
parser.add_option('-d', dest='dname', type='string',\
help='specify dictionary file')
parser.add_option('-b', dest='bname', type='string',\
help='specify brute force')
(options, arg) = parser.parse_args()
if (options.zname == None) | (options.dname == None) | (options.bname == None):
print (parser.usage)
exit(0)
else:
zname = options.zname
dname = options.dname
bname = options.bname
zFile = zipfile.ZipFile(zname)
passFile = open(dname)
brute = open(bname)
for line in passFile.readlines():
password = line.strip('\n')
t = Thread(target=extract_zip, args=(zFile, password))
t.start()
if args.brute:
characters = '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
for length in range(1, int(args.brute)):
to_attempt = product(characters, repeat=length)
t = Thread(target=extract_zip, args=(zFile, password))
t.start()
if __name__ == '__main__':
Main()