# X-MAS CTF 2018 - Santa's List 1 & 2 Writeup

These two challenge are very similar: the only difference is that in the first one we can do how many requests we want to the server, while in the second one we are limited to 5 requests. We’ll treat only the second, showing a solution that works in 4 requests.

We’re given the Python code used on the server:

## Code Analysis

The code looks very simple, basically we’re given the encrypted flag, encrypted with a secure RSA key with the standard exponent (as it is not specified when creating the key). We can encrypt whatever we want, but we can’t decrypt things that, when decrypted, are multiples of the flag or multiples of the things we’ve encrypted.

## Attack

The first thing is to recover the modulus : suppose we encrypt two different integers obtaining , then we have that

and so , most likely with if we choose the integers such that .

Once we recovered the rest is trivial: take the least prime such that it divides the decrypted flag (I’m lazy so I waited for it to be equal to 2), so we have

then simply decrypt 2 to get and multiply it with the previous result to get the decimal value of the flag. Use whatever long_to_bytes function to get the string.

Here’s the Python code for the attack, I did the last part by hand using the interactive mode from pwntools, the script simply recovers .

## Bonus

The modulus can be recovered with only one request, that is

The flag can be also recovered with only one requests, but this is a little bit trickier and left to the reader :) simply notice that, with this method, we only need 2 requests!