利用Python ZipFile模块破解加密文档
利用Python ZipFile模块破解加密文档
`import zipfile
import optparse
import threading
import sys
import os
import queue
class ZipDecrypt:
def init(self) -> None:
self.filename = self.get_params()[0]
self.wordlist = self.get_params()[1]
self.q = queue.Queue()
print("""
Start to crack*******************
""")
def get_params(self):
parser = optparse.OptionParser('Usage: ./%s -f filename -w wordlist' % sys.argv[0])
parser.add_option('-f', '--filename', dest='filename', type='string', help='Specify filename to crack')
parser.add_option('-w', '--wordlist', dest='wordlist', type='string', help='Specify wordlist')
options, args = parser.parse_args()
if options.filename is None or options.wordlist is None:
print('[-]',parser.usage)
sys.exit()
if not os.path.isfile(options.filename):
print("[-] The file does not exist")
sys.exit()
if not os.path.isfile(options.wordlist):
print("[-] The wordlist does not exist")
sys.exit()
return options.filename, options.wordlist
def decrypt(self,password):
try:
zipper = zipfile.ZipFile(self.filename)
zipper.extractall(pwd=password.encode('utf-8'))
print('[+] Password Found: %s' % password)
self.q.put(password)
sys.exit()
except:
pass
def run(self):
with open(self.wordlist,'r') as f:
while True:
if not self.q.empty(): # Password has been found, no need to carry on loop
break
try:
line = f.readline()
if len(line) == 0:
break
password = line.strip()
t = threading.Thread(target=self.decrypt,args=(password,))
t.start()
# t.join()
except:
continue
if self.q.empty():
print('[-] Failed to crack')
if name == 'main':
zip_object = ZipDecrypt()
zip_object.run()`
STRIVE FOR PROGRESS,NOT FOR PERFECTION