Summary
Cacti up to version 1.2.30 contains a command injection vulnerability in its rrdtool graphing pipeline, where user-controlled graph template data can reach shell_exec without proper escaping.
Under configurations where graph templates or host variables are editable by users or integrated systems, an attacker could inject OS commands into the constructed command line and execute them with the web server's privileges.
Affected context
This vulnerability occurs in Cacti installations using the rrdtool graphing functionality, where graph templates and their text_format fields are processed to build shell commands.
It is most relevant in environments where administrators, operators, or external automation can modify graph templates or host-related variables that feed into the rrdtool_function_graph() pipeline.
When those values are treated as trusted and passed through escape_command() (which is effectively a no-op) into shell_exec, the risk of command injection arises.
Exploit preconditions
- Attack surface: Web application interface, API endpoints, or configuration channels that allow modification of graph templates or host variables used by Cacti.
- Required access: Ability to create or edit graph templates, text_format values, or host variable substitutions that are incorporated into rrdtool command construction; this might be via authenticated admin or delegated roles, or misconfigured integration endpoints.
- Trigger point: Execution paths that call rrdtool_function_graph() and subsequently __rrd_execute(), which build the rrdtool command line and invoke shell_exec($full_commandline).
- Why exploitation is possible: The escape_command() function at lib/rrd.php returns the command string unchanged, so text_format values and substituted host variables can inject shell metacharacters and commands into the final command line passed to shell_exec, enabling arbitrary OS command execution.
Why this happens
The root cause is the construction of shell commands by concatenating unsanitized, user-influenced data and executing them via shell_exec without robust escaping or argument handling.
Instead of treating graph template fields and host variables as untrusted input, the escape_command() function acts as a no-op, leaving the command unmodified.
This aligns with CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') and CWE-88: Argument Injection or Modification, where input is not properly constrained before being used as command-line arguments or shell syntax.
Potential impact
- An attacker can execute arbitrary OS commands with the privileges of the web server or Cacti process.
- System compromise of the Cacti host, including installation of malware or backdoors.
- Unauthorized access to monitoring data, credentials, and configuration stored on the Cacti server.
- Lateral movement to other systems if the compromised host has network access or stored secrets.
- Disruption of monitoring operations, including tampering with performance and fault data.
General mitigation guidance
Mitigation generally focuses on removing direct shell command construction from user-influenced data and enforcing strict boundaries between configuration and execution.
Secure design patterns include:
- Using parameterized process execution APIs that pass arguments as arrays instead of concatenated strings, so shell metacharacters are not interpreted.
- Implementing rigorous validation of template fields and host variables, restricting them to expected formats (such as numeric values, constrained identifiers, or whitelisted tokens).
- Centralizing command-building logic with well-defined escaping rules and denying arbitrary shell syntax within configuration fields.
- Running the monitoring application with least-privilege permissions and isolating it from sensitive system resources to limit blast radius.
- Separating user-editable display strings from executable command parameters, ensuring no presentation data becomes part of a shell command.
How teams detect issues like this
Detection strategies typically rely on a combination of code-level and operational signals:
- Static analysis rules that flag use of shell_exec, exec, or similar functions when they concatenate user-controlled variables into command strings.
- Code review practices focusing on any function that constructs commands or calls external utilities, with particular attention to no-op "escaping" helpers.
- Configuration audits to identify where user-editable template fields or host variables are incorporated into command lines without strict validation.
- Runtime monitoring for anomalous command executions by the web server user, such as unexpected shells, network utilities, or file manipulation commands.
- Adoption of automated security scanning tools that can recognize OS command injection patterns in PHP and other languages used by Cacti-like systems.

