Computer >> Hướng Dẫn Máy Tính >  >> Kết Nối Mạng >> An Ninh Mạng

Wireshark trong an ninh mạng: Công cụ phân tích gói tin, phát hiện mối đe dọa, hướng dẫn sử dụng

Wireshark là gì?

Wireshark là bộ phân tích giao thức mạng (Network Protocol Analyzer) mã nguồn mở, miễn phí, phổ biến nhất thế giới. Cho phép bắt gói tin (packet capture) real-time, phân tích offline, hiển thị chi tiết từng trường protocol từ Layer 2 đến Layer 7.

Trước đây tên là Ethereal (đổi tên 2006 do vấn đề thương hiệu). Chạy trên Windows, Linux, macOS, BSD.

Tại sao Wireshark quan trọng cho an ninh mạng?

  • Công cụ tiêu chuẩn ngành cho: Network Forensics, Incident Response, Threat Hunting, Malware Analysis
  • Phát hiện: C2 traffic, data exfiltration, lateral movement, reconnaissance, DDoS, ARP spoofing, DNS tunneling
  • Troubleshooting: Hiệu năng mạng, retransmission, latency, protocol errors
  • Miễn phí, mã nguồn mở, cộng đồng lớn, cập nhật thường xuyên

4 trường hợp sử dụng chính (Four Main Uses)

Vai tròMục đích sử dụng Wireshark
Network AdminTroubleshooting kết nối, hiệu năng, cấu hình sai, loop, broadcast storm
Security EngineerPhân tích malware traffic, phát hiện C2, data exfil, lateral movement, IOC extraction
QA EngineerVerify ứng dụng mạng: handshake TLS, API calls, protocol compliance
DeveloperDebug implementation protocol, test custom protocol, analyze packet flow

Tính năng cốt lõi

  • Live Capture: Bắt gói tin từ interface (Ethernet, Wi-Fi, Bluetooth, USB, Loopback...)
  • Offline Analysis: Mở file .pcap/.pcapng từ công cụ khác (tcpdump, Zeek, firewall logs)
  • Display Filters (Bộ lọc hiển thị): Cú pháp mạnh: `ip.addr==192.168.1.1`, `http.request.method==POST`, `tcp.flags.syn==1`, `dns.qry.name contains "evil"`
  • Capture Filters (Bộ lọc bắt): BPF syntax: `host 192.168.1.1`, `port 80`, `tcp port 443` - áp dụng KHI bắt để giảm dung lượng
  • Protocol Dissectors: Hỗ trợ 3000+ protocol, decode tự động, hiển thị cây phân cấp
  • Follow TCP/UDP Stream: Xem toàn bộ hội thoại (conversation) dạng text/hex
  • IO Graphs: Biểu đồ throughput, packet rate, latency theo thời gian
  • Expert Info: Tự động cảnh báo: Retransmission, Zero Window, Malformed packet, Decryption issues
  • Decryption: TLS/SSL (với session key), WPA2/WPA3 (với PSK), IPsec, SRTP...

Hướng dẫn bắt đầu (Windows)

  1. Tải tại wireshark.org → Cài đặt (chọn Npcap khi cài)
  2. Mở Wireshark → Chọn interface (có biểu tượng cuộn sóng = đang có traffic) → Double-click hoặc Click mũi tên xanh "Start"
  3. Sinh traffic: Mở web, ping, download file...
  4. Click đỏ "Stop" → Phân tích
  5. Áp dụng Display Filter: `http`, `dns`, `tcp.port==443`, `ip.addr==8.8.8.8`...

Bộ lọc (Filters) hữu ích cho Security Analysis

Mục đíchDisplay Filter
Tìm traffic đáng ngờ tới C2`http.request.uri contains "cmd" or http.request.uri contains "powershell"`
Phát hiện DNS Tunneling`dns.qry.name.len > 50 and dns.qry.type == TXT`
ARP Spoofing / Poisoning`arp.duplicate-address-detected` hoặc `arp.opcode == 2` (reply) từ nhiều MAC cho 1 IP
Port Scanning`tcp.flags.syn == 1 and tcp.flags.ack == 0` (SYN scan) - lọc theo source IP
Cleartext Password (FTP, Telnet, HTTP Basic Auth)`ftp.request.command == "PASS" or telnet.data contains "Password" or http.authbasic`
Data Exfiltration (Large upload)`tcp.len > 1000 and ip.dst != internal_subnet` (cần baseline bình thường)
TLS Handshake Issues`tls.handshake.type == 1` (Client Hello) → Check cipher suites, version
Malformed Packets`expert.severity == error`

Wireshark có thể đánh cắp mật khẩu?

CÓ - Nếu traffic KHÔNG được mã hóa (HTTP, FTP, Telnet, SMTP/IMAP/POP3 không TLS, SNMPv1/v2c, Syslog...). Wireshark chỉ "nghe" (sniff) traffic đi qua interface. Nó KHÔNG tự động "hack" hay "crack" mật khẩu.

Giải pháp: Luôn dùng HTTPS, SSH, SFTP, TLS 1.2/1.3, WPA2/WPA3, IPsec, MACsec. Wireshark có thể giải mã TLS NẾU có session key (pre-master secret log từ browser/app).

Vấn đề pháp lý & Đạo đức

  • CHỈ bắt gói tin trên mạng BẠN SỞ HỮU hoặc ĐƯỢC PHÉP
  • Bắt traffic mạng công ty без sự cho phép = Vi phạm chính sách, có thể vi phạm pháp luật (Computer Fraud and Abuse Act - Mỹ, Luật An ninh mạng - VN...)
  • Trên Wi-Fi công cộng: Chỉ bắt traffic CỦA BẠN (promiscuous mode trên Wi-Fi phức tạp hơn Ethernet)
  • Enterprise: Cần chính sách rõ ràng, monitoring agreement, SIEM/NDR thay vì Wireshark ad-hoc

Wireshark trên Linux

# Ubuntu/Debian
sudo apt update && sudo apt install wireshark
# Chọn "Yes" cho non-superuser capture
sudo usermod -a -G wireshark $USER
# Logout/login lại
wireshark

Lỗi "Running as root": Không nên chạy Wireshark GUI as root. Dùng dumpcap (backend) với quyền root, GUI chạy user thường.

Công cụ thay thế / Bổ sung

  • tcpdump / WinDump: CLI, nhẹ, cho server không GUI, script tự động
  • Zeek (formerly Bro): Network Security Monitor, log-structured, scripting mạnh
  • Suricata: IDS/IPS, rule-based, multi-threaded, Eve JSON output
  • TShark: CLI version của Wireshark, automation, server headless
  • NetworkMiner: GUI, trích xuất file, credential, artifact từ pcap
  • CloudShark: Web-based pcap analysis, chia sẻ team

Kết luận

Wireshark là "dao quân السويس" (Swiss Army Knife) của người làm mạng/an ninh. Nắm vững Wireshark = hiểu bản chất giao thức, tư duy gói tin, khả năng điều tra sự cố và mối đe dọa từ gốc rễ. Hãy học filter, follow stream, expert info, IO graph, decryption - những kỹ năng cốt lõi nhất.