Summary
e107 CMS contains a command injection flaw in how it constructs ImageMagick resize commands, allowing partial user-controlled input into the destination path.
Under specific non-default configuration settings, an authenticated non-admin attacker can craft a news title that injects shell syntax into the ImageMagick convert invocation, potentially leading to arbitrary command execution on the server.
Affected context
The vulnerability arises in e107 deployments that use ImageMagick for image resizing within the "submit news" upload flow.
It affects instances where:
resize_methodis set toImageMagicksubnews_attachis enabled to allow attachments to submitted newsupload_enabledis enabled for user uploadssubnews_resizeis configured to a numeric value between 30 and 5000- Non-admin users belong to roles permitted by both
subnews_classandupload_class
In this context, parts of the user-controlled news title are incorporated into the ImageMagick destination filename and passed into a shell command.
Exploit preconditions
- Attack surface: HTTP-based news submission and file upload interface of e107.
- Required access: Authenticated non-admin account in classes allowed to submit news and upload attachments, as configured by
subnews_classandupload_class. - Application configuration: All of the following non-default options must be enabled:
resize_method=ImageMagicksubnews_attach=1upload_enabled=1subnews_resizeset to a numeric value between 30 and 5000- Trigger point: The submit-news flow that processes an uploaded image and invokes ImageMagick's
convertcommand for resizing. - Why exploitation is possible: The destination path passed to
convertcontains the first six characters of the user-controlled news title, inserted inside double quotes without robust shell-escaping. While the source path is protected withescapeshellarg(), the destination segment still allows special shell constructs—such as command substitution and control characters like tabs—to survive inside the quoted argument and be interpreted by/bin/sh -c.
Why this happens
This issue stems from unsafe construction of shell commands that mix partially sanitized and unsanitized user input.
The resize_image() function correctly wraps the source path using escapeshellarg(), but it builds the ImageMagick convert command line by embedding the destination filename directly inside double quotes without equivalent escaping.
In the submit-news upload flow, the destination filename is derived from the first six characters of the news title, which is filtered only to remove literal spaces, not shell metacharacters or tab characters.
As a result, shell syntax such as $(), backticks, and other constructs can be preserved inside the quoted argument and interpreted by /bin/sh -c when the command is executed.
This pattern maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, where input feeding into a command line is not fully neutralized, enabling an attacker to alter the command's behavior.
Potential impact
- Execution of arbitrary OS commands with the privileges of the web server process
- Unauthorized access to application data and configuration files
- Lateral movement within the hosting environment, depending on local protections
- Modification, deletion, or exfiltration of uploaded media and other content
- Potential use of the compromised server as a pivot point for further attacks
General mitigation guidance
Risk reduction centers on eliminating direct shell command construction and tightening trust boundaries around user input:
- Prefer API-level or library-based invocation of ImageMagick (e.g., using bindings that avoid
/bin/sh -c) instead of shelling out with concatenated strings. - If shell execution is unavoidable, build command arguments as arrays passed directly to process execution functions that do not invoke a shell, ensuring each parameter is treated as data, not command syntax.
- Apply strict normalization and encoding to any user-derived data used in filenames or command arguments, allowing only a conservative set of characters and rejecting or sanitizing all others.
- Separate user-facing metadata (like titles) from filesystem paths, generating destination filenames from server-controlled identifiers rather than user input.
- Run the web application and image processing utilities with least-privilege accounts and constrained filesystem permissions, limiting the blast radius of a successful injection.
- Consider disabling complex or rarely needed upload and auto-resize paths unless they are strictly required, especially when they rely on external command-line tools.
How teams detect issues like this
Detection efforts can focus on both code-level and runtime signals:
- Static analysis rules or custom linters that flag:
- Concatenation of user-controlled variables into shell command strings
- Use of
/bin/sh -cor equivalent shells with interpolated data - Partial escaping patterns (e.g., only some arguments passed through
escapeshellarg()). - Manual code review concentrating on:
- Image processing and upload handlers
- Places where titles, filenames, or other user metadata influence OS-level operations
- Misaligned validation, such as filters that remove spaces but leave shell metacharacters intact.
- Policy and CI enforcement:
- Build-time checks that reject new code introducing shell-based tooling where safer APIs exist
- Security-focused unit or integration tests that feed crafted titles into the upload pipeline to detect unexpected command execution.
- Runtime monitoring:
- Logging and alerting around ImageMagick invocations, especially commands containing unusual characters in paths
- Host-based intrusion detection to spot anomalous child processes spawned from the web server.

