Skip to content
OpenSmartRoute
Skillv1.0.0

detecting-command-injection-patterns

Scan a source tree for command-injection vulnerable patterns: shell=True calls in Python subprocess, os.system / os.popen with interpolated strings, Node child_process.exec with template literals, Rub

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (skills/.curated/detecting-command-injection-patterns/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill detecting-command-injection-patterns. Copyright stays with the author (MIT).

Detecting Command Injection Patterns

Overview

Command injection (CWE-78, OWASP A03:2021) shows up wherever an application shells out to a binary. Image conversion (convert), archive extraction (tar, unzip), video processing (ffmpeg), DNS lookup (dig), and "we just need to call this CLI tool once" are the common origins.

The vulnerability shape is universal: a string is built including user input, then handed to a shell interpreter. The shell parses the string with normal shell semantics — including ;, |, &, $(), backticks. Any of those in the user-controlled portion becomes shell-executable.

When the skill produces findings

Finding Severity Threshold Affected control
Python subprocess.run(..., shell=True) with interpolation CRITICAL f-string / concat / format argument with shell=True CWE-78
Python os.system(...) with interpolation CRITICAL non-literal argument CWE-78
Python os.popen(...) with interpolation CRITICAL non-literal argument CWE-78
Node child_process.exec(...) with template literal CRITICAL ${...} in the command string CWE-78
Node child_process.execSync(...) with template CRITICAL same CWE-78
Ruby backticks with interpolation CRITICAL `cmd #{var}` CWE-78
Ruby Kernel#system(string) with interpolation CRITICAL system("cmd #{var}") CWE-78
Go exec.Command("sh", "-c", ...) with interpolation HIGH shell wrapper with var CWE-78
PHP system / exec / passthru / shell_exec with $-interp CRITICAL system("cmd $var") CWE-78
Java Runtime.exec(String) with concat HIGH single-string form (vs array) with var CWE-78

Prerequisites

  • Python 3.9+
  • Target source tree on local filesystem

Instructions

Step 1 — Run the scanner

python3 ${CLAUDE_PLUGIN_ROOT}/skills/detecting-command-injection-patterns/scripts/scan_cmdi.py /path/to/repo

Options:

Usage: scan_cmdi.py PATH [OPTIONS]

Options:
  --output FILE      Write findings to FILE
  --format FMT       json | jsonl | markdown (default: markdown)
  --min-severity SEV (default: info)
  --include-tests    Include test directories (default: excluded)
  --languages LIST   Comma-separated subset to scan

Step 2 — Interpret findings

CRITICAL = direct user-input → shell construction. Fix immediately.

HIGH = pattern where the shell layer exists but user-input reachability needs verification.

Step 3 — Remediation

The universal fix: pass arguments as a list (array), not a single string. Most APIs have a list form that bypasses shell entirely.

See references/PLAYBOOK.md for per-language patterns.

Examples

Example 1 — Pre-commit on a media-processing service

python3 ${CLAUDE_PLUGIN_ROOT}/skills/detecting-command-injection-patterns/scripts/scan_cmdi.py \
    --min-severity high $(git diff --name-only main...HEAD | tr '\n' ' ')

Example 2 — CI gate

- name: Command-injection scan
  run: |
    python3 plugins/security/penetration-tester/skills/detecting-command-injection-patterns/scripts/scan_cmdi.py \
        . --min-severity high

Output

JSON / JSONL / Markdown. Exit codes: 0 clean, 1 high/critical, 2 error.

Error Handling

False positives common in build scripts that interpolate fixed build constants. Verify each finding by reading whether the interpolated value is user-reachable.

Resources

  • references/THEORY.md — Why shell=True is the default footgun, per-language shell-out idioms, argument-vector vs command-string semantics
  • references/PLAYBOOK.md — Per-language safe-shellout patterns (Python subprocess list-args, Node spawn, Ruby Open3.capture3, Go exec.Command list-args, Java ProcessBuilder, PHP escapeshellarg)

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-detecting-com-4a8261/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-detecting-com-4a8261.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-detecting-com-4a8261",
  "kind": "skill",
  "name": "detecting-command-injection-patterns",
  "description": "Scan a source tree for command-injection vulnerable patterns: shell=True calls in Python subprocess, os.system / os.popen with interpolated strings, Node child_process.exec with template literals, Ruby backticks / Kernel#system / Kernel#exec with interpolation, Go exec.Command with shell wrapping, PHP system / passthru / shell_exec / backticks with $-interpolation, Java Runtime.exec with concatenated args. Use when: pre-commit gate on code that calls out to shell utilities, audit of file-processing / archive-handling / image-conversion code, post-bug-report investigation for \"we shell out to a tool.\" Threshold: any shell-invocation API called with a string that contains a variable interpolation, OR shell=True with anything other than a fixed literal. Trigger with: \"scan command injection\", \"shell=True audit\", \"find exec calls\", \"check os.system\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "security",
      "static-analysis",
      "command-injection",
      "pentest",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Scan a source tree for command-injection vulnerable patterns: shell=True calls in Python subprocess, os.system / os.popen with interpolated strings, Node child_process.exec with template literals, Ruby backticks / Kernel#system / Kernel#exec with interpolation, Go exec.Command with shell wrapping, PHP system / passthru / shell_exec / backticks with $-interpolation, Java Runtime.exec with concatenated args. Use when: pre-commit gate on code that calls out to shell utilities, audit of file-processing / archive-handling / image-conversion code, post-bug-report investigation for \"we shell out to a tool.\" Threshold: any shell-invocation API called with a string that contains a variable interpolation, OR shell=True with anything other than a fixed literal. Trigger with: \"scan command injection\", \"shell=True audit\", \"find exec calls\", \"check os.system\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "skills/.curated/detecting-command-injection-patterns/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/skills/.curated/detecting-command-injection-patterns/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/skills/.curated/detecting-command-injection-patterns/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read",
      "Bash(python3:*)",
      "Glob",
      "Grep"
    ],
    "license": "MIT"
  },
  "instructions": "# Detecting Command Injection Patterns\n\n## Overview\n\nCommand injection (CWE-78, OWASP A03:2021) shows up wherever an\napplication shells out to a binary. Image conversion (`convert`),\narchive extraction (`tar`, `unzip`), video processing (`ffmpeg`),\nDNS lookup (`dig`), and \"we just need to call this CLI tool once\"\nare the common origins.\n\nThe vulnerability shape is universal: a string is built including\nuser input, then handed to a shell interpreter. The shell parses\nthe string with normal shell semantics — including `;`, `|`, `&`,\n`$()`, backticks. Any of those in the user-controlled portion\nb",
  "cost": {
    "context_tokens": 962
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-detecting-com-4a8261/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.