T09 · Insecure Skill Coding Practices
- Location
server.py:189- Finding
Unvalidated Scan Parameters Permit Nmap Option and NSE Script Injection
- Content
View full analysis
dict: """ Run nmap with -oX - to get XML output, parse it with python-nmap, return a structured dict. """ nm = nmap.PortScanner() args_str = " ".join(extra_args) log.info("python-nmap scan: target=%s args=%s", target, args_str) try: nm.scan(hosts=target, arguments=args_str, timeout=timeout) ``` The following tool parameters are inserted into that argument string without validation: ```python result = _nmap_structured( target, ["-sT", "-p", ports, "-T4", "--open"], timeout=TIMEOUTS["standard"] ) ``` ```python result = _nmap_structured( target, ["--privileged", "-sU", "-p", ports, "-T4"], timeout=TIMEOUTS["deep"] ) ``` ```python port_args = ["--top-ports=1000"] if ports == "common" else ["-p", ports] extra = ["-sT", f"--script={scripts}", "-T4"] + port_args ``` Equivalent unvalidated `ports` handling also appears in service detection, vulnerability scanning, and full reconnaissance. ### Technical Analysis The public MCP tools accept `ports` and `scripts` as arbitrary strings. Although these values are initially placed in Python lists, `_nmap_structured` joins the entire list into a single string before passing it to `python-nmap`. Whitespace and option prefixes inside user-controlled values can therefore be interpreted as additional Nmap command-line options. The stricter checks implemented for `nmap_custom_scan`, including `_DANGEROUS_FLAGS`, are not applied to these tools. Consequently, an attacker can attempt to append output options, data-directory options, or NSE script selections through a crafted port value. The `scripts` parameter is particularly sensitive ...[truncated 2065 chars]- Remediation
View remediation
