lauantai 27. elokuuta 2016

IceCTF 2016 RSA?

This is a writeup of the "RSA?" Challenge in IceCTF 2016



RSA cool! Opening up the challenge, a description of John messing around and in the end a flag.txt file given:



John was messing with RSA again... he encrypted our flag! I have a strong feeling he had no idea what he was doing however, can you get the flag for us? flag.txt


The flag.tx contains:



N=0x180be86dc898a3c3a710e52b31de460f8f350610bf63e6b2203c08fddad44601d96eb454a34dab7684589bc32b19eb27cffff8c07179e349ddb62898ae896f8c681796052ae1598bd41f35491175c9b60ae2260d0d4ebac05b4b6f2677a7609c2fe6194fe7b63841cec632e3a2f55d0cb09df08eacea34394ad473577dea5131552b0b30efac31c59087bfe603d2b13bed7d14967bfd489157aa01b14b4e1bd08d9b92ec0c319aeb8fedd535c56770aac95247d116d59cae2f99c3b51f43093fd39c10f93830c1ece75ee37e5fcdc5b174052eccadcadeda2f1b3a4a87184041d5c1a6a0b2eeaa3c3a1227bc27e130e67ac397b375ffe7c873e9b1c649812edcd


e=0x1



c=0x4963654354467b66616c6c735f61706172745f736f5f656173696c795f616e645f7265617373656d626c65645f736f5f63727564656c797d

Okok, so far my experience from RSA has been telling customers at work how their email server certificate is for completely different server/domain or how they are missing a cert in the chain etc.. basic stuff needed for Comptia Security+.


So my guess is "c" stands for cipher but what are the other e and N? N looks like a key but what is e and why is it so small 0x1 = 1 in decimal.


Bringing up the RSA page from wikipedia and studying the math behind it.

https://en.wikipedia.org/wiki/RSA_(cryptosystem)

Ok so "e" is the public exponent used in encryption of messages and N is the modulus which is built out of two big prime numbers and this modulus is used in encryption and decryption. Encrypted with "e" and decrypted with a private exponent "d". We were not given the private exponent so that we would be able to decrypt the "c" so there gotta be something else to it then.

After extensive web research on the subject I started to notice that all the examples use 
something bigger as the public exponent, mostly 0x10001 = 65537
Then it hit me straight to the face.. for an example: 10^1 = 10

How was the message encrypted again?

c = m^e (mod n) = m 

where c is the encrypted message, m is the plaintext message, e is the private exponent and n is the modulus.
You gotta be kidding: c = m


Ok so we know that c is not encrypted at all because the exponent is 1

Lets take the cipher message and put it through hex to ascii converter (some online converter).


0x4963654354467b66616c6c735f61706172745f736f5f656173696c795f616e645f7265617373656d626c65645f736f5f63727564656c797d


--


IceCTF{falls_apart_so_easily_and_reassembled_so_crudely}


Haha! Feels so funny, it was right there all along, only hex encoded. This was definitely one of my favorites. It made me study hard how the math behind RSA works and how to manually encrypt/decrypt. Awesome!




Ei kommentteja:

Lähetä kommentti