【技术分析】Dolibarr ERP CRM 小于v8.0.2 SQL注入漏洞分析

liudao  1900天前

图片.png


【技术分析】Dolibarr ERP CRM < v8.0.2 SQL注入漏洞分析

0x00 概述

Dolibarr 是一款开源的企业ERP和CRM管理软件,拥有一个活跃的用户社区,商业模式类似苹果iTunes应用商店。在FOFA上搜了一下大概有3k+用户。近日在网上看到爆出了几个漏洞。以前也分析过这个系统的一个代码注入漏洞(https://nosec.org/home/detail/1677.html)。所以这次顺便分析了一下。此此漏洞影响8.0.2及以下版本这是一个后台漏洞(滑稽)。

图片.png

0x01漏洞分析

影响范围

8.0.2及以下版本

漏洞文件

user/card.php
product/card.php

分析

首先看user/card.php这个文件,在文件的302-513行:

if ($action == 'update' && ! $cancel)
    {
        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';

        if ($caneditfield)    // Case we can edit all field
        {
            $error = 0;

            if (!$_POST["lastname"]) {
                setEventMessages($langs->trans("NameNotDefined"), null, 'errors');
                $action = "edit";       // Go back to create page
                $error ++;
            }
            if (!$_POST["login"]) {
                setEventMessages($langs->trans("LoginNotDefined"), null, 'errors');
                $action = "edit";       // Go back to create page
                $error ++;
            }

            if (!$error)
            {
                $ob ject->fetch($id);

                $ob ject->oldcopy = clone $ob ject;

                $db->begin();

.................................................................................................              
                $ob ject->fk_user = GETPOST("fk_user",'int') > 0 ? GETPOST("fk_user",'int') : 0;
                $ob ject->employee = GETPOST('employee');

                $ob ject->thm = GETPOST("thm",'alphanohtml') != '' ? GETPOST("thm",'alphanohtml') : '';
                $ob ject->tjm = GETPOST("tjm",'alphanohtml') != '' ? GETPOST("tjm",'alphanohtml') : '';
                $ob ject->salary = GETPOST("salary",'alphanohtml') != '' ? GETPOST("salary",'alphanohtml') : '';
                $ob ject->salaryextra = GETPOST("salaryextra",'alphanohtml') != '' ? 
.................................................................................................

                if (!$error) {
                    $ret = $ob ject->update($user);
                    if ($ret < 0) {
                        $error++;
                        if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
                            $langs->load("errors");
                            setEventMessages($langs->trans("ErrorLoginAlreadyExists", $ob ject->login), null, 'errors');

                        $sql .= " WHERE rowid=".$ob ject->id;

当action为update的时候,$ob ject->employee = GETPOST('employee');,这里会用GETPOST方法直接获取employee参数的值。且employee的值只有0和1两个。

之后又调用了update方法,$ret = $ob ject->update($user);,这里是漏洞触发点。跟进update方法。

在user/class/user.class.php中的1348-1633行:

function update($user, $notrigger=0, $nosyncmember=0, $nosyncmemberpass=0, $nosynccontact=0)
    {
        global $conf, $langs;

        $nbrowsaffected=0;
        $error=0;

        dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncmember=".$nosyncmember.", nosyncmemberpass=".$nosyncmemberpass);

        // Clean parameters

        $this->employee        = $this->employee?$this->employee:0;
        $this->dateemployment     = empty($this->dateemployment)?'':$this->dateemployment;

        $this->db->begin();

        // Update datas
        $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
        $sql.= " lastname = '".$this->db->escape($this->lastname)."'";
        $sql.= ", firstname = '".$this->db->escape($this->firstname)."'";
        $sql.= ", employee = ".$this->employee;
.................................................................................................
        $resql = $this->db->query($sql);

在update方法中,直接将上一步获取的employee参数的值拼接到了SQL语句中,$sql.= ", employee = ".$this->employee;,而且这里没有引号包裹,所以可以直接利用。

接下来定位功能模块。这里位于用户信息编辑的地方。访问/user/card.php?id=1&action=edit。

图片.png

填好信息提交并抓包:

图片.png

找到employee参数,根据源码可知,类型为update注入。所以这里我才用延时注入。可能由于本地服务器问题,响应时间2s左右,但并没有影响延时效果。sleep(2)的时候响应4s,sleep(4)的时候响应6s。

图片.png图片.png

另一处位于product/card.php中,漏洞点在product/class/product.class.php中。和上面漏洞同理。

0x02

目前官方已更新到8.0.4版本。该漏洞已修复。另外一点就是,该框架安装完成后,默认情况并不会删除install目录,也就是说存在重装的风险。配合注入等漏洞可以获得网站shell。所以该漏洞即便是后台的漏洞,如果不删除install目录,仍然存在被入侵的风险。

建议相关用户安装成功后删除install目录,并更新到最新版本!!!

最新评论

Vc-kin  :  **
1898天前 回复
Vc-kin  :  **
1898天前 回复
Vc-kin  :  嘎嘎嘎
1898天前 回复
保川  :  回复 @ Vc-kin &nbsp;:&nbsp; &nbsp;小姐姐
1898天前 回复
保川  :  回复 @ Vc-kin &nbsp;:&nbsp; &nbsp;小姐姐
1898天前 回复
保川  :  回复 @ Vc-kin &nbsp;:&nbsp; &nbsp;小姐姐
1898天前 回复
保川  :  回复 @ Vc-kin &nbsp;:&nbsp; &nbsp;小姐姐
1898天前 回复
保川  :  sads
1898天前 回复
保川  :  回复 @ Vc-kin &nbsp;:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a**sa
1898天前 回复
保川  :  **sa**f
1898天前 回复
保川  :  safff
1898天前 回复
昵称
邮箱
提交评论