Summary
A time-based blind SQL injection vulnerability in LibreNMS allows authenticated users to manipulate database queries via the address parameter in address-search.inc.php.
By supplying crafted subnet prefix values, an attacker can alter query logic and infer sensitive database information from timing differences in responses.
Affected context
This vulnerability occurs in LibreNMS deployments using versions 25.12.0 and below, specifically within the address search functionality backed by a PHP/MySQL stack.
The issue is present when user-supplied address (subnet prefix) input is concatenated directly into SQL queries without parameter binding or proper sanitization.
It is only reachable through authenticated functionality, meaning any logged-in user with access to the affected search feature can reach the vulnerable code path.
Exploit preconditions
- Attack surface: Web application interface for address or subnet search (typically authenticated dashboard or search form).
- Required access: Valid authenticated LibreNMS account with permission to perform address searches.
- Input vector: The
addressparameter (subnet prefix) submitted toaddress-search.inc.php. - Trigger point: Execution of the SQL query that embeds the attacker-controlled prefix directly into the WHERE clause or related SQL expression.
- Why exploitation is possible: The application constructs SQL statements by concatenating raw user input instead of using prepared statements with parameter binding, enabling the attacker to inject conditional logic that impacts execution time and reveals data through timing side channels.
Why this happens
The core issue is direct string concatenation of user-controlled input into SQL statements, violating the principle of treating all external input as untrusted.
Rather than using prepared statements and bound parameters, the code interpolates the address (subnet prefix) value into the query text, which allows an attacker to introduce additional SQL syntax, including time-based conditional expressions.
This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the application fails to correctly separate data from command logic in database interactions.
Potential impact
- Extraction of sensitive database information (such as configuration data or user-related metadata) via time-based inference.
- Enumeration of database structure, including table and column names.
- Potential pivot into broader data manipulation, depending on the breadth of injection and database permissions.
- Increased risk of chained attacks if database-stored secrets or credentials are discovered.
- Degradation of service performance due to repeated time-based probing.
General mitigation guidance
Effective mitigation focuses on eliminating direct concatenation of user input into SQL and enforcing strong separation between data and command logic.
Recommended defensive patterns include:
- Using parameterized queries or prepared statements for all database interactions, ensuring that user input is always bound as data, not as part of the SQL syntax.
- Centralizing database access through an abstraction layer that enforces parameter binding and disallows raw query construction where possible.
- Applying robust server-side validation and normalization for fields like IP addresses and subnet prefixes, reducing the chance that arbitrary SQL fragments can be injected.
- Restricting database account privileges to the minimum required for the application's functions so that injected queries have limited effect.
- Adopting secure coding guidelines and code review checklists that specifically flag dynamic SQL construction as a pattern requiring scrutiny.
How teams detect issues like this
Detection typically involves a combination of code-centric and behavior-centric approaches:
- Static analysis: Apply SAST rules to identify dynamic SQL construction, particularly concatenation involving request parameters such as
$_GET,$_POST, or equivalent variables feeding into query builders. - Code review signals: Treat any ad-hoc SQL assembly in PHP (e.g., string-based queries with embedded variables) as a review hotspot and verify that parameter binding or safe query APIs are used.
- Runtime monitoring: Use application-level logging and database monitoring to spot unusually slow, repetitive, or patterned queries that may indicate time-based probing.
- Security testing: Incorporate automated and manual SQL injection testing into CI/CD pipelines and regular security assessments, focusing on authenticated flows as well as public endpoints.
- Policy enforcement: Establish coding standards that prohibit unparameterized queries and integrate automated checks in pull requests to enforce these standards.

