Skip to content

Implement multiprocessing for brute-force password attempts#1

Open
bloodstiller wants to merge 3 commits into
toneillcodes:mainfrom
bloodstiller:main
Open

Implement multiprocessing for brute-force password attempts#1
bloodstiller wants to merge 3 commits into
toneillcodes:mainfrom
bloodstiller:main

Conversation

@bloodstiller
Copy link
Copy Markdown

Refactor bfkeepass.py to use multiprocessing for password attempts and improve argument parsing.

Summary

Refactors bfkeepass to improve bruteforce performance through parallelism, add real-time verbose progress reporting, and harden error handling.


Changes

Performance

  • Replaced sequential password attempts with ProcessPoolExecutor for true multiprocessing — KeePass KDF (Argon2/AES) is CPU-bound so processes bypass the GIL where threads cannot
  • Added -t / --threads argument to control worker count (default: 4)
  • Wordlist is consumed in configurable batches (BATCH_SIZE = 200) to avoid loading large wordlists (e.g. rockyou.txt) fully into memory

Early Termination

  • Added a multiprocessing.Manager shared Event (stop_flag) passed to all workers
  • Workers check the flag at the start of each attempt and exit immediately once a password is found, preventing wasted CPU cycles across all processes

Verbose Output

  • Moved all print calls to the main process — worker process stdout is unreliable across process boundaries
  • Verbose mode now prints each attempted password with its attempt index in real time using flush=True
  • Final summary line reports total passwords attempted regardless of outcome

Error Handling

  • Replaced bare except: with explicit CredentialsError catch — the expected failure path for a wrong password
  • Unexpected exceptions in workers are now surfaced as [WARN] messages to stderr rather than silently swallowed
  • Wordlist open errors now distinguish FileNotFoundError from general OSError and exit with code 1

Code Quality

  • Removed type=ascii from argparse arguments and the subsequent .replace("'", "") workaround
  • Extracted dump_entries() and iter_batches() as standalone functions
  • Workers serialize PyKeePass entries to plain dicts before returning — PyKeePass objects are not picklable across process boundaries
  • Added type hints throughout

Verified On Test KDBX

image

Refactor bfkeepass.py to use multiprocessing for password attempts and improve argument parsing.
Add session management and rich console output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant