-1

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
  • 1
    `for a in "${letter[@]}"; do for b in "${lowercase[@]}"; do for c in "${digits[@]}"; do` just `echo {A..z}{a..z}{0..9}`. What do you mean by `try all the password combinations automatically?`? How does your script does not do what you want? `to my exact needs:` what are your exact needs? What exactly are your needs? How do they differ from the script presented? You tagged "sed" how is your problem related to `sed`? – KamilCuk Jan 16 '20 at 23:35
  • I'd need the script to try out Myword66$, then Myword 67$, and Myword24!. Basically Myword[0-9][0-9][0-9][!$] –  Jan 16 '20 at 23:39
  • 1
    So basically `echo Myword{0..9}{0..9}{$,'!'}` ? – KamilCuk Jan 17 '20 at 00:09

1 Answers1

0

EDIT: got it! And I found the password I was looking for...
Turns out the script I had had a typo at the "digits" word and therefore didn't execute properly. I modified the for loop to:

for a in "${digit[@]}"; do
    for b in "${digit[@]}"; do
        TryPassword "Myword$a$b%"
    done
done

(the "%" is just one of the special characters I tried)