Monday, September 30, 2019

My crypto submission to HackTheBox

I greatly enjoy completing cryptography CTF's and so figured I could try creating my own simple challenge to submit to HackTheBox. There are quite a few crypto submissions though, and only a certain amount are allowed to be active at a time, so even if my challenge does get accepted, it could be quite a while until I'm able to link it to anybody, so instead lets talk about it here for now instead.



I remember my first exposure to crypto and CTF's in general was Google's 2018 summer CTF and the challenge 'dm collision' in which you were given a python script 'not_des.py', a slight alteration on the DES one-way compression function, and find collisions in it, ie two inputs which yielded the same output. This challenge was far outside of my abilities, and still would be difficult for me today, however I did find a write up for it online (really recommend this if you're interested in the challenge: https://fortenf.org/e/ctfs/crypto/2018/06/26/google-ctf-2018-dm-collision.html) and found everything being explained incredibly interesting, it undoubtedly lit the spark for my interest in crypto, and more specifically breaking it. As this challenge was more or less about DES, I ended up reading up a lot on DES and it's vulnerabilities, and so it's something I already know a lot about to make a challenge on. As such, my challenge submitted to HTB involves taking a ciphertext encrypted using DES, and finding it's plaintext.



So our ciphertext comes in base64 format as is standard for raw data like this and decodes into non-printable characters. If we count the number of characters, we find that it's a multiple of 8, thus indicating it's likely a ciphertext encrypted by a block-cipher.

The challenge description is where the real clue on where to go with this is given.

'We've uncovered an old encrypted message that seems to date back to the early 70's. Can you help us crack it?'

The 'leap of faith', characteristic to CTF's, is realizing that the only block-cipher to exist in the early 70's was DES, and so that must be the algorithm used (hence the challenge name 'Old School'). From there the challenger is intended to research DES (the wikipedia page would suffice) to find it's unique property in regards to weak keys. That is, keys wherein the operation of encryption becomes the same as decryption. Due to DES's symmetric nature of operation, keys such as all 0's or all 0xFF's will mean that whatever ciphertext is created using them will be able to be decrypted by simply encrypting the ciphertext again with the same key. A challenger could take this knowledge to iterate over all known weak keys as listed on wikipedia and try encrypting the ciphertext, checking against the output for anything legible.

f
Well, not directly, but Microsoft do use a bad implementation of 'tripple' DES that can be reduced down to a single DES operation, which is still used in wifi authentication protocols today!

I've demonstrated here a basic python script that can be used (with the help of a package called pyDes) to decrypt the cipher. Obviously without already knowing the key was all '0xFF's you would require a loop of all known weak keys, but this is redundant for the example.

Creating this challenge was a lot of fun, and taught me a little about how to properly store and output raw binary data with non-printable characters, as usually I'm only dealing with the other end of things and only trying to take a decrypt things, rather than share encrypted data. I hope HTB can approve the challenge, in which case I may have to take this post down less people go looking for the flag!

No comments:

Post a Comment