PHPMailer Exploit – Remote Code Execution
legalhackers.com
PHPMailer Exploit – Remote Code Execution
1–10 of 109 posts
Re: PHPMailer Exploit – Remote Code Execution
#2Edit: Seems like another exploit found 8 hours ago: https://github.com/PHPMailer/PHPMailer/issues/924
Probably wise to disable phpmailer on your servers for now.
Re: PHPMailer Exploit – Remote Code Execution
#3Re: PHPMailer Exploit – Remote Code Execution
#4It would seem much safer to establish a TCP connection to the local MTA over port 25 or 587 and send the message that way.
Admins can just use iptables to restrict access to the port to localhost, and/or do the same in their MTA config.
Re: PHPMailer Exploit – Remote Code Execution
#5Out of curiosity, why is PHPMailer invoking the command line at all? It would seem much safer to establish a TCP connection to the local MTA over port 25 or 587 and send the message that way. Admins can just use iptables to restrict access to the port to localhost, and/or do the same in their MTA config.
Re: PHPMailer Exploit – Remote Code Execution
#6But then again, why would you send e-mail to just any address someone enters, without validating it for correctness? I know it is tough to validate all addresses according to RFC, but I'd rather block some legitimate users (which btw. probably know more about RFC than me and I'm sure can find a "nicer" e-mail address if they want to) than let some attacker use some vulnerability like this. Always whitelist valid input, never (just) blacklist it.
Also, I am baffled that frameworks I encountered never demanded from developer to specify exactly what kind of input it expects via POST & co.. It is trivial to write a set of functions like this:
function input_post_email($field_name, $default_value)
function input_post_string($field_name, $validation_regex, $default_value)
...
The point here is that framework should DEMAND from developer to specify format of each and every input var it needs. It should be difficult to bypass these restrictions, to demotivate developers doing it.This is a first thing I made in every PHP project I started. Combined with Content Security Policy and output filtering it's... well, better than most other solutions. :)
Re: PHPMailer Exploit – Remote Code Execution
#7TL;DR: PHPmailer fails to properly sanitize input. When configured to use CLI sendmail, this can lead to arbitrary command execution. But then again, why would you send e-mail to just any address someone enters, without validating it for correctness? I know it is tough to validate all addresses according to RFC, but I'd rather block some legitimate users (which btw. probably know more about RFC than me and I'm sure c…
filter_var($app->request()->post('email'), FILTER_VALIDATE_EMAIL)Re: PHPMailer Exploit – Remote Code Execution
#8TL;DR: PHPmailer fails to properly sanitize input. When configured to use CLI sendmail, this can lead to arbitrary command execution. But then again, why would you send e-mail to just any address someone enters, without validating it for correctness? I know it is tough to validate all addresses according to RFC, but I'd rather block some legitimate users (which btw. probably know more about RFC than me and I'm sure c…
It's also why I far-too-often run into forms that won't let me use a "+" in the username part of my email address, which I use to track who's responsible for sending my email account off to third parties (e.g., "rob+paypal@....").
Some kinds of email validation are better than others. Using regular expressions and strictly adhering to the RFC is the one that developers are usually talking about when they say not to do it. filter_var(..., FILTER_VALIDATE_EMAIL) is sort of okay, although there are lots of edge cases that it doesn't handle correctly.
Re: PHPMailer Exploit – Remote Code Execution
#9TL;DR: PHPmailer fails to properly sanitize input. When configured to use CLI sendmail, this can lead to arbitrary command execution. But then again, why would you send e-mail to just any address someone enters, without validating it for correctness? I know it is tough to validate all addresses according to RFC, but I'd rather block some legitimate users (which btw. probably know more about RFC than me and I'm sure c…
That's not correct. PHPMailer can be configured to send mail through raw SMTP, by directly invoking sendmail, or by calling PHP's mail() function (which is itself a wrapper around sendmail). This vulnerability affects only the last mode, when PHP's mail() calls sendmail. If you have PHPMailer configured to call sendmail directly, this vulnerability does not apply.
Re: PHPMailer Exploit – Remote Code Execution
#10The advisory says exploitation is not limited to just systems running the original Sendmail MTA, but Postfix' "sendmail" wrapper apparently ignores the "-X" parameter... so how can a Postfix-based system be exploited?
On one of my web-facing servers running Postfix:
root@:/home/rob# sendmail -X/home/rob/test.log
sendmail: fatal: unsupported: -X/