Symmetric vs asymmetric
Understanding the difference between symmetric and asymmetric encryption —and above all the modes of operation— is the basis for exploiting most real-world crypto flaws. The theory is simple; what’s exploitable lives in the usage details: the mode, the IV/nonce, and the absence of authentication.
What it is
Section titled “What it is”Symmetric encryption uses the same key to encrypt and decrypt; it’s fast and suited to large volumes of data (AES, ChaCha20). Asymmetric encryption uses a key pair —public and private— and solves key distribution and signing, but it’s much slower (RSA, ECC).
| Symmetric | Asymmetric | |
|---|---|---|
| Keys | One shared | Public/private pair |
| Speed | Very fast | Slow |
| Problem | Sharing the key | Performance |
| Use | Bulk data | Key exchange, signing |
In practice everything is hybrid: asymmetric to exchange a session key, symmetric to encrypt the data. That’s how TLS, PGP, and Signal work.
How hybrid encryption works
Section titled “How hybrid encryption works”sequenceDiagram
participant A as Sender
participant B as Receiver
B->>A: B's public key
A->>A: Generates session key K (CSPRNG)
A->>B: K encrypted with B's public key (or ECDHE)
A->>B: Data encrypted with K (AES-GCM)
B->>B: Decrypts K with its private key, then the data
The asymmetric part only protects a small value (the session key). The bulk of the traffic goes with authenticated symmetric encryption.
Modes of operation (where AES breaks)
Section titled “Modes of operation (where AES breaks)”AES encrypts 128-bit blocks. The mode says how to chain blocks, and that’s where the flaws live (NIST SP 800-38A/D):
- ECB: each block is independent, so equal plaintext blocks give equal ciphertext. Pattern leakage (the “ECB penguin”) and block cut-and-paste. Never use it.
- CBC: chains with an XOR of the previous block; needs a random IV. Malleable without a MAC (bit-flipping) and vulnerable to padding oracle. See Padding oracle.
- CTR: turns AES into a stream cipher (keystream XOR plaintext). Reusing
(key, nonce)is catastrophic: the XOR of two plaintexts reveals both. - GCM: CTR + authentication (AEAD) → confidentiality and integrity. Recommended, but the nonce must be unique per key: repeating it breaks authentication and allows tag forgery.
Theory: why the mode matters more than the cipher
Section titled “Theory: why the mode matters more than the cipher”The block cipher (AES) is, on its own, a permutation of a single block. Without a mode that provides diffusion across blocks and authentication, the attacker doesn’t need to break AES: they manipulate the structure. That’s why the modern recommendation isn’t “use AES” but “use an AEAD” (AES-GCM or ChaCha20-Poly1305), which integrates encryption and MAC into one malleability-resistant operation.
Red Team
Section titled “Red Team”Detecting and exploiting ECB
Section titled “Detecting and exploiting ECB”# Encryption oracle: send repeated blocks and look for repeated ciphertext# 32 'A' = two identical AES blocks -> if the ciphertext repeats, it's ECBpayload = b"A" * 32# "ECB byte-at-a-time": if the server encrypts INPUT||SECRET in ECB,# the secret is recovered byte by byte by aligning blocks (classic Cryptopals challenge)Keystream reuse (CTR/stream with a repeated nonce)
Section titled “Keystream reuse (CTR/stream with a repeated nonce)”# C1 = P1 XOR KS ; C2 = P2 XOR KS (same nonce -> same keystream KS)# C1 XOR C2 = P1 XOR P2 -> with "crib dragging" both plaintexts are recovered without the keyc1_xor_c2 = bytes(a ^ b for a, b in zip(c1, c2))Malleability / bit-flipping (CBC without a MAC)
Section titled “Malleability / bit-flipping (CBC without a MAC)”Altering a byte of the IV or the ciphertext block in CBC changes the decrypted plaintext of the next block in a controlled way. Typical example: turning role=user into role=admin without knowing the key.
# Reproduce modes with openssl to prototypeopenssl enc -aes-128-ecb -K 00112233445566778899aabbccddeeff -in plain.bin -out ecb.binopenssl enc -aes-128-cbc -K 00112233445566778899aabbccddeeff -iv 000102030405060708090a0b0c0d0e0f -in plain.bin -out cbc.binBlue Team
Section titled “Blue Team”- AEAD by default: AES-GCM or ChaCha20-Poly1305; never raw CBC/CTR without a MAC.
- Unique nonce per key (counter or 96 random bits in GCM); random, unpredictable IV in CBC.
- Ban ECB. If not using AEAD, encrypt-then-MAC with an HMAC verified before decrypting.
- Key rotation and management with KMS/HSM; cap data per key in GCM (nonce-collision risk).
CVEs and real-world cases
Section titled “CVEs and real-world cases”- ECB in cookies/tokens: structure leakage and block cut-and-paste, recurring in web audits.
- GCM nonce reuse: authentication breakage; documented in misconfigured TLS and VPN implementations.
- Zerologon (CVE-2020-1472): abuse of AES-CFB8 with an all-zero IV in Netlogon, allowing authentication as the domain controller.
Checklist
Section titled “Checklist”- Identify algorithm and mode (block size 16 → AES)
- ECB test: repeated blocks → repeated ciphertext
- ECB byte-at-a-time if there’s an
INPUT‖SECREToracle - CTR/stream: look for nonce reuse (XOR of plaintexts)
- CBC without MAC: try bit-flipping and Padding oracle
- GCM: is the nonce repeated? → tag forgery
- Verify the defense uses AEAD and a unique nonce