Exploit-DB #28175
Description: Sophos Web Protection Appliance - Multiple Vulnerabilities
Type: webapps
Platform: linux
Date: 2013-09-09
Author: Core Security

Exploit:
Core Security - Corelabs Advisory
http://corelabs.coresecurity.com/

Sophos Web Protection Appliance Multiple Vulnerabilities


1. *Advisory Information*

Title: Sophos Web Protection Appliance Multiple Vulnerabilities
Advisory ID: CORE-2013-0809
Advisory URL:
http://www.coresecurity.com/advisories/sophos-web-protection-appliance-multiple-vulnerabilities
Date published: 2013-09-06
Date of last update: 2013-09-06
Vendors contacted: Sophos
Release mode: Coordinated release


2. *Vulnerability Information*

Class: OS command injection [CWE-78], OS command injection [CWE-78]
Impact: Code execution, Security bypass
Remotely Exploitable: Yes
Locally Exploitable: No
CVE Name: CVE-2013-4983, CVE-2013-4984


3. *Vulnerability Description*

Sophos Web Protection Appliance [1] provides advanced web malware
protection, URL filtering and content control (including scanning of
HTTPS traffic) in a Secure Web Gateway appliance. Sophos Web Protection
Appliance is available both as a hardware appliance and as a VMware
virtual appliance.

Multiple vulnerabilities have been found in Sophos Web Protection
Appliance that could allow an unauthenticated remote attacker to execute
arbitrary OS commands and escalate privileges to gain root permissions
within the appliance. The OS command injection vulnerability can be
exploited by remote unauthenticated attackers that can reach the web
interface of the appliance. The privilege escalation vulnerability
allows an attacker that already gained code execution on the appliance
to escalate privileges from the operating system user 'spiderman' to
'root'.


4. *Vulnerable Packages*

   . Sophos Web Appliance v3.7.9 and earlier.
   . Sophos Web Appliance v3.8.0.
   . Sophos Web Appliance v3.8.1.
   . Other versions may be affected too but they were no checked.

5. *Non-Vulnerable Packages*

   . Sophos Web Protection Appliance v3.7.9.1.
   . Sophos Web Protection Appliance v3.8.1.1.

6. *Vendor Information, Solutions and Workarounds*

Sophos published release notes and a knowledgebase article acknowledging
the issue and the assistance given by Core Security in tracking it down
[2][3].


7. *Credits*

This vulnerability was discovered and researched by Francisco Falcon
from Core Exploit Writers Team. The publication of this advisory was
coordinated by Fernando Miranda from Core Advisories Team.


8. *Technical Description / Proof of Concept Code*

 


8.1. *Pre-authentication OS command injection vulnerability*

[CVE-2013-4983] The file '/opt/ui/apache/htdocs/end-user/index.php' can
be accessed by unauthenticated users at
'https://<WPA_server>/end-user/index.php'. It also can be reached
through plain HTTP at 'http://<WPA_server>/index.php', since Apache's
'httpd.conf' configuration file defines a VirtualHost at port 80 having
DocumentRoot '/opt/ui/apache/htdocs/end-user/'. The 'run()' function in
this PHP script obtains the requested controller from its 'c' GET
parameter and calls the appropriate handler.

Available handlers are defined in
'/opt/ui/apache/htdocs/config/UsrSiteflow.php':


/-----
<?php
require_once('AbstractSiteFlow.php');
class UsrSiteflow extends AbstractSiteFlow {
    public function __construct() {
        $this->flow = array(
            "index" => "UsrBlocked.php",
            "blocked" => "UsrBlocked.php",        
            "invalid_certificate" => "UsrBlocked.php",
            "rss" => "UsrRss.php",
        );
    }
}
?>
-----/

That means that, for example, when requesting
'https://<WPA_server>/end-user/index.php?c=blocked', the
'UsrBlocked.php' script will be used to render the page. Looking at the
code in '/opt/ui/apache/htdocs/controllers/UsrBlocked.php':

/-----
<?php
[...]
    if(isset($_GET['action'])) {
    if($_GET['action'] == 'continue') {
                // use sblistpack to allow access
                $url = base64_decode($_POST['url']);
        $scheme = parse_url($url,PHP_URL_SCHEME);
        if($scheme == "https" &&
$this->config->read('wsa_proxy.https_scan') != 'yes') {
        $host = parse_url($url,PHP_URL_HOST);
        $args['url'] = $scheme . '://' . $host;
        } else {
        $args['url'] = $url;
                }
        if($_POST['args_reason'] == 'filetypewarn') {
        $key = $_POST['url'];
        $packer = '/opt/ws/bin/ftsblistpack';
        $value = $_POST['filetype'];
        }
        else {
            $key = $_POST['domain'];
            $packer = '/opt/ws/bin/sblistpack';
            $catParts = explode("|",$_POST['raw_category_id']);
            $value = $catParts[0];
        }
        if(strlen(trim($_POST['user'])) > 0)
            $user = base64_decode($_POST['user_encoded']);
        else
            $user = $_POST['client-ip'];
            if($user == '-') $user = $_POST['client-ip'];

            $key = escapeshellarg($key);
            $user = escapeshellarg($user);
            $value = escapeshellarg($value);
        shell_exec("$packer $key $user $value");
[...]
?>      
-----/

we can see that the Perl script '/opt/ws/bin/sblistpack' will be
executed when the following conditions are met:

   1. the 'action' GET parameter is set to 'continue', and
   2. the 'args_reason' POST parameter is set to anything different that
'filetypewarn';
Variables whose content is controlled by the user '($key, $user,
$value)' are properly escaped by using 'escapeshellarg()' before calling
'shell_exec()', making the UsrBlocked.php script not vulnerable to OS
command injection at that point. However, the invoked
'/opt/ws/bin/sblistpack' Perl script itself is vulnerable to OS command
injection, because its 'get_referers()' function doesn't escape the
first argument of the script before using it within a string that will
be executed as a command by using backticks:


/-----
sub get_referers {
    my $domain = shift;

    if(! -f $referer_list) {