T09 · Insecure Skill Coding Practices
- Location
SKILL.md:182- Finding
Shell Command Injection Through an Unvalidated Scan Target
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 182–273
Vulnerability Type: OS command injection
Risk Level: Highpython def __init__(self, target): self.target = target self.results = {} self.report_dir = "reports" os.makedirs(self.report_dir, exist_ok=True) def quick_recon(self): result = self._run_command(f"nmap -sn -T4 {self.target}") self.results["host_discovery"] = result def full_scan(self): result = self._run_command( f"nmap -p- -sV -sC -A -T4 {self.target}" ) self.results["full_scan"] = result def vuln_scan(self): result = self._run_command( f"nmap --script vuln {self.target}" ) self.results["vuln_scan"] = result result = self._run_command( f"nuclei -u http://{self.target} -t cves/ -t vulnerabilities/" ) self.results["nuclei_scan"] = result def ssl_scan(self): result = self._run_command(f"sslscan {self.target}") self.results["ssl_scan"] = result def web_scan(self): result = self._run_command( f"nikto -h http://{self.target} -o {self.report_dir}/nikto_{self.target}.txt" ) self.results["web_scan"] = result def _run_command(self, command): try: result = subprocess.run( command, shell=True, capture_output=True, text=True, timeout=600 ) return result.stdout if result.stdout else result.stderr except subprocess.TimeoutExpired: return "Scan timed out" except Exception as e: return f"Error: {str(e)}"Technical Analysis
The documented implementation stores the externally supplied
targetvalue without validation and inserts it directly into multiple command strings._run_commandthen invokes these strings throughsubprocess.runwithshell=True.Consequently, the operating-system shell interprets metacharacters contained in the targ ...[truncated 1723 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove
shell=Trueand pass each command as an argument list:python subprocess.run( ["nmap", "-sn", "-T4", self.target], shell=False, capture_output=True, text=True, timeout=600, check=False, ) -
Validate the target before use. Accept only explicitly supported IP addresses, CIDR networks, or DNS hostnames. Python's
ipaddressmodule should be used for IP addresses and networks. -
If hostnames are supported, apply strict length and label validation and reject whitespace, control characters, shell metacharacters, URL paths, and command-line options.
-
Reject targets beginning with
-so they cannot be interpreted as scanner options. -
Construct nuclei and nikto URLs using a URL-building API rather than string concatenation.
-
Run scanners as an unprivileged, isolated account or container with restricted filesystem and network access.
-
Add tests covering command separators, substitutions, redirections, newlines, leading hyphens, and malformed hostnames.
-
