0

I am reading the book Violent Python and one example is a zip file cracker, which tests a dictionary file of potential passwords (a text file) against a zip file.

I am trying to use the docopt library to parse the command line and give me the filenames for these two files. Here is my code.

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Basic zip bruteforcer

Usage:
  your_script.py (-f <file>) (-z <zip> )
  your_script.py -h | --help

Options:
  -h --help     Show this screen.
  -f --file     specify dictionary file. (Required argument)
  -z --zip      specify zip file.(Required argument)
  -t --thread   Thread count. (Optional)
  -v --verbose  Turn debug on. (Optional)
"""
from docopt import docopt
import zipfile
from threading import Thread

def extractzip(zfile, password):
    try:
        zfile.extractall(pwd = password)
        print 'password found: ', password
    except:
        return

def main():
    zfile = zipfile.ZipFile(zip)
    with open(file, 'r') as pass_file:
        for line in pass_file.readlines():
            password = line.strip('\n')
            t = Thread(target = extractzip, args = (zfile, password))
            t.start()  

if __name__ == "__main__":
    arguments = docopt(__doc__, version='0.1a')
    extractzip(arguments['<file>'], ['<zip>'])

Here is my code.

ravenwingz
  • 117
  • 1
  • 2
  • 11

1 Answers1

0

You can do something like

  print arguments['<file>']

to get the file name, and similarly the zip file. I personally haven't used extractzip and am not sure how that works. But since arguments is simply a list, you can easily get the values by accessing the required index directly.

pecey
  • 651
  • 5
  • 13