[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: PNG File image (1).png     PNG File image (2).png     PNG File image (3).png     PNG File image (4).png     PNG File image (5).png     PNG File image (6).png     PNG File image.png     GIF File invalid_clientip_remembered_somewhere.gif     File zabbix_server_time_based_blind_sqli.py    
Issue Links:
Causes
Duplicate
is duplicated by ZBX-24877 Zabbix Security Advisories and CVE da... Closed
Team: Team A
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 Exploit

1. 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
Image F3064173: image.png 87.24 KiB


2. Extract logged in user "sessionid" from zbx_session cookie(decode it as base64 and grab sessionid from json)

3. Extract any hostid available to this user (open Monitoring->Hosts, host id will be in response)


4. Execute attached exploit zabbix_server_time_based_blind_sqli.py, use --help if needed. In standard case "ip", "sessionid" and "hostid" should be enough:

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 "" is just to filter output, otherwise pwntools prints too many debug data. As a result you will get admin session_id and session_key used to sign zbx_session cookie, so you can generate admin token now.

Steps to PoC if Time Based Blind SQLi

1. 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 

 
You will see 3 requests and backend sleeps for 1,5 and 10 secs before response. You will see request/response packets to understand that sleep happens on backend.

Steps to PoC to Generate Error in Zabbix Logs

1. 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 Output

Impact

Allows 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 ]
Mitre ID CVE-2024-22120
CVSS score 9.1
CVSS vector https://www.first.org/cvss/calculator/3.1#CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H
Severity Critical
Summary Time Based SQL Injection in Zabbix Server Audit Log
Description 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.
Common Weakness Enumeration (CWE) CWE-20 Improper Input Validation
Common Attack Pattern Enumeration and Classification (CAPEC) CAPEC-253 Remote Code Inclusion
Known attack vectors Allows 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.
Patch provided  No
Component/s Server
Affected and fixed version/s 6.0.0 - 6.0.27 / 6.0.28rc1
6.4.0 - 6.4.12 / 6.4.13rc1
7.0.0alpha1 - 7.0.0beta1 / 7.0.0beta2
Fix compatibility tests -
Resolution Fixed
Workarounds -
Acknowledgements Zabbix wants to thank Maxim Tyukov (mf0cuz) who submitted this report in HackerOne bounty hunter platform
Comment by rio-h [ 2024 May 21 ]

Does this failure information include previous versions?
For example, version 3, 5, etc.

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.
I understand, your answers were very informative to me.

Comment by dimir [ 2024 May 24 ]

Looks like the issue was introduced in ZBXNEXT-6768, which is 6.0.0alpha1 .

Comment by Ingrid [ 2024 May 24 ]

is it correct this way? By only upgrading zabbix-server

 

wget http://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix/zabbix-server-mysql_6.0.28-1+ubuntu22.04_amd64.deb

 

 

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.

Generated at Wed Apr 30 06:37:59 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.