Symmetric Cryptography
Index of symmetric crypto pages - AES modes, ECB/CBC attacks, padding oracle, and stream ciphers.
Symmetric Cryptography
Symmetric cryptography uses a shared secret key to both encrypt plaintext and decrypt ciphertext; the same mathematical operations reverse each other when applied with the correct key. How it works: Block ciphers (AES) encrypt fixed-size chunks; a mode of operation (ECB, CBC, CTR) chains blocks together to handle arbitrary-length messages; without proper mode implementation, identical plaintext blocks produce identical ciphertext (ECB) or IVs leak information (CBC with predictable IVs). Why it matters: AES is cryptographically secure; attacks target mode weaknesses and improper key/IV handling; padding oracle attacks, bit-flipping exploits, and keystream reuse are common CTF vectors; essential for understanding real-world encryption failures.
Pages in This Subsection
| Page | Difficulty | Key Attack |
|---|---|---|
| AES Modes Overview | Intermediate | Understand ECB/CBC/CTR weaknesses |
| ECB Attacks | Intermediate | Byte-at-a-time oracle, cut-and-paste |
| CBC Attacks | Intermediate | Bit flipping, IV=key, padding oracle |
| Padding Oracle | Advanced | Decrypt any CBC ciphertext |
| Stream Ciphers | Intermediate | Nonce reuse, keystream recovery |
Quick Attack Selection
| Observation / Given | Attack / Technique |
|---|---|
| Encrypted cookie, same data encrypts same way | ECB byte-at-a-time oracle |
| CBC cipher, ciphertext can be modified | CBC bit flip (alter to change ) |
| CBC cipher, server reveals padding error | Padding oracle |
| Two ciphertexts, same key and nonce | Stream cipher nonce reuse ( leaks XOR of plaintexts) |
| AES-CTR, same nonce twice | Same as stream cipher nonce reuse |
| MAC = style | Length extension (see Hashing) |
Python AES Template
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import os
key = os.urandom(16)
iv = os.urandom(16)
# ECB
cipher = AES.new(key, AES.MODE_ECB)
ct = cipher.encrypt(pad(plaintext, 16))
pt = unpad(AES.new(key, AES.MODE_ECB).decrypt(ct), 16)
# CBC
cipher = AES.new(key, AES.MODE_CBC, iv)
ct = cipher.encrypt(pad(plaintext, 16))
pt = unpad(AES.new(key, AES.MODE_CBC, iv).decrypt(ct), 16)
# CTR
cipher = AES.new(key, AES.MODE_CTR, nonce=iv[:8])
ct = cipher.encrypt(plaintext) # no padding neededLast updated on