Hashing & cracking
Hashes are everywhere: passwords, integrity, signatures, tokens. This card covers what guarantees they give —and which they don’t—, how passwords get cracked in practice, and structural attacks like length extension and collisions.
What it is
Section titled “What it is”A cryptographic hash (SHA-256, SHA-3, BLAKE2) is a function that turns an input of any size into a fixed-length fingerprint. To be secure it must satisfy three properties:
- Preimage resistance: given
h, it’s infeasible to findmwithhash(m) = h. - Second-preimage resistance: given
m1, it’s infeasible to findm2 ≠ m1with the same hash. - Collision resistance: it’s infeasible to find any pair
m1 ≠ m2with the same hash.
Threat model
Section titled “Threat model”The core mistake is confusing integrity with authenticity or with password storage. Each use has its tool:
- Integrity / fingerprint: SHA-256 or SHA-3 are fine.
- Authenticity: do not use a bare hash; use HMAC (RFC 2104) or a signature.
- Passwords: do not use SHA/MD5; use Argon2id, bcrypt, or scrypt (slow hash + salt).
Why plain SHA-256 is bad for passwords
Section titled “Why plain SHA-256 is bad for passwords”SHA-256 is fast: a modern GPU computes billions of hashes per second, which allows dictionary-cracking almost any weak password. The defense combines three pieces:
- Salt: a unique random value per user that defeats rainbow tables and precomputed hashes.
- Cost factor (slow): Argon2/bcrypt make each attempt cost time and memory, so the GPU stops being profitable.
- Pepper: a global secret stored outside the database (defense in depth).
Theory: Merkle-Damgård and length extension
Section titled “Theory: Merkle-Damgård and length extension”flowchart LR
IV[IV] --> B1[Compress block 1]
B1 --> B2[Compress block 2]
B2 --> B3[Compress ... padding]
B3 --> H[Final hash = internal state]
MD5, SHA-1, SHA-256, and SHA-512 use the Merkle-Damgård construction: the final hash is the internal state after processing the last block. If you know hash(secret‖msg) and len(secret), you can resume the computation and produce hash(secret‖msg‖padding‖extra) without knowing the secret. This breaks homemade MACs of the form sha256(secret + data). SHA-3 (Keccak) and BLAKE2 are not vulnerable.
Red Team
Section titled “Red Team”Password cracking (authorized lab)
Section titled “Password cracking (authorized lab)”# 1. Identify the hash typehashid '$2b$12$abcdefghijklmnopqrstuv'# 2. Pick the hashcat mode (-m): 0=MD5, 100=SHA1, 1400=SHA256, 3200=bcrypt, 1800=sha512crypt# 3. Dictionary + ruleshashcat -m 1400 hashes.txt rockyou.txt -r rules/best64.rule# 4. Mask (structured brute force) if the dictionary failshashcat -m 1400 hashes.txt -a 3 '?u?l?l?l?l?d?d?d'# John the Ripper equivalentjohn --format=raw-sha256 --wordlist=rockyou.txt hashes.txtFor Windows/AD hashes (NTLM, Net-NTLMv2, Kerberos) see AD credentials and Kerberos.
Length extension
Section titled “Length extension”# Vulnerable scheme: signature = sha256(secret || data)# Knowing the hash and len(secret), extend the message and recompute the signaturehash_extender --data 'user=guest' --secret 16 --append '&admin=1' \ --signature <known_hash> --format sha256# Fix: use HMAC-SHA256 (not extensible) or SHA-3/BLAKE2Collisions
Section titled “Collisions”- MD5: trivial collisions today (seconds). Never for signatures or integrity.
- SHA-1: a real collision since SHAttered (2017) and a chosen-prefix collision (2019). Deprecated.
- Impact: two different files with the same hash (certificates, signed binaries).
Blue Team
Section titled “Blue Team”- Passwords: Argon2id (RFC 9106) or bcrypt/scrypt, with a per-user salt and high cost parameters.
- Integrity/authenticity: HMAC-SHA256 or a signature; never
hash(secret‖msg). - Drop MD5/SHA-1 for any security use; monitor credential leaks.
- Rate limiting and MFA so that, even with stolen hashes, the impact is limited.
- Compare hashes and tokens in constant time.
CVEs and real-world cases
Section titled “CVEs and real-world cases”- SHAttered (2017): first practical SHA-1 collision (two different PDFs, same hash).
- Flame (2012): malware that forged a Microsoft certificate by abusing an MD5 collision.
- LinkedIn (2012): leak of ~6.5 million unsalted SHA-1 hashes, cracked almost entirely.
Checklist
Section titled “Checklist”- Identify the hash algorithm (
hashid/hashcat --identify) - Passwords with a fast, unsalted hash? → dictionary cracking
- Run hashcat/John with dictionary + rules, then masks
-
hash(secret‖msg)scheme? → try length extension - MD5/SHA-1 in signatures/integrity? → collision risk
- Verify passwords use Argon2/bcrypt/scrypt
- Check constant-time comparison