Last active
October 19, 2017 13:16
-
-
Save e23z/8534faf3251a4ae2f6bd7a141ed149a2 to your computer and use it in GitHub Desktop.
[Password Crackr] A python script to crack the password of zip files. #scripts #password #security #utils #whitehacking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Process, Queue | |
import zipfile | |
import datetime | |
import shutil | |
import argparse | |
import os | |
class Crackr: | |
buffer_size = 1024000 | |
max_threads = 10 | |
exit_command = '@_###_###__EXIT__###_###_@' | |
def __init__(this): | |
# | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-f', '--file', required = True, help = 'The file to be password cracked') | |
parser.add_argument('-d', '--dictionary', required = True, help = 'The password dictionary file') | |
parser.add_argument('-o', '--output', default = './extracted', help = 'The output directory for the extracted files') | |
args = parser.parse_args() | |
# | |
this.zip_path = args.file | |
this.dictionary = args.dictionary | |
this.output = args.output | |
def process(this, zip, output, id): | |
buffer = this.file.read(this.buffer_size) | |
while len(buffer): | |
if not this.queue.empty(): | |
break | |
for line in buffer.split('\n'): | |
password = line | |
try: | |
zip.extractall(pwd = password.encode(), path = output) | |
this.queue.put_nowait(password) | |
this.queue.put_nowait(this.exit_command) | |
break | |
except: | |
pass | |
else: | |
buffer = this.file.read(this.buffer_size) | |
continue | |
break | |
if this.queue.empty(): | |
this.queue.put_nowait(this.exit_command) | |
zip.close() | |
def init_threads(this): | |
this.processes = [] | |
this.queue = Queue() | |
for x in range(this.max_threads): | |
# | |
output = this.output + '/' + str(x) | |
dst = output + '/to_crack.zip' | |
if not os.path.exists(output): | |
os.makedirs(output) | |
shutil.copy(this.zip_path, dst) | |
# | |
z = zipfile.ZipFile(dst) | |
p = Process(target = this.process, args = (z, output, x,)) | |
this.processes.append(p) | |
for p in this.processes: | |
p.start() | |
def watch(this): | |
while this.queue.empty(): | |
pass | |
this.password = this.queue.get_nowait() | |
def run(this): | |
start_time = datetime.datetime.now() | |
this.file = open(this.dictionary, 'r', errors = 'ignore') | |
this.init_threads() | |
this.watch() | |
this.file.close() | |
end_time = datetime.datetime.now() | |
delta = end_time - start_time | |
print('Password: {}'.format(this.password) if this.password != this.exit_command else 'Password not found!') | |
print('Completed after: {}'.format(delta)) | |
if __name__ == '__main__': | |
c = Crackr() | |
c.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment