Summary
LibreNMS 1.46 contains an authenticated SQL injection flaw in the MAC accounting graph endpoint, where the sort parameter is incorporated into database queries without proper sanitization.
An authenticated remote attacker can manipulate this parameter using time-based blind SQL injection techniques to infer and extract sensitive database information.
Affected context
The vulnerability occurs in LibreNMS 1.46 within the MAC accounting graph functionality, where user-controlled input is used to influence database queries.
It is present in deployments where authenticated users can access the MAC accounting graph endpoint and where the sort parameter is passed directly or indirectly into SQL statements.
The issue is most relevant when LibreNMS is exposed to untrusted or semi-trusted users, such as shared deployments, MSP environments, or installations with multiple operator accounts.
Exploit preconditions
- Attack surface: Web interface of LibreNMS, specifically the MAC accounting graph endpoint.
- Required access: Valid authenticated LibreNMS user account with permission to access MAC accounting graphs.
- Trigger point: Submission of crafted requests where the
sortparameter contains malicious SQL fragments. - Why exploitation is possible: The
sortparameter is concatenated into SQL queries without strict validation, parameterization, or whitelisting, enabling time-based blind SQL injection.
Why this happens
This issue stems from constructing SQL queries using string concatenation with user-supplied data instead of using parameterized queries or strict input validation.
The sort parameter, intended to control ordering or presentation, is treated as trusted and inserted directly into the query, allowing an attacker to modify query logic.
This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, where user-controlled input is not safely handled before being used by the SQL engine.
More broadly, it reflects a design pattern where presentation-related parameters (sorting, filtering, pagination) are not constrained to a safe set of values.
Potential impact
- Extraction of sensitive database information such as user-related data or configuration details.
- Discovery of database schema, table names, and column metadata.
- Leveraging database information for further lateral movement or privilege escalation in the environment.
- Increased ability to plan secondary attacks (e.g., targeted credential attacks, system enumeration).
General mitigation guidance
Mitigation should focus on neutralizing user input before it reaches the database and reducing the trust placed in client-provided parameters:
- Use parameterized queries or prepared statements for all dynamic SQL, including ordering and filtering logic.
- Apply strict allowlists for parameters like
sort, constraining them to a predefined set of column names and directions. - Avoid building SQL fragments directly from HTTP parameters; instead, map user choices to known-safe server-side constants.
- Implement least-privilege database accounts so that even if a query is manipulated, access to sensitive tables and operations is limited.
- Centralize database access patterns in a data-access layer to enforce secure query construction across the application.
How teams detect issues like this
Effective detection combines code-level analysis and runtime monitoring:
- Use static analysis tools or linters configured with rules to detect string-concatenated SQL queries and unsanitized use of request parameters.
- During code review, flag any direct use of request variables (like
$_GET,$_POST, or framework equivalents) inside query-building logic, especially for sorting and filtering. - Introduce application-security tests (DAST) that perform automated SQL injection probes against web endpoints, including authenticated paths.
- Monitor database logs for anomalous patterns such as frequent time-based queries, unexpected delays, or unusual query structures coming from the application.
- Enforce secure coding policies in CI/CD pipelines that reject builds with identified unsafe query construction patterns.

