Keys - Hackthebox Crypto

Keys - “Can you decrypt the message?” This is a Hackthebox challenge under the Crypto Challenges. You must be signed up to https://hackthebox.eu to access this box.

URL: Crypto Challenges

Difficulty: Easy / Medium

Author: pwn4magic

We are given an archive with a .txt file called keys.txt.

There is some cypher text in the file:

hBU9lesroX_veFoHz-xUcaz4_ymH-D8p28IP_4rtjq0=
gAAAAABaDDCRPXCPdGDcBKFqEFz9zvnaiLUbWHqxXqScTTYWfZJcz-WhH7rf_fYHo67zGzJAdkrwATuMptY-nJmU-eYG3HKLO9WDLmO27sex1-R85CZEFCU=

I initially thought this was Base64, but there are some characters you would not expect in a Base64 value.

Anyway, converting from base64 gives us this:

..=.ë+¡{Þ..óÅG.Ï.¦.?)ÛÂ.â»c«

This just seems wrong.

We have been given two different base64-like strings, maybe one is a key? I looked up some algorithms and clues and finally found this:

Fernet (symmetric encryption)

Fernet guarantees that a message encrypted using it cannot be manipulated or read without the key.

Here is our script that imports the first string as a key, and the second as the token which we decrypt.

>>> from cryptography.fernet import Fernet
>>> key = "hBU9lesroX_veFoHz-xUcaz4_ymH-D8p28IP_4rtjq0="
>>> f = Fernet(key)
>>> token = "gAAAAABaDDCRPXCPdGDcBKFqEFz9zvnaiLUbWHqxXqScTTYWfZJcz-WhH7rf_fYHo67zGzJAdkrwATuMptY-nJmU-eYG3HKLO9WDLmO27sex1-R85CZEFCU="
>>> print(f.decrypt(token))
Flag : HTB{N0t_A_Fl1g!}

Fernet

Written on July 3, 2020