SSD Advisory – SquirrelMail Remote Code Execution

Credit to Author: Maor Schwartz| Date: Tue, 25 Apr 2017 05:24:06 +0000

Want to get paid for a vulnerability similar to this one?
Contact us at: sxsxdx@xbxexyxoxnxdxsxexcxuxrxixtxy.xcom

Vulnerability Summary
The following advisory describes Remote Code Execution found in SquirrelMail version 1.4.22.

SquirrelMail is a standards-based webmail package written in PHP. It includes built-in pure PHP support for the IMAP and SMTP protocols, and all pages render in pure HTML 4.0 (with no JavaScript required) for maximum compatibility across browsers. It has very few requirements and is very easy to configure and install. SquirrelMail has all the functionality you would want from an email client, including strong MIME support, address books, and folder manipulation.

Credit
An independent security researcher, Dawid Golunski (https://legalhackers.com/), has reported this vulnerability to Beyond Security’s SecuriTeam Secure Disclosure program.

Vendor Responses
SquirrelMail has released patches to address this vulnerability, for more details see: https://squirrelmail.org/security/issue/2017-04-24

Vulnerability Details
SquirrelMail is affected by a Remote Code Execution vulnerability which stems from insufficient escaping of user-supplied data when SquirrelMail has been configured with Sendmail as the main transport. An authenticated attacker may be able to exploit the vulnerability to execute arbitrary commands on the target and compromise the remote system.

When SquirrelMail has been configured with Sendmail as delivery transport,

SquirrelMail uses the following function to send out user emails:

It passes a sender’s email address to the sendmail command interface in the $envelopefrom variable.

SquirrelMail allows logged-in users to change the envelope from’s email address by going to:

The option however filters out spaces to prevent injection of additional parameters to the sendmail program.

It is possible to bypass this filter by using TABS instead of SPACES as shown in this request:

As we can see in new_email_addres parameter, the spaces have been replaced with %09 which is tab ascii character.

Such request will cause SquirrelMail to invoke popen() process to sendmail interface with the following arguments when a new email is sent out:

-X parameter allows to set a log file, and -oQ allows to set a tmp directory.

If the installed MTA is Sendmail on the target system, and an attackers sends a new email, with a malicious content containing a php script in the body of the email to an arbitrary email address, the log of the email containing the payload will be saved in the location desired by the attacker. In the example above, the output file would be /tmp/sqhack.

Example compose message request which a simple php payload:

The request should run the following sendmail command process:

After the command has completed the log with the payload can be found in /tmp/sqhack.

If file permissions have been incorrectly set within squirrelmail web document root or any other web application installed on the target server, the attacker could write the payload to a file like /var/www/sqhack.php and retrieve it by:

https://blogs.securiteam.com/index.php/feed