sts10 / medic

Check the "health" of passwords in a KeePass database
https://sts10.github.io/2019/02/01/medic.html
MIT License
23 stars 2 forks source link
haveibeenpwned hibp hibpwned keepass keepassxc offline password passwords rust

Medic

A Rust CLI that provides a variety of ways to check the "health" of a given KeePass database, including checking passwords against the Have I Been Pwned password list.

⚠️ WARNING ⚠️: This program is unmaintained and was largely a personal project to learn Rust. Use on real passwords at your own risk!

Read a blog post about this project.

Maybe use KeePassXC instead...

I'll note here that KeePassXC, as of version 2.6.0, has a lot of the same features as Medic, some of which are accessible through its easy-to-use graphical interface. I understand that you can also use the KeePassXC CLI tool to check your database against an offline list of password hash digests.

But if you want a simple-ish CLI tool, written in Rust, that you could realistically read over/audit yourself, Medic may be for you.

What this tool does

Medic can check the passwords of a given KeePass database in four ways:

  1. Check passwords against the HaveIBeenPwned password database, via the HaveIBeenPwned API
  2. Check passwords against a file of password hashes. This requires users to download a large list of SHA-1 hashes of breached or compromised passwords. I tailored it to work with the Pwned Passwords lists from HaveIBeenPwned, which anyone can download here. Medic will then display a list of any passwords from the given KeePass database that also appear in the list of breached passwords.
  3. Check for weak passwords, using zxcvbn
  4. Check for duplicate passwords

If you're familiar with 1Password's Watchtower feature, Medic aims to accomplish similar functionality for KeePass databases (with the additional benefit of optionally working entirely offline).

Usage

Usage: medic [OPTIONS] <KEEPASS DATABASE FILE>

Arguments:
  <KEEPASS DATABASE FILE>  KeePass database to check. Can either be a kdbx file or an exported CSV version of a KeePass database

Options:
      --debug                           Use debug mode, which, among other things, displays received arguments and hides progress bar when checking passwords against a file of hashed passwords
  -k, --keyfile <KEYFILE>               Provide key file, if unlocking the KeePass databases requires one
      --online                          Check passwords against breached passwords online via the HaveIBeenPwned API. More info here: https://www.troyhunt.com/ive-just-launched-pwned-passwords-version-2/#cloudflareprivacyandkanonymity
  -p, --passwordsfile <PASSWORDS_FILE>  Provide file passwords to check database against. Passwords should be cleartext
  -a, --hashfile <HASH_FILE>            Provide file containing SHA-1 hashes of passwords to check database against
  -d, --duplicate                       Check database for duplicate passwords
  -w, --weak                            Check database for weak passwords
  -o, --output <OUTPUT>                 Print results of health check to a file
  -h, --help                            Print help information
  -V, --version                         Print version information

Examples

Installation/Setup

  1. Install Rust if you haven't already
  2. Run: cargo install --git https://github.com/sts10/medic --branch main or for better performance decrypting AES KeePass databases (see below), run: RUSTFLAGS='-C target-cpu=native' cargo install --git https://github.com/sts10/medic --branch main. See keepass-rs documentation for more optimizations.
  3. Optional: If you'd like to check if any of your passwords have been breached without sending any information about them over the internet, you'll need to download the Pwned Passwords list.

Note: As of May 2022, Pwned Passwords has changed the way it makes hashed passwords available.

Dependencies

On Debian-based distros like Ubuntu, Medic may require libssl-dev. Install with: sudo apt-get install libssl-dev.

Downloading breached passwords from HaveIBeenPwned via torrent

If you're new to torrents, Transmission is a decent choice for an application to download torrents, which apparently works on Mac and Windows. (Personally, on Kubuntu, I used KTorrent.) Once you have Transmission or another torrent-handling application installed, click the green "torrent" button on the Pwned Passwords site. Save the (very small) .torrent file to your computer, then open that file with your torrent-downloading software. You may have to click "OK" or "Start", but once you do you'll be (probably slowly) downloading hundreds of millions of hashed passwords.

A note on KeePass databases that use an AES KDF (key derivation function)

By default, if your KeePass database uses an AES KDF (key derivation function) Medic will not use your CPU to decrypt your KeePass database. That means that if your databases is locked with a high number of AES key transformation rounds, it will take a while for Medic to open your database.

To solve this, either switch your database's KDF from "AES-KDF" to "Argon2", or install Medic by running this command: RUSTFLAGS='-C target-cpu=native' cargo install --git https://github.com/sts10/medic --branch main. If you've already installed Medic without the RUSTFLAG, try running RUSTFLAGS='-C target-cpu=native' cargo install --force --git https://github.com/sts10/medic --branch main

More info here and here.

How I choose to use this tool

  1. Download the PwnedPasswords list in the SHA-1 format, ordered by prevalence (this text file will be about 11 GB compressed, 22GB extracted).
  2. Open your KeePass database in KeePassXC or whatever desktop app you use to open your database.
  3. Export your KeePass database to a CSV file (In KeePassXC: Database menu > "Export to CSV...") (Heads up, this file includes your passwords, so be careful).
  4. Lock your KeePass database.
  5. Install Medic using instructions above.
  6. Run Medic by entering the following command: medic -a=pwnedpassword_hashes.txt -dw <my-exported-database>.csv. Note any compromised passwords and change them ASAP.
  7. When finished, securely delete that exported CSV file. If on MacOS, run srm <my-exported-database>.csv. On Ubuntu-based Linux distributions, try shred -ufv --iterations=60 <my-exported-database>.csv. Your sensitive data should now be safely deleted, but feel free to securely delete Medic itself if so inclined.

Running tests

cargo test --release, though you'll need a file with a list of hashed passwords to pass one of the tests.

Note that all test databases passwords are password.

Checking for security vulnerabilities in Medic's dependencies

You can programmatically check Medic's dependencies for security vulnerabilities with cargo audit.

If you find vulnerabilities that concerns you, you can attempt to update the offending dependent crate yourself in the Cargo.toml file. Also, please open an issue on this repo.

To do

See Issues on GitHub for more, but here are some broad ideas:

Reference

Similar projects

Useful projects in Rust