Tom Nook is testing a new encryption scheme for nookphones, but it seems to be a bit faulty… can you break it?
nookcrypt is a netcat service that have no source code released. There are two functions exposed:
hello world
).For example, this is what I had when trying out the options:
Since the response is consistent after reconnecting to the netcat service for multiple times, I assume that the parameters are constant.
Since it is mentioning elliptic curves in its services, the first thing I was doing is to recover the parameters, namely, , and for the elliptic curve .
My attempt is to encrypt a bunch of messages:
Define be the ciphertexts of some message . By direct substitution, we have for all .
Assume that we have three ciphertexts. We can deduce that:
From above, we know is a multiple of .
So we have collected a bunch of "multiples of " and take their gcd. We have recovered that .
Then it is rather obvious to recover and .
Question. What if it is not defined on a prime field? Well… I didn't think of that. But who cares? I could probably observe this if my approach doesn't work out.
Note. I did not think of this during the game. Stupid me.
Knowing that the ciphertext is a multiple of the message , i.e., , we can simply encrypt :
What can we do? Since this is , we can simply search this on Google:
Ta-da
Well, I was even more confused to notice that is a secure curve. I personally don't have a backdoor of secp128r2 (I am much appreciated if you tell me if you do) and thought the challenge isn't doable.
Fours hours later the organizers released a hint in the Discord server:
When I was being played writing an interactor with the service, I observed that there was a strange behaviour regarding to the flag encryption method:
Oh. So the error was caused by the cosmic ray. Okay.
Did you really get it instantly when the hint is announced? No.
Ten hours later, somebody from Discord claimed that he has a strange observation:
Who was the somebody? Me.
We made a bunch of assumptions. Cutting the crap, we assumed that the same generator is being multipled in a same way, except that the curve is operated on new modulo . This matches the author's statement regarding on the prime being corrupted.
However, obviously, it is very likely that may not be a point the above curve. Luckily (or unluckily), we can assume that it is operating on another curve , such that is on it.
For now, we are given two points on this curve (the ciphertexts of the flag and the message hello world
). Since is known we can easily recover by:
The order of the generator should be a large prime for an elliptic curve to be secure. Clearly this property may not hold on those new modulos struck by cosmic may. For instance, suppose that we have . Since 67 is a factor of , we are indeed working on the curve . has a order 74, and . It implies that .
By collecting a bunch of linear congruences, we can find by the Chinese Remainder Theorem. Eventually we have the flag: uiuctf{th4t_5ur3_w4s_f4ulty_huh?}
.
CTF