T09 · Insecure Skill Coding Practices
- Location
scripts/build_rc.py:55- Finding
Metasploit Resource Script Command Injection via Unvalidated Module and Payload Arguments
- Content
View full analysis
- Remediation
View remediation
None: if any(ord(ch) < 32 or ord(ch) == 127 for ch in value): raise ValueError(f"{field} contains prohibited control characters") ``` 3. **Use field-specific validation** Do not rely solely on generic quoting. Validate each argument according to its semantics: - Module and payload: constrained resource paths. - Ports: enforce the range `1–65535`. - Hosts: validate expected hostname, IP address, or CIDR syntax. - Option keys: retain the existing strict key allowlist. - File paths: reject line breaks and apply an explicit path policy where appropriate. 4. **Fail safely before writing output** Validate all arguments before creating parent directories or writing the resource file. On validation failure, return a nonzero status and avoid leaving a partial script. 5. **Add regression tests** Include tests proving rejection of: - `\n` and `\r\n` injection in module and payload arguments. - Control characters in all other string arguments. - Embedded resource-script commands. - Invalid module-path characters. - Out-of-ran ...[truncated 246 chars]
