1337 Local CTF: Baby-AES — Known Plaintext → Tiny Keyspace

220 words
1 minute
1337 Local CTF: Baby-AES — Known Plaintext → Tiny Keyspace

Baby-AES#

Challenge Context#

The challenge provided aes.py. The script reads the flag, uses it as an AES key padded with null bytes, encrypts a 16-byte zero block in ECB mode, and prints the ciphertext.

Reconnaissance#

The important part of the source was:

with open("flag.txt", "rb") as f:
flag = f.read().strip()
key = flag + b"\x00" * (16 - len(flag))
cipher = AES.new(key, AES.MODE_ECB)
pt = b"\x00" * 16
ct = cipher.encrypt(pt)
print("len(flag): ", len(flag))
print("Ciphertext (hex):", ct.hex())

The output told us:

len(flag): 9
Ciphertext (hex): 489b02c7245f7d5b6221ba7bd7f85c29

Vulnerability / Core Idea#

The flag is the AES key. Because the flag length is 9 and the format is leet{...}, only three bytes are unknown:

leet{???}

This is not an AES break. The cryptographic mistake is turning a low-entropy, format-constrained secret into a symmetric key and revealing a known plaintext/ciphertext pair.

Exploitation#

For each candidate leet{XYZ}:

  1. Pad it with seven null bytes to produce a 16-byte AES key.
  2. Encrypt 00 * 16 under AES-ECB.
  3. Compare the output to 489b02c7245f7d5b6221ba7bd7f85c29.
from Crypto.Cipher import AES
import itertools, string
target = bytes.fromhex("489b02c7245f7d5b6221ba7bd7f85c29")
pt = b"\x00" * 16
charset = string.ascii_letters + string.digits + "_!@#$%^&*()-+=[]{}|;:',.<>?/~`"
for a, b, c in itertools.product(charset, repeat=3):
flag = f"leet{{{a}{b}{c}}}".encode()
key = flag + b"\x00" * 7
if AES.new(key, AES.MODE_ECB).encrypt(pt) == target:
print(flag.decode())
break

Flag#

leet{lol}

Lesson Learned#

Known plaintext plus a tiny keyspace turns strong primitives into a dictionary check. The primitive was fine; the key derivation was the bug.


Cover: Wallhaven xelyx3.

Share Article

If this article helped you, please share it with others!

1337 Local CTF: Baby-AES — Known Plaintext → Tiny Keyspace
https://achux21.github.io/posts/1337-local-ctf-baby-aes/
Author
ACHUX21
Published at
2026-06-27
License
CC BY-NC-SA 4.0
Profile Image of the Author
ACHUX21
CTF player & security researcher
Notice
CTF writeups and security research. New posts coming soon.
Music
Cover

Music

No playing

0:00 0:00
No lyrics available
Categories
Tags
Site Statistics
Posts
28
Categories
3
Tags
81
Total Words
26,137
Running Days
0 days
Last Activity
0 days ago

Table of Contents