Flowtriq/ftagent
GitHub: Flowtriq/ftagent
一款面向 Linux 服务器的轻量级 DDoS 检测 Agent,集成流量监控、攻击识别、PCAP 取证和自动缓解功能。
Stars: 3 | Forks: 0
# ftagent
**Flowtriq DDoS Detection Agent** 针对 Linux 服务器的实时流量监控、攻击检测、PCAP 捕获和自动缓解。
需要有效的 [Flowtriq](https://flowtriq.com) 账户和 API key。在 **[flowtriq.com](https://flowtriq.com)** 开始免费 7 天试用。
## 系统要求
- Linux (Ubuntu 20.04+, Debian 11+, CentOS 8+, 或同等版本)
- Python 3.8+
- Root / sudo (原始数据包捕获需要)
- Flowtriq 账户 — [免费注册](https://flowtriq.com/signup)
## 安装
### pip (推荐)
```
pip install ftagent[full]
```
`[full]` 额外选项会安装所有依赖,包括用于数据包捕获的 `scapy` 和用于系统指标的 `psutil`。
### 从源码安装
```
git clone https://github.com/flowtriq/ftagent.git
cd ftagent
pip install -e .[full]
```
## 快速开始
最快上手的方式是使用内置的设置向导和服务安装程序。无需手动编辑配置。
### 1. 获取您的 API key
登录您的 [Flowtriq 仪表板](https://flowtriq.com/dashboard) → **Nodes** → **Add Node** → 复制显示的 API key 和 Node UUID。
### 2. 运行设置向导
```
sudo ftagent --setup
```
这将创建 `/etc/ftagent/config.json`,包含您的 API key、Node UUID 和合理的默认值。它会逐项提示您输入值。
### 3. 安装为服务
```
sudo ftagent --install-service
sudo systemctl enable --now ftagent
```
就这样。Agent 将注册您的节点,建立基线,并开始监控。您的节点将在 30 秒内出现在 Flowtriq 仪表板中。
### 手动配置 (替代方案)
如果您更喜欢手动创建配置:
```
sudo mkdir -p /etc/ftagent
sudo cp packaging/config.example.json /etc/ftagent/config.json
sudo nano /etc/ftagent/config.json
```
将 `api_key` 和 `node_uuid` 设置为您 Flowtriq 仪表板中的值。
### 验证连接
```
sudo ftagent --test
```
这将发送一个测试心跳,以确认 Agent 可以访问 Flowtriq API。
### 检查服务状态
```
sudo systemctl status ftagent
sudo journalctl -u ftagent -f
```
## 配置参考
配置文件:`/etc/ftagent/config.json`
| 键 | 默认值 | 描述 |
|---|---|---|
| `api_key` | — | **必填。** 您的 Flowtriq 节点 API key |
| `node_uuid` | — | **必填。** 来自您的 Flowtriq 仪表板 → Nodes 的 Node UUID |
| `api_base` | `https://flowtriq.com/api/v1` | API endpoint |
| `interface` | `"auto"` | 要监控的网络接口 (`eth0`, `ens3` 等) 或 `"auto"` |
| `pcap_enabled` | `true` | 在事件期间启用 PCAP 捕获 |
| `pcap_dir` | `/var/lib/ftagent/pcaps` | PCAP 文件的目录 |
| `pcap_max_packets` | `10000` | 每个 PCAP 文件的最大数据包数 |
| `pcap_max_seconds` | `60` | 每个 PCAP 文件的最大秒数 |
| `pcap_retention_days` | `7` | 删除超过 N 天的 PCAP |
| `log_file` | `/var/log/ftagent.log` | 日志文件路径 |
| `log_level` | `"INFO"` | 日志级别:`DEBUG`, `INFO`, `WARNING`, `ERROR` |
| `dynamic_threshold` | `true` | 根据流量基线自动调整检测阈值 |
| `baseline_window_minutes` | `60` | 用于基线计算的滚动窗口 |
| `threshold_multiplier` | `3.0` | 当 PPS 超过 `baseline × multiplier` 时告警 |
| `heartbeat_interval` | `30` | 心跳 ping 之间的秒数 |
| `metrics_interval` | `10` | 指标报告之间的秒数 |
## CLI 标志
```
sudo ftagent [options]
--setup Interactive setup wizard (creates config)
--install-service Install systemd service unit
--config PATH Config file path (default: /etc/ftagent/config.json)
--test Test API connectivity and exit
--version Show version
```
## 工作原理
1. **基线**:Agent 收集流量指标,并为节点建立正常的 PPS/BPS 范围。
2. **L3/L4 检测**:每个指标窗口都与基线进行比较。如果 PPS 超过 `baseline x multiplier`,则会开启一个事件。
3. **L7 检测**:启用后,Agent 会追踪您的 Web 服务器访问日志 (nginx, Apache, Caddy, LiteSpeed, HAProxy),并通过请求速率激增、IP 集中度、endpoint 定向和错误率分析来检测 HTTP flood。
4. **分类**:攻击流量通过协议分布、TCP flags、端口模式、数据包大小和 IP 熵进行分类。
5. **PCAP**:当事件开启时,立即开始数据包捕获,为您提供用于分析取证的数据。
6. **上报**:事件被上报给 Flowtriq,后者将告警分发到您配置的通道 (Discord, Slack, Teams, PagerDuty 等)。
7. **缓解**:如果您配置了缓解规则,Agent 会立即执行批准的防火墙命令 (iptables, Cloudflare WAF 等)。
8. **解决**:当流量恢复到基线时,事件关闭,撤销命令运行,并上传 PCAP。
## 文档
完整文档:[flowtriq.com/docs](https://flowtriq.com/docs)
## 支持
- 文档:[flowtriq.com/docs](https://flowtriq.com/docs)
- 问题:[github.com/flowtriq/ftagent/issues](https://github.com/flowtriq/ftagent/issues)
- 邮箱:[hello@flowtriq.com](mailto:hello@flowtriq.com)
标签:DDoS检测, Linux服务器安全, Mitigation, NIDS, PCAP抓包, Python, Scapy, TLS, 子域名枚举, 安全代理, 容器化, 抗D, 无后门, 流量基线, 流量清洗, 流量监控, 系统安全, 网络安全, 自动缓解, 请求响应过滤, 逆向工具, 配置错误, 防御工具, 隐私保护