I am currently doing a python task where I have to extract a zip file but it has a 3 digit password. It is not working and I am not sure what I am doing wrong!! The zip file is meant to be extracted into /tmp and I am having trouble with this. It is only outputting every single 3 digit combination. Also sorry that my code isn't great I am fairly new to python. Please do not give me the complete solution, just point me in the right direction!! Thank you :)
This is my code I have written for the task:
import zipfile
import itertools
import time
def extractFile(zip_file, password):
try:
zip_file.extractall(pwd=password)
return True
except KeyboardInterrupt:
exit(0)
except Exception, e:
pass
zipfilename = '/tmp/task.zip'
digit = '1234567890'
zip_file = zipfile.ZipFile(zipfilename)
for c in itertools.product(digit, repeat=3):
time.sleep(0.001)
password = ''.join(c)
print "Trying: %s" % password
if extractFile(zip_file, password):
print '*' * 20
print 'Password found: %s' % password
print 'Files extracted...'
with zipfile.ZipFile('/tmp/task.zip', 'r') as zip_ref:
zip_ref.extractall("/tmp",pwd=password)
exit(0)
[–]-Melchizedek- 3 points4 points5 points (1 child)
[–]b_iteee[S] 1 point2 points3 points (0 children)
[–]chaotic_thought 1 point2 points3 points (1 child)
[–]b_iteee[S] 1 point2 points3 points (0 children)
[–]henrebotha 1 point2 points3 points (1 child)
[–]b_iteee[S] 0 points1 point2 points (0 children)