-1

I have a dictionary with 10 words (one IS the correct password)

script on python3 (on Raspberry) iterates over dictionary

when it gets to the right password , pauses/stops (extracts the zip file) but resumes the script and does not exit nor it print "password is.."

#!/usr/bin/env python3

import zipfile
import sys

def crackzip(el_zip, clave):
    try:
        el_zip.extractall(pwd = clave)
        sys.exit("password is : " + clave)
    except:
        pass


file_zip = 'file_to_crack.zip'
dictionary = 'dictionary.txt'
zippy = zipfile.ZipFile(file_zip)
with open(dictionary, 'r') as f:
    for line in f.readlines():
        password = line.strip('\n')
        print(password)
        crackzip(zippy, password.encode('utf-8'))
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • I would have the `crackzip` function return either true or false, and branch depending on the outcome. Shouldn't have to use `sys.exit` that much – ddg Jan 31 '21 at 03:31
  • Side note: the question isn't specific to [tag:raspberry-pi], so that tag can probably be removed. – costaparas Jan 31 '21 at 09:40

2 Answers2

1

I found that I wasn't stoping the process when the password was found, so now this is added and password showed when found!!

THANKS!!!

´´´ #!/usr/bin/env python3

import zipfile
import sys

def crackzip(el_zip, clave):
    try:
        el_zip.extractall(pwd = clave.enconde('uft-8'))
        print("password found: " + clave)
        revisor = 1
        return revisor
    except:
        revisor = 0
        return revisor


file_zip = 'file_to_crack.zip'
dictionary = 'dictionary.txt'
zippy = zipfile.ZipFile(file_zip)
revisor = 0
with open(dictionary, 'r') as f:
    for line in f.readlines():
        password = line.strip('\n')
        print(password)
        revisor = crackzip(zippy, password.encode('utf-8'))
        if revisor == 1:
            quit()

´´´

0

you are trying to concatenate a string object with a bytes object which is not a valid operation.

This produces an exception which your code squashes and continues.

plugwash
  • 9,724
  • 2
  • 38
  • 51