Diagnostic playbook
Weak cryptography: hardcoded keys/IV and ECB/CBC misuse enabling token forgery
Web / Cryptographic Failures
Knowledge identity
Definition and taxonomy
Summary
Authentication tokens are encrypted with weak or misused cryptography whose keys and IVs are hardcoded in source, letting an attacker decrypt, modify, and re-encrypt tokens to impersonate any user including administrators.
Severity rationale
Demonstrated full token forgery in the authorized lab: XOR with a hardcoded key (low), AES-128-ECB with a hardcoded key (medium), and AES-128-CBC with a hardcoded key and fixed IV (high). Allowed logging in as an administrator by re-encrypting crafted plaintext. No data modified; only forged authentication tokens submitted.
Aliases
Crypto failures, hardcoded encryption key, ECB cut-and-paste, CBC/ECB token forgery, XOR encryption
Standards
CWE-321,CWE-327 CAPEC-97 A02:2021-Cryptographic Failures
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N
1. First Signal
What should make an agent suspicious
Symptoms
Intercepted tokens decrypt to plaintext using keys found in source; re-encrypting modified plaintext yields a token accepted as a higher-privilege user; ECB tokens share identical blocks for identical plaintext prefixes.
Prerequisites
Authorized lab session and read access to the application source (hardcoded keys). The attacker can submit crafted ciphertext.
2. Recognition Logic
How to recognize this next time
If an app encrypts tokens/credentials, check the source for hardcoded keys and IVs. If ECB is used, look for block repetition. With the key known, decrypt, modify, re-encrypt. XOR with a known key is trivial to reverse.
3. Diagnostic Procedure
Safe checks, in order
- Confirm authorized scope. 2. Locate the encryption key/IV in source. 3. Decrypt an intercepted token. 4. Modify fields (user, level, exp) and re-encrypt with the same key. 5. Submit the forged token. 6. Use a negative control (unmodified token has lower privileges). 7. Record the crypto parameters.
4. Proof
Evidence
DVWA cryptography: low XOR+base64 token decrypted to 'Your new password is: Olifant' (login succeeded); medium forged AES-ECB token yielded 'Welcome administrator Sweep' while the real user token gave 'not as the right user'; high forged AES-CBC token returned {"status":200,"user":"Geoffery","level":"admin"}.
5. Controls
Negative checks
Unmodified medium user token decrypted correctly but did not satisfy admin+valid+user conditions (control); no external systems involved.
6. Avoid Bad Memory
False positives and traps
A token that decrypts to readable text is only exploitable if the attacker has the key and can submit modified ciphertext; the confirmation here is successful privilege escalation with forged tokens.
7. Why It Matters
Impact
Full authentication bypass: an attacker forges valid tokens as any user, including administrator, without the original credentials.
8. Why It Happened
Root cause
Encryption keys and IVs hardcoded in source; weak algorithms (XOR) or misuse (ECB) and a fixed IV for CBC provide no real secrecy.
9. Fix
Remediation and prevention
Store keys in a secure secret manager; use authenticated encryption (AES-GCM) with random per-message IVs; use HMAC-signed or JWT-based tokens with server-side validation; never trust client-supplied encryption parameters.
10. Re-test
Verification steps
- After fix, verify forged tokens are rejected. 2. Confirm keys are not in source and IVs are random. 3. Confirm tokens are authenticated (MAC). 4. Regression tests.
Reference
Tools and sources
Tools used
openssl CLI, python3, curl, docker exec for read-only source review
References
OWASP Cryptographic Storage Cheat Sheet; CWE-321; CWE-327
Intelligence
Products and history
Technologies
PHP, openssl, XOR, AES-128-ECB, AES-128-CBC, base64
Affected products / versions
DVWA (Damn Vulnerable Web Application) current master
History
First documented in DVWA cryptography module in the 2026-08 benchmark run.
Exploit knowledge
Variants and references
Attack surface
Encoded message/decoder form (low), session token form (medium), check_token_high.php JSON endpoint (high)
Exploit maturity
proof-of-concept
Known variants
XOR with hardcoded key (low), AES-ECB with known key (medium), AES-CBC with known key and fixed IV (high), any token scheme whose secrets live in source
Defensive signatures
Encryption keys/IVs visible in source or debug comments, ECB mode (identical plaintext blocks -> identical ciphertext blocks), tokens that decrypt to readable JSON with the key from source
Reproduction commands
Low (XOR key 'wachtwoord'): python3 decode base64 token then XOR with b'wachtwoord' -> 'Your new password is: Olifant'; login password=Olifant Medium (AES-128-ECB key 'ik ben een aardbei'): openssl enc -aes-128-ecb -K $(python3 -c "print(b'ik ben een aardbei'[:16].hex())") with plaintext '{"user":"sweep","ex":1893456000,"level":"admin","bio":"x"}' -> forged token; POST token=<hex> High (AES-128-CBC key 'rainbowclimbinghigh' IV '1234567812345678'): openssl enc -aes-128-cbc -K <keyhex> -iv <ivhex> with PKCS7-padded 'userid:1' -> {'token': b64, 'iv': b64}; POST to source/check_token_high.php -> status 200 Geoffery admin
Exploit references
No external references stored; all evidence from the authorized local lab.
Case provenance