[ZBX-24505] Time Based SQL Injection in Zabbix Server Audit Log (CVE-2024-22120) Created: 2024 Feb 21 Updated: 2024 Aug 12 Resolved: 2024 Mar 18 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Server (S) |
Affects Version/s: | None |
Fix Version/s: | 6.0.28rc1, 6.4.13rc1, 7.0.0beta2 |
Type: | Defect (Security) | Priority: | Critical |
Reporter: | Maris Melnikovs (Inactive) | Assignee: | dimir |
Resolution: | Fixed | Votes: | 0 |
Labels: | None | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Attachments: |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
||||||||||||
Issue Links: |
|
||||||||||||
Team: | |||||||||||||
Sprint: | S24-W8/9, S24-W10/11, S24-W12/13 | ||||||||||||
Story Points: | 2 |
Description |
Summary:Zabbix server can perform command execution for configured scripts. After command is executed, audit entry is added to "Audit Log". Due to "clientip" field is not sanitized, it is possible to injection SQL into "clientip" and exploit time based blind SQL injection. Steps To Reproduce:I will provide 3 variations of steps to reproduce, 1st one is real exploitation running attached exploit, it will extract admin session_id and session_key to sign zbx_session, this data together can be used to generate correct admin zbx_session. 2nd is easier version which will simply make PoC of time based SQL injection, you will see 3 requests and how backend sleeps for 1,5, and 10 seconds. 3rd is another simple PoC which you can verify via zabbix_server.log Steps To Exploit1. Login to low privileged user. User should have access to at least 1 host to be able to run command against it, like here on screenshot
3. Extract any hostid available to this user (open Monitoring->Hosts, host id will be in response)
python3 zabbix_server_time_based_blind_sqli.py --ip 192.168.223.128 --sid a6094b4f052fd133adc335382f0297f6 --hostid 10607 | grep "(+)"
Exploit time execution can take ~10 mins, but you will see progress update every few secs. Exploit takes that much time because of time based SQLi, it require to sleep() for a while on each guess(see exploit code). Pipe to grep " Steps to PoC if Time Based Blind SQLi1. Perform steps 1-3 from "Steps To Exploit" (extract low priv user sessionid and any available hostid) 2. Execute Exploit (replace ip, sessionid and hostid with yours from previous step) python3 zabbix_server_time_based_blind_sqli.py LOG_LEVEL=error --ip 192.168.223.128 --sid a6094b4f052fd133adc335382f0297f6 --hostid 10607 --poc Steps to PoC to Generate Error in Zabbix Logs1. Perform steps 1-3 from "Steps To Exploit" (extract low priv user sessionid and any available hostid) 2. Execute Exploit (replace ip, sessionid and hostid with yours from previous step) python3 zabbix_server_time_based_blind_sqli.py LOG_LEVEL=error --ip 192.168.223.128 --sid a6094b4f052fd133adc335382f0297f6 --hostid 10607 --poc2 3. Check zabbix_server.log, you will see that query is failed but injected ' + version() + ' and its result is in place Technical Details:SQL injection is in audit.c, function zbx_auditlog_global_script: ... 2225: if (ZBX_DB_OK > zbx_db_execute("insert into auditlog (auditid,userid,username,clock,action,ip,resourceid," 3226: "resourcename,resourcetype,recordsetid,details) values ('%s'," ZBX_FS_UI64 ",'%s',%d,'%d','%s'," 4227: ZBX_FS_UI64 ",'%s',%d,'%s','%s')", auditid_cuid, userid, username, (int)time(NULL), 5228: ZBX_AUDIT_ACTION_EXECUTE, clientip, hostid, hostname, AUDIT_RESOURCE_SCRIPT, auditid_cuid, 6229: details_esc)) 7230: { 8231: ret = FAIL; 9232: } clientip is NOT sanitized and controlled by attacker, as a result we can put SQL query here. Only time based SQLi will work(see exploit code). Exploit OutputImpactAllows to dump any values from database. As an example of exploit above allows privilege escalation from user to admin. In some cases SQL injection leads to RCE. |
Comments |
Comment by dimir [ 2024 Mar 11 ] | ||||||||||||||||||||||||||||||||
For which version are we fixing this, supposedly starting from 6.0? | ||||||||||||||||||||||||||||||||
Comment by dimir [ 2024 Mar 11 ] | ||||||||||||||||||||||||||||||||
Fixed in development branch for 6.0: https://git.zabbix.com/projects/ZBX/repos/zabbix/pull-requests/7257/overview | ||||||||||||||||||||||||||||||||
Comment by dimir [ 2024 Mar 15 ] | ||||||||||||||||||||||||||||||||
Fixed in
| ||||||||||||||||||||||||||||||||
Comment by Maris Melnikovs (Inactive) [ 2024 Apr 18 ] | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
Comment by rio-h [ 2024 May 21 ] | ||||||||||||||||||||||||||||||||
Does this failure information include previous versions? | ||||||||||||||||||||||||||||||||
Comment by Orion Poplawski [ 2024 May 22 ] | ||||||||||||||||||||||||||||||||
Is it time to set the fix versions field? Presumably this made it into 6.0.28/6.4.13/7.0.0? | ||||||||||||||||||||||||||||||||
Comment by Orion Poplawski [ 2024 May 22 ] | ||||||||||||||||||||||||||||||||
Also, as 5.0 LTS is still active, it would be good to know if this applies to that release. | ||||||||||||||||||||||||||||||||
Comment by Orion Poplawski [ 2024 May 22 ] | ||||||||||||||||||||||||||||||||
Although since it appears that zbx_auditlog_global_script is not present in 5.0.42, I'm going to assume that it is not affected. | ||||||||||||||||||||||||||||||||
Comment by dimir [ 2024 May 22 ] | ||||||||||||||||||||||||||||||||
3 and 5 are not affected as audit log was introduced in 6.0 . | ||||||||||||||||||||||||||||||||
Comment by dimir [ 2024 May 22 ] | ||||||||||||||||||||||||||||||||
Fixed Versions set, thanks for pointing out. | ||||||||||||||||||||||||||||||||
Comment by rio-h [ 2024 May 23 ] | ||||||||||||||||||||||||||||||||
Thank you all for your responses. | ||||||||||||||||||||||||||||||||
Comment by dimir [ 2024 May 24 ] | ||||||||||||||||||||||||||||||||
Looks like the issue was introduced in | ||||||||||||||||||||||||||||||||
Comment by Ingrid [ 2024 May 24 ] | ||||||||||||||||||||||||||||||||
is it correct this way? By only upgrading zabbix-server
| ||||||||||||||||||||||||||||||||
Comment by dimir [ 2024 Jun 27 ] | ||||||||||||||||||||||||||||||||
Sorry, what do you mean? Install the fix? Unless you really care about the specific Zabbix version it's rather: sudo apt update sudo apt install zabbix-server-mysql | ||||||||||||||||||||||||||||||||
Comment by dimir [ 2024 Jul 01 ] | ||||||||||||||||||||||||||||||||
For those that do not want to upgrade disabling audit log will eliminate the vulnerability. |