Summary
Chamilo LMS contains an OS command injection vulnerability in the file move functionality, where user-controlled path values are passed directly into shell commands without proper escaping.
Any authenticated user with teacher privileges in a course can abuse crafted directory names and the document move feature to execute arbitrary commands as the web server user.
Affected context
This vulnerability occurs in Chamilo LMS deployments where:
- The file move functionality in
fileManage.lib.phpis available. - User-supplied paths from
document.php(move_toPOST parameter) are passed to shell commands. - The application relies on HTML-focused filters like
Security::remove_XSS()instead of shell-specific escaping. - Authenticated users can create courses and gain teacher roles (default configuration).
Under these conditions, path components controlled by teachers can influence the parameters passed into exec("mv $source $target") and related shell calls.
Exploit preconditions
- Attack surface: Web interface for document management (
document.php) in Chamilo LMS. - Required access: Authenticated account with teacher privileges in at least one course (including self-created courses under default settings).
- Trigger point: Performing a "move document" operation where the destination directory name contains shell metacharacters and is passed as
move_toin a POST request. - Additional setup: Ability to create or import a directory whose name includes shell metacharacters (e.g., via Course Backup Import) so that this name is later used as a target path.
- Why exploitation is possible: The
move()function infileManage.lib.phpconcatenates user-controlled paths directly into shell commands (viaexec()andmv), and only HTML-oriented sanitization is applied. Because shell arguments are not escaped (e.g., viaescapeshellarg()), the shell treats metacharacters as control operators, allowing execution of attacker-controlled commands in the context of the web server user.
Why this happens
The underlying flaw is the direct inclusion of user-controlled data in shell command strings without using shell-safe escaping or argument passing APIs.
In the vulnerable move() function, the move_to parameter—after passing only through Security::remove_XSS()—is concatenated into expressions like exec("mv $source $target"). This pattern trusts that HTML-focused sanitization is sufficient for shell usage, which it is not.
This aligns with CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where untrusted input is interpreted by the command processor and can escape the intended command structure.
Potential impact
- Execution of arbitrary OS commands as the web server user (e.g.,
www-data). - Reading or modifying application data and course content accessible to the web server account.
- Planting web shells or backdoors on the server filesystem.
- Lateral movement within the hosting environment, depending on existing permissions and network access.
- Disruption of service through deletion or modification of critical files.
- Potential compromise of other tenants on shared hosting environments.
General mitigation guidance
Effective mitigation centers on eliminating direct shell command construction with untrusted data and tightening privilege boundaries:
- Replace generic shell execution (
exec,system, backticks) with safer, high-level filesystem APIs provided by the language or framework for file operations like move, copy, and delete. - Where invoking external programs is unavoidable, pass arguments as an array or use APIs that do not invoke a shell, ensuring that user input cannot be interpreted as shell syntax.
- Apply shell-specific escaping to any remaining user-influenced arguments using dedicated escaping functions, and avoid interpolating user input into command strings.
- Introduce strict validation and canonicalization of file paths, allowing only expected characters and directory structures, and rejecting any input containing shell metacharacters.
- Enforce least-privilege execution for the web server and application runtime so that, even if a command is injected, its reach is limited.
- Segment file storage areas used for user-controlled content from sensitive system and application directories.
How teams detect issues like this
Detection efforts can focus on both code-level patterns and runtime behavior:
- Static analysis: Configure rules to flag:
- Use of
exec,system, or similar functions where command strings are built via concatenation or interpolation. - Any shell command that incorporates request parameters (e.g.,
$_POST,$_GET, session variables) without passing through a dedicated shell escaping routine. - Functions that use HTML-focused sanitizers for data later used in OS command contexts.
- Code review: During manual review:
- Look for file management helpers that wrap shell utilities (
mv,cp,rm) instead of using built-in filesystem APIs. - Trace data flows from document management endpoints to shell execution points, checking for missing or inappropriate sanitization.
- Question any use of external commands where a language-native alternative exists.
- Runtime monitoring: At the infrastructure level:
- Enable logging of command invocations from the web server user and alert on unexpected binaries or arguments.
- Use host-based intrusion detection to flag anomalous child processes spawned by the web server.
- Automated SAST and security-focused code scanning tools can be configured to enforce policies that disallow direct shell command construction with user input.

