Reply CTF 2018 - Crypto1 & Crypto2 Writeup
Crypto1 - RoXor (100 pt.)
We’re given a Python code and a file TOP_secret.zip.enc
1 | #!/usr/bin/python2.7 |
Code Analysis
- The function
decriptMe
simply opens the encrypted file and return its content. - The function
encryptionKey
generates the md5 hash of the keyk
given in input. - The function
decryption
, given a key and the ciphertext, gives back the plaintext. Observe that every recovered character is added at the end of the key and is reused 32 charaters later. Noticed this, the decryption process is a simple xor, as the title of the challenge suggests. - The function
encryption
does exactly what it is supposed to do. The only interesting part is that it uses as a key the md5 hash of the real key, then the process is the same as the decryption one. - The function
check
checks if the file has been decrypted correctly, comparing the last 65 bytes with the last 65 bytes of the real file (as a string in the source). Here is the weakness of the cryptosystem.
Attack
What we have to do now is to reconstruct the original file starting from the last 65 bytes and knowing that part of these bytes are also in the key so, basically, we have to do in reverse the encryption process:
1 | def solve(): |
the function returns 9dc5616a9df448ce476be9d8dd638a9c
; calling the decryption function with this key and redirecting the result to a file gives a zip which, when extracted, gives a text file with the flag: {FLG:Y0yNe3dT0goD33peR!}
Crypto 2 - Something is missing (200 pt.)
In this challenge we are only given a file, without any explanation. The file contains some encrypted data and, using hexeditor, we can see that there are a lot of zeros at the beginning of the file. After some time the organizers gave us an hint: the file is encrypted using RSA. Since we have no informations or public key we assume that the attack does not depend on the modulus: the simpler attack is supposing that the file has been encrypted with
1 | from Crypto.Util.number import bytes_to_long |
The script returns }!Erc33Qre0Z:TYS{ :ryvs CVM rug ebs qrra hbl qebjffnc rug fv fvuG
: reverting the string and decrypting with rot-13
gives the flag {FLG:M0reD33peR!}
.