Công cụ bắt gói tin mạng mạnh mẽ và modular cho Linux với giao diện TUI real-time và hệ thống module phân tích mở rộng.
English | Tiếng Việt
- Bắt Gói Tin Real-time - Hiệu suất cao sử dụng Scapy/libpcap
- Giao Diện TUI Tương Tác - Giao diện text đẹp mắt để giám sát gói tin trực tiếp
- Tự Động Quay Vòng Theo Giờ - Tự động xoay file PCAP với cấu hình lưu trữ linh hoạt
- Hệ Thống Plugin - Kiến trúc module mở rộng cho phân tích gói tin tùy chỉnh
- Chế Độ Daemon - Chạy như systemd service để giám sát 24/7
- Bộ Giải Mã Nâng Cao - Hỗ trợ sẵn Ethernet, IPv4, IPv6, TCP, UDP, ICMP, ARP
- Tạm Dừng/Tiếp Tục - Điều khiển capture mà không mất dữ liệu
- BPF Filters - Hỗ trợ Berkeley Packet Filter để capture có mục tiêu
sudo apt update
sudo apt install git -y
sudo apt install curl -y
curl -sSL https://raw.githubusercontent.com/ntu168108/sniff/main/scripts/install.sh | sudo bashXong! Sau đó chạy:
sudo sniff- Linux OS (đã test trên Ubuntu 20.04+, Debian 11+)
- Python 3.8 trở lên
- Quyền root/sudo (cần thiết để bắt gói tin)
Phương Pháp 1: Tự Động Cài Đặt (Khuyến Nghị)
Một lệnh cài đặt Python, dependencies và SNIFF:
curl -sSL https://raw.githubusercontent.com/ntu168108/sniff/main/scripts/install.sh | sudo bashPhương Pháp 2: Cài Đặt Thủ Công với pip
# Cài từ GitHub repo
sudo pip3 install git+https://github.com/ntu168108/sniff.gitPhương Pháp 3: Clone và Cài Đặt
git clone https://github.com/ntu168108/sniff.git
cd sniff
sudo pip3 install .# Chế độ menu tương tác
sudo sniff
# Capture nhanh trên interface cụ thể
sudo sniff -i eth0
# Capture với BPF filter
sudo sniff -i eth0 -f "tcp port 80"
# Chạy như daemon
sudo sniff -i eth0 -d
# Kiểm tra trạng thái daemon
sudo sniff --status
# Dừng daemon
sudo sniff --stop
# Liệt kê các interface có sẵn
sudo sniff --list-interfacesCách dễ nhất để sử dụng SNIFF là menu tương tác:
sudo sniffMenu sẽ hiển thị:
- Quick capture trên bất kỳ interface nào
- Advanced capture với cài đặt tùy chỉnh
- Duyệt các file PCAP đã capture
- Cấu hình settings
sniff [-h] [-i INTERFACE] [-f FILTER] [-s SNAPLEN] [-p]
[-b {low,balanced,fast,max}] [-o OUTPUT] [-r RETENTION]
[-d] [--status] [--stop] [--list-interfaces]
Tùy chọn:
-i, --interface INTERFACE Interface mạng để capture
-f, --filter FILTER BPF filter (ví dụ: "tcp port 80")
-s, --snaplen SNAPLEN Độ dài capture (mặc định: 65535)
-p, --no-promisc Tắt chế độ promiscuous
-b, --buffer PROFILE Profile buffer: low, balanced, fast, max
-o, --output OUTPUT Thư mục output (mặc định: ./sniff_data)
-r, --retention DAYS Số ngày lưu file (mặc định: 7)
-d, --daemon Chạy như daemon (background)
--status Hiển thị trạng thái daemon
--stop Dừng daemon
--list-interfaces Liệt kê interfaces có sẵnGiám sát traffic web:
sudo sniff -i eth0 -f "port 80 or port 443"Capture DNS queries:
sudo sniff -i eth0 -f "port 53"Debug traffic từ host cụ thể:
sudo sniff -i eth0 -f "host 192.168.1.100"Giám sát 24/7 với daemon:
sudo sniff -i eth0 -d -b fast -r 30Để giám sát production 24/7:
# Dùng script cài đặt có sẵn
sudo ./scripts/install-service.sh eth0
# Hoặc thủ công:
sudo cp scripts/sniff.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable sniff
sudo systemctl start sniff
# Kiểm tra trạng thái
sudo systemctl status sniff
# Xem logs
sudo journalctl -u sniff -fsniff/
├── core/ # Core capture engine
│ ├── capture.py # Packet capture với Scapy
│ ├── decoder.py # Bộ giải mã gói tin
│ ├── pcap_writer.py # PCAP file I/O
│ ├── rotator.py # Tự động xoay file theo giờ
│ └── constants.py # Constants và configs
├── modules/ # Các module phân tích
│ ├── base.py # Module base class
│ ├── runner.py # Module executor
│ └── dummy/ # Module mẫu
├── ui/ # Giao diện Text
│ ├── menu.py # Menu chính
│ ├── list_view.py # Hiển thị danh sách gói tin
│ ├── detail_view.py # Xem chi tiết gói tin
│ └── colors.py # Màu terminal
├── sniff.py # Entry point chính
├── setup.py # Package setup
└── requirements.txt # Dependencies
Tạo module phân tích tùy chỉnh dễ dàng:
from modules.base import BaseModule, Summary, Detection
class MyModule(BaseModule):
@property
def name(self) -> str:
return "my_module"
def analyze(self, pcap_path, output_dir, interface, time_window) -> Summary:
# Logic phân tích của bạn ở đây
detections = []
# ... phân tích packets ...
summary = Summary(
module_name=self.name,
total_hits=len(detections),
# ...
)
self.write_output(output_dir, interface, time_window, summary, detections)
return summaryMặc định, SNIFF lưu dữ liệu trong ./sniff_data/:
sniff_data/
├── raw/ # File PCAP thô
│ └── YYYY-MM-DD/
│ └── interface_YYYY-MM-DD_HH.pcap
└── modules/ # Kết quả phân tích
└── module_name/
└── YYYY-MM-DD/
├── interface_YYYY-MM-DD_HH.summary.json
└── interface_YYYY-MM-DD_HH.index.jsonl
low- Tối thiểu bộ nhớ (1MB buffer, 100 queue)balanced- Mặc định (4MB buffer, 500 queue)fast- Hiệu suất cao (16MB buffer, 2000 queue)max- Throughput tối đa (64MB buffer, 10000 queue)
Cấu hình tự động xóa file cũ:
sudo sniff -i eth0 -r 30 # Giữ file trong 30 ngày- SNIFF yêu cầu quyền root để truy cập raw socket
- Systemd service bao gồm security hardening (
ProtectSystem,ProtectHome) - BPF filters giúp giảm bề mặt tấn công
- Dữ liệu capture có thể chứa thông tin nhạy cảm - bảo mật phù hợp
# Đảm bảo chạy với sudo
sudo sniff -i eth0# Liệt kê các interface có sẵn
sudo sniff --list-interfaces
# Kiểm tra interface đang up
ip link show# Cài đặt Scapy
sudo pip3 install scapy>=2.5.0# Giảm buffer size
sudo sniff -i eth0 -b low
# Hoặc filter traffic cụ thể
sudo sniff -i eth0 -f "host 192.168.1.100"- Hướng Dẫn Đầy Đủ - Documentation chi tiết
- Quick Start - Bắt đầu trong 2 phút
- Project Files - Danh sách files trong project
MIT License - xem file LICENSE để biết chi tiết
Contributions được hoan nghênh! Vui lòng submit Pull Request.
TuEx3
- Được xây dựng với Scapy - thư viện xử lý gói tin mạnh mẽ
- Lấy cảm hứng từ tcpdump, Wireshark và các công cụ phân tích mạng khác
# Cài đặt
curl -sSL https://raw.githubusercontent.com/ntu168108/sniff/main/scripts/install.sh | sudo bash
# Chạy
sudo sniff
# Enjoy!Star repo nếu bạn thấy hữu ích!