Home
Writeups Misc About
ProSign 3

ProSign 3

Big kudos to ConnorM on the Cryptohack Discord for the help. This challenge is super sneaky, as the implementation looks very sound, and it bears great resemblance to the example of the Python-ecdsa module.

I learnt two lessons from this. First, please do code fuzzing carefully - I was very close to the actual solution but simply missed the crucial idea. Second, do not make assumptions about one's code - vulnerabilities can start from something very silly. ECDSA: Handle with Care is an excellent article from TrailofBits demonstrating the vulnerablities evident in ECDSA with nonce bias.

The vulnerability in the challenge is the way that the message is signed.

The random number generated is within the range of (1, n), but n is not the order of the group as intended, but n is the value of int(now.strftime("%S")). Hence, the value of the random number k is dependent on the time that we requested for the time signature. This allows us to use the exploit that broke PS3's encryption and quite easily obtain the secret key, hence the name of the challenge ProSign 3. We can retrieve the private key used with two different messages using the same nonce, referred from this page.

The n used in randrange is the second in the requested time for the signature. randrange(1, 2) will always return 1, therefore a message requested at the time with the number of seconds being 2 will always have a nonce of 1. However, the form of the message is month:seconds, so we cannot request another message at the time with the number of seconds being 2 again, as the form of the message is the same. Hence, we will use the next possible time - second 3. However, this only yields a 50% chance of the same nonce 1 being used, as the possible value from randrange(1, 3) is 1, 2. If we fail, we can always retry and do again. Another crucial point is that we should wait for 1 minute after the first message - requesting the next message immediately will lead to wrong timings on the server side.

Python Implementation

Note that there is also a solution using LLL based on the TrailofBits article above. Kudos to terrynini38514 on Cryptohack for this solution.