Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Session 03 - Python for Forensics

The code here is to support the Session 03 lecture.

passwordCrackZipExtB.py

import argparse, zipfile

def main():
    parser = argparse.ArgumentParser(description="Zip file password cracker.")
    parser.add_argument('-f', dest='zname', type=str, help='specify zipfile')
    parser.add_argument('-d', dest='dname', type=str, help='specify dictionary file')
    args = parser.parse_args()

    if not (args.zname and args.dname):
        parser.print_help()
        exit(0)

    zname = args.zname
    dname = args.dname

    zFile = zipfile.ZipFile(zname)
    with open(dname, 'r') as f:
        for line in f.readlines():
            password = line.strip('\n')
            try:
                zFile.extractall(pwd=password.encode('utf-8'))
                message = 'Password Found: %s' % password
                print(message)
            except Exception as e:
                pass

if __name__ == '__main__':
    main()
[ Last updated: Tuesday 28 October 2025 @ 22:16:52 +0000 // branch: master // commit: 5ebe398 ]