corCTF 2024 - the conspiracy
Description: Our intelligence team created a chat app, and secretly distributed it to the lemonthinker gang. We've given you the application source and a capture taken by one of our agents - can you uncover their plans?
Solves: 283
Solution:
The challenge gives 2 files, challenge.pcap
and source.py
. Let's start off by looking at the source code:
Breaking this down bit by bit, we see that the script first reads from a CSV file chatlogs.csv
, which has source IPs, destination IPs, and the messages that are being sent. From here, these are then loaded into 3 lists: sources, destinations, and messages.
Next, we have an encrypt function. This function goes through each character in a message, converts it to its ASCII value, and then multiplies it by a random number between 10 and 100. The random numbers used to multiply are stored in a list called keys, and the final encrypted message is stored in a list of numbers called finalmessage
.
Finally, the script goes through each message and encrypts it. It then creates 2 packets for each message: one with the encrypted message and one with the keys used to encrypt the message. These packets are then sent to the destination IP.
Now, let's look at the pcap file. We can see from the script that that the pcap file contains a lot of TCP packets, sent between 3 IP addresses. (I'm using wireshark for the purposes of this writeup, but you can use any pcap viewer of your choice.)
As hinted by the script, the messages are sent in pairs, so we can look at adjacent packets for messages and keys, as seen below with the TCP payloads in packets 7 and 8:
We can see that the first packet contains the encrypted message, and the second packet contains the keys used to encrypt the message. We can write a script to decrypt the messages, given we know the method use to encrypt them from the script:
Running this script, we get the output "hello blinkoid". This shows us that our method of decryption is correct, and we can now decrypt all the messages in the pcap file. To extract all payloads, you can use the below script:
We can then write these to a file, and read off of the file and decrypt the messages, by dividing each encrypted character by its corresponding key. The final script to decrypt all the messages is below:
As a result, you get the output below:
Flag: corctf{b@53d_af_f0r_th3_w1n}
Bonus: Creating the challenge and unintendeds
The inspiration/theming for this challenge came from 2 things - the first being a Darknet Diaries episode (146) about the FBI building a backdoor into a chat app that was to be distributed to criminals, allowing them to read all messages being sent, and using this to catch criminals. The second was making "gangs" out of 3 of the emotes used in the CoR discord - the lemonthinkers, the msfroggers, and the afs. This emote theme was also used in other challenges, such as infiltration, and msfrogofwar3.
Secondly, a slight unintended solution which we discovered during testing was being able to run strings on the file, which gets the message codes and keys, without having to use scapy to extract it.
In the end, we decided to keep this in, as the main complexity with the challenge was in decrypting the messages.
Last updated