Skip to content

Instantly share code, notes, and snippets.

@nachtmaar
Last active January 30, 2022 18:14
Show Gist options
  • Save nachtmaar/9e1758e988d4fa25be707a68aa1726f1 to your computer and use it in GitHub Desktop.
Save nachtmaar/9e1758e988d4fa25be707a68aa1726f1 to your computer and use it in GitHub Desktop.
I lost a password in my Keypass database and was looking for a way to search the lost password in all my backups easily and fast
#!/usr/bin/env bash
echo -n "please enter the password for the keypass database:"
read -rs pw
echo
KEYPASS_KEY="$1"
SEARCH_PATTERN="$2"
echo "performing search in the following keypass databases:"
for i in "${@:3}"; do
echo "$i"
done
echo
echo "starting search ..."
for i in "${@:3}"; do
echo "searching in $i, output:"
keepassxc-cli ls -q -R -k "$KEYPASS_KEY" "$i" <<< "$pw" | grep -i "$SEARCH_PATTERN"
# keepassxc-cli locate -q "$i" $SEARCH_PATTERN -k "$KEYPASS_KEY" <<< "$pw"
echo
done
@nachtmaar
Copy link
Author

nachtmaar commented Dec 9, 2021

I used the script to search in a Keypass database that uses a keyfile and a password. If you don't have a keyfile, you need to slightly modify the script.

How I used it:

./find-keypass-entry.sh <path-to-keyfile>           <search-pattern-ignore-case> <list of all databases>
./find-keypass-entry.sh /tmp/keychains/database.key "fin"                        ~/Downloads/database*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment