Advisory ID: SGMA17-001
Title: Squirrelmail Remote Code Execution
Product: Squirrelmail
Version: 1.4.22 and probably prior
Vendor: squirrelmail.org
Type: Command Injection
Risk level: 4 / 5
Credit: filippo.cavallarin@wearesegment.com
CVE: CVE-2017-7692
Vendor notification: 2017-04-04
Vendor fix: N/A
Public disclosure: 2017-04-19
DETAILS
Squirrelmail version 1.4.22 (and probably prior) is vulnerable to a remote code execution vulnerability because
it fails to sanitize a string before passing it to a popen call. It's possible to exploit this vulnerability to
execute arbitrary shell commands on the remote server.
The problem is in Deliver_SendMail.class.php on initStream function that uses escapeshellcmd() to sanitize the
sendmail command before executing it. The use of escapeshellcmd() is not correct in this case since it don't
escapes whitespaces allowing the injection of arbitrary command parameters.
$this->sendmail_command = "$sendmail_path $this->sendmail_args -f$envelopefrom";
$stream = popen(escapeshellcmd($this->sendmail_command), "w");
The $envelopefrom variable is controlled by the attacker, hence it's possible to trick sendmail to use an
attacker-provided configuration file that triggers the execution of an arbitrary command.
In order to exploit this vulnerability the MTA in use must be sendmail and Squirrelmail must be configured
to use it as commandline (useSendmail directive of the config file set to true).
Also, the edit_identity directive of the config file must be bet to true, but this is the default configuration.
To reproduce the issue follow these steps:
1. Create a rogue sendmail.cf that triggers the execution of a /usr/bin/touch:
[...]
Mlocal, P=/usr/bin/touch, F=lsDFMAw5:/|@qPn9S, S=EnvFromL/HdrFromL, R=EnvToL/HdrToL,
T=DNS/RFC822/X-Unix,
A=X /tmp/executed
2. Upload it as a mail attachment and get it's remote name (ex: lF51mGPJwdqzV3LEDlCdSVNpohzgF7sD)
3. Go to Options -> Personal Informations and set the following payload as Email Address: