1 Length Extension on MD5, SHA1, SHA256
Hash length extension is an attack against Merkle-Damgard hash functions (MD5, SHA1, SHA256) used naively as MACs. The internal state at the end of computing H(secret||data) is the hash output itself. An attacker can resume hashing from that state to compute H(secret||data||padding||extra) without knowing the secret.
Vulnerable pattern:
import hashlib
# Server creates MAC: sha256(secret + data)
secret = b"server_secret"
data = b"user_id=123&action=view"
mac = hashlib.sha256(secret + data).hexdigest()Attack:
- Attacker knows: mac, data, length of secret (often guessable)
- Attacker uses HashPump or similar tool to compute H(secret||data||padding||"&action=admin") without knowing secret
- Attacker submits new data + forged MAC — server verifies it as valid!
This attack was used against Flickr API and Vimeo in real-world breaches. Any API using SHA256(secret + message) is vulnerable.