针对 Clawdbot/Moltbot 安装实例的安全加固工具,可检测并修复暴露的网关。
检测并修复暴露的 Clawdbot/Moltbot 网关
问题 • 功能 • 快速开始 • Docker • 命令行 • 修复内容 • 开发
目前有 900 多个 Clawdbot/Moltbot 实例暴露在互联网上(可在 Shodan 上看到,端口 18789),且没有任何身份验证。这使得任何人都可以:
问题并非 bug,而是配置不当。用户将 gateway.bind 改为 0.0.0.0 或使用 Docker 的 -p 18789:18789 且未设置合适的身份验证时,便会完全暴露。
ClawdGuard 可以解决这个问题。
cargo install clawdguard
# 运行
clawdguard
# 克隆仓库
git clone https://github.com/fadidevv/clawdguard.git
cd clawdguard
# 构建(首次约需 2 分钟)
cargo build --release
# 运行
./target/release/clawdguard
# 克隆仓库
git clone https://github.com/fadidevv/clawdguard.git
cd clawdguard
# 构建镜像(首次约需 3-5 分钟)
docker build --no-cache -t clawdguard .
# 运行(挂载您的配置目录)
docker run -v ~/.moltbot:/root/.moltbot clawdguard
# 或用于旧版 Clawdbot:
docker run -v ~/.clawdbot:/root/.clawdbot clawdguard
clawdguard
就这么简单!ClawdGuard 将:
ClawdGuard 会生成一个安全令牌。请保存好它!
╭────────────────────────────────────────────────────────────────────╮
│ ⚠️ 重要提示:请保存您的新网关令牌! │
│ │
│ clwd_a8f2k9x3m1p7v4q2b6n8... │
│ │
│ 您将需要此令牌从控制界面或 CLI 进行连接。 │
╰────────────────────────────────────────────────────────────────────╯
针对未安装 Rust 用户的完整 Docker 文档。
# 1. 克隆仓库
git clone https://github.com/fadidevv/clawdguard.git
cd clawdguard
# 2. 构建镜像(首次约需 3-5 分钟)
docker build --no-cache -t clawdguard .
# 3. 运行扫描(挂载您的配置目录)
# 用于 Moltbot(较新版本):
docker run -v ~/.moltbot:/root/.moltbot clawdguard
# 用于 Clawdbot(旧版):
docker run -v ~/.clawdbot:/root/.clawdbot clawdguard
# 使用详细模式
docker run -v ~/.moltbot:/root/.moltbot clawdguard --verbose
# 仅扫描(不修复)
docker run -v ~/.moltbot:/root/.moltbot clawdguard --scan-only
# 自动模式(无交互提示)
docker run -v ~/.moltbot:/root/.moltbot clawdguard --auto
# 显示帮助
docker run clawdguard --help
使用 docker-compose 简化语法:
# 使用 docker-compose 运行
docker-compose run clawdguard
# 带详细模式
docker-compose run clawdguard --verbose
# 仅扫描
docker-compose run clawdguard --scan-only
# 自动模式
docker-compose run clawdguard --auto
| 挂载点 | 用途 |
|---|---|
~/.moltbot:/root/.moltbot | 您的 Moltbot 配置目录(较新版本) |
~/.clawdbot:/root/.clawdbot | 您的 Clawdbot 配置目录(旧版) |
./results:/app/results | 将结果保存到本地 |
# 创建别名以便使用(请使用您自己的配置目录)
alias clawdguard='docker run -v ~/.moltbot:/root/.moltbot clawdguard'
# 或用于旧版 Clawdbot:
alias clawdguard='docker run -v ~/.clawdbot:/root/.clawdbot clawdguard'
# 然后直接运行:
clawdguard
clawdguard --scan-only
clawdguard --verbose
clawdguard [选项]
选项:
--scan-only 仅扫描问题,不应用修复
--auto 自动应用所有修复,无需确认提示
--backup-dir <目录> 备份文件的自定义目录
--skip-firewall 跳过添加防火墙规则
--skip-restart 跳过重启网关服务
--token <令牌> 使用特定令牌而非生成
-v, --verbose 显示详细输出
--json 以 JSON 格式输出结果(适用于脚本)
-h, --help 打印帮助
-V, --version 打印版本
# 基本用法 - 扫描、修复、验证
clawdguard
# 仅扫描(不修复任何内容)
clawdguard --scan-only
# 自动修复所有内容(无提示)
clawdguard --auto
# 使用您自己的令牌
clawdguard --token "my-secure-token-here"
# 故障排除时使用详细输出
clawdguard --verbose
# 脚本中使用 JSON 输出
clawdguard --json
# 组合选项
clawdguard --auto --skip-firewall --verbose
# 自定义备份目录
clawdguard --backup-dir /tmp/backups
ClawdGuard 计算 0-10 分的风险评分:
| 分数 | 等级 | 含义 |
|---|---|---|
| 0-3 | 🟢 低 | 小问题或已安全 |
| 4-6 | 🟡 中 | 存在一些安全问题 |
| 7-10 | 🔴 严重 | 已暴露到互联网,立即修复 |
风险评分计算规则:
🦞 ClawdGuard
Security hardening for Clawdbot/Moltbot
v1.0.0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ 随时可按 Ctrl+C 取消
[1/4] 🔍 检测安装...
✓ 配置文件: ~/.clawdbot/clawdbot.json
✓ 服务: bot.molt.gateway (运行中,PID 1234)
✓ 端口 18789 活跃
[2/4] ⚠️ 分析安全风险...
╭──────────────────┬─────────────────────────┬──────────╮
│ 问题 │ 当前值 │ 严重程度 │
├──────────────────┼─────────────────────────┼──────────┤
│ 网关绑定 │ 0.0.0.0 │ 严重 │
│ 身份验证 │ none │ 严重 │
│ mDNS 广播 │ full │ 中等 │
╰──────────────────┴─────────────────────────┴──────────╯
风险评分: 9/10 🔴 严重
⚠ 这将会修改您的配置文件以修复安全问题。
ℹ 任何更改前都会创建备份。
执行修复? [y/N]: y
[3/4] 🔧 应用修复...
✓ 备份: ~/.clawdbot/clawdbot.json.backup.20260128_143022
✓ 设置 gateway.bind = "loopback" (原值: "0.0.0.0")
✓ 设置 gateway.auth.mode = "token" (原值: "none")
✓ 设置 gateway.auth.token = <已生成>
✓ 修复文件权限 (600)
已生成令牌: clwd_a8f2k9x3m1p7v4q2b6n8...
[4/4] ✅ 验证修复...
✓ 网关服务已重启
✓ 端口 18789 已无法从外部访问
✓ 网关在 localhost 上正常响应
✓ 现在需要身份验证
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
╭────────────────────────────────────────────────────────────────────╮
│ │
│ 🎉 成功!您的 Clawdbot/Moltbot 现已安全。 │
│ │
╰────────────────────────────────────────────────────────────────────╯
clawdguard --json
{"status": "fixed", "token": "clwd_a8f2k9x3m1p7v4q2b6n8...", "backup": "~/.clawdbot/clawdbot.json.backup.20260128_143022"}
扫描过程中,随时按 Ctrl+C 安全停止。
[2/4] ⚠️ 分析安全风险...
^C
⚠ 已中断!正在退出...
在您确认之前不会进行任何更改,因此随时中断都是安全的。
# 添加到您的 shell 配置文件 (~/.bashrc, ~/.zshrc 等)
export CLAWDBOT_GATEWAY_TOKEN="clwd_your_token_here"
如果需要远程访问,请使用以下安全方法之一:
| 方法 | 命令 |
|---|---|
| Tailscale(推荐) | tailscale serve --bg 18789 |
| SSH 隧道 | ssh -L 18789:localhost:18789 your-server |
| Cloudflare Tunnel | cloudflared tunnel --url http://localhost:18789 |
切勿将 gateway.bind 改回 0.0.0.0 或直接暴露端口。
请确保:
~/.moltbot/ 或 ~/.clawdbot/ 目录)~/.moltbot/moltbot.json 或 ~/.clawdbot/clawdbot.json请尝试手动重启:
clawdbot gateway restart
# 或
moltbot gateway restart
clwd_ 前缀)请确保您的配置目录可读:
# 用于 Moltbot(较新版本)
chmod 755 ~/.moltbot
chmod 644 ~/.moltbot/moltbot.json
# 用于 Clawdbot(旧版)
chmod 755 ~/.clawdbot
chmod 644 ~/.clawdbot/clawdbot.json
| 平台 | 状态 | 服务管理器 |
|---|---|---|
| macOS | ✅ 完整支持 | launchd |
| Linux | ✅ 完整支持 | systemd(用户) |
| Windows | ⚠️ WSL2 | 在 WSL2 内运行 |
┌─────────────────────────────────────────────────────────────────┐
│ ClawdGuard v1.0 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ 检测 │ → │ 分析 │ → │ 修补 │ → │ 验证 │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
│ │ │ │ │ │
│ ▼ ▼ ▼ ▼ │
│ 查找配置文件 检查风险 修复配置 确认安全 │
│ 查找服务 评估危险 生成令牌 测试端口 │
│ 查找进程 列出问题 修复权限 重启服务 │
│ │
└─────────────────────────────────────────────────────────────────┘
clawdguard/
├── Cargo.toml # 依赖项
├── Dockerfile # Docker 构建
├── docker-compose.yml # Docker Compose
├── .dockerignore
├── README.md
├── LICENSE
├── .gitignore
├── assets/
│ └── screenshot.png # README 截图
├── src/
│ ├── main.rs # CLI 入口
│ ├── lib.rs # 库根模块
│ ├── detect/ # 安装检测
│ │ ├── mod.rs
│ │ ├── config.rs # 配置文件检测
│ │ ├── process.rs # 进程检测
│ │ └── service.rs # 服务检测 (launchd/systemd)
│ ├── analyze/ # 安全分析
│ │ ├── mod.rs
│ │ ├── config_risk.rs
│ │ ├── network.rs # 端口暴露检测
│ │ └── permissions.rs
│ ├── patch/ # 配置修补
│ │ ├── mod.rs
│ │ ├── config.rs
│ │ ├── firewall.rs
│ │ └── token.rs # 安全令牌生成
│ ├── verify/ # 修复验证
│ │ ├── mod.rs
│ │ ├── port_check.rs
│ │ └── service.rs
│ └── output/
│ ├── mod.rs
│ └── printer.rs # 彩色 CLI 输出
└── tests/
└── integration.rs
方式 A:原生(Rust)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh)方式 B:Docker
原生:
# 克隆仓库
git clone https://github.com/fadidevv/clawdguard.git
cd clawdguard
# 构建调试版(编译更快)
cargo build
# 构建发布版(优化)
cargo build --release
Docker:
# 克隆仓库
git clone https://github.com/fadidevv/clawdguard.git
cd clawdguard
# 构建镜像
docker build --no-cache -t clawdguard .
# 运行所有测试
cargo test
# 带输出运行
cargo test -- --nocapture
# 格式化代码
cargo fmt
# 运行 linter
cargo clippy
# 检查而不构建
cargo check
欢迎贡献!请按以下步骤操作:
git checkout -b feature/improvement)cargo test)cargo clippy)cargo fmt)git commit -m '添加改进')git push origin feature/improvement)贡献思路:
本工具仅用于安全目的。
作者不对滥用本工具承担任何责任。
MIT 许可证 - 请参见 LICENSE 文件了解详情。
保持安全!🦞🔐
| 风险 |
|---|
| 影响 |
|---|
| 获取 API 密钥 | 窃取 OpenAI、Anthropic 等凭据 |
| 执行命令 | 在您的机器上运行任意 shell 命令 |
| 控制浏览器 | 接管您的浏览会话 |
| 读取邮件 | 访问 Gmail、日历、联系人 |
| 读取聊天记录 | 查看您的所有聊天历史 |
| 劫持机器人 | 以您的名义发送消息 |
| 命令 | 描述 |
|---|
docker build --no-cache -t clawdguard . | 构建镜像 |
docker run clawdguard --help | 显示帮助 |
docker run -v ... clawdguard | 运行扫描 |
docker run -v ... clawdguard --scan-only | 仅扫描 |
docker run -v ... clawdguard --auto | 自动修复 |
docker run -v ... clawdguard --verbose | 详细模式 |
docker-compose run clawdguard | 使用 compose 运行 |
| 设置项 | 修复前(不安全) | 修复后(安全) |
|---|
gateway.bind | "0.0.0.0" / "lan" / "all" | "loopback" |
gateway.auth.mode | "none" / 缺失 | "token" |
gateway.auth.token | 缺失 | 已生成安全令牌 |
discovery.mdns.mode | "full" | "minimal" |
| 文件权限 | 644 / 755 | 600 |