Summary
A command injection vulnerability in the DCMTK storescp component allows crafted input to influence OS command execution in the executeOnReception/executeOnEndOfStudy logic.
In networked deployments where untrusted DICOM data or remote peers can reach storescp, an attacker may trigger arbitrary command execution with the privileges of the storescp process.
Affected context
This vulnerability affects deployments using the DCMTK storescp application up to version 3.7.0 where:
- The executeOnReception and/or executeOnEndOfStudy features are enabled to run external commands
- Command strings are constructed based on incoming DICOM association parameters or file metadata
- storescp is reachable over the network from untrusted or semi-trusted DICOM peers
The issue is most relevant in PACS, gateways, or test environments where storescp is exposed as a general DICOM receiver and not strictly isolated.
Exploit preconditions
- Attack surface: Network-accessible DICOM Storage SCP (storescp) service.
- Required access: Ability to establish a DICOM association and send crafted DICOM traffic or parameters to the vulnerable storescp instance.
- Trigger point: Invocation of executeOnReception or executeOnEndOfStudy hooks that build and execute shell commands using untrusted data.
- Why exploitation is possible: User-controlled or protocol-derived values are interpolated into shell command lines without proper quoting, escaping, or safer API usage, allowing attackers to break out of expected arguments and inject additional commands.
Why this happens
The underlying bug is an OS command injection issue, aligning with CWE-78.
In the affected storescp code path, external commands are assembled as shell strings that incorporate values influenced by DICOM associations or file metadata.
Because these values are not robustly validated or safely passed as separate arguments to a process-spawning API, the shell interprets embedded metacharacters (e.g., separators, redirection operators) as additional commands or options.
Conceptually, this represents an insecure pattern where application logic mixes trusted templates with untrusted input to form executable command lines instead of using parameterized or non-shell invocation mechanisms.
Potential impact
- Execution of arbitrary OS commands with the privileges of the storescp process
- Exposure or modification of medical imaging data handled by the affected system
- Compromise of the host running DCMTK (e.g., installing backdoors, pivoting further into the network)
- Disruption of DICOM services through data deletion, service stoppage, or resource exhaustion
- Use of the compromised host as a foothold for lateral movement in healthcare or imaging networks
General mitigation guidance
Effective mitigation focuses on eliminating command injection patterns and reducing the trust boundary of external command hooks:
- Replace shell-based command composition with APIs that execute programs using argument arrays (e.g., exec-style calls) to avoid shell parsing where possible.
- Treat all data derived from DICOM peers or files as untrusted: perform strict validation, allowlists, and normalization before including values in any command context.
- Avoid passing raw user-controlled strings into command templates; if external tools must be invoked, map inputs to pre-defined safe options instead of free-form arguments.
- Limit or disable executeOnReception/executeOnEndOfStudy behavior in environments where it is not strictly required.
- Run storescp under a dedicated, least-privileged account with constrained filesystem and network access to minimize blast radius if exploitation occurs.
- Isolate DICOM receiver services via network segmentation and application-layer access controls to reduce exposure to untrusted senders.
How teams detect issues like this
Detection can combine code-centric and deployment-centric approaches:
- Static analysis and manual review to flag patterns where:
- Command strings are built via string concatenation/formatting using data derived from network input or file metadata.
- Shell interpreters (e.g., system(), popen(), /bin/sh) are invoked with a single string parameter.
- Configuration and policy checks that:
- Identify use of executeOnReception/executeOnEndOfStudy or similar hooks that run external commands.
- Enforce secure coding guidelines for external process execution (e.g., require argument-array APIs and allowlists).
- Runtime monitoring:
- Capture and inspect process creation events from storescp, looking for unexpected commands, arguments, or spikes in process spawning.
- Use host-based intrusion detection or EDR agents to alert on suspicious shell activity originating from storescp processes.
- CI/CD integration:
- Incorporate automated scanners that understand C/C++ process-spawning APIs and flag high-risk command construction patterns early in development.

