Created
October 9, 2014 12:33
-
-
Save cnmcgrath/30e2617df0966b3e0cb7 to your computer and use it in GitHub Desktop.
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
import zipfile | |
import itertools | |
import time | |
import sys | |
print("\nWelcome to the Password Cracker") | |
print("Make sure this script is in the same directory as the target zip file") | |
print("This script either brute forces or uses a dictinary attack") | |
print("\nSpecify the file name then either brute or dict to start attack\n") | |
file_location = input("Enter Zip Name: ") | |
attack_type = input("Enter either brute or dict to attack: ") | |
zip_file = zipfile.ZipFile(file_location) | |
letter_list = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz' | |
#format time correctly | |
def format_time (seconds): | |
m, s = divmod(seconds, 60) | |
h, m = divmod(m, 60) | |
print ('Time to Complete:',"%d:%02d:%f" % (h, m, seconds)) | |
#brute force password | |
def brute_force (): | |
start = time.clock() | |
no_password = True | |
x=1 | |
while no_password: | |
res = itertools.product(letter_list, repeat=x) | |
for i in res: | |
a = ''.join(i) | |
print(" Trying..... ",a, end="\r") | |
try: | |
zip_file.extractall(pwd=a.encode()) | |
end = time.clock() | |
format_time((end-start)) | |
print('Found password',a,'\n') | |
no_password = False | |
break | |
zip_file.close() | |
except: | |
pass | |
x+=1 | |
return | |
def password_dict (): | |
dictionary = input("Enter in dictionary: ") | |
start = time.clock() | |
with open(dictionary,'r',encoding='utf-8') as f: | |
for line in f.readlines(): | |
password=line.strip('\n') | |
print(line,end='\r') | |
try: | |
zip_file.extractall(pwd=password.encode()) | |
end = time.clock() | |
format_time((end-start)) | |
print('Found password',password) | |
break | |
except: | |
pass | |
return | |
if attack_type.lower() == "brute": | |
brute_force() | |
elif attack_type.lower() == "dict": | |
password_dict() | |
else: | |
print("Enter in valid input") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment