Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบเครือข่าย >> ความปลอดภัยเครือข่าย

Snort ในความปลอดภัยเครือข่าย คืออะไร ทำงานอย่างไร และการใช้งาน

Snort คืออะไร?

Snort เป็น Open Source Network Intrusion Detection System (NIDS) และ Intrusion Prevention System (NIPS) ที่ได้รับความนิยมมากที่สุดโลก พัฒนาโดย Martin Roesch (Founder Sourcefire) ปัจจุบันดูแลโดย Cisco Talos (หลัง Cisco ซื้อ Sourcefire ปี 2013)

ความสามารถหลัก 3 แบบ (Three Primary Modes)

โหมดคำอธิบายกรณีใช้งาน
Packet Sniffer (Packet Logger)จับแพ็กเก็ตผ่าน Network Interface แสดง/บันทึกลงไฟล์ (PCAP)Network Troubleshooting, Traffic Analysis, Forensics
Packet Loggerบันทึกแพ็กเก็ตที่ตรงเงื่อนไขลงไฟล์ (Binary/ASCII/PCAP)Audit Trail, Compliance, Offline Analysis
NIDS/NIPS (Intrusion Detection/Prevention)โหมดหลัก วิเคราะห์ Traffic แบบ Real-time ตรงกับ Rules → Alert / Block (Inline)Network Security Monitoring, Threat Detection, Automated Blocking

Snort ทำงานอย่างไร? (Architecture & Detection Engine)

1. Packet Acquisition (การรับแพ็กเก็ต)

  • ใช้ libpcap (Linux/Unix) หรือ WinPcap/Npcap (Windows)
  • ตั้งค่า Network Interface ให้เป็น Promiscuous Mode (รับแพ็กเก็ตทั้งหมดบน Segment)
  • รองรับ AF_PACKET, PF_RING, Netmap, DPDK สำหรับ High Performance

2. Preprocessors (การประมวลผลก่อนตรวจจับ)

Normalize/Decode/Reassemble Traffic ก่อนส่งให้ Detection Engine:

  • Frag3: IP Defragmentation (IPv4/IPv6)
  • Stream5/Stream6: TCP/UDP Stream Reassembly (Session Tracking)
  • HttpInspect: HTTP Normalization (Decode, Decompress, Unicode)
  • SMTP/POP/IMAP/FTP/Telnet/SSH/DNS/SSL Preprocessors: Protocol Decoding
  • Portscan Detector: ตรวจจับ Port Scanning
  • ARP Spoof Detector: ตรวจจับ ARP Poisoning

3. Detection Engine (เครื่องมือตรวจจับหัวใจ)

  • ใช้ Rule-based Language (Snort Rules)
  • ตรวจสอบแบบ Signature-based (Misuse Detection) + Anomaly-based (ผ่าน Preprocessors)
  • Rule Actions: alert, log, pass, activate, dynamic, drop, reject, sdrop
  • Rule Options: content, pcre, metadata, flow, http_*, file_*, dns_*, ssl_*, appid, ґи detection plugins

4. Output/Alerting (การแจ้งเตือนและบันทึก)

  • Unified2 (Binary): รูปแบบมาตรฐาน สำหรับ Barnyard2 / Snort 3
  • Syslog: ส่งไป SIEM (Splunk, Elastic, QRadar)
  • Alert Fast/Full/Console: แสดงบน Console/Log File
  • PCAP: บันทึกแพ็กเก็ตเต็มรูปแบบ

Snort Rules (กฎการตรวจจับ)

โครงสร้าง Rule

Action Protocol Source_IP Source_Port Direction Destination_IP Destination_Port (Options)
alert tcp $EXTERNAL_NET any -> $HOME_NET 80 (msg:"WEB-ATTACK SQL Injection"; flow:to_server,established; content:"UNION SELECT"; nocase; sid:1000001; rev:1;)

ตัวอย่าง Rules

  • SQL Injection: `alert tcp any any -> $HOME_NET 80 (msg:"SQLi"; content:"union select"; http_uri; sid:1000001;)`
  • Malware C2: `alert tcp $HOME_NET any -> any 443 (msg:"Malware C2"; tls_ja3_fingerprint; sid:1000002;)`
  • Log4Shell: `alert tcp any any -> $HOME_NET 8080 (msg:"Log4Shell"; content:"jndi:ldap"; http_header; sid:1000003;)`

