Skip to content

Instantly share code, notes, and snippets.

@tbhaxor
Created January 23, 2022 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbhaxor/1a548b0d9619b3657f84568b0c1d0845 to your computer and use it in GitHub Desktop.
Save tbhaxor/1a548b0d9619b3657f84568b0c1d0845 to your computer and use it in GitHub Desktop.
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