### `HDWiki`简介
* 互动维客开源系统(`HDWiki`)作为中国第一家拥有自主知识产权的中文维基(`Wiki`)系统,由互动在线(北京)科技有限公司于2006 年11月28日正式推出,力争为给国内外众多的维基(`Wiki`)爱好者提供一个`免费`、`易用`、`功能强大`的维基(Wiki)建站系统。
### 漏洞原理
* 参数未经严格过滤,直接被带入至`SQL`语句中进行查询,导致注入漏洞的产生
### 漏洞分析
* 第一处`SQL`注入:
* 查看`/control/user.php`文件
```
$username=string::hiconv(trim($this->post['username']));
$password=md5($this->post['password']);
$error=$this->setting['checkcode']!=3?$this->docheckcode($this->post['code'],1):'OK';
if($error=='OK'){
// LDAP 登录检测
$ldap_login = $_ENV['user']->ldap_login($username,$this->post['password']);
if(!empty($ldap_login) && is_array($ldap_login)) {
if(1 !== $ldap_login['status']) {
$this->message($ldap_login['message'], 'BACK',$this->post['indexlogin']?2:0);
}
}
// LDAP 登录检测 结束
$user=$this->db->fetch_by_field('user','username',$username);
```
* 分析上面代码段:
```
$username=string::hiconv(trim($this->post['username']));
......
$user=$this->db->fetch_by_field('user','username',$username);
```
* `username`参数通过`POST`传入后进入了`hiconv()`函数进行编码转换。然后带入`fetch_by_field()`函数中,跟进这个函数:
```
function fetch_by_field($table,$field,$value,$select_fields='*'){
$query=$this->query("SELECT $select_fields FROM ".DB_TABLEPRE."$table WHERE $field='$value'");
return $this->fetch_array($query);
}
```
* 这个函数内`参数`没有经过过滤直接带入`SQL`语句中进行查询,可以利用宽字节技巧进行注入。因为这里是`select`,没有回显,只能`time-based`盲注
* 第二处`SQL`注入:
* 查看`/control/doc.php`文件
```
function doverify(){
$ajaxtitle=trim($this->post['title']);
if (WIKI_CHARSET == 'GBK'){$ajaxtitle = string::hiconv($ajaxtitle);}
$title=string::substring(string::stripscript($ajaxtitle),0,80);
if($_ENV['doc']->have_danger_word($title)){
$this->message("-1","",2);
}
if($ajaxtitle!=string::stripscript($ajaxtitle)){
$this->message("-2","",2);
}
if($synonym=$_ENV['synonym']->get_synonym_by_src($ajaxtitle)){
$this->message($synonym[destdid]." ".$synonym[desttitle],"",2);
}
$data=$this->db->fetch_by_field('doc','title',$title);
if(!(bool)$data){
$this->message("1","",2);
}else{
$this->message("0","",2);
}
}
```
* 分析上面代码段:
```
$ajaxtitle=trim($this->post['title']);
......
$data=$this->db->fetch_by_field('doc','title',$title);
```
* 注入点分析同第一处`SQL`注入
### 漏洞修复
* 完善参数过滤措施
暂无评论