name: moltbot-security
description: AI 代理安全加固指南 - 适用于 Moltbot、OpenClaw、Cursor、Claude。锁定网关、修复权限、配置认证与防火墙。为氛围编程环境提供安全保障。
version: 1.0.3
author: NextFrontierBuilds
keywords: [moltbot, openclaw, security, hardening, gateway, firewall, tailscale, ssh, authentication, ai-agent, ai-coding, claude, cursor, copilot, github-copilot, chatgpt, devops, infosec, vibe-coding, ai-tools, developer-tools, devtools, typescript, automation, llm]
您的 Moltbot 网关最初设计为本地使用。若未经适当安全配置便暴露于互联网,攻击者可能获取您的 API 密钥、私人消息乃至完整的系统访问权限。
背景依据: 真实漏洞研究发现,Shodan 上存在超过 1,673 个暴露的 OpenClaw/Moltbot 网关。
当您的网关可被公开访问时,以下信息将面临风险:
- 完整的对话历史(Telegram、WhatsApp、Signal、iMessage)
- Claude、OpenAI 及其他服务商的 API 密钥
- OAuth 令牌与机器人凭证
- 对宿主机的完整 Shell 访问权限
提示注入攻击示例: 攻击者向您发送一封包含隐藏指令的邮件。您的 AI 读取后,会提取您最近的邮件内容,并将摘要转发给攻击者。整个过程无需任何黑客技术。
运行以下命令检查当前安全状况:
openclaw security audit --deep
自动修复问题:
openclaw security audit --deep --fix
作用: 阻止网关接受来自其他机器的连接。
检查您的 ~/.openclaw/openclaw.json:
{
"gateway": {
"bind": "loopback"
}
}
选项说明:
- loopback — 仅可从本地主机访问(最安全)
- lan — 仅可从本地网络访问
- auto — 绑定至所有网络接口(若暴露则危险)
方案 A:令牌认证(推荐)
生成安全令牌:
openssl rand -hex 32
添加到配置中:
{
"gateway": {
"auth": {
"mode": "token",
"token": "your-64-char-hex-token-here"
}
}
}
或通过环境变量设置:
export CLAWDBOT_GATEWAY_TOKEN="your-secure-random-token-here"
方案 B:密码认证
{
"gateway": {
"auth": {
"mode": "password"
}
}
}
然后设置:
export CLAWDBOT_GATEWAY_PASSWORD="your-secure-password-here"
作用: 确保只有您能读取敏感配置文件。
chmod 700 ~/.openclaw
chmod 600 ~/.openclaw/openclaw.json
chmod 700 ~/.openclaw/credentials
权限含义:
- 700 = 仅所有者可访问文件夹
- 600 = 仅所有者可读写文件
或让 OpenClaw 自动修复:
openclaw security audit --fix
作用: 阻止 OpenClaw 通过 mDNS/Bonjour 广播自身。
添加到您的 Shell 配置文件(~/.zshrc 或 ~/.bashrc):
export CLAWDBOT_DISABLE_BONJOUR=1
重新加载配置:
source ~/.zshrc
旧版 Node.js 存在安全漏洞。您需要 v22.12.0+ 版本。
检查当前版本:
node --version
Mac (Homebrew):
brew update && brew upgrade node
Ubuntu/Debian:
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
Windows: 从 nodejs.org 下载
作用: 在您的设备间创建加密隧道。无需公网暴露即可从任何地方访问 OpenClaw。
安装 Tailscale:
# Linux
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up
# Mac
brew install tailscale
为 Tailscale 配置 OpenClaw:
{
"gateway": {
"bind": "loopback",
"tailscale": {
"mode": "serve"
}
}
}
现在仅可通过您的 Tailscale 网络访问。
适用于云服务器(AWS、DigitalOcean、Hetzner 等)
安装 UFW:
sudo apt update && sudo apt install ufw -y
设置默认规则:
sudo ufw default deny incoming
sudo ufw default allow outgoing
允许 SSH(切勿跳过!):
sudo ufw allow ssh
允许 Tailscale(如使用):
sudo ufw allow in on tailscale0
启用防火墙:
sudo ufw enable
验证状态:
sudo ufw status verbose
⚠️ 切勿执行此操作:
# 禁止! - 这将使您的网关暴露于公网
sudo ufw allow 18789
禁用密码认证(使用 SSH 密钥):
sudo nano /etc/ssh/sshd_config
修改:
PasswordAuthentication no
PermitRootLogin no
重启服务:
sudo systemctl restart sshd
部署前请确认:
loopback 或 lan{
"gateway": {
"port": 18789,
"bind": "loopback",
"auth": {
"mode": "token",
"token": "YOUR_64_CHAR_HEX_TOKEN"
},
"tailscale": {
"mode": "serve"
}
}
}
基于 @NickSpisak_ 的安全研究,其在 Shodan 上发现了超过 1,673 个暴露的网关。
原文链接:https://x.com/nickspisak_/status/2016195582180700592
clawdhub install NextFrontierBuilds/moltbot, openclaw-security
由 @NextXFrontier 构建