Back to skill

Security audit

Port Manager

Security checks for vulnerabilities and agentic risk

Overview

The skill mostly matches its port-management purpose, but it needs review because it can terminate local processes and handles port input too loosely.

Review carefully before installing. Use it only in local development contexts, avoid running it with elevated privileges, and verify the exact process before approving any port release. The publisher should add strict port validation, quote command arguments, show every target PID before termination, prefer graceful shutdown, and remove or explain the bundled sample port records.

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/port.sh:83
Finding

Unvalidated Port Input Can Alter Process Selection and Terminate Unintended Processes

Content
View full analysis

Vulnerability Details

File Location: scripts/port.sh, lines 83-105
Vulnerability Type: Shell argument injection and unsafe process termination
Risk Level: High

Vulnerable Code

bash
free() {
    local port=$1
    
    if [ -z "$port" ]; then
        echo "用法: port free <端口>"
        return 1
    fi
    
    # 获取占用进程
    local pid=$(lsof -t -i :$port 2>/dev/null)
    
    if [ -z "$pid" ]; then
        echo "端口 $port 没有被占用"
        return 1
    fi
    
    local pname=$(ps -p $pid - comm= 2>/dev/null | head -1)
    echo "⚠️  端口 $port 被 $pname (PID: $pid) 占用"
    echo "是否释放? (y/n)"
    
    read -r confirm
    if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
        kill $pid
        echo "✅ 已释放端口 $port (终止了进程 $pid)"
    else
        echo "❌ 已取消"
    fi
}

Technical Analysis

The port parameter is checked only for emptiness. It is not restricted to a decimal TCP/UDP port in the valid range of 1 through 65535.

The value is expanded without quotes in:

bash
lsof -t -i :$port

Shell word splitting therefore allows a port argument containing whitespace to become multiple arguments to lsof. Additional tokens may be interpreted as lsof selection options rather than as part of the requested port specification. This can change or broaden the set of processes returned.

The resulting pid value is also expanded without validation or quoting in ps and kill. If lsof returns multiple process IDs, kill $pid attempts to terminate all of them after confirmation. The script does not verify that each value is a numeric PID, that the process still owns the requested port, or that the process shown to the user is the same process terminated.

Related functions in this file reuse the same unsafe pattern at lines 27, 68, 92, 99, 105, 121, 124, 138, 164, and 179. The allocation path at lines 155-169 additionally places an unvalid ...[truncated 1478 chars]

Remediation
View remediation

Remediation Suggestions

  1. Validate every supplied port before using it:

    bash
    validate_port() {
        case "$1" in
            ''|*[!0-9]*) return 1 ;;
        esac
        [ "$1" -ge 1 ] && [ "$1" -le 65535 ]
    }
    
  2. Reject invalid values before invoking lsof, performing arithmetic, recording data, or terminating processes:

    bash
    if ! validate_port "$port"; then
        printf '%s\n' "Invalid port: expected an integer from 1 to 65535" >&2
        return 1
    fi
    
  3. Quote all parameter expansions:

    bash
    pid_output=$(lsof -t -i ":$port" 2>/dev/null)
    
  4. Parse the result one PID at a time and require every value to match ^[0-9]+$.

  5. Before termination, repeat the port lookup and verify that each PID still owns the requested listening socket. This reduces time-of-check/time-of-use risk and PID reuse issues.

  6. Display and confirm every selected PID individually. Do not display only the first process and then terminate the entire PID list.

  7. Use kill -- "$pid" where supported, check its exit status, and report success only when termination actually succeeds.

  8. Apply the same validation to record, query, check, and allocate. Convert a validated decimal value before arithmetic rather than evaluating an arbitrary user-provided expression.

T09 · Insecure Skill Coding Practices

Error
Location
port-manager/scripts/port.sh:83
Finding

Duplicate Port Manager Script Contains Unvalidated Process-Termination Input

Content
View full analysis

Vulnerability Details

File Location: port-manager/scripts/port.sh, lines 83-105
Vulnerability Type: Shell argument injection and unsafe process termination
Risk Level: High

Vulnerable Code

bash
free() {
    local port=$1
    
    if [ -z "$port" ]; then
        echo "用法: port free <端口>"
        return 1
    fi
    
    # 获取占用进程
    local pid=$(lsof -t -i :$port 2>/dev/null)
    
    if [ -z "$pid" ]; then
        echo "端口 $port 没有被占用"
        return 1
    fi
    
    local pname=$(ps -p $pid - comm= 2>/dev/null | head -1)
    echo "⚠️  端口 $port 被 $pname (PID: $pid) 占用"
    echo "是否释放? (y/n)"
    
    read -r confirm
    if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
        kill $pid
        echo "✅ 已释放端口 $port (终止了进程 $pid)"
    else
        echo "❌ 已取消"
    fi
}

Technical Analysis

This file is a duplicate of the root scripts/port.sh implementation and contains the same vulnerability. A caller-controlled port is expanded without quotes into lsof, and the returned PID data is passed to ps and kill without strict validation.

Whitespace in the supplied port can create additional command-line arguments for lsof, changing its process-selection behavior. If multiple PIDs are returned, the process display is reduced to its first line while kill $pid can signal the complete list.

The same unsafe input is reused by the record, query, check, and allocation functions. In particular, the preferred port supplied to allocate reaches arithmetic expressions without first being constrained to a decimal integer.

Attack Path

  1. An attacker supplies a crafted port argument containing whitespace and additional lsof selection arguments.
  2. The script passes the value into free.
  3. Unquoted expansion splits the input into separate arguments.
  4. lsof returns a broader or otherwise altered PID set.
  5. The script does n ...[truncated 775 chars]
Remediation
View remediation

Remediation Suggestions

Apply the same hardening to this duplicate implementation:

  1. Accept only decimal port strings matching ^[0-9]+$.
  2. Enforce the inclusive range 1 through 65535 before any command or arithmetic use.
  3. Quote the complete lsof selector as ":$port".
  4. Validate each returned PID as a positive decimal integer.
  5. Confirm each target separately and show the executable associated with every PID.
  6. Recheck port ownership immediately before sending a signal.
  7. Invoke kill -- "$pid" individually and verify its return status.
  8. Validate inputs consistently in record, query, check, and allocate.
  9. Remove the duplicate script or establish one canonical implementation so that security fixes cannot be applied to only one copy.
Vulnerability Patterns
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (7)

Tp4

High
Category
MCP Tool Poisoning
Confidence
94% confidence
Finding

The code substantially matches the declared port-management purpose: it checks port usage, lists recorded ports, and can release occupied ports by terminating the owning process after confirmation. However, it also includes an additional undeclared capability: automatic port allocation (allocate) that selects an available port and records it. The script also persistently stores service-port mappings in a JSON file under the workspace, which is more than merely checking/releasing ports, though this is somewhat implied by 'track.' Because the evaluation criteria say to flag undeclared capabilities, the extra allocation feature makes this a mismatch, albeit a relatively minor one.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill instructs users to 'free' a port by terminating the process that owns it, but it does not warn that this may abruptly stop critical services, interrupt active sessions, or cause data loss/corruption. In an agent context, this omission is dangerous because the action is destructive and could be suggested or performed during routine troubleshooting without sufficient user understanding.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

The implementation example includes kill $(lsof -t -i :5432), which is a direct destructive command with no safety guidance, validation, or graceful shutdown step. This can terminate the wrong or an important production process if used blindly, making the documentation itself a risky operational pattern for an agent or user to follow.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The skill explicitly instructs users to free a port by terminating the process bound to it, but it does not warn that this can abruptly stop critical services, cause data loss, or kill the wrong process if the port mapping is misunderstood. Because this skill is specifically designed to manage live system ports, the omission of confirmation, safety checks, and process-identification guidance makes unsafe termination more likely in normal use.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The implementation guidance includes kill $(lsof -t -i :5432), which is a destructive command that can terminate one or more processes without verification or user confirmation. In a port-management skill, this is especially risky because users may copy-paste the command directly, leading to service interruption, accidental termination of important processes, or inconsistent application state.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

This shell script presents its descriptions, prompts, and usage text in Chinese throughout, which effectively forces a specific language on all users. The file does not offer any language selection, opt-in, or justification that the skill is intended only for a Chinese-language environment.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The script's user-facing strings, usage text, and prompts are written in Chinese throughout the file. Under the stated policy, forcing a specific language without user opt-in or clear region-specific justification is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.