### `HDWiki`简介
* 互动维客开源系统(`HDWiki`)作为中国第一家拥有自主知识产权的中文维基(`Wiki`)系统,由互动在线(北京)科技有限公司于2006 年11月28日正式推出,力争为给国内外众多的维基(`Wiki`)爱好者提供一个`免费`、`易用`、`功能强大`的维基(Wiki)建站系统。
### 漏洞原理
* 参数未经严格过滤,直接被带入至`SQL`语句中进行查询,导致注入漏洞的产生
### 漏洞分析
* 查看`/control/doc.php`文件
```
function doedit(){
    $this->_anti_copy();
    if(isset($this->post['predoctitle'])){
        $title = $this->post['predoctitle'];
        $content=string::stripscript($_ENV['doc']->replace_danger_word($this->post['content']));
        $this->view->assign("content",stripslashes($content));
        $this->view->assign("title",$title);
        //$this->view->display("previewdoc");
        $_ENV['block']->view('previewdoc');
        return;
    }
    if(isset($this->post['tagtext'])){
        $tags = $this->post['tagtext'];
        if(string::hstrtoupper(WIKI_CHARSET)=='GBK'){
            $tags=string::hiconv($tags,'gbk','utf-8');
        }
        $tags = trim(strip_tags($_ENV['doc']->replace_danger_word($tags)));
        $did = $this->post['did'];
        if(!is_numeric($did)){
            exit($this->view->lang['parameterError']);
        }
        $_ENV['doc']->update_field('tag',$tags,$did);
        echo 'OK';
        return;
    }
```
* 分析上面代码段:
```
$tags = $this->post['tagtext'];
if(string::hstrtoupper(WIKI_CHARSET)=='GBK'){
    $tags=string::hiconv($tags,'gbk','utf-8');
    
}
$_ENV['doc']->update_field('tag',$tags,$did);
```
* `tags`参数在这进行了全局转义
 * 但`gbk`版中,`tags`的内容会进入`hiconv()`函数进行编码转换
 * 之后被带入至`update_field()`函数内
 * 跟进这个函数,查看`/model/doc.class.php`文件
```
function update_field($field,$value,$did,$type=1){
    if($type){
        $sql="UPDATE ".DB_TABLEPRE."doc SET $field='$value' WHERE did= $did ";
    }else{
        $sql="UPDATE ".DB_TABLEPRE."doc SET $field=$field+$value WHERE did= $did ";
    }
    $this->db->query($sql);
}
```
* `value`参数这里直接带入至`SQL`语句中进行查询,也就是上面的`tags`参数被直接带入至`SQL`语句中进行查询,且未经过滤,所以可以导致注入漏洞的产生
### 漏洞修复
* 完善参数过滤措施
### 参考链接
* [http://www.wooyun.org/bugs/wooyun-2016-0190340](http://www.wooyun.org/bugs/wooyun-2016-0190340)
                       
                       
        
          
暂无评论