Snort 2.9 vs Snort 3 (Snort++)

FeatureSnort 2.9 (Legacy)Snort 3 (Current)
ArchitectureSingle-threadedMulti-threaded (Scale to 100Gbps+)
Configurationsnort.conf (Complex)snort.lua (Lua-based, Modular)
Plugin SystemLimited (Shared Libs)Full Plugin API (C++, Lua)
Rule SyntaxClassicClassic + Stapled Expressions (Strex)
HTTP/2, TLS 1.3LimitedNative Support
Container/K8sDifficultNative Support

การติดตั้งและใช้งาน Snort บน Linux (Ubuntu/Debian)

# 1. Install Dependencies
sudo apt update && sudo apt install -y build-essential libpcap-dev libpcre3-dev libdumbnet-dev zlib1g-dev luajit libluajit-5.1-dev pkg-config

# 2. Install DAQ (Data Acquisition Library)
wget https://www.snort.org/downloads/snort/daq-2.0.7.tar.gz
tar xzf daq-2.0.7.tar.gz && cd daq-2.0.7 && ./configure && make && sudo make install

# 3. Install Snort 3
wget https://github.com/snort3/snort3/archive/refs/tags/3.1.80.0.tar.gz
tar xzf 3.1.80.0.tar.gz && cd snort3-3.1.80.0
./configure_cmake.sh --prefix=/usr/local/snort
cd build && make -j$(nproc) && sudo make install

# 4. Download Rules (ต้องมี Oinkcode จาก snort.org)
# Community Rules (Free): https://www.snort.org/downloads/community/community-rules.tar.gz
# Subscriber Rules (Paid): ต้องสมัครสมาชิก

# 5. Run Snort 3 (IDS Mode)
sudo /usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/snort.lua -i eth0 -A alert_fast

# 6. Run Snort 3 (IPS Mode - Inline) ต้องการ NFQUEUE
sudo iptables -I FORWARD -j NFQUEUE --queue-num 0
sudo /usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/snort.lua -i eth0 -Q --daq nfq --daq-var queue=0

Rule Sets (ชุดกฎ) - สำคัญมาก

จุด mạnhและข้อจำกัด

Rule Setค่าใช้จ่ายความครอบคลุมอัปเดต
Community RulesFreeBasic, Older SignaturesWeekly
Snort Subscriber Rules (Talos)~$399/year (Personal) ~$1,999+/year (Business)Comprehensive, Zero-day, Malware, Exploit, C2Daily (Real-time)
Emerging Threats (ET/Proofpoint)Free (ET Open) / Paid (ET Pro)Good Coverage, Fast ResponseDaily
จุด mạnhข้อจำกัด
ฟรี Open Source, Community ใหญ่Single-threaded (Snort 2) ต้องใช้ Snort 3 สำหรับ High Throughput
Rule Language ยืดหยุ่น เขียนเองได้False Positives สูง ต้อง Tuning มาก
รองรับ Protocol หลายรูปแบบPerformance ขึ้นกับ Hardware/Rule Count
Integrate กับ SIEM/SOAR ได้ดีไม่มี GUI จัดการ Rule เอง (ใช้ PulledPork, SnortSam, หรือ Commercial Console)
มาตรฐานอุตสาหกรรม (De facto)Encrypted Traffic (TLS 1.3) ตรวจจับได้จำกัด ต้อง SSL Decryption

สรุป

Snort เป็น NIDS/NIPS Open Source มาตรฐานอุตสาหกรรม ใช้ Rule-based Detection ทำงาน 3 โหมด: Sniffer, Logger, IDS/IPS สำคัญคือ Rule Tuning, Rule Set Selection (Talos/ET), และ Migration ไป Snort 3 สำหรับ Production High-throughput Environment ปัจจุบันใช้ร่วมกับ Suricata, Zeek, และ Cloud-native NDR (Corelight, Vectra) เพื่อ Coverage ที่ครอบคลุม