Summary
A SQL injection vulnerability in Cacti allows attacker-controlled rfilter input to be concatenated directly into RLIKE clauses without proper validation.
On instances with guest graph viewing enabled, an unauthenticated attacker can inject arbitrary SQL through graph_view.php, threatening the confidentiality, integrity, and availability of the monitoring database.
Affected context
This vulnerability occurs in Cacti deployments that expose the graph_view.php endpoint with guest graph viewing enabled and rely on rfilter-based queries to render graphs or trees. In affected versions, the rfilter request parameter is retrieved via a raw input accessor and placed directly into SQL RLIKE clauses in lib/html_graph.php and lib/html_tree.php. The issue manifests when user-supplied filter values are treated as part of the SQL expression itself, without robust validation or parameterization, allowing crafted payloads to escape the intended pattern-matching context and alter database queries.
Exploit preconditions
- Attack surface: HTTP requests to graph_view.php on Cacti installations.
- Required access: No authentication required when guest graph viewing is enabled.
- Trigger point: Submission of a malicious rfilter parameter that becomes part of a RLIKE clause in SQL.
- Why exploitation is possible: The rfilter parameter is obtained via a raw accessor (grv()) and concatenated into SQL strings without using parameterized queries or regex validation (FILTER_VALIDATE_IS_REGEX via gfrv()), permitting unbalanced quotes and other meta-characters to break out of the intended filter and inject arbitrary SQL.
Why this happens
The underlying bug maps directly to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'). Application code composes SQL statements by concatenating raw HTTP parameter values into query strings used for RLIKE operations, rather than treating user input as data bound through prepared statements or validated patterns. The use of a non-filtering accessor (grv()) bypasses the regex validation that would reject malformed patterns, allowing attackers to introduce unbalanced quotes and other control characters that modify the structure of the query. This insecure pattern—building SQL with untrusted, unnormalized input—creates a direct path for arbitrary SQL execution against the backing database.
Potential impact
- An attacker may read sensitive configuration data or monitoring metrics stored in the database.
- An attacker could modify or delete graph, host, and performance data, disrupting monitoring operations.
- An attacker may create or alter user accounts and permissions, leading to broader application compromise.
- An attacker could corrupt database tables or drop schemas, impacting availability of Cacti and dependent systems.
- An attacker can potentially chain database access into further infrastructure attacks, depending on stored credentials and integrations.
General mitigation guidance
Effective mitigation centers on eliminating dynamic SQL construction with untrusted input and constraining how filter parameters are handled. Code paths that accept user-supplied filter values should rely on parameterized queries or prepared statements so data is bound rather than concatenated into SQL expressions. When patterns or regular expressions are required, inputs can be validated against strict whitelists or dedicated regex validators, with rejection or neutralization of unbalanced quotes and control characters. Adopting secure-by-default input accessors that enforce validation, and confining filter logic to a narrow set of supported operators, reduces the risk of injection. Additionally, designing query-building routines to separate query structure from user-provided values and limiting database privileges for the application account can limit blast radius if a flaw appears.
How teams detect issues like this
Detection commonly involves reviewing code for string-built SQL that incorporates request parameters directly, especially in filter and search functionality. Static analysis tools can flag use of raw accessors, concatenation of user input into WHERE or RLIKE clauses, and absence of parameterized queries in data-access layers. During code review, maintainers can look for helper functions that bypass validation (such as non-filtering getters) and confirm that all database interactions use prepared statements and consistent input validation. Runtime monitoring, including database query logging and application-layer anomaly detection, may surface suspicious patterns like unbalanced quotes or unexpected control characters in queries. Security policies and CI checks can enforce standardized data-access APIs and disallow ad hoc SQL assembly with untrusted input.

