The handle_request function in lib/HTTPServer.pm in Monitorix before 3.3.1 allows remote attackers to execute arbitrary commands via shell metacharacters in the URI.
Monitorix versions prior to 3.3.1 are vulnerable to a critical remote command execution (RCE) flaw. Attackers can leverage this vulnerability to inject and execute arbitrary commands on the server through specially crafted HTTP requests, potentially leading to complete system compromise and data exfiltration.
Step 1: Craft Malicious Request: The attacker constructs a malicious HTTP request targeting the Monitorix server. The request includes a URI containing shell metacharacters and the desired commands to be executed. For example, GET /index.html;id would attempt to execute the id command.
Step 2: Request Processing: The Monitorix server receives the crafted HTTP request and passes it to the handle_request function.
Step 3: URI Parsing and Command Injection: The handle_request function parses the URI. Due to the lack of proper input validation, the shell metacharacters within the URI are not escaped or filtered.
Step 4: Command Execution: The URI, including the injected shell metacharacters and commands, is then passed to a system call (e.g., system(), exec(), or similar). The operating system's shell interprets the metacharacters and executes the injected commands.
Step 5: Command Output (Optional): The attacker may be able to retrieve the output of the executed command, depending on the nature of the command and the server's configuration. This could include sensitive information or the results of further exploitation attempts.
The vulnerability stems from insufficient input validation within the handle_request function of lib/HTTPServer.pm. This function processes incoming HTTP requests, including the URI. The lack of proper sanitization allows attackers to inject shell metacharacters (e.g., ;, |, &, $) into the URI. These metacharacters are then passed to the underlying operating system's shell, where they are interpreted and executed as commands. The root cause is a failure to escape or filter these potentially malicious characters before they are used in a system call, resulting in command injection.