Athena Wiki

Hash Cracking

cryptobeginner

Identify and crack MD5, SHA-1, SHA-256, bcrypt, and NTLM hashes using hashcat and john.

cryptohashinghashcatjohncrackingmd5sha1bcryptwordlist

Hash Cracking

Hash cracking challenges give you a hash and ask you to find the original plaintext. CTF hashes are usually weak (common password, default credential) or specifically derived from the flag format.

Hash Cracking Workflow

You have:        "5f4dcc3b5aa765d61d8327deb882cf99"

                   [Identify hash type]

                   Likely MD5 (32 hex chars)

              [Try online database first]

              CrackStation.net: Found!

        Plaintext: "123456"

Step 1: Identify the Hash

# hashid can identify hash type
pip3 install hashid
hashid '$2y$10$...'
hashid 'd41d8cd98f00b204e9800998ecf8427e'

# Or use hash-identifier
hash-identifier
# Enter the hash at the prompt

Visual identification guide:

PatternHash Type
32 hex charsMD5
40 hex charsSHA-1
56 hex charsSHA-224
64 hex charsSHA-256
96 hex charsSHA-384
128 hex charsSHA-512
$2y$ / $2a$bcrypt
$6$SHA-512 crypt
$5$SHA-256 crypt
$1$MD5 crypt
$apr1$Apache MD5
32 hex (UPPERCASE)NTLM
aad3b435b51404eeaad3b435b51404eeEmpty LM hash

Step 2: Quick Online Lookups

Before running hashcat, check databases:

SiteURLBest For
CrackStationcrackstation.netMD5, SHA-1, SHA-256
MD5Decryptmd5decrypt.netMD5
Hashes.comhashes.com/en/decryptMany types
cmd5cmd5.comMD5/SHA-1

hashcat - GPU Hash Cracking

# Basic wordlist attack (mode -a 0)
hashcat -m 0 hash.txt /usr/share/wordlists/rockyou.txt        # MD5
hashcat -m 100 hash.txt /usr/share/wordlists/rockyou.txt      # SHA-1
hashcat -m 1400 hash.txt /usr/share/wordlists/rockyou.txt     # SHA-256
hashcat -m 1700 hash.txt /usr/share/wordlists/rockyou.txt     # SHA-512
hashcat -m 3200 hash.txt /usr/share/wordlists/rockyou.txt     # bcrypt ($2y)
hashcat -m 1000 hash.txt /usr/share/wordlists/rockyou.txt     # NTLM

# With rules (mangling/mutations)
hashcat -m 0 hash.txt rockyou.txt -r /usr/share/hashcat/rules/best64.rule

# Brute force all 4-char alphanumeric (-a 3)
hashcat -m 0 hash.txt -a 3 ?a?a?a?a

# Combinator attack (wordlist1 + wordlist2)
hashcat -m 0 hash.txt -a 1 wordlist1.txt wordlist2.txt

# Show cracked result
hashcat -m 0 hash.txt --show
hashcat running
hashcat: GPU-accelerated cracking (example output)

hashcat Mode Numbers

ModeHash Type
0MD5
100SHA-1
1400SHA-256
1700SHA-512
1800sha512crypt $6$
3200bcrypt $2*$
1000NTLM
1500DES / crypt(3)
500md5crypt $1$
400phppass / WordPress
3000LM

john - CPU Hash Cracking

# Auto-detect hash type
john hash.txt

# With wordlist
john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt

# Specify format
john hash.txt --format=raw-md5 --wordlist=rockyou.txt
john hash.txt --format=bcrypt --wordlist=rockyou.txt

# Show cracked passwords
john hash.txt --show

# Rule-based mutations
john hash.txt --wordlist=rockyou.txt --rules=best64
john the ripper
John the Ripper: CPU-based cracking example

john format strings:

raw-md5, raw-sha1, raw-sha256, raw-sha512
bcrypt, sha512crypt, sha256crypt, md5crypt
nt (NTLM), lm, mssql, mysql-sha1
zip, 7z, rar, pdf, ssh

Password Complexity Rules in hashcat

Use masks for structured passwords:

# Masks:
# ?l = lowercase a-z
# ?u = uppercase A-Z
# ?d = digit 0-9
# ?s = special char
# ?a = all above

# All 8-char lowercase
hashcat -m 0 hash.txt -a 3 ?l?l?l?l?l?l?l?l

# Capital + 6 lowercase + 2 digits (password like "Secret12")
hashcat -m 0 hash.txt -a 3 ?u?l?l?l?l?l?l?d?d

# 4-digit PIN
hashcat -m 0 hash.txt -a 3 ?d?d?d?d

# With custom charset
hashcat -m 0 hash.txt -a 3 -1 ?l?d ?1?1?1?1?1?1?1?1

Cracking Specific CTF Scenarios

Hash of the flag itself

# The flag is "flag{something}" - wordlist with flag format
python3 -c "
import itertools, string
for combo in itertools.product(string.ascii_lowercase + string.digits + '_', repeat=6):
    print('flag{' + ''.join(combo) + '}')
" > flag_wordlist.txt

hashcat -m 0 hash.txt flag_wordlist.txt

Hash with a salt

# Format: hash:salt
echo "hash:salt" > salted.txt
hashcat -m 10 salted.txt wordlist.txt    # MD5(pass+salt)
hashcat -m 20 salted.txt wordlist.txt    # MD5(salt+pass)

Double-hashed

import hashlib
# If hash = MD5(MD5(password)):
h = hashlib.md5(hashlib.md5(b'password').hexdigest().encode()).hexdigest()

Python: Quick Hash Generation and Cracking

import hashlib

def crack_md5(target_hash, wordlist_path):
    with open(wordlist_path, 'r', errors='ignore') as f:
        for word in f:
            word = word.strip()
            h = hashlib.md5(word.encode()).hexdigest()
            if h == target_hash:
                return word
    return None

result = crack_md5("5f4dcc3b5aa765d61d8327deb882cf99", "/usr/share/wordlists/rockyou.txt")
print(result)  # → "password"

Last updated on

On this page