Summary
Chamilo LMS versions prior to 2.0.0-RC.3 contain an OS command injection flaw in the gradebook AJAX endpoint, where a course code from session data is concatenated directly into a shell command.
If an attacker can manipulate the _cid session value, they can inject shell metacharacters and execute arbitrary commands on the underlying server with the web application's privileges.
Affected context
This vulnerability occurs in Chamilo LMS when the main/inc/ajax/gradebook.ajax.php endpoint is used with the export_all_certificates action.
The issue involves course codes derived from $_SESSION['_cid'] via api_get_course_id() being embedded directly in a shell_exec() string.
It is relevant in deployments where users can influence or poison their session state (e.g., through other bugs, weak session handling, or custom integrations) and where the web server has permission to execute system commands.
Exploit preconditions
- Attack surface: HTTP(S) requests reaching
main/inc/ajax/gradebook.ajax.phpwith theexport_all_certificatesaction enabled. - Required access: Ability to obtain a valid session and manipulate the
_cidvalue in$_SESSION(through direct control, session fixation/poisoning, or related flaws). - Trigger point: Invocation of
export_all_certificates, which builds a shell command using the course code and passes it toshell_exec(). - Why exploitation is possible: The course identifier is concatenated into a shell command without sanitization, validation, or quoting (e.g.,
escapeshellarg()), allowing shell metacharacters to be interpreted by the system shell.
Why this happens
The root cause is the direct interpolation of untrusted data into a shell command, executed via shell_exec() without proper escaping or validation.
This aligns with CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where user-controllable input is treated as part of executable system-level instructions.
Conceptually, the code conflates data (a course code) with control (shell syntax), granting an attacker the ability to terminate the intended command context and append arbitrary commands.
Potential impact
- Execution of arbitrary OS commands with the web server's privileges
- Reading sensitive files such as configuration files and credential stores
- Modifying application files or injecting backdoors for persistent access
- Direct manipulation of the application database contents
- Deletion or corruption of course materials and user data
- Denial of service by consuming system resources or deleting critical files
General mitigation guidance
Mitigation typically focuses on eliminating direct shell invocation and enforcing strict separation between data and commands.
Recommended defensive patterns include:
- Avoiding
shell_exec()and similar APIs in favor of native PHP or library functions that do not invoke a shell. - If shell commands are unavoidable, passing arguments as a parameter array to process-spawning APIs that bypass shell parsing, rather than building command strings.
- Applying strict validation to course identifiers (e.g., fixed patterns, whitelists of allowed characters, or lookup by internal numeric IDs).
- Using robust escaping mechanisms when interacting with the operating system, ensuring untrusted values are treated as literal arguments, not shell syntax.
- Running the web application with least-privilege OS accounts and constrained execution contexts to limit damage if a command is injected.
How teams detect issues like this
Effective detection involves both code-centric and environment-centric approaches:
- Static analysis: Configure rules that flag use of
shell_exec(),exec(),system(), orpassthru()where any part of the command string includes variables derived from user input, session data, cookies, or request parameters. - Code review: Pay special attention to any command construction in PHP code; look for string concatenation or interpolation involving request/session data feeding into OS-level APIs.
- Policy enforcement: Establish secure coding policies that discourage direct shell calls and require justification and peer review when they are used.
- Runtime monitoring: Use application and system logs, combined with security monitoring tools, to detect unusual command-line invocations originating from the web server process.

