1337 Local CTF: numbA thiri — CRT Reconstruction
201 words
1 minute
1337 Local CTF: numbA thiri — CRT Reconstruction
numbA thiri
Challenge Context
The challenge converted the flag to an integer m, generated all primes below 105, and printed two things:
m // prod(primes)- A list of
(m % p, p)residues for each small prime.
Reconnaissance
The source logic was:
m = bytes_to_long(flag)primes = []sieve()residues = [(m % p, p) for p in primes]print(m // math.prod(primes))print(residues)Vulnerability / Core Idea
The residues reveal m mod P, where P is the product of all listed primes. The quotient reveals the high part of m:
m = quotient * P + (m mod P)So the problem is a direct Chinese Remainder Theorem reconstruction.
Exploitation
import mathfrom Crypto.Util.number import long_to_bytes
quotient = 100785residues = [(0, 2), (0, 3), (4, 5), (4, 7), ...]
P = math.prod(p for _, p in residues)x = 0for r, p in residues: Mi = P // p x = (x + r * Mi * pow(Mi, -1, p)) % P
m = quotient * P + xprint(long_to_bytes(m))The recovered bytes include a trailing newline in the original flag file, but the submitted flag is the text without the newline.
Flag
leet{R3al_F149_HH}Lesson Learned
If you publish enough modular residues plus the quotient by the modulus product, you have published the whole integer.
Cover: Wallhaven 8gk26o.
Share Article
If this article helped you, please share it with others!
1337 Local CTF: numbA thiri — CRT Reconstruction
https://achux21.github.io/posts/1337-local-ctf-numba-thiri/ 1337 Local CTF: Notebook — Smarty SSTI → WAF Bypass → File Read
1337 Local CTF: ret2win — Token Validation → Return Address Control
Related Posts Smart
1
1337 Local CTF: Baby-AES — Known Plaintext → Tiny Keyspace
CTF Recovering a 9-byte AES key by using the known flag format and a known plaintext/ciphertext pair.
2
1337 Local CTF: holy bytes hh — Timing Side Channel
CTF Extracting a flag bit-by-bit from a deliberate timing leak in a Python loop.
3
1337 Local CTF: intro to zk — Broken Fiat-Shamir Binding
CTF Forging a Sigma protocol proof because the verifier's challenge is constant and not bound to the commitment.
4
1337 Local CTF: baby overflow — Integer Overflow
CTF Using an 8-bit integer wraparound to satisfy a numeric check.
5
1337 Local CTF: July pool 2024 — Dangling Git Commits
CTF Recovering a split flag from unreachable Git objects inside a piscine project archive.
Random Posts Random