Summary
DigitalOcean Droplet Agent through version 1.3.2 contains a command injection vulnerability in its troubleshooting actioner component, which builds and executes shell commands from metadata without adequately sanitizing user-controlled content.
An attacker who can influence metadata service responses can inject arbitrary OS commands into the TroubleshootingAgent.Requesting array entries and have them executed with root privileges when the agent retrieves metadata after specially crafted TCP packets are sent to the SSH port.
Affected context
The vulnerability occurs within the Droplet Agent's troubleshooting subsystem, specifically in environments where:
- The agent (≤ 1.3.2) is installed and running with root privileges
- It automatically queries the metadata service at
http://169.254.169.254/metadata/v1.jsonin response to network activity on the SSH port - The metadata service responses can be influenced, intercepted, or spoofed by an attacker on the same network or with control over the metadata path
Under these conditions, entries in the TroubleshootingAgent.Requesting array are treated as trusted command specifications once they pass a basic artifact whitelist check, even though their command bodies are not sanitized.
Exploit preconditions
- Attack surface: Network-triggered via the Droplet's SSH port and associated metadata fetch to
169.254.169.254. - Required access:
- Ability to send crafted TCP packets with specific sequence characteristics to the SSH port to trigger troubleshooting behavior, and
- Ability to control, spoof, or tamper with metadata responses from the instance metadata endpoint (e.g., network-level man-in-the-middle, compromised infrastructure, or misconfigured metadata routing).
- Trigger point: When the Droplet Agent's troubleshooting actioner:
- Receives the trigger condition on the SSH port,
- Fetches
metadata/v1.json, - Parses the
TroubleshootingAgent.Requestingarray, - And passes the associated commands through the command parser into
exec.CommandContextwithout sanitization. - Why exploitation is possible: The implementation verifies that referenced "artifacts" appear in a
validInvestigationArtifactsmap but does not validate or sanitize the command string content after thecommand:prefix. This leaves the actual shell commands fully attacker-controlled while being executed with root privileges.
Why this happens
The core bug is the direct use of untrusted metadata content to construct OS command invocations without sufficient validation or escaping.
In internal/troubleshooting/actioner/actioner.go, the TroubleshootingAgent.Requesting array is parsed and cross-checked only against a whitelist of artifacts, not against a safe command schema. The associated logic in internal/troubleshooting/command/command.go parses command descriptors but treats the command payload as trusted, and internal/troubleshooting/command/exec.go ultimately calls exec.CommandContext with whatever command string was provided.
This pattern maps to CWE-94: Improper Control of Generation of Code, and more concretely to command injection, where externally supplied data is allowed to influence executable content (in this case, OS commands) without constraining it to a safe subset or using a parameterized, non-shell-based abstraction.
Potential impact
- Full remote execution of arbitrary OS commands with root privileges on the affected Droplet
- Complete system compromise, including installation of persistent backdoors or alteration of critical services
- Data exfiltration from local storage, attached volumes, and accessible services
- Privilege escalation from non-privileged footholds to root (if the agent is reachable from a lower-privileged context)
- Lateral movement across cloud infrastructure by using the compromised instance as a pivot
- Disruption or sabotage of workloads running on the Droplet (e.g., stopping services, corrupting data)
General mitigation guidance
Effective mitigation focuses on treating metadata and troubleshooting instructions as untrusted input and separating command intent from executable content:
- Replace free-form command strings with structured, declarative actions (e.g., "collect logs from X", "run diagnostic Y") that are mapped on the server side to fixed, hard-coded command templates without embedding raw user data into shell commands.
- Avoid invoking the shell altogether where possible. Use direct system APIs or library calls instead of spawning shell commands, and if process execution is necessary, supply arguments as separate parameters to
exec.CommandContext(or equivalent) without string concatenation. - Introduce strict schema validation for metadata fields:
- Only allow predefined operations and arguments
- Reject or ignore unknown fields, unexpected separators, or control characters
- Enforce allowlists of acceptable commands and parameters rather than checking only artifact identifiers.
- Apply principle of least privilege to the agent:
- Run the agent with the minimum required system privileges rather than as root, where feasible
- Restrict its access to sensitive files, sockets, and APIs that are not needed for troubleshooting.
- Harden the metadata consumption path:
- Treat the metadata endpoint as untrusted and validate that responses match expected structure and content
- Prefer secure channels or environment-scoped configuration where the platform supports it
- Consider rate-limiting or gating auto-triggered troubleshooting flows behind additional policy checks.
How teams detect issues like this
Organizations can use a mix of code-level and runtime strategies to detect similar issues:
- Static analysis and SAST rules:
- Flag uses of
exec.Command,exec.CommandContext, or equivalents where command strings are derived from network, metadata, or configuration inputs. - Detect string concatenation or interpolation used to construct command arguments.
- Identify parsing logic that accepts free-form
command:fields without corresponding sanitization or allowlist logic. - Code review practices:
- Require explicit documentation of trust boundaries for metadata, cloud instance data, and troubleshooting instructions.
- Treat any feature that converts remote configuration into executable commands as high risk, requiring security review and sign-off.
- Policy enforcement and CI checks:
- Enforce policies that disallow shell-based execution paths in agents or daemons unless they use a tightly constrained set of commands.
- Integrate automated security linters and policy-as-code engines to block merges when dangerous patterns are detected.
- Runtime monitoring:
- Monitor the troubleshooting agent process for unusual patterns of command execution (e.g., outbound network tools, archiving utilities, or shells being launched).
- Use host intrusion detection or EDR tooling to alert on suspicious child processes spawned by the agent or system services.

