Code Monkey home page Code Monkey logo

medic's Introduction

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

  • medic --online passwords.kdbx checks the passwords of passwords.kdbx using the HaveIBeenPwned API. Prints report to the terminal.

  • medic --online -dw passwords.kdbx checks the passwords of passwords.kdbx using the HaveIBeenPwned API, as well as looks for weak and duplicate passwords. Prints report to the terminal.

  • medic --online -dw --output=./report.txt passwords.kdbx checks the passwords of passwords.kdbx using the HaveIBeenPwned API, as well as looks for weak and duplicate passwords. Prints result not to the terminal, but to a new text file ./report.txt.

  • medic --online -w -k=test-files/test_key_file test-files/test_db.kdbx checks the passwords of test_db.kdbx -- which requires key file test_key_file -- using the HaveIBeenPwned API, as well as looks for weak passwords. Prints results to terminal.

  • medic -a=../pwned-passwords-sha1-ordered-by-count-v4.txt my_db.kdbx checks the passwords of my_db.kdbx against the password hashes found in ../pwned-passwords-sha1-ordered-by-count-v4.txt, which is a large text file of password hashes. Medic will display any of the accounts in the my_db.kdbx with passwords that appear in the list to the terminal.

  • medic -dw passwords.kdbx checks the passwords of passwords.kdbx for weak and duplicate passwords.

  • medic -dw passwords.kdbx --output=./password-report.txt checks the passwords of passwords.kdbx for weak and duplicate passwords. Results are printed to a text file located at ./password-report.txt.

  • medic -d -a=pwnedpasswords.txt kp_database_exported_csv_file.csv checks an exported csv file against the hashes in pwnedpasswords.txt, as well as searches for duplicate passwords.

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:

  • Better error handling (especially if user gets CLI arguments wrong or is using an incompatible KDF)
  • Write more tests
  • Have the program be able to use multiple threads
  • Offer real packaging / installation options?
  • Offer an option to check for similar passwords (maybe using zxcvbn?)
  • Design/commission a logo?!

Reference

Similar projects

Useful projects in Rust

medic's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

medic's Issues

Improve error handling (read: remove more `unwrap` calls)

Specifically in lib.rs.

For example:

  • Consider replacing the unwraps with real error-handling tools, such as eprintln!, expect, or unwrap_or_else
  • Specifically: Consider changing the output of get_entries function to a Result to make error handling more natural.
  • More broadly, figure out the best place in the "chain" of functions to handle errors. Where do the turtles end? Every unwrap should be a question: What should happen if the provided file has no file extension, etc. (Reference 1; reference 2)

Don't allow app to connect to internet at all

Currently, for convenience, this tool allows users to check the passwords of a KeePass database against the HaveIBeenPwned Pwned Passwords list. Users can perform this check in one of two ways:

1. ONLINE HIBP Check

This tool takes the first 5 characters of the hash of a password, and sends it to HaveIBeenPwned servers via the service's API. A number of potential matches come back, at which point the tool searches for an exact match (which would indicate an exposed password). As explained in the API documentation:

When a password hash with the same first 5 characters is found in the Pwned Passwords repository, the API will respond with an HTTP 200 and include the suffix of every hash beginning with the specified prefix, followed by a count of how many times it appears in the data set. The API consumer can then search the results of the response for the presence of their source hash and if not found, the password does not exist in the data set.

Note: I currently force users to give explicit permission to perform this check:

println!("\n\nHeads up! I'll be sending the first 5 characters of the hashes of your passwords over the internet to HaveIBeenPwned. \nType allow to allow this");
if gets().unwrap() == "allow" {
    println!("Cool, I'll check your KeePass passwords over the internet now...\n");
    // ...

2. OFFLINE HIBP Check

The tool also allows users to perform this check entirely offline, however the user must first download the ~11GB exposed passwords list themselves, then provide that text file to this tool so it can do the check. To execute this procedure, this tool does not need to connect to the internet.

For a variety of reasons, the OFFLINE method is more secure. Even though the ONLINE method only sends 5 characters of a hash of user passwords, that's still more than nothing.

Thus I'm thinking of removing the ONLINE option (option 2). This way the entire tool never connects to the internet, which would be more in line with how KeePassXC, a commonly used application for interacting with KeePass databases, works by default (except features like "Download favicon").

I could even put a "paranoid" check in place such that tool can't open a KeePass database if it's able to connect to the internet, forcing the user to disable their internet connection in order to use the tool at all.

Questions

What do you think? Should I offer the ONLINE check at all? Make it harder to access somehow?

Are you less likely to use this tool because there's an option to send 5 characters of your passwords' hashes over the internet? Does removing that feature in order to allay these security concerns provide a net benefit that outweighs the usefulness of the online check?

Test for more types of KeePass database failures

Write tests for following possible cases:

  • no file extension on given keepass database
  • "corrupted" DB
  • fail to open db for other reason
  • A KeePass entry that has no title

Next, make sure that, whether the new tests pass or fail, the program itself handles these cases (relatively) well!

Accept files of actual passwords for comparison

Currently, Medic can accept a list of SHA1 hashes to check against the given KeePass database's passwords.

Wondering if it would be useful if, through a different flag/option, Medic could take a file of actual, non-hashed passwords; which users might have. Should be pretty easy to implement...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.