T09 · Insecure Skill Coding Practices
Error
- Location
- src/service.js:46
- Finding
- Privileged Remote Command Injection Through Service Names<![CDATA[ ## Vulnerability Details **File Location**: `src/service.js:46-102` **Vulnerability Type**: OS command injection in privileged remote service-management commands **Risk Level**: Critical ### Vulnerable Code ```js const result = await execSSH(serverName, `sudo systemctl start ${serviceName}`); ``` The same unsafe construction is used for `stop`, `restart`, `reload`, `enable`, and `disable` operations. ### Technical Analysis `serviceName` is inserted directly into a shell command sent through SSH. No validation, argument quoting, or metacharacter rejection is performed. Because the remote SSH server interprets the command through a shell, a value containing separators such as `;`, `&&`, command substitution, redirection, or newlines can escape the intended `systemctl` argument. The command also invokes `sudo`, so the injected command may run with root privileges when the connected account has non-interactive sudo authorization. The `systemctl enable` behavior is part of the declared service-management functionality and is not covert persistence by itself. The vulnerability is that arbitrary shell syntax can be injected into that privileged operation. ### Attack Path 1. An attacker or untrusted caller supplies a crafted service name, such as `nginx; id`. 2. The Skill constructs: ```sh sudo systemctl start nginx; id ``` 3. The remote shell starts the service and then executes the injected command. 4. If a suitable sudo rule is available, an attacker can substitute a payload that modifies privileged files, creates users, installs services, or establishes persistence. ### Impact Assessment Successful exploitation provides arbitrary command execution on the selected remote server under the SSH account. Depending on sudo configuration, it can provide root-level control. Potential consequences include: - Starting, stopping, or disabling critical services. - Installing or enabling persistent system services. - Modifying privileged configu ...[truncated 153 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not concatenate untrusted values into shell command strings. - Validate service names against a restrictive allowlist, for example: ```js if (!/^[A-Za-z0-9_.@-]+$/.test(serviceName)) { throw new Error('Invalid service name'); } ``` - Validate `state` against an explicit list such as `all`, `active`, `inactive`, and `failed`. - Use a well-reviewed POSIX shell-argument escaping function if a shell cannot be avoided. - Require explicit user confirmation for destructive or persistent actions such as `stop`, `disable`, and `enable`. - Configure sudo so the SSH account can invoke only the required `systemctl` subcommands and approved service units. - Record an audit event containing the selected host, service, action, and requesting identity before execution. ]]>
