PP{modulo_hashing_is_not_collision_resistant::fGWQMe7UvDiF}
Summary
"Commitments are basically hashes, signatures are essentially hashes, and hashes are
fundamentally encryption" — so the challenge is the hash. hash_pw(pw) = b2l(pw)^e mod N
with e = 17 and a per-connection 1337-bit-prime RSA modulus N. Two bugs, both classic
RSA misuse:
flag0 — no domain separation ⇒ trivial collision. The "hash" is just modular exponentiation of the raw password integer with no salt/padding/domain tag. Two distinct
NLEN-byte passwordsxandx + Nsatisfyx ≡ x+N (mod N), hencehash(x) == hash(x+N). The register routine treats a hash collision as an "unexpected database storage optimization" and prints flag0.flag1 — small message, no modular wrap ⇒ integer root.
admin_secretis only 19 bytes (≤ 152 bits), soadmin_secret^17 < 2^2584whileN ≥ 2^2672(two 1337-bit primes). The modular reduction never happens:pw_hash = admin_secret^17as an exact integer. The login banner leaksadmin'spw_hash, so we take the plain integer 17th root to recover the admin password, then answer the challenge/response.
Both flags live in one connection — N and admin_secret are fresh per TCP connection
(socat fork EXEC:python server.py), so flag0 (register) and flag1 (login as admin) must
be done in the same session.
Solution / Exploit
Exploit: unholytrinity_exploit.py
1python3 unholytrinity_exploit.py --host HOST --port PORT
2python3 unholytrinity_exploit.py --local # spawns server.py with dummy flags
The primitive
1def hash_pw(pw: bytes) -> int:
2 return pow(b2l(pw), e, N) # e = 17, N = p*q (2 x 1337-bit primes)
Server banner gives N and e; NLEN = (N.bit_length()+7)//8 = 335 bytes.
flag0 — collision via x and x + N
1pw1 = make_password(NLEN) # NLEN bytes, satisfies password policy
2v1 = int.from_bytes(pw1, "big")
3v2 = v1 + N # fits in 8*NLEN bits -> still NLEN bytes
4pw2 = v2.to_bytes(NLEN, "big")
5# hash_pw(pw1) == pow(v1, e, N) == pow(v1+N, e, N) == hash_pw(pw2)
Register pw1 as alice, then pw2 as bob. The audit_log collision check fires:
ERROR: Something happened. It was probably a pentest. Have this for now:
PP{modulo_hashing_is_not_collision_resistant::fGWQMe7UvDiF}
Notes on the password policy (it is enforced before the hash): str(password) is checked
for one lowercase, one uppercase, one digit and one special char, and len == NLEN. The
solver builds head = b"A9!" and pads with random bytes; both pw1 and pw2 must be
distinct and pass the policy, so a few random attempts may be needed.
flag1 — integer 17th root of the leaked hash
The login path prints the committed hash before the challenge/response:
Authenticating 'admin' with committed pw_hash <int>...
Because admin_secret < 2^152 and e = 17, pw_hash = admin_secret^17 with no
modular reduction. Take the exact integer root:
1def iroot(x, n): # exact integer n-th root, raises if not perfect
2 ...
3secret = iroot(h, e)
4assert pow(secret, e) == h # verified
Now login as admin. The server runs a Fiat–Shamir-style protocol for
ROUNDS = 256 // e.bit_length() + 1 = 65 rounds:
- We send
announcement = k^e mod Nfor a randomk(withgcd,≠0checks). - Server replies
Challenge: cwithca random hash mode. - We reply
response = k · secret^c mod N, which satisfiesresponse^e ≡ announcement · pw_hash^c (mod N).
Knowing secret we answer every round correctly, and the server prints the flag:
Welcome, admin!
Here is your flag: PP{rsa_messages_need_to_be_sufficiently_large::89gDoeIsXkoC}
Flags
PP{modulo_hashing_is_not_collision_resistant::fGWQMe7UvDiF} # flag0 (collision)
PP{rsa_messages_need_to_be_sufficiently_large::89gDoeIsXkoC} # flag1 (integer root)
Notes / Pitfalls
- One connection only.
N,dandadmin_secretare regenerated in a fresh process per TCP connection. Get flag0 and flag1 in the same socket. - A failed login kills the server.
main()exits withMITM detected. Shutting down server for security reasons.on any failed round — so once you start the admin login you must answer every one of the 65 rounds correctly. Recovery first, then login. - The
e = 17root is only valid because the message is small. This is the whole point: ifadmin_secretwere large enough thatsecret^17 ≥ N, the reduction would apply and the root would fail (the exploit'sassert pow(secret, e) == hcatches this). - Collision needs
v1 + Nto still fit inNLENbytes, i.e.v1must be small enough. The solver retries randomv1until both passwords satisfy the policy and the byte length. d = pow(e, -1, (p-1)(q-1))is computed at startup; ifgcd(e, (p-1)(q-1)) != 1the loop retries. Irrelevant to the attack but explains the banner delay.- The contrived "zero-knowledge server authentication" is just textbook RSA challenge/response; there is no zero-knowledge here, and no signature forgery is needed — the leaked hash is the only break.