Knowledge Repository
Skills: Programming, cryptography, GitHub, steganography, forensics
Last updated
Skills: Programming, cryptography, GitHub, steganography, forensics
Last updated
Participation page: https://sunshinectf.org/
Event weight on ctftime: 34
START: 2023-10-07 14:00 UTC
FINISH: 2023-10-09 14:00 UTC
Flag Format: sun{stuffs}
Category: Miscellaneous
Points system: Dynamic reducing based on number of solves
Points collected: 396
The challenge gives us a zip file. I unzipped it and saw an EML file in there. Since I had never encountered an EML in a CTF file before, I had to read up about it. https://www.adobe.com/uk/acrobat/resources/document-files/text-files/eml.html
It is just a plain text file where an E-mail conversation is stored. The contents of the E-mail were base64 encoded.
Upon inspecting the file, I saw that there was an attachment too.
After decoding the message contents, I saw this message:
I used an online EML viewer to directly download the attachment. This was a Git bundle.
I then created a new git repo and verified the bundle
I cloned the repository then.
Upon visiting the recently cloned repository, I saw an audio file.
Upon listening to this audio file, it felt like a simple frequency varying beeps file. The beeps were quickly changing and had only 2 distinguishable tones. This indicated it was probably a morse code.
Upon deciphering it on an online tool https://morsecode.world/international/decoder/audio-decoder-adaptive.html, I noticed some text come out. This initially didn't make sense.
Upon analyzing this in dcode.fr, I observed that it is NATO encoded text.
Further, upon deciphering it, I noticed that it was english for "="
Since, this is not at all a flag, there has to be more to it. Further, it can be speculated that "=" is the end of a base64 or base32 encoded string.
I examined the github repo a bit more and found out that a total of 3000+ commits were there.
git rev-list --count --all
Upon inspecting git log and a few of the commits (reverting repo to the commit), I observed that in each commit, data file was of different size. So, the data file must have different character/word which would be later combined together to give us the next clue.
Now upon checking different commits, I see different data files. I inspect a few data files and turns out each one of then had a single character (Alfa, Bravo, Delta etc.)
All of these files are encoded in NATO phonetic encoding and it goes like A,B,C for Alfa, Bravo, Charlie etc.
To extract the message, we might need to combine all of these together. Now, doing this for 3016 commits is cumbersome. So, a programmatic approach was essential to save some time.
I found a script online that would extract all the files in a repository here: https://gist.github.com/magnetikonline/5faab765cf0775ea70cd2aa38bd70432
But since the script was only producing output related to the commits name, I had to modify the script so that it is numbered (in order to view from first to last commit)
Script used was:
Upon running the script we see the data was being renamed as per the numbers
Now, upon inspecting the data files in these folders, I see some of them had the same sizees. For example, files with size 4444 corresponded to the alphabet "6"
Now, an algorithm is needed to rename these files based on the size to alphanumeric conversion. Since there are 26 english alphabets and 10 numerals, I need to classify 36 files of different sizes and put them in a dictionary for conversion. I wrote a simple Python script to rename size 4444 to 6 first and tested it out. Before that, I ran simple CLI commands to ensure how many files of size 4444 are there.
Putting this through wc would give me how many files have 4444 size.
I wrote this small script to replace files with size 4444 with the digit 6. The dictionary "size_to_code" can be extended for other files as well. But for testing I just tried to replace all the files with 4444 sizee first.
I saw that a total 94 files were renamed. I confirmed this earlier in the CLI too. I then grepped and saw that all the files were renamed properly.
So the algorithm to solve and extract the message is as follows:
Classify 36 files (decode audio morse) manually and based on their sizes, add them to the dictionary "size_to_code" in Python script. To obtain the directory names of these 36 different files, write a simple bash script.
Rename the files from NATO phonetic to their respective plaintext conversion.
Open folders one by one using Python and read the file name. Keep appending the filename in a text file.
Reverse the obtained string.
Decode base64 to plaintext and save in a file.
Extract the message.
I wrote a small script to find out the folders with data files of similar sizes:
The script classifies a size then tells which folders have "data" file of the same sizes.
This shortened my looking up time in audio files. Now I can manually go ahead and decode them, then add the decoded value in my solution script's dictionary.
Also, since the audio files showed no case sensitivity, it is safe to assume the message could also be base32 where all letters are capital. The final dictionary becomes:
Upon running the modified solution script, we can see that whole 3016 files were renamed to their respective mappings.
Finally, a script was created to read the audio file names in respective folder, append those filenames in a file called output.txt
The script upon running gave an output.txt file. Since it starts with === sign, this gives me an idea that the base32 string is reversed.
So, to make it a proper base32 string, I then finally reversed this string and saved the output in a file called final.
This turned out to be a gz file. Then finally, I used gunzip to extract a text file out of this archive and obtained the flag!
Alternate: One can also use python based decoders like morse2ascii and wav2ascii to do this. I tried it using that but a lot of the small length audio files were not being decoded correctly. Also, the same algorithm I devised can be done using md5 checksums of the files.