Skip to content

Instantly share code, notes, and snippets.

@tbhaxor
Created Jan 23, 2022
Embed
What would you like to do?
Brute force the zip file password using multithreading in python 3
#!/usr/bin/env python3
import sys
from threading import Thread
from queue import Queue
from zipfile import ZipFile, BadZipFile
from tempfile import mkdtemp
from blessings import Terminal
TMPDIR = mkdtemp()
passwords = Queue()
z = ZipFile("PDF.zip")
with open("dictionary.txt") as wordlist:
for password in wordlist:
passwords.put(password.strip())
pass
pass
def worker(y):
while not passwords.empty():
password = passwords.get()
try:
z.extractall(path=TMPDIR, pwd=password.encode())
print(t.move(y, 0) + "Thread {}: Password Found: {}. Contents are extracted to {}".format(y, password, TMPDIR) + t.clear_eol)
with passwords.mutex:
passwords.queue.clear()
return
except:
print(t.move(y, 0) + "Thread {}: Tried password: {}".format(y, password) + t.clear_eol)
print(t.move(y, 0) + "Thread {}: Failed to crack zip file".format(y) + t.clear_eol)
pass
t = Terminal()
with t.fullscreen():
threads = []
for i in range(1, 6):
thread = Thread(target=worker, args=(i, ), daemon=True)
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
msg = "All done! Press any key to exit."
print(t.move(len(threads) + 1, (t.width - len(msg)) // 2) + msg)
input()
z.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment