Back to skill

Security audit

Nmap Pro Pentest Scans

Security checks for vulnerabilities and agentic risk

Overview

This authorized Nmap planning skill is coherent, but it needs review because it generates runnable scan commands with unescaped targets and reports findings without scan evidence.

Install only for authorized security testing. Review scope controls before use, constrain output paths, and do not run generated commands unless the target value is trusted and shell-safe. Treat generated findings as planning placeholders unless backed by actual Nmap output.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (2)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/nmap_pentest_scans.py:64
Finding

Shell Command Injection Through Unvalidated Target Values in Generated Nmap Commands

Content
View full analysis

Vulnerability Details

File Location: scripts/nmap_pentest_scans.py, lines 64-119 and 158-161
Vulnerability Type: Shell command injection in generated command artifacts
Risk Level: High

Vulnerable Code

python
def build_command_plan(target: str, profile: str, include_udp: bool) -> list[dict[str, str]]:
    target_basename = normalize_target_basename(target)

    if profile == "stealth":
        timing = "-T2"
        rate = "--max-retries 2 --scan-delay 5ms"
    elif profile == "fast":
        timing = "-T4"
        rate = "--min-rate 500 --max-retries 1 --host-timeout 10m"
    else:
        timing = "-T3"
        rate = "--min-rate 100 --max-retries 2"

    plan: list[dict[str, str]] = [
        {
            "stage": "host-discovery",
            "command": (
                f"nmap -sn {target} -n --reason "
                f"-oA results/{target_basename}-01-discovery"
            ),
            "purpose": "Detect responsive hosts and collect probe reasons.",
        },
        {
            "stage": "tcp-triage",
            "command": (
                f"nmap -sS --top-ports 1000 {target} -n {timing} {rate} --reason "
                f"-oA results/{target_basename}-02-tcp-top1000"
            ),
            "purpose": "Find common exposed TCP services quickly.",
        },
        {
            "stage": "service-enum",
            "command": (
                f"nmap -sV -sC -p <OPEN_TCP_PORTS> {target} -n {timing} --reason "
                f"-oA results/{target_basename}-03-svc-default"
            ),
            "purpose": "Fingerprint service versions and run default safe scripts.",
        },
        {
            "stage": "web-tls",
            "command": (
                f"nmap -p 80,443 --script http-title,http-headers,http-methods,ssl-cert "
                f"{target} -n --script-timeout 30s "
                f"-oA results/{tar
...[truncated 3217 chars]
Remediation
View remediation

Remediation Suggestions

  1. Parse targets using strict allowlists:
    • Use Python's ipaddress module for IPv4, IPv6, and CIDR values.
    • Validate DNS names label by label.
    • Reject whitespace, control characters, newlines, shell metacharacters, leading hyphens, and unsupported Nmap target expressions.
  2. Represent commands internally as argument arrays rather than shell strings, for example:
    python
    command = ["nmap", "-sn", validated_target, "-n", "--reason", "-oA", output_prefix]
    
  3. If live execution is later implemented, use subprocess.run(command, shell=False, check=True) and never pass target-derived strings through a shell.
  4. If human-readable shell commands must be exported, serialize every argument with shlex.quote() and clearly mark the file as informational rather than executable.
  5. Test rejection of semicolons, pipes, command substitutions, redirections, embedded newlines, whitespace-separated extra arguments, and targets beginning with -.
  6. Keep output-path normalization, but do not mistake filename normalization for command-argument validation.

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/nmap_pentest_scans.py:124
Finding

Unconditional Fabrication of Security Findings Without Scan Evidence

Content
View full analysis

Vulnerability Details

File Location: scripts/nmap_pentest_scans.py, lines 124-145, 203-205, and 233-273
Vulnerability Type: Unverified security-result generation and report integrity failure
Risk Level: Medium

Vulnerable Code

python
def build_finding(target: str) -> dict:
    now = datetime.now(timezone.utc).isoformat()
    return {
        "finding_id": f"{SKILL_NAME.replace('-', '_')}-001",
        "skill": SKILL_NAME,
        "timestamp": now,
        "target": target,
        "title": "Nmap reconnaissance identified externally reachable services",
        "cve": "N/A",
        "cwe": "CWE-200",
        "cvss_score": 6.5,
        "cvss_vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:N",
        "owasp_category": "A05:2021 - Security Misconfiguration",
        "mitre_attack": "TA0007 - Discovery",
        "severity": "Medium",
        "description": "Service exposure was identified and should be reviewed against hardened baseline policy.",
        "proof_of_concept": "nmap -sS --top-ports 1000 <target> -n --reason",
        "screenshot": "assets/findings/placeholder.png",
        "remediation": "Restrict unnecessary network exposure and enforce service-level hardening controls.",
        "references": ["https://nmap.org/docs.html", "https://nmap.org/book/nse.html"],
        "status": "open",
    }
python
payload = load_payload(args.input)
plan = build_command_plan(args.target, args.profile, args.include_udp)
finding = build_finding(args.target)
artifacts: list[str] = []
python
findings_json = resolve_artifact_path(report_path.parent, "findings/nmap-pentest-findings.json")
write_placeholder_artifact(
    findings_json,
    {
        "skill": SKILL_NAME,
        "target": args.target,
        "generated_at": datetime.now(timezone.utc).isoformat(),
        "findings": [finding],
        "plan_summary": [item["stage"] for ite
...[truncated 2632 chars]
Remediation
View remediation

Remediation Suggestions

  1. Return an empty findings list in dry-run mode because no evidence has been collected.
  2. Distinguish explicitly between:
    • Proposed scan plans
    • Executed scans
    • Parsed observations
    • Confirmed security findings
  3. If live scanning is in scope, execute approved commands through safe argument arrays and parse generated Nmap XML rather than inferring results from the plan.
  4. Create findings only when parsed evidence identifies reachable hosts and open services.
  5. Include evidence fields such as the exact host, protocol, port, service, Nmap output artifact, scan timestamp, and parser confidence.
  6. Derive severity and CVSS from the actual exposure and context instead of assigning a fixed score to every target.
  7. If placeholder records are required for schema testing, label them unambiguously with fields such as "synthetic": true and "status": "not_observed", and exclude them from production findings.
  8. Add tests confirming that dry runs and plan-only executions cannot produce asserted security findings.
Vulnerability Patterns
  • YARA SignaturesMalware Match, Webshell Match, Cryptominer Match
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (3)

YARA rule 'offensive_tool_references': References to well-known offensive security tools [hacktools]

High
Category
YARA Match
Confidence
70% confidence
Finding

YARA rule matched a hack tool or exploit indicator (offensive tools, reconnaissance, privilege escalation, or exploit frameworks).

Content

Scanner excerpt · references/scan-profiles.md (reported line 43)May include surrounding context.

r/root when required (-sS, raw packet features).

  • Save outputs with -oA <OUT> whenever possible.

2) Baseline Setup

bash
# Version check
nmap --version

# Basic syntax check on a target list
nmap -iL <TARGETS_FILE> -sn -n --reason -oA <OUT>-discovery

Use -n to skip DNS when speed and signal fidelity matter.

3) Host Discovery Profiles

bash
# Standard ICMP + common probes
nmap -sn <TARGET> -n --reason -oA <OUT>-host-discovery

# ARP discovery on local network segment
nmap -sn -PR <TARGET> -n --reason -oA <OUT>-arp-discovery

# Discovery with TCP SYN ping to common service ports
nmap -sn -PS22,80,443,3389,445 <TARGET> -n --reason -oA <OUT>-syn-ping

# Discovery with TCP ACK ping
nmap -sn -PA80,443,3389 <TARGET> -n --reason -oA <OUT>-ack-ping

# Discovery with UDP ping
nmap -sn -PU53,67,68,123,161 <TARGET> -n --reason -oA <OUT>-udp-ping

# Treat all hosts as up (when ping is blocked)
nmap -Pn -sn <TARGET> -n --reason -oA <OUT>-no-ping

Use -Pn carefully bec

YARA rule 'offensive_tool_references': References to well-known offensive security tools [hacktools]

High
Category
YARA Match
Confidence
70% confidence
Finding

YARA rule matched a hack tool or exploit indicator (offensive tools, reconnaissance, privilege escalation, or exploit frameworks).

Content

Scanner excerpt · scripts/nmap_pentest_scans.py (reported line 89)May include surrounding context.

python
timing = "-T2"
        rate = "--max-retries 2 --scan-delay 5ms"
    elif profile == "fast":
        timing = "-T4"
        rate = "--min-rate 500 --max-retries 1 --host-timeout 10m"
    else:
        timing = "-T3"
        rate = "--min-rate 100 --max-retries 2"

    plan: list[dict[str, str]] = [
        {
            "stage": "host-discovery",
            "command": (
                f"nmap -sn {target} -n --reason "
                f"-oA results/{target_basename}-01-discovery"
            ),
            "purpose": "Detect responsive hosts and collect probe reasons.",
        },
        {
            "stage": "tcp-triage",
            "command": (
                f"nmap -sS --top-ports 1000 {target} -n {timing} {rate} --reason "
                f"-oA results/{target_basename}-02-tcp-top1000"
            ),
            "purpose": "Find common exposed TCP services quickly.",
        },
        {
            "stage": "service-enum",
            "command": (
                f"nm

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
93% confidence
Finding

The skill declares executable behavior that can write multiple output artifacts, but it does not define any explicit tool scope such as permissions or allowed-tools. In an agentic environment, this creates an authorization gap where file-writing may occur without clear policy constraints, increasing the chance of unintended filesystem modification or misuse in broader automation chains.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.