diff --git a/README.md b/README.md index fcf7a08..e75390b 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,6 @@ Optional charset format * Example: lower alpha, upper alpha, and digits: `lud` ex. `bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp lud` * Example: upper alpha and symbols+space: `us` ex. `bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp us` * Example: `bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp lud` -* Example: `bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp` \ No newline at end of file +* Example: `bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp` + +Thanks to [Tak](https://taksshack.com/members/thumbtak/) for some bug fixes! \ No newline at end of file diff --git a/bd_crack.sh b/bd_crack.sh index 323ffed..2f03625 100644 --- a/bd_crack.sh +++ b/bd_crack.sh @@ -1,9 +1,10 @@ #!/bin/bash +# set -e # Exit immediately if a command exits with a non-zero status. # Cracking helper for breachdirectory.org # Usage: ./bd_crack.sh # Optional charset format: -# Default charset is luds meaning lower alpha, upper alpha, digits, and symbols+space -# Mix and match any of the following: +# Default charset is luds meaning lower alpha, upper alpha, digits, and symbols+space +# Mix and match any of the following: # l = lower case alpha (a-z) # u = upper case alpha (A-Z) # d = digit (0-9) @@ -11,63 +12,77 @@ # h = lower case hex (0-9a-f) # H = upper case hex (0-9A-F) # b = bytes (0x00-0xFF) -# Example: lower alpha, upper alpha, and digits: lud ex. bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp lud -# Example: upper alpha and symbols+space: us ex. bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp us +# Example: lower alpha, upper alpha, and digits: lud ex. bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp lud +# Example: upper alpha and symbols+space: us ex. bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp us # Example: bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp lud # Example: bash bd_crack.sh c8ea28d3285e468961a76b5de75871fbe539808a passp -if [ -z $1 -o -z $2 ]; then # check to maek sure both required args are present +if [ -z "$1" ] || [ -z "$2" ]; then # check to make sure both required args are present echo -e "Mandatory arguments missing!\nPlease see README for more details\nUsage:\n\tbd_crack.sh \nexiting" - exit # die on fail after printing usage bullshit :lmao: + exit 1 # die on fail after printing usage bullshit :lmao: fi if [ ${#1} -ne 40 ]; then # check da length of da hashie boi echo -e "First arguement should be the SHA1 hash, exactly 40 hex characters long!\nPlease see README for more details\nUsage:\n\tbd_crack.sh \nexiting" - exit + exit 1 fi -if [ ${#2} -ne 5 ]; then # maek sure da known chars are precisely 5 chars otherwise fail +if [ ${#2} -ne 5 ]; then # make sure da known chars are precisely 5 chars otherwise fail echo -e "Second argument should be exactly five characters!\nPlease see README for more details\nUsage:\n\tbd_crack.sh \nexiting" - exit + exit 1 fi -if [ ! -z $3 ]; then # if charset is specified +# Initialize charset_formatted early +charset_formatted="" + +if [ -n "$3" ]; then # if charset is specified (using -n for non-empty string) charset="$3" # just rename $3 for whatever reason lmfao im so high - charset_formatted="?" # start with da ? at the start frong valid_charsets="ludhHsb" # regex bit of valid charsssssss if [[ "$charset" =~ ^["$valid_charsets"]+$ ]]; then # sanity checkan da stupid chars :wheeze: just some shitty regex bullsh8it + # Unique and sorted characters, removed newline (as original script did) charset=$(grep -o . <<< "$charset" | sort -u | tr -d '\n') + + # Construct hashcat's custom charset string (e.g., "?l?u?d") + for (( i=0; i<${#charset}; i++ )); do + if [ $i -eq 0 ]; then + charset_formatted+="?" # Start with '?' + fi + charset_formatted+="${charset:$i:1}" # Add current char + if [ $i -lt $((${#charset}-1)) ]; then + charset_formatted+="?" # Add '?' between chars + fi + done else echo -e "INVALID CHARSET, DEFAULTING TO DEFAULT CHARSET" charset_formatted="?l?u?d?s" # just replicate da default charset here because lazy as fucxk lmafao fi - - for (( i=0; i<${#charset}; i++ )); do - charset_formatted+="${charset:$i:1}" # add current char to charset_formatted - - # add ? after each character except da last char in da string - if [ $i -lt $((${#charset}-1)) ]; then - charset_formatted+="?" - fi - - done else # if charset is not specified default to digit, upper alpha, lower alpha, and symbols+space charset_formatted="?l?u?d?s" fi outfile="$2-$1-$(date +"%d-%m-%Y-%H%M")-cracked.txt" # using a fookin outfile because da hashcat.potsmoke or whatever the fuck is stupid -hashcat -a3 -m100 $1 -1 $charset_formatted "$2?1?1?1?1?1?1?1?1" --increment --increment-min=5 -O -o "$outfile" +hashcat -a3 -m100 "$1" -1 "$charset_formatted" "$2?1?1?1?1?1?1?1?1" --increment --increment-min=5 -O -o "$outfile" retcode=$? # jus gettin da return code from hashcat rq -if [ $retcode -eq 0 ]; then # check if hashcat exited with a 0 meaning successful crack\ - # real_user="${SUDO_USER:-$USER}" # stupid hack to get the real current user regardless of any sudo usage - # sudo chown $real_user:$real_user "$outfile" # fix da fuckin perms jfc lmao +if [ $retcode -eq 0 ]; then # check if hashcat exited with a 0 meaning successful crack + # THIS IS THE CRITICAL ADDITION: Check if the file ACTUALLY exists + if [ -f "$outfile" ]; then # Explicitly check if the file was created + # real_user="${SUDO_USER:-$USER}" # stupid hack to get the real current user regardless of any sudo usage + # sudo chown "$real_user":"$real_user" "$outfile" # fix da fuckin perms jfc lmao - echo -e "\nCracked! Result:\n\t$(cat "$outfile")\n" # show da contents of da outfile for helpfuls + echo -e "\nCracked! Result:\n\t$(cat "$outfile")\n" # show da contents of da outfile for helpfuls - echo "Cracked Successfully! Password will be in ./${outfile}!" -else # otherwise inform of failure - echo "Stopped or Ended! Password not found!" + echo "Cracked Successfully! Password will be in ./${outfile}!" + else + # Hashcat returned 0, but no file. This means no crack was found. + echo "Stopped or Ended! Password not found within the specified mask/charset. Hashcat completed without errors." + echo "Output file '$outfile' was not created because no crack was found." + exit 1 # Exit with an error + fi +else # otherwise inform of failure (hashcat returned a non-zero error code) + echo "Hashcat encountered an error or was stopped unexpectedly (exit code: $retcode)." + echo "Please review hashcat's output above for details." + exit 1 # Exit with an error fi \ No newline at end of file