I lost my modulus. Can you find it for me?
Time
2 hours
First blood
Behavior
The server implement paillier cryptosystem. It gives us a encrypted flag at start.
There are two operations, A and B, Operation A return the ciphertext of our input. Operation B gives us the last byte of plaintext. We can run atmost 2048 operations.
Unfortunately, we know nothing about n,p,q,g.
Solution
TL;DR
- Leak 8 ~ 1024 bits of n bit-by-bit (1008 OPs).
- Last byte is
-ret
(0 OPs). - Leak 16 bytes of flag (16 OPs).
- Repeat with a new connection.
We can calculate m modn by encrypting it and then decrypting, If m<n, we get the last byte of $m$. However, if m≥n, we get the last byte of m modn. We can leak n bit-by-bit by selecting 2b as m. Moreover, the return value is −n mod256 if m≥n, which means we have 16 operations left for leaking 16 bytes of flag.
For example, Let n:=233∗263=61279=0b01110⋯ 216 modn215 modn215+214 modn215+214+213 modn215+214+213+212 modn−nmod256=161=0=0=0=161⋯=161
To decrypt the flag, we can use the homomorphic property of paillier: c1×c2 modn2c1m2 modn2=Enc(m1+m2 modn)=Enc(m1∗m2 modn) Decrypt it with following recursive equation: ctmt=(ct−1/Enc(mt−1))1/256 modn2=Dec(ct) mod256