NahamCon2021 CTF - $Echo - Writeup
Introduction
Today we're doing a CTF writeup for the $Echo challenge from the NahamCon2021 CTF. $Echo is a web-based challenge and after we started the challenge we received a URL to interact with:After some testing, we find that the web-app repeats alpha-numeric input from the user and outputs it to the page, except:
The input may not be longer than 15 characters long, and the string may not include special characters, with a few exceptions.
The exempt special characters being forward slash ( / ), periods ( . ), backticks ( ` ), and less-than bracket ( < ). With the backticks, we can break out of the command being issued by the web-app and perform command injection on the web-server.
input `ls`
We can assume that index.php is the file contains the web-app we're interacting with, but we'll look at that later. For now, let's locate the flag:
input `ls ..`
The flag is located one directory above our web-root directory. We could access it with the following command:
input `cat ../flag.txt`
But the string exceeds the 15 character limit for our commands. This is where it's important to know how the web-app works, so we use the command injection to read the index.php file:
input `cat index.php`
This is promising, but it looks like the code has been cut off, so let's view the source of this page to get all the info:
view-source:http://challenge.nahamcon.com:32312/?echo=`cat+index.php`
bash -c ‘echo “ . $to_echo . ”’"
In this case, $to_echo is the input we send the to web-app. Now that we know that the web-app is already instructing the server to echo something, we can cat out the flag file by shortening our command injection string to fit the echo command being sent:
input `< ../flag.txt`
bash -c 'echo < ../flag.txt'
Meaning that the echo command was taking input from the flag.txt file in the directory above the working directory.
Summary
The web-app was vulnerable to command injection through the use of backticks to escape the command being sent. We were able to enumerate the web-app code through command injection and web-page source view. This allowed us to find the correct command injection to obtain our objective flag file.
Finish
Comments
Post a Comment