First let me just say I'm a pretty noob programmer, but still I'm not the kind of guy that decided he wanted to make a MMO game. My question relates to zip files.I've been researching and I couldn't find how to use the zipfile module. My idea is that you will put in the path of the zip, and out comes the password.
Here's the command I found that I thought I code use
ZipFile.open(name, mode='r', pwd=None)
But the problem is I have no idea what i'm doing.
You have one way of doing this and it is brute force.
So you would need a brute force algorithm (of your own liking or design) and/or a rainbow table that supplies your script with passwords. After that you just iterate over it in a loop until you find your password.
https://docs.python.org/2/tutorial/errors.html#handling-exceptions
This is simplified an non optimised code
rainbowTable = ['Password', '123abc', 'qwerty', 'qwerty123'] # etc...
x = 0
data = ''
for x in xrange(len(rainbowTable)):
try:
data = ZipFile.open(name, mode='r', pwd=rainbowTable[x])
if data != ''
break
As pointed out, the solution above is unpythonic (but imo easier to grasp if you come from another language). This is how it should be written.
for password in rainbowTable:
try:
data = ZipFile.open(name, mode='r', pwd=password)
if data != ''
break
else:
print password
Python however is not the best choice. You would probably want to use C for this specific task.
Here is a real world example of a Python example: https://github.com/igniteflow/violent-python/blob/master/pwd-crackers/zip-crack.py
From the sample:
try:
zip_file.extractall(pwd=password)
password = 'Password found: %s' % password
except:
pass
print password
The total amount of code is 17 lines so i recommend reading it for better understanding.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.