user3462271
user3462271

Reputation:

Zip file cracker python 3 will only use password at end of text file

I have been searching and mucking around for days trying to make a zip cracker in python 3.

I have a text file with my passwords in it called passwords.txt. and each password in on a new line. (no space in between lines)

e.g:

password
house
qwerty

the script runs ok and will extract the file in my zip. (zip password was qwerty). BUT if I rearrange my list like so:

password
qwerty
house

the script will not crack the zip. It will work fine with 'qwerty' as the only password in the list and will work if 'qwerty' is the last password in the list. To me its like the script is not terminating after using the correct password. I need a bit of a push in the right direction.

here is my (simple) code: (i'm no expert)

import zipfile
with open('passwords.txt') as passwordList:
    myZip = zipfile.ZipFile('test.zip')
    for line in passwordList:
        try:
            myZip.setpassword(pwd=line.encode())
            myZip.extractall()

        except:
            pass

myZip.close()

any help will be appreciated.

Upvotes: 1

Views: 3170

Answers (2)

justin
justin

Reputation: 1

justin =  '''
    +=======================================+

    |..........Zip Cracker v 1.........|

    +---------------------------------------+

    |#Author: JUSTIN                    |

    |#Contact: www.fb.com/rootx        |


    +=======================================+

    |..........ZIP Cracker v 1.........|

    +---------------------------------------+
'''

print justin

import zipfile

z1 = raw_input("Enter Your Zip File:")

z = zipfile.ZipFile(z1)

pf1=str(raw_input( "Enter password list: "))

pf=open(pf1,'r')

for x in pf.readlines():

password = x.strip('\n')

try:

    z.extractall(pwd=password)

    print "pass=" +password+ "\n"

    exit(0)

except Exception,e:
   pass

Upvotes: 0

Omid Raha
Omid Raha

Reputation: 10680

Remove \n from your line variable with line.strip(b'\n') and not line.strip(), because password may have whitespace around itself.

Also you can pass pwd to extractall directly.

import zipfile

zip_file = zipfile.ZipFile('test.zip')
output_verbose = 2  # increase that for long password list
with open('passwords.txt', 'rb') as password_list:
    for index, line in enumerate(password_list):
        try:
            pwd = line.strip(b'\n')
            zip_file.extractall(pwd=pwd)
        except RuntimeError:
            if index % output_verbose == 0:
                print('{}. The {} word not matched.'.format(index + 1, pwd))
        else:
            print('{}. Wow ! found the password: {}'.format(index + 1, pwd))
            break

zip_file.close()

Demo:

1. The b'password' word not matched.
2. Wow ! found the password: b'qwerty'

Upvotes: 3

Related Questions