SH

shellcheck-security-scan

Scans shell scripts for security vulnerabilities and dangerous coding patterns.

Install

mkdir -p .claude/skills/shellcheck-security-scan && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/10505" && unzip -o skill.zip -d .claude/skills/shellcheck-security-scan && rm skill.zip

Installs to .claude/skills/shellcheck-security-scan

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Scan shell scripts for security vulnerabilities using ShellCheck static analysis. Scan files *.sh, *.bash, shell code in Dockerfiles, .github/workflows/*.yml, Makefiles, npm scripts. (1) Detects command injection, arbitrary code execution, reverse shell patterns, data exfiltration, obfuscated payloads (base64/hex), unsafe rm operations, dangerous PATH manipulation. (2) Use for standalone scripts, CI/CD pipelines, installation scripts,build systems. For shell scripts containing embedded Python/other code, also run language-specific scanners. Combine with graudit -d exec for patterns ShellCheck may miss (e.g., base64 | bash).
631 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Intermediate

Key capabilities

  • Detect command injection
  • Identify unsafe patterns
  • Scan CI/CD scripts
  • Audit Dockerfiles

How it works

Uses static analysis to identify bugs and security vulnerabilities in shell scripts.

Inputs & outputs

You give it
Shell script file
You get back
Security vulnerability report

When to use shellcheck-security-scan

  • Scan install script
  • Audit CI pipeline script
  • Secure shell code in Dockerfile

About this skill

ShellCheck Security Scan Skill

ShellCheck is a static analysis tool that identifies bugs, security vulnerabilities, and stylistic issues in shell scripts. It supports bash, sh, dash, and ksh scripts.

When to Use This Skill

Invoke this skill when:

  • Analyzing shell scripts (.sh, .bash) for security vulnerabilities
  • Checking for command injection risks in shell code
  • Detecting unquoted variable expansions that could lead to code execution
  • Reviewing installation scripts, CI/CD pipelines, or build scripts
  • Scanning for obfuscated or suspicious shell patterns
  • Auditing Dockerfiles' RUN commands containing shell code
  • Checking shell scripts in package managers (npm scripts, Makefiles)
  • Triaging potentially malicious or compromised scripts
  • Incident response requiring rapid shell script analysis

Malicious Code Detection Priority

When scanning for potentially malicious or compromised shell scripts, use this prioritized approach:

Critical Checks (Always Enable)

CodePatternMalicious Intent
SC2091$(curl http://...)Remote code execution, payload download
SC2086rm -rf $VARCommand injection, arbitrary file deletion
SC2046cmd $(user_input)Subshell injection
SC2115rm -rf "$DIR/"*Root filesystem wipe when var is empty

High-Risk Patterns (Suspicious Behavior)

CodePatternIndicator
SC2211*.sh as commandArbitrary script execution
SC2216find | xargs rmMass file deletion attack
SC2029SSH command injectionRemote command confusion
SC2087Unquoted heredocCredential/data injection

Indicators of Malicious Intent (Manual Review)

Beyond ShellCheck findings, flag scripts containing:

  • Reverse shells: bash -i, /dev/tcp/, nc -e, mkfifo
  • Data exfiltration: curl -d "$(cat /etc/passwd)", encoded POST data
  • Obfuscation: base64 -d | bash, eval "$(printf '\x...')", xxd -r
  • Persistence: crontab manipulation, /etc/init.d/, systemd service creation
  • Privilege escalation: SUID manipulation, sudo config changes
  • Defense evasion: history -c, unset HISTFILE, log deletion

Prerequisites

Installation

macOS (Homebrew):

brew install shellcheck

Ubuntu/Debian:

apt-get install shellcheck

Fedora/RHEL:

dnf install ShellCheck

Using Cabal (Haskell):

cabal update
cabal install ShellCheck

Docker:

docker pull koalaman/shellcheck

Verify Installation

shellcheck --version

Core Commands

Basic Security Scan

# Scan a single script
shellcheck script.sh

# Scan with severity threshold (error, warning, info, style)
shellcheck --severity=warning script.sh

# Scan multiple files
shellcheck *.sh

# Scan recursively
find . -name "*.sh" -exec shellcheck {} +

Output Formats

# JSON output for parsing
shellcheck --format=json script.sh

# SARIF output for security tools
shellcheck --format=sarif script.sh

# GCC-compatible format
shellcheck --format=gcc script.sh

# Checkstyle XML format
shellcheck --format=checkstyle script.sh

# Quiet mode (only show errors)
shellcheck --format=quiet script.sh

Shell Dialect Selection

# Specify shell dialect
shellcheck --shell=bash script.sh
shellcheck --shell=sh script.sh
shellcheck --shell=dash script.sh
shellcheck --shell=ksh script.sh

Advanced Options

# Enable all optional checks
shellcheck --enable=all script.sh

# Exclude specific checks
shellcheck --exclude=SC2086,SC2046 script.sh

# Check scripts sourced from stdin
cat script.sh | shellcheck -

# Follow source statements
shellcheck --source-path=SCRIPTDIR script.sh

Deep Security Scan for Malicious Code

Comprehensive Single-File Analysis

# Maximum security scan with all checks, filter critical issues
shellcheck --enable=all --severity=style --format=json script.sh | \
  jq '[.[] | select(.code | tostring | test("^20(86|46|91|29|87|68|34|64|89|90)|2115|2116|2211|2216"))]'

Prioritized Critical Check Scan

# Focus on high-risk injection patterns only
shellcheck --enable=all script.sh 2>&1 | \
  grep -E "SC20(86|46|91)|SC2115|SC2211|SC2216"

Project-Wide Malicious Code Hunt

# Scan all shell scripts with security focus, exclude vendor
find . -type f \( -name "*.sh" -o -name "*.bash" \) \
  ! -path "./vendor/*" ! -path "./node_modules/*" \
  -exec shellcheck --enable=all --severity=warning --format=gcc {} + 2>&1 | \
  sort -t: -k4 | uniq -c | sort -rn

CI/CD Pipeline Script Audit

# Extract and scan shell code from GitHub Actions workflows
find .github -name "*.yml" -exec grep -l "run:" {} + | \
  xargs -I{} sh -c 'grep -A5 "run:" "{}" | grep -v "^--$"' | \
  shellcheck --shell=bash -

Detecting Obfuscated Malicious Payloads

ShellCheck's static analysis may miss sophisticated obfuscation. Combine with pattern detection:

Base64 Payloads

# Find base64 decode + execute patterns
grep -rn --include="*.sh" -E "(base64\s+(-d|--decode)|decode.*base64).*\|\s*(ba)?sh" .

Hex/Octal Encoding

# Find printf-based obfuscation
grep -rn --include="*.sh" -E "printf.*\\\\x[0-9a-fA-F]{2}" .
grep -rn --include="*.sh" -E '\$\(printf.*\\[0-7]{3}' .

Reverse Shell Signatures

# Common reverse shell patterns
grep -rn --include="*.sh" -E "(bash\s+-i|/dev/tcp/|nc\s+(-e|-c)|mkfifo|0<&[0-9])" .

Eval-Based Execution

# Dangerous eval patterns
grep -rn --include="*.sh" -E "eval\s+['\"]?\\\$\(" .

These patterns should trigger manual review even if ShellCheck passes.

Security-Relevant Checks

CodeSeverityDescriptionSecurity Impact
SC2086WarningDouble quote to prevent globbing and word splittingCommand injection, arbitrary file access
SC2046WarningQuote to prevent word splitting on command substitutionCommand injection
SC2091WarningRemove surrounding $() to avoid executing outputArbitrary code execution
SC2155WarningDeclare and assign separately to avoid masking return valuesLogic bypass
SC2012WarningUse find instead of ls to better handle non-alphanumeric filenamesPath traversal
SC2029WarningCommands run on client, not serverUnintended local execution
SC2034WarningVariable appears unusedDead code, possible data leak
SC2064WarningUse single quotes for trap commandsUnexpected expansion timing
SC2068WarningDouble quote array expansionsArgument injection
SC2087WarningQuote heredoc to prevent variable expansionData injection
SC2089WarningQuotes/backslashes in variables don't workEscape bypass
SC2090WarningQuotes/backslashes will be treated literallyCommand injection
SC2116WarningUseless echo? Instead of echo $(cmd), use cmdUnnecessary subshell
SC2129StyleConsider using redirections instead of pipesEfficiency
SC2145WarningArgument mixes string and arrayUnexpected behavior
SC2148WarningTips depend on target shellWrong shell execution
SC2154WarningVariable is referenced but not assignedUndefined behavior
SC2162Warningread without -r mangles backslashesInput manipulation
SC2174Warningmkdir -m only applies to the deepest directoryPermission bypass
SC2206WarningQuote to prevent word splittingArray injection
SC2211WarningGlob used as command nameArbitrary command execution
SC2215WarningFlag appears after filenameArgument confusion
SC2216WarningPiping to rm is unsafeArbitrary file deletion
SC2220WarningInvalid flagsUnexpected behavior
SC2222WarningRemove invalid flagsUnexpected behavior
SC2223WarningQuote to prevent empty commandLogic errors
SC2224WarningNumeric comparison on non-numberLogic bypass
SC2225WarningSource outside of subroutineScope leakage
SC2226WarningUse -exec or -exec + instead of -execdirPath injection

MITRE ATT&CK Mappings

Technique IDTechnique NameRelevant Checks
T1059.004Command and Scripting Interpreter: Unix ShellSC2086, SC2046, SC2091
T1027Obfuscated Files or InformationSC2089, SC2090
T1105Ingress Tool TransferSC2029 (curl/wget patterns)
T1222.002File and Directory Permissions ModificationSC2174
T1070.004Indicator Removal: File DeletionSC2216
T1552.001Unsecured Credentials: Credentials in FilesSC2034 (unused sensitive vars)

Security Triage Workflow

Step 1: Quick Risk Assessment

# Count security-relevant findings by severity
shellcheck --enable=all --format=json script.sh | \
  jq -r '.[] | "\(.level): \(.code)"' | sort | uniq -c | sort -rn

Step 2: Critical Issue Identification

# Extract only critical security issues
shellcheck --enable=all --format=json script.sh | \
  jq -r '.[] | select(.code == 2086 or .code == 2046 or .code == 2091 or .code == 2115) | 
    "[\(.level)] Line \(.line): \(.message)"'

Step 3: Context Analysis

For each critical finding, assess exploitability:

  • SC2086 in rm/curl/wget: Likely exploitable → HIGH PRIORITY
  • SC2086 in echo/printf: Lower risk → MEDIUM PRIORITY
  • SC2091: Always critical → IMMEDIATE REVIEW
  • SC2115: Empty variable + rm = catastrophic → CRITICAL

Step 4: Malicious Intent Assessment

# Look for network activity + execution patterns together
grep -E "(curl|wget|nc).*\|.*(ba)?sh" script.sh && echo "⚠️  SUSPICIOUS: Download-and-execute pattern"

# Check for data exfiltration patterns
grep -E "curl.*-d.*\$|wget.*--post-data" script.sh && echo "⚠️  SUSPICIOU

---

*Content truncated.*

When not to use it

  • For non-shell scripts
  • When the script is too complex for static analysis

Prerequisites

shellcheck

Limitations

  • Cannot detect all obfuscated malicious payloads
  • May produce false positives

How it compares

Provides automated security auditing for shell code rather than manual review.

Compared to similar skills

shellcheck-security-scan side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
shellcheck-security-scan (this skill)06moReviewIntermediate
secrets-management53moReviewAdvanced
fix-cves16moNo flagsIntermediate
sca-trivy16moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

secrets-management

wshobson

Implement secure secrets management for CI/CD pipelines using Vault, AWS Secrets Manager, or native platform solutions. Use when handling sensitive credentials, rotating secrets, or securing CI/CD environments.

585

fix-cves

okteto

Fix all CVEs in the Okteto CLI Docker image by scanning with Trivy and updating vulnerable dependencies and binaries

12

sca-trivy

rohunj

Software Composition Analysis (SCA) and container vulnerability scanning using Aqua Trivy for identifying CVE vulnerabilities in dependencies, container images, IaC misconfigurations, and license compliance risks. Use when: (1) Scanning container images and filesystems for vulnerabilities and misconfigurations, (2) Analyzing dependencies for known CVEs across multiple languages (Go, Python, Node.js, Java, etc.), (3) Detecting IaC security issues in Terraform, Kubernetes, Dockerfile, (4) Integrating vulnerability scanning into CI/CD pipelines with SARIF output, (5) Generating Software Bill of Materials (SBOM) in CycloneDX or SPDX format, (6) Prioritizing remediation by CVSS score and exploitability.

12

security-automation

Ed1s0nZ

安全自动化的专业技能和方法论

12

sca-setup

robertsinfosec

SCA scanning setup workflow. Use when adding software composition analysis to a repository, configuring Dependabot, setting up npm audit in CI, or when a repo is missing dependency vulnerability scanning. Produces working Dependabot config and CI checks.

00

go-vuln-remediate

infobloxopen

Run Wiz-based vulnerability scan and automatic Go module remediation for containerized Go services in the konk repository. Use when you need to build images, scan CVEs, patch vulnerable dependencies in go.mod/go.sum across konk-service and konk-provision modules, validate builds, and prepare a PR su

00

Search skills

Search the agent skills registry