Skip to main content
AES itself has never been broken. Every AES challenge you encounter in a CTF is attacking something else: the mode of operation, the initialization vector, the padding scheme, or the way the cipher is wired into a larger application. Your first job on any AES challenge is to identify the mode (ECB, CBC, CTR, GCM, etc.) and the key/IV management strategy. Once you know the mode, the attack surface becomes obvious. This walkthrough covers the four most common vulnerability classes you’ll see, with working Python code for each.

Identifying the Mode

Before you can attack AES, you need to know which mode you’re dealing with. If source code is provided, read it — the mode is always explicit in the cipher constructor. If you only have a black-box oracle, you can often fingerprint the mode empirically.
ECB mode is the only common AES mode where encrypting identical plaintext blocks always produces identical ciphertext blocks. If you see duplicate 16-byte chunks in any ciphertext, you’re dealing with ECB.

Attack Workflow

1

Identify the Mode and Obtain an Oracle

Determine whether you have an encryption oracle, decryption oracle, or both. Read any provided source code to find the mode, key, and IV handling. Note whether the IV is fixed, random-per-session, or (dangerously) equal to the key.
2

Select Your Attack

Match the mode and oracle type to the appropriate attack class. Use the tabs below for detailed instructions on ECB, CBC, and CTR attacks.
3

Execute and Collect Data

Most AES attacks require multiple oracle queries. Automate your data collection early — even a simple loop that queries the oracle and saves responses will save time.
4

Recover the Plaintext or Key

Apply the relevant attack algorithm to reconstruct the plaintext, recover the key, or forge a valid ciphertext depending on what the challenge requires.
5

Extract the Flag

Decode the recovered bytes and look for your flag format. Some challenges require you to forge a specific ciphertext (e.g., role=admin) rather than decrypt an existing one.

AES Mode Attacks

ECB (Electronic Code Book) mode encrypts each 16-byte block independently with the same key. This means identical plaintext blocks always produce identical ciphertext blocks — a critical information leak.

Detection

Encrypt 48 bytes of identical data (three full blocks). If two or more output blocks are identical, the oracle is using ECB.

Byte-at-a-Time Oracle Attack

If the oracle appends a secret to your input before encrypting (AES_ECB(your_input || secret)), you can recover the secret one byte at a time.
This attack requires exactly block_size * secret_length oracle queries in the worst case. For a 16-byte flag, that’s at most 4,096 requests — fast enough to run interactively.

Local Testing Setup

Use this template to reproduce any of the attacks locally before targeting the challenge server.

Quick Reference

Last modified on July 23, 2026