发新话题
打印

[转载]意识漏洞?(FCKEditor in php)

[转载]意识漏洞?(FCKEditor in php)

文章作者:SuperHei
信息来源:www.ph4nt0m.org

意识漏洞?
文/SuperHei_[At]_ph4nt0m.org 2006-2-12
2006-02-09日milw0rm公布了FCKEditor的一个上传漏洞[1]。FCKEditor是一款有多个语
言版本的(asp,cgi,aspx,php,cfm,...)的在线编辑的class[2],很多web系统都使用了这
个class。其实这个东西的漏洞,国内早有人挖过,比如asp版(nb文章系统由于使用这个
导致的上传漏洞),这里我们看看php版本的:

\editor\filemanager\browser\default\connectors\php\config.php

行35-36:

$Config['AllowedExtensions']['File'] = array() ; //允许的上穿类型
$Config['DeniedExtensions']['File'] = array('php','php3','php5','phtml','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','dll','reg','cgi') ;//禁止上传的类型

我们看$Config['DeniedExtensions']['File']里禁止的类型显然不够,我们可以上传php2、php4、inc、pwml、asa、cer ...等等。我们在看看具体的upfile函数

\editor\filemanager\browser\default\connectors\php\commands.php

function FileUpload( $resourceType, $currentFolder )
{
.......................

$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
$sExtension = strtolower( $sExtension ) ; //得到文件的后缀(以.为标志取最后1个)

global $Config ;

$arAllowed = $Config['AllowedExtensions'][$resourceType] ;
$arDenied = $Config['DeniedExtensions'][$resourceType] ;

if ( ( count($arAllowed) == 0 || in_array( $sExtension, $arAllowed ) ) && ( count($arDenied) == 0 || !in_array( $sExtension, $arDenied ) ) ) //判断合法后缀
{
$iCounter = 0 ;

while ( true )
{
$sFilePath = $sServerDir . $sFileName ;

.......................

move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
//上传 注意它保存的文件直接用的$sFilePath = $sServerDir . $sFileName,而没有使用$sExtension为后缀
//导致在win下在上传文件后面加个.来突破[未测试][3]
........................
}

为什么说这个漏洞为"意识漏洞"呢?如果我们把AllowedExtensions/DeniedExtensions的设置"反"一下:

$Config['AllowedExtensions']['File'] = array('rar','zip') ; //允许的上穿类型
$Config['DeniedExtensions']['File'] = array() ;//禁止上传的类型

把设置DeniedExtensions改为设置AllowedExtensions,就不会出现上面的漏洞了,不过这样在某些情况下,照样可以突破,问题还是出在这里:

move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
//上传 注意它保存的文件直接用的$sFilePath = $sServerDir . $sFileName,而没有使用$sExtension为后缀

在apache下,因为"apache文件名解析缺陷漏洞"[3]而出现漏洞[未测试]。

小结:
其实很多web程序员都有这个"意识漏洞",在过滤上传文件类型时,不应该‘被动’的去过滤非法后缀,应该是‘主动’过滤允许上传的类型。

参考:
[1] FCKEditor 2.0 <= 2.2 (connector.php) Remote Shell Upload Exploit
http://www.milw0rm.com/id.php?id=1484

[2] FCKEditor官方 :http://www.fckeditor.net/

[3] 《系统特性与web安全》
人情如冰六月寒,花做一份艳,为谁笑人间? 如果任何人发现我转载的有图像的文章中图像失效或者文章有问题,请及时短消息通知我。先谢谢。::)) coup de foudre

TOP

发新话题