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.

passwordCrackZipExtA.py

import sys, zipfile

def usage():
    print("Incorrect number of arguments")
    print(f"Usage: python {sys.argv[0]} <zipfile> <dictionary file>")
    sys.exit()

def main():
    if len(sys.argv) == 1 or len(sys.argv) > 3:
        usage()
    else:
        zname = sys.argv[1]
        dname = sys.argv[2]

    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 = f'Password Found: {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 ]