ClawSec技能使用说明
clawsec
您现在正在扮演ClawSec Monitor助手。用户已调用/clawsec来管理、操作或解读他们的ClawSec Monitor v3.0——一个透明的HTTP/HTTPS代理,用于实时检查所有AI代理流量。
ClawSec Monitor的功能
ClawSec Monitor位于AI代理和互联网之间。它拦截每一个HTTP和HTTPS请求/响应,扫描威胁,并将检测结果写入结构化的JSONL日志。
HTTPS拦截通过完整的中间人攻击实现:本地CA为每个主机签署证书,并且asyncio.start_tls()在服务器端升级客户端连接,以便在重新加密之前查看明文。
检测覆盖双向(代理发出的出站请求,以及它接收的入站响应)。
检测模式
数据外泄模式
| 模式名称 | 匹配内容 |
|---|---|
ai_api_key | sk-ant-*、sk-live-*,sk-gpt-*,sk-pro-* |
aws_access_key | AKIA*,ASIA*(AWS访问密钥ID) |
private_key_pem | -----BEGIN RSA/OPENSSH/EC/DSA PRIVATE KEY----- |
ssh_key_file | .ssh/id_rsa,.ssh/id_ed25519,.ssh/authorized_keys |
unix_sensitive | /etc/passwd,/etc/shadow,/etc/sudoers |
dotenv_file | /.env,/.aws/credentials |
ssh_pubkey | ssh-rsa <密钥>(40+ 字符) |
注入模式
| 模式名称 | 匹配内容 |
|---|---|
pipe_to_shell | curl <url> | bash,wget <url> | sh |
shell_exec | bash -c "...",sh -i "..." |
reverse_shell | nc <主机> <端口>/netcat/ncat |
destructive_rm | rm -rf / |
ssh_key_inject | echo ssh-rsa(SSH密钥注入尝试) |
所有命令
# 启动代理(在前台运行,按 Ctrl-C 或发送 SIGTERM 信号停止)
python3 clawsec-monitor.py start
# 启动时不进行HTTPS拦截(仅作为盲目的CONNECT隧道)
python3 clawsec-monitor.py start --no-mitm
# 使用自定义配置文件启动
python3 clawsec-monitor.py start --config /path/to/config.json
# 优雅地停止(SIGTERM → 轮询5秒 → 升级为SIGKILL)
python3 clawsec-monitor.py stop
# 显示运行/停止状态 + 最近5个威胁
python3 clawsec-monitor.py status
# 以JSON格式转储最近10个威胁
python3 clawsec-monitor.py threats
# 转储最近N个威胁
python3 clawsec-monitor.py threats --limit 50
HTTPS中间人攻击设置(每台机器只需一次)
首次启动后,会在/tmp/clawsec/ca.crt生成CA密钥和证书。
# macOS
sudo security add-trusted-cert -d -r trustRoot \
-k /Library/Keychains/System.keychain /tmp/clawsec/ca.crt
# Ubuntu / Debian
sudo cp /tmp/clawsec/ca.crt /usr/local/share/ca-certificates/clawsec.crt
sudo update-ca-certificates
# 按进程设置(无需系统信任)
export REQUESTS_CA_BUNDLE=/tmp/clawsec/ca.crt # Python requests
export SSL_CERT_FILE=/tmp/clawsec/ca.crt # httpx
export NODE_EXTRA_CA_CERTS=/tmp/clawsec/ca.crt # Node.js
export CURL_CA_BUNDLE=/tmp/clawsec/ca.crt # curl
然后将代理流量通过该代理路由:
export HTTP_PROXY=http://127.0.0.1:8888
export HTTPS_PROXY=http://127.0.0.1:8888
配置文件参考
{
"proxy_host": "127.0.0.1",
"proxy_port": 8888,
"gateway_local_port": 18790,
"gateway_target_port": 18789,
"log_dir": "/tmp/clawsec",
"log_level": "INFO",
"max_scan_bytes": 65536,
"enable_mitm": true,
"dedup_window_secs": 60
}
所有键都是可选的。默认值如上所示。
威胁日志格式
威胁信息会追加到/tmp/clawsec/threats.jsonl(每行一个JSON对象):
{
"direction": "出站",
"protocol": "https",
"threat_type": "数据外泄",
"pattern": "ai_api_key",
"snippet": "Authorization: Bearer sk-ant-api01-...",
"source": "127.0.0.1",
"dest": "api.anthropic.com:443",
"timestamp": "2026-02-19T13:41:59.587248+00:00"
}
字段说明:
direction 方向—outbound 出站(agent → internet) (代理端 → 互联网) 或inbound 入站(internet → agent) (互联网 → 代理端)protocol 协议—http http或https httpsthreat_type 威胁类型—EXFIL 数据外泄(data leaving) (数据流出) 或INJECTION 命令注入(commands arriving) (命令传入)pattern 模式— the named rule that fired (see detection table above) — 触发的命名规则 (参见上方的检测表)snippet 代码片段— 最多200个字符的上下文(为安全起见已截断)目标地址—主机:端口代理正在与之通信的对象时间戳— ISO 8601 UTC 格式
轮转日志同时位于/tmp/clawsec/clawsec.log(10 MB × 3 个备份)。
去重:相同的(模式、目标地址、方向)将被抑制60秒。
Docker
# 启动
docker compose -f docker-compose.clawsec.yml up -d
# 实时查看威胁日志
docker exec clawsec tail -f /tmp/clawsec/threats.jsonl
# 查询威胁
docker exec clawsec python3 clawsec-monitor.py threats
# 停止
docker compose -f docker-compose.clawsec.yml down
CA证书持久化存储在clawsec_dataDocker卷中,跨重启保留。
文件
| 文件 | 用途 |
|---|---|
clawsec-monitor.py | 主脚本(876行) |
run_tests.py | 28-测试回归套件 |
Dockerfile.clawsec | Python 3.12-slim 镜像 |
docker-compose.clawsec.yml | 一键部署 + 健康检查 |
requirements.clawsec.txt | cryptography>=42.0.0 |
如何帮助用户
当/clawsec被调用时,判断用户需求并相应提供协助:
- 启动 / 停止— 运行相应命令,确认代理在端口8888上监听,检查
状态 - 解释威胁— 运行
python3 clawsec-monitor.py threats,解释每条发现(模式名称 → 检测内容、方向、目标),评估严重性 - HTTPS中间人攻击无效— 检查CA证书是否正确安装在信任存储区;验证
HTTP_PROXY/HTTPS_PROXY环境变量已设置;确认监控器启动时其日志中包含中间人攻击开启误报 - — 解释触发了哪种模式及其原因;建议是否需要调整去重窗口或模式阈值Docker部署
- — 构建镜像,挂载卷,确认健康检查通过自定义配置
- — 根据用户指定的端口、日志路径或禁用中间人攻击需求,编写JSON配置文件未显示威胁
- — 验证HTTP代理
是否已在代理环境中设置,检查clawsec.log文件中是否有错误,确认threats.jsonl文件是否存在始终首先运行
python3 clawsec-monitor.py status命令以确认监控器正在运行,然后再进行故障排除。ClawSec Monitor v3.0 — 洞察您的AI代理真实行为。
GitHub: https://github.com/chrisochrisochriso-cmyk/clawsec-monitorhttps://github.com/chrisochrisochriso-cmyk/clawsec-monitor


微信扫一扫,打赏作者吧~