T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/main.py:274
- Finding
- SSH Command-Line Option Injection Through an Unvalidated Hostname<![CDATA[ ## Vulnerability Details **File Location**: `scripts/main.py`, lines 274-291 **Vulnerability Type**: SSH command-line option injection **Risk Level**: High ### Vulnerable Code ```python if 'user' in options: sshname = f"{options['user']}@{options['hostname']}" else: sshname = options['hostname'] ssh_command.extend([sshname, 'exit']) try: start_time = time.time() result = subprocess.run( ssh_command, capture_output=True, text=True, timeout=timeout + 2 ) ``` ### Technical Analysis The destination passed to `ssh` is taken from the parsed `Hostname` option without validation. If no username is present and the hostname begins with `-`, OpenSSH may interpret the value as a command-line option rather than as the destination. Although `subprocess.run` uses an argument list and does not invoke a shell, this only prevents shell metacharacter expansion. It does not prevent option injection into the invoked SSH client. A value resembling an SSH option, including a dangerous `ProxyCommand` configuration, may alter SSH behavior or cause a local process to be launched. The Skill supports arbitrary configuration files through `--config`, so exploitation does not necessarily require modification of the user's default SSH configuration. ### Attack Path 1. An attacker supplies or modifies an SSH configuration file that the victim will inspect with the Skill. 2. The attacker adds a host entry whose `Hostname` begins with an SSH option, such as a value representing `-oProxyCommand=...`. 3. The entry omits `User` so that the value remains the first component of `sshname`. 4. The victim runs: ```bash python3 scripts/main.py test --host malicious --config attacker-config ``` 5. The Skill places the attacker-controlled value into the SSH argument vector before the intended destination. 6. The SSH client interprets the value as an option and may execute the configured proxy command under the victim's local ...[truncated 444 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Reject hostnames and usernames that begin with `-`. 2. Validate hostnames against strict hostname, IPv4, or IPv6 syntax and validate usernames against an appropriate allowlist. 3. Insert an SSH-supported end-of-options delimiter before the destination where compatibility permits. 4. Explicitly disable dangerous SSH behaviors during tests, including `ProxyCommand`, `LocalCommand`, and `PermitLocalCommand`. 5. Consider invoking SSH with the selected host alias and a controlled configuration file rather than reconstructing a destination from untrusted configuration values. 6. Add regression tests covering values such as `-oProxyCommand=...`, `-F...`, and other option-shaped hostnames. ]]>
