1bnBattuta/Lodestone
GitHub: 1bnBattuta/Lodestone
一款基于 C 语言的高性能网络数据包捕获与分析工具,通过零拷贝技术和多协议解析实现高线速流量监控与实时异常检测。
Stars: 1 | Forks: 0
# Lodestone
[](https://www.gnu.org/licenses/gpl-3.0)
[]()
[]()
[]()
一个使用 C 语言为 Linux 系统编写的、功能丰富且高性能的网络数据包捕获与分析工具。
## 功能
### 核心能力
- **高性能捕获**
- 标准 AF_PACKET 原始套接字捕获
- 内存映射 (mmap) 零拷贝捕获,实现极致性能 (10Gbps+)
- 大容量内核缓冲区,防止数据包丢失
- 多线程架构
- **协议支持**
- **二层**: Ethernet, ARP
- **三层**: IPv4, IPv6 (包含扩展头部)
- **四层**: TCP, UDP, ICMP, ICMPv6
- **应用层**: DNS, HTTP 检测
- **高级分析**
- TCP 流重组与追踪
- 实时异常检测 (端口扫描、SYN 洪泛、ARP 欺骗)
- 连接追踪与流分析
- 协议统计与活跃主机 (top talkers) 排名
- **灵活输出**
- 带颜色的实时终端显示 (简要、详细、十六进制、完整模式)
- PCAP 格式 (兼容 Wireshark)
- 多种日志格式 (Text, CSV, JSON, XML)
- 实时统计信息
- **强大的过滤功能**
- 支持 BPF (Berkeley Packet Filter)
- 复杂的过滤条件组合
## 目录
- [环境要求](#requirements)
- [安装说明](#installation)
- [快速开始](#quick-start)
- [使用说明](#usage)
- [过滤器示例](#filter-examples)
- [架构](#architecture)
- [贡献指南](#contributing)
- [许可证](#license)
- [作者](#authors)
## 环境要求
### 系统要求
- **操作系统**: Linux (内核 2.6.27 或更高版本)
- **架构**: x86_64, ARM64 (任何受 Linux 支持的架构)
- **内存**: 最低 512MB (对于高流量捕获,建议 2GB+)
- **权限**: Root 权限 (用于原始套接字操作)
### 软件依赖
- **GCC**: 7.0 或更高版本
- **Make**: GNU Make 3.81+
- **libpcap**: 1.9.0+ (libpcap-dev)
- **libc**: glibc 2.17+ 或 musl
### 测试环境
- Arch Linux (最新版)
## 安装说明
### 从源码构建
#### Arch Linux
```
# 安装 dependencies
sudo pacman -S base-devel libpcap git
# Clone 和 build
git clone https://github.com/1bnBattuta/Lodestone.git
cd Lodestone
make
sudo make install
```
### 构建选项
```
# 标准优化 build
make
# Debug build(带 symbols,无优化)
make debug
# 启用 checksum validation 的 build
make checksums
# 清理 build artifacts
make clean
# 卸载
sudo make uninstall
```
## 快速开始
```
# 基本 packet capture
sudo ./bin/Lodestone -i eth0
# 捕获 100 个 packets
sudo ./bin/Lodestone -i eth0 -c 100
# 捕获 HTTP 流量
sudo ./bin/Lodestone -i eth0 -f "tcp port 80"
# 保存到 PCAP 文件
sudo ./bin/Lodestone -i eth0 -o capture.pcap
# 带统计的详细分析
sudo ./bin/Lodestone -i eth0 -c 1000 -s -d detailed
```
## 使用说明
### 命令行选项
```
Usage: Lodestone [OPTIONS]
Capture Options:
-i, --interface Network interface (required)
-c, --count Capture N packets then stop
-f, --filter BPF filter expression
-p, --promiscuous Enable promiscuous mode (default)
-P, --no-promiscuous Disable promiscuous mode
-m, --mmap Use zero-copy mmap capture
Output Options:
-o, --output Save packets to PCAP file
-l, --log Log packets to file
-F, --log-format Log format: text, csv, json, xml
-d, --display Display: brief, detailed, hex, full
-C, --no-color Disable colored output
-q, --quiet Quiet mode (no display)
-v, --verbose Verbose output
Analysis Options:
-r, --reassemble Enable TCP stream reassembly
-a, --detect-anomalies Enable anomaly detection
-A, --show-alerts Show security alerts
-s, --stats Show detailed statistics
Other:
-h, --help Show help message
```
### 示例
#### 基础捕获
```
# 捕获所有流量
sudo ./bin/Lodestone -i eth0
# 捕获 1000 个 packets 并进行统计
sudo ./bin/Lodestone -i eth0 -c 1000 -s
# 静默捕获到文件
sudo ./bin/Lodestone -i eth0 -q -o capture.pcap
```
#### 特定协议
```
# HTTP 流量
sudo ./bin/Lodestone -i eth0 -f "tcp port 80" -d detailed
# HTTPS 流量
sudo ./bin/Lodestone -i eth0 -f "tcp port 443"
# DNS 查询
sudo ./bin/Lodestone -i eth0 -f "udp port 53"
# SSH 连接
sudo ./bin/Lodestone -i eth0 -f "tcp port 22"
# ICMP (ping)
sudo ./bin/Lodestone -i eth0 -f "icmp"
```
#### IPv6
```
# 所有 IPv6 流量
sudo ./bin/Lodestone -i eth0 -f "ip6"
# IPv6 HTTP
sudo ./bin/Lodestone -i eth0 -f "ip6 and tcp port 80"
# ICMPv6
sudo ./bin/Lodestone -i eth0 -f "icmp6"
```
#### 高级分析
```
# TCP 流重组
sudo ./bin/Lodestone -i eth0 -f "tcp port 80" -r -v
# 异常检测
sudo ./bin/Lodestone -i eth0 -a -A
# 完整安全分析
sudo ./bin/Lodestone-i eth0 -r -a -A -s -o security.pcap
# 高性能捕获
sudo ./bin/Lodestone -i eth0 -m -q -o highspeed.pcap
```
#### 日志记录
```
# 记录到 CSV
sudo ./bin/Lodestone -i eth0 -l packets.csv -F csv
# 记录到 JSON
sudo ./bin/Lodestone -i eth0 -l packets.json -F json
# 将 DNS 记录到 JSON
sudo ./bin/Lodestone -i eth0 -f "port 53" -l dns.json -F json -q
```
## 过滤器示例
### 基础过滤器
```
# Protocol 过滤器
sudo ./bin/Lodestone -i eth0 -f "tcp"
sudo ./bin/Lodestone -i eth0 -f "udp"
sudo ./bin/Lodestone -i eth0 -f "icmp"
# Port 过滤器
sudo ./bin/Lodestone -i eth0 -f "port 80"
sudo ./bin/Lodestone -i eth0 -f "src port 443"
sudo ./bin/Lodestone -i eth0 -f "dst port 22"
# IP 地址过滤器
sudo ./bin/Lodestone -i eth0 -f "host 192.168.1.100"
sudo ./bin/Lodestone -i eth0 -f "src host 8.8.8.8"
sudo ./bin/Lodestone -i eth0 -f "net 192.168.0.0/16"
```
### 组合过滤器
```
# HTTP 或 HTTPS
sudo ./bin/Lodestone -i eth0 -f "port 80 or port 443"
# 到特定 host 的 TCP
sudo ./bin/Lodestone -i eth0 -f "tcp and host 192.168.1.100"
# 排除 SSH
sudo ./bin/Lodestone -i eth0 -f "not port 22"
# 来自 subnet 的 Web 流量
sudo ./bin/Lodestone -i eth0 -f "src net 192.168.1.0/24 and (port 80 or port 443)"
```
### 高级过滤器
```
# TCP SYN packets
sudo ./bin/Lodestone -i eth0 -f "tcp[tcpflags] & tcp-syn != 0"
# 大型 packets
sudo ./bin/Lodestone -i eth0 -f "greater 1000"
# Port 范围
sudo ./bin/Lodestone -i eth0 -f "portrange 1000-2000"
```
有关详尽的过滤器文档,请参阅 [FILTER_GUIDE.md](docs/FILTER_GUIDE.md)。
## 架构
```
┌─────────────────────────────────────────────────────────┐
│ Application Layer │
│ ┌─────────────┐ ┌──────────────┐ ┌────────────────┐ │
│ │ Display │ │ Logger │ │ Statistics │ │
│ └─────────────┘ └──────────────┘ └────────────────┘ │
└────────────────────────┬────────────────────────────────┘
│
┌────────────────────────┴────────────────────────────────┐
│ Analysis Layer │
│ ┌────────────────┐ ┌────────────────────────────────┐ │
│ │ Stream Tracker │ │ Anomaly Detector │ │
│ │ (TCP Reassembly)│ │ (Scans, Floods, Spoofing) │ │
│ └────────────────┘ └────────────────────────────────┘ │
└────────────────────────┬────────────────────────────────┘
│
┌────────────────────────┴────────────────────────────────┐
│ Parser Layer │
│ ┌──────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐│
│ │ Eth │→ │ IP │→ │IPv6 │→ │ TCP │→ │ UDP │→ │ICMP ││
│ └──────┘ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘│
└────────────────────────┬────────────────────────────────┘
│
┌────────────────────────┴────────────────────────────────┐
│ Capture Layer │
│ ┌────────────────────────┐ ┌─────────────────────────┐│
│ │ AF_PACKET Raw Socket │ │ TPACKET_V3 (mmap) ││
│ │ (Standard Capture) │ │ (Zero-Copy Capture) ││
│ └────────────────────────┘ └─────────────────────────┘│
└────────────────────────┬────────────────────────────────┘
│
┌──────┴───────┐
│ BPF Filter │
│ (Kernel) │
└──────────────┘
```
## 许可证
本项目基于 GNU General Public License v3.0 授权,并包含用于商业用途的附加条款 - 详情请参阅 [LICENSE](LICENSE) 文件。
### 商业用途
商业用途需要明确的书面许可。如需咨询授权事宜,请联系 hostilewire@proton.me。
## 作者
- **Merroun Omar** - *初始工作* - [GitHub 主页](https://github.com/1bnBattuta)
## 致谢
- Linux 内核网络栈开发者
- libpcap/tcpdump 团队
- 所有贡献者和测试人员
## 联系方式
- **问题**: [GitHub Issues](https://github.com/1bnBattuta/Lodestone/issues)
- **邮箱**: [hostilewire@proton.me]
标签:客户端加密, 目录遍历, 网络嗅探, 防御绕过