I was fooling around with Disk Utility's encrypted .dmg feature. I accidentally put an important file in there and partly forgot the password. (I KNOW!) I know exactly what the first part of the password was, but the last 2-4 digits I have just a cloudy idea of. Something like Myword55& or Urword934!
How could I bruteforce to try all the password combinations automatically? I found this following bash script but don't know how to modify it to my exact needs:
#!/bin/bash
dmgfile="Your Encrypted File.dmg"
function TryPassword
{
echo -n "$1 "
r=$(echo -n "$1" | hdiutil verify -stdinpass "$dmgfile" 2>&1)
if ! [[ $r =~ "Authentication error" ]]; then
echo ""
echo "Found! The password is: $1"
exit
fi
}
chars=$(echo {0..9} {A..z})
alphanum=( $(echo $chars | sed -E 's/[^A-Za-z0-9 ]+/ /g') )
letter=( $(echo $chars | sed -E 's/[^A-Za-z ]+/ /g') )
lowercase=( $(echo $chars | sed -E 's/[^a-z ]+/ /g') )
uppercase=( $(echo $chars | sed -E 's/[^A-Z ]+/ /g') )
digit=( $(echo $chars | sed -E 's/[^0-9 ]+/ /g') )
for a in "${letter[@]}"; do
for b in "${lowercase[@]}"; do
for c in "${digit[@]}"; do
TryPassword "$a$b$c"
done
done
done