I’ve learned that if you shuffle your text, it’s elrlay hrda to tlle htaw eht nioiglra nutpi aws.
Solution
The script shufflebox.py generates a permutation, PERM of the integers 0-16. Then, it uses random.shuffle(PERM) to shuffle the permutation. Lastly, it iterates through each line in an input file, grabbing the character at the index specified by the shuffled permutation, and writing it to an output file.
We are given 2/3 of the shuffled output, and need to find the third, which is the flag. The first input we were given is grouped into four. Because the order of this, we can identify possible permutations for each group of four. For example, take aaaa. In the output, the index of the first a could be [2, 6, 13, or 15]. We can generate all possible permutations for each group of four, and then check the second input to find the correct permutation. Once we have the correct permutation, we can use it to find the flag.
These are the possible permutations for the first input. We can then check the second input to find the correct permutation. So, let’s start with A:
permutation[0]:
2: in2[0] == out2[2]→a == a Correct!
6: in2[0] == out2[6]→a == d Incorrect
13: in2[0] == out2[13]→a == c Incorrect
15: in2[0] == out2[15]→a == b Incorrect
permutation[1]:
6: in2[1] == out2[6]→b == d Incorrect
13: in2[1] == out2[13]→b == c Incorrect
15: in2[1] == out2[15]→b == b Correct!
permutation[2]:
6: in2[2] == out2[6]→c == d Incorrect
13: in2[2] == out2[13]→c == c Correct!
permutation[3]:
6: in2[3] == out2[6]→d == d Correct!
So, the first four of the permutation is [2, 15, 13, 6]. We continue this process for the other three groups of four, and then use the correct permutation to find the flag. We can automate this entire process with the following script:
Web
Zoo Feedback Form
The webpage is a simple feedback form with only one input field. Upon clicking “Submit Feedback”, a POST request is sent:
with a response of:
Feedback sent to the Emus: a
Testing around, we can determine that the form is unfiltered. For example, sending < yields an XML parsing error about invalid element name. Thus, this form is vulnerable to XXE (XML External Entity) injection. Specifically, we can use the <!ENTITY> directive to read the contents of files on the server (along with other possibilities, but for getting the flag, this is all we need).
This script sends a POST request with the payload containing the <!ENTITY> directive to read the contents of flag.txt. The response contains the flag!
CO2
A group of students who don’t like to do things the “conventional” way decided to come up with a CyberSecurity Blog post. You’ve been hired to perform an in-depth whitebox test on their web application.
We are given a simple blog website with some basic functionality: the ability to register, the ability to create posts, and the ability to leave feedback. I started by taking a look at the source code, and everything looked good for the most part, until I noticed a comment in app/routes.py:
“dynamically add fields” sounds pretty interesting. Looking further into the feedback route:
It uses the merge function to merge the data from the request into the Feedback object. Let’s quickly check the merge function:
This immediately reminded me of JavaScript’s prototype pollution vulnerability, but I wasn’t sure if this existed in Python. I copied the merge function and googled it, and found a blog posting detailing Prototype Pollution in Python! Huge shoutout to Abdulrah33m for all the research and teaching me something new! So, we know it’s vulnerable, but what is the flag condition?
My first intuition was set the flag environment variable to true. I created a quick test script utilizing the logic from the blog post:
And it worked! I was able to get from None to true. However, when testing this payload on the actual remote server, I was not able to get the flag. After some thinking, I realized that that this change is not persistent. The get_flag endpoint checks the value of the global variable flag, which is set to os.getenv("flag") when the server starts. This means that even if we change the environment variable, the server will still check the original value. So, we need to find a way to change the value of the global variable flag. This is actually simpler than setting the environment variable, as we can just set the value of the global variable directly.
And we get the flag!
Misc
Intercepted Transmission
Those monsters! They’ve kidnapped the Quokkas! Who in their right mind would capture those friendly little guys.. We’ve managed to intercept a CCIR476 transmission from the kidnappers, we think it contains the location of our friends! Can you help us decode it? We managed to decode the first two characters as ’##’
We’re told that the transmission is CCIR476 encoded. A quick search tells us that it is a radio communication protocol where each character is represented by a 7-bit code. Four of the bits are 1 and three are 0, to allow for single bit error correction.
All we need is a mapping of the 7-bit code to the character it represents, which we can find here.
There are two special control characters, LTRS and FIGS, which switch between letters and figures respectively, so we need to keep track of what mode we’re in.