Snort - Network Intrusion Detection System

Giới thiệu
Trong thời đại kỹ thuật số hiện nay, bảo vệ hệ thống và dữ liệu trở thành một yếu tố quan trọng hơn bao giờ hết. Để đảm bảo an toàn cho mạng máy tính nhằm phát hiện các cuộc tấn công vào mạng nội bộ, cần triển khai hệ thống phát hiện xâm nhập. Hệ thống phát hiện xâm nhập có thể là thiết bị chuyên dụng hoặc dưới dạng phần mềm.
Snort, một công cụ phần mềm mã nguồn mở mạnh mẽ, được sử dụng phổ biến để phát hiện và ngăn chặn các mối đe dọa an ninh mạng.
Chuẩn bị
1 máy ảo Ubuntu
1 máy ảo Windows được cài DVWA Server
1 máy ảo Kali Linux
Mô hình cài đặt

Thông tin thiết bị:
Kali Linux: 192.168.16.132/24
IDS Snort: 192.168.16.130/24
DVWA Server: 192.168.16.128/24
Video
Cài đặt
Chạy các lệnh bằng quyền sudo
sudo su
Tiến hành cập nhật thiết bị
apt update && apt upgrade
Cách 1: Cài đặt theo gói mặc định trong Ubuntu
Cài đặt snort theo gói được cung cấp sẵn trên hệ điều hành Ubuntu
apt install -y snort
Kiểm tra cài đặt
snort -V

Hoàn thành việc cài đặt Snort.
Cách 2: Cài đặt thủ công Snort
Bước 1. Cài đặt các gói phần mềm bổ trợ
sudo apt-get install -y build-essential libpcap-dev libpcre3-dev libdumbnet-dev bison flex zlib1g-dev liblzma-dev openssl libssl-dev libntirpc-dev
Bước 2: Tạo thư mục chứa mã nguồn Snort và cài đặt Snort
Trước tiên, tạo thư mục chứa mã nguồn Snort
mkdir ~/snort_src
cd ~/snort_src
Tiếp theo, tải lần lượt 2 gói daq-2.0.7.tar.gz và snort-2.9.20.tar.gz tại trang tải xuống của Snort.
wget https://www.snort.org/downloads/snort/daq-2.0.7.tar.gz
wget https://www.snort.org/downloads/snort/snort-2.9.20.tar.gz
Đây là 2 gói cần thiết cho việc cài đặt ở những bước tiếp theo.

Sau khi tải hoàn tất, tiến hành cài đặt lần lượt từng tệp.
- Cài đặt DAQ
cd ~/snort_src
sudo tar -xvzf daq-2.0.7.tar.gz
cd daq-2.0.7
sudo ./configure
sudo make
sudo make install
- Cài đặt SNORT
cd ~/snort_src sudo tar -zxf snort-2.9.20.tar.gz cd snort-2.9.20 sudo ./configure --enable-sourcefire --disable-open-appid sudo make CFLAGS=-I/usr/include/ntirpc sudo make installCập nhật thư viện chia sẻ
sudo ldconfigĐưa liên kết các thư viện của Snort vào /usr/sbin
sudo ln /usr/local/bin/snort /usr/sbin/snort
Hoàn thành các bước ở trên, ta sẽ chạy thử để kiểm tra Snort:
snort -V

Snort đã được cài thành công.
Bước 3.1. Cấu hình Snort chạy ở chế độ phát hiện xâm nhập mạng (NIDS mode)
Tạo các thư mục cho Snort:
sudo mkdir /etc/snort
sudo mkdir /etc/snort/rules
sudo mkdir /etc/snort/rules/iplists
sudo mkdir /etc/snort/preproc_rules
sudo mkdir /usr/local/lib/snort_dynamicrules
sudo mkdir /etc/snort/so_rules
Tạo các tệp tin chứa tập luật cơ bản cho Snort:
sudo touch /etc/snort/rules/iplists/black_list.rules
sudo touch /etc/snort/rules/iplists/white_list.rules
sudo touch /etc/snort/rules/local.rules
sudo touch /etc/snort/sid-msg.map
Tạo thư mục chứa log:
sudo mkdir /var/log/snort
sudo mkdir /var/log/snort/archived_logs
Tạo các bản sao tệp tin cấu hình của Snort:
cd ~/snort_src/snort-2.9.20/etc
sudo cp *.conf* /etc/snort
sudo cp *.map /etc/snort
sudo cp *.dtd /etc/snort
cd ~/snort_src/snort-2.9.20/src/dynamic-preprocessors/build/usr/local/lib/snort_dynamicpreprocessor/
sudo cp * /usr/local/lib/snort_dynamicpreprocessor/

Sau khi thiết lập các thư mục, ta chỉnh sửa các tham số trong tệp tin: /etc/snort/snort.conf. Sử dụng nano hoặc bất cứ trình soạn thảo nào khác.
nano /etc/snort/snort.conf
/etc/snort/snort.confĐặt lại địa chỉ mạng cần bảo vệ
# Setup the network addresses you are protecting ipvar HOME_NET 192.168.16.0/24 # Set up the external network addresses. Leave as "any" in most situations ipvar EXTERNAL_NET !$HOME_NETChỉnh lại các các vị trí thư mục
# Path to your rules files (this can be a relative path) # Note for Windows users: You are advised to make this an absolute path, # such as: c:\snort\rules var RULE_PATH /etc/snort/rules var SO_RULE_PATH /etc/snort/so_rules var PREPROC_RULE_PATH /etc/snort/preproc_rules # If you are using reputation preprocessor set these # Currently there is a bug with relative paths, they are relative to where snort is # not relative to snort.conf like the above variables # This is completely inconsistent with how other vars work, BUG 89986 # Set the absolute path appropriately var WHITE_LIST_PATH /etc/snort/rules/iplists var BLACK_LIST_PATH /etc/snort/rules/iplistsTại phần rules, thêm dấu
#vào trước các tập rules không cần sử dụng. Để thiết lập các rules dành cho vùng mạng local, ta sẽ viết vào tệplocal.rules.################################################### # site specific rules include $RULE_PATH/local.rules #include $RULE_PATH/app-detect.rules #include $RULE_PATH/attack-responses.rules #include $RULE_PATH/backdoor.rules #include $RULE_PATH/bad-traffic.rules #include $RULE_PATH/blacklist.rules #include $RULE_PATH/botnet-cnc.rules #include $RULE_PATH/browser-chrome.rules #include $RULE_PATH/browser-firefox.rules ...Sau khi chỉnh sửa hoàn tất, lưu tệp và thoát.
Bước 3.2. (Tùy chọn) Cài đặt Community rules
Snort cung cấp cho chúng ta một gói rules được viết sẵn từ cộng đồng. Để cài đặt gói rules này vào công cụ Snort trên máy, ta thực hiện các bước sau:
Tải gói rules community tại trang chính thức của Snort
wget https://www.snort.org/downloads/community/community-rules.tar.gz -O ~/community.tar.gzGiải nén gói vừa tải
tar -xvf ~/community.tar.gz -C ~/Sao chép tệp vừa giải nén vào đường dẫn
/etc/snort/rulescp ~/community-rules/* /etc/snort/rulesGói
community.rulesđã được cài đặtls -l /etc/snort/rules/ total 2336 -rw-r--r-- 1 root root 7834 Oct 18 21:54 AUTHORS -rw-r--r-- 1 root root 1809345 Oct 18 21:54 community.rules drwxr-xr-x 2 root root 4096 Oct 18 21:02 iplists -rw-r--r-- 1 root root 15127 Oct 18 21:54 LICENSE -rw-r--r-- 1 root root 0 Oct 18 21:02 local.rules -rw-r--r-- 1 root root 493045 Oct 18 21:54 sid-msg.map -rw-r--r-- 1 root root 30249 Oct 18 21:54 snort.conf -rw-r--r-- 1 root root 21084 Oct 18 21:54 VRT-License.txtChỉnh sửa tệp
snort.conf, thêm dòng sau vào phần rules để áp dụng đượccommunity.rulesvừa cài đặt.include $RULE_PATH/community.rulesFile
snort.conf:################################################### # site specific rules include $RULE_PATH/local.rules include $RULE_PATH/community.rules
Bước 4. Kiểm tra sự hoạt động của Snort
Sau mỗi lần chỉnh sửa cấu hình, dùng câu lệnh sau để kiểm tra Snort đã được cấu hình đúng chưa
snort -T -c /etc/snort/snort.conf
Hiển thị như sau là đã cấu hình đúng

Rules
Các tập rule được Snort sử dụng sẽ được đặt trong path /etc/snort/rules
Để thiết lập các rules dành cho vùng mạng local, ta sẽ viết vào tệp local.rules :
nano /etc/snort/rules/local.rules

Các rules được sử dụng:
# Detect ICMP
alert icmp any any -> $HOME_NET any (msg:"Detected ICMP"; sid:1000001; rev:001;)
# Detect Scan
alert tcp any any -> $HOME_NET any (msg:"SCAN Detected"; detection_filter: track by_src, count 10000, seconds 5; flags:S; classtype:network-scan; sid:1000222; rev:1;)
# Detect Suspicious TCP Traffic to High-Numbered Port
alert tcp any any -> any [1024:65535] (msg:"Suspicious TCP Traffic to High-Numbered Port"; threshold:type both,track by_src,count 50,seconds 60; sid:1000021; rev:1;)
# Detect Fuzzing Attempt
alert tcp any any -> $HOME_NET 80 (msg:"Possible Fuzzing Attempt Detected"; flow:to_server,established; content:"GET"; http_method; threshold:type both,track by_src,count 5,seconds 1; classtype:web-application-attack; sid:1000125; rev:1;)
# Brute Force Login Attempt
alert tcp any any -> $HOME_NET 80 (msg:"Brute Force Login Attempt via HTTP"; flow:to_server,established; content:"GET"; http_method; content:"username="; nocase; content:"password="; nocase; detection_filter:track by_src, count 5, seconds 1; classtype:attempted-user; sid:1000027; rev:1;)
# Repeated User-Agent Detected
alert tcp any any -> $HOME_NET any (msg:"Repeated User-Agent Detected"; flow:to_server,established; content:"User-Agent:"; http_method; http_header; detection_filter:track by_src, count 5, seconds 1; classtype:attempted-recon; sid:1000126; rev:1;)
# Alert attempts using the ' keyword:
alert tcp any any -> any 80 (msg: "Keyword {'} Injection Detected"; content: "%27" ; sid:1000002; )
# Alert attempts using the " keyword:
alert tcp any any -> any 80 (msg: "Keyword {"} Injection Detected"; content: "%22" ; sid:1000003; )
# Alert attempts using the ";" keyword:
alert tcp any any -> any 80 (msg: "Comma keyword Injection Detected"; content: "%3B" ; sid:1000004; )
# Alert attempts using the "--" keyword:
alert tcp any any -> any 80 (msg: "Keyword {--} Injection Detected"; content: "--" ; sid:1000005; )
# Alert attempts using the "OR" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using OR Keyword"; flow:to_server,established; content:"or"; nocase; sid:1000006; rev:1;)
alert tcp any any -> any any (msg:"Alert Attempt Using || Keyword"; flow:to_server,established; content:"%7c%7c"; sid:1000007; rev:1;)
# Alert attempts using the "AND" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using AND Keyword"; flow:to_server,established; content:"and"; nocase; sid:1000008; rev:1;)
alert tcp any any -> any any (msg:"Alert Attempt Using && Keyword"; flow:to_server,established; content:"%26%26"; sid:1000009; rev:1;)
# Alert attempts using the "UNION" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using UNION Keyword"; flow:to_server,established; content:"union"; nocase; sid:1000010; rev:1;)
# Alert attempts using the "ORDER" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using UNION Keyword"; flow:to_server,established; content:"order"; nocase; sid:1000011; rev:1;)
# Alert attempts using the "SELECT" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using SELECT Keyword"; flow:to_server,established; content:"select"; nocase; sid:1000012; rev:1;)
# Alert attempts using the "UPDATE" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using UPDATE Keyword"; flow:to_server,established; content:"update"; nocase; sid:1000013; rev:1;)
# Alert attempts using the "INSERT" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using INSERT Keyword"; flow:to_server,established; content:"insert"; nocase; sid:1000014; rev:1;)
# Alert attempts using the "DELETE" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using DELETE Keyword"; flow:to_server,established; content:"delete"; nocase; sid:1000015; rev:1;)
# Alert attempts using the "DROP" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using DROP Keyword"; flow:to_server,established; content:"drop"; nocase; sid:1000016; rev:1;)
# Alert attempts using the "TRUNCATE" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using TRUNCATE Keyword"; flow:to_server,established; content:"truncate"; nocase; sid:1000017; rev:1;)
# Alert attempts using the "ALTER" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using ALTER Keyword"; flow:to_server,established; content:"alter"; nocase; sid:1000018; rev:1;)
# HTTP traffic to suspicious user-agents:
alert tcp any any -> any any (msg:"HTTP Traffic to Suspicious User-Agent"; flow:to_server,established; content:"User-Agent|3A 20|"; http_header; pcre:"/(\\b(BlackWidow|bot|crawler|scanner|spider|wget|nikto|sqlmap|metasploit|curl|libwww-perl)\\b)/i"; sid:1000019; rev:1;)
snort -T -c /etc/snort/snort.conf để kiểm tra cấu hình vừa thiết lập.Test Cases
Thực hiện lệnh sau để kích hoạt quá trình lắng nghe của Snort
snort -A console -i ens37 -c /etc/snort/snort.conf
-A console:
-A: Đặt chế độ xuất đầu ra (alert mode)
console: Thông báo cảnh báo (alert) sẽ được hiển thị trực tiếp trên màn hình terminal.
-i ens37:
-i: Chỉ định giao diện mạng (network interface) mà Snort sẽ giám sát.
ens37: Là tên giao diện mạng cụ thể cần lắng nghe. Chỉ định chính xác interface thì Snort mới hoạt động.
-c /etc/snort/snort.conf: chỉ định cấu hình tệp sử dụng

Log sẽ được hiển thị trên màn hình console. Để ngừng việc theo dõi traffic, nhấn tổ hợp Ctrl-C để kết thúc quá trình.
Log sẽ được lưu lại trong thư mục /var/log/snort dưới dạng snort.log.xxxx (xxxx là dãy số hiển thị cho từng phiên theo dõi)
ICMP
- Rules cảnh báo phát hiện gói ICMP
# Detect ICMP
alert icmp any any -> $HOME_NET any (msg:"Detected ICMP"; sid:1000001; rev:001;)
- Tiến hành ping từ máy Kali Linux đến máy DVWA
ping 192.168.16.128

- Log nhận được:

Network Scan
- Rules cảnh báo phát hiện hành vi quét mạng bao gồm:
- Áp dụng với các gói tin TCP có cờ SYN được bật. Thường các cuộc quét mạng gửi hàng loạt gói SYN để tìm các cổng mở.
# Detect Scan
alert tcp any any -> $HOME_NET any (msg:"SCAN Detected"; detection_filter: track by_src, count 10000, seconds 5; flags:S; classtype:network-scan; sid:1000222; rev:1;)
- Phát hiện các cổng có số cổng cao (từ 1024 trở lên)
# Detect Suspicious TCP Traffic to High-Numbered Port
alert tcp any any -> any [1024:65535] (msg:"Suspicious TCP Traffic to High-Numbered Port"; threshold:type both,track by_src,count 50,seconds 60; sid:1000021; rev:1;)
- Thực hiện Nmap trên máy Kali Linux
nmap -p- -A -T4 192.168.16.128/24

- Log nhận được:

Scanning Directory
- Rules cảnh báo phát hiện hoạt động fuzzing thư mục:
- Dựa vào số lượng gói GET mà máy nhân được trong một khoảng thời gian.
# Detect Fuzzing Attempt
alert tcp any any -> $HOME_NET 80 (msg:"Possible Fuzzing Attempt Detected"; flow:to_server,established; content:"GET"; http_method; threshold:type both,track by_src,count 5,seconds 1; classtype:web-application-attack; sid:1000125; rev:1;)
- Số lượng User-Agent giống nhau xuất hiện liên tục trong một khoảng thời gian. Điều này thường xuất hiện trong các hoạt động fuzzing.
# Repeated User-Agent Detected
alert tcp any any -> $HOME_NET any (msg:"Repeated User-Agent Detected"; flow:to_server,established; content:"User-Agent:"; http_method; http_header; detection_filter:track by_src, count 5, seconds 1; classtype:attempted-recon; sid:1000126; rev:1;)
- Sử dụng công cụ ffuf để thực hiện việc fuzzing các đường dẫn của trang web
ffuf -w /usr/share/dirbuster/wordlists/directory-list-2.3-small.txt:FUZZ -u http://192.168.16.128/FUZZ


- Log nhận được:

Brute Force Username/Password
- Rules cảnh báo phát hiện quá trình brute force username và password
- Cảnh báo phát hiện nhiều gói GET có chứa content bao gồm ‘
username=’ và ‘password=’
# Brute Force Login Attempt
alert tcp any any -> $HOME_NET 80 (msg:"Brute Force Login Attempt via HTTP"; flow:to_server,established; content:"GET"; http_method; content:"username="; nocase; content:"password="; nocase; detection_filter:track by_src, count 5, seconds 1; classtype:attempted-user; sid:1000027; rev:1;)
- Số lượng User-Agent giống nhau xuất hiện liên tục trong một khoảng thời gian. Điều này thường xuất hiện trong các hoạt động fuzzing.
# Repeated User-Agent Detected
alert tcp any any -> $HOME_NET any (msg:"Repeated User-Agent Detected"; flow:to_server,established; content:"User-Agent:"; http_method; http_header; detection_filter:track by_src, count 5, seconds 1; classtype:attempted-recon; sid:1000126; rev:1;)
- Sử dụng công cụ hydra thực hiện việc bruteforce như sau:
hydra 192.168.16.128 http-get-form "/dvwa/vulnerabilities/brute/:username=^USER^&password=^PASS^&Login=Login:H=Cookie\\: input_cookie_here:F=Username and/or password incorrect." -L Desktop/wordlist/user_list.txt -P Desktop/wordlist/pass_list.txt
Sử dụng Burp Suite bắt request → lấy cookie thay vào payload bên trên để thực hiện tấn công.

- Log nhận được:

SQL Injection
- Rules cảnh báo khai thác lỗ hổng SQL Injection
Cảnh báo khi phát hiện các ký tự nhạy cảm như:
‘,“,;,#,--,||,&&Hoặc các keywords như:
OR,AND,UNION,ORDER,SELECT, …
# Alert attempts using the ";" keyword:
alert tcp any any -> any 80 (msg: "Comma keyword Injection Detected"; content: "%3B" ; sid:1000004; )
# Alert attempts using the "--" keyword:
alert tcp any any -> any 80 (msg: "Keyword {--} Injection Detected"; content: "--" ; sid:1000005; )
# Alert attempts using the "OR" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using OR Keyword"; flow:to_server,established; content:"or"; nocase; sid:1000006; rev:1;)
alert tcp any any -> any any (msg:"Alert Attempt Using || Keyword"; flow:to_server,established; content:"%7c%7c"; sid:1000007; rev:1;)
# Alert attempts using the "AND" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using AND Keyword"; flow:to_server,established; content:"and"; nocase; sid:1000008; rev:1;)
alert tcp any any -> any any (msg:"Alert Attempt Using && Keyword"; flow:to_server,established; content:"%26%26"; sid:1000009; rev:1;)
# Alert attempts using the "UNION" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using UNION Keyword"; flow:to_server,established; content:"union"; nocase; sid:1000010; rev:1;)
# Alert attempts using the "ORDER" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using ORDER Keyword"; flow:to_server,established; content:"order"; nocase; sid:1000011; rev:1;)
# Alert attempts using the "SELECT" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using SELECT Keyword"; flow:to_server,established; content:"select"; nocase; sid:1000012; rev:1;)
# Alert attempts using the "UPDATE" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using UPDATE Keyword"; flow:to_server,established; content:"update"; nocase; sid:1000013; rev:1;)
# Alert attempts using the "INSERT" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using INSERT Keyword"; flow:to_server,established; content:"insert"; nocase; sid:1000014; rev:1;)
# Alert attempts using the "DELETE" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using DELETE Keyword"; flow:to_server,established; content:"delete"; nocase; sid:1000015; rev:1;)
# Alert attempts using the "DROP" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using DROP Keyword"; flow:to_server,established; content:"drop"; nocase; sid:1000016; rev:1;)
# Alert attempts using the "TRUNCATE" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using TRUNCATE Keyword"; flow:to_server,established; content:"truncate"; nocase; sid:1000017; rev:1;)
# Alert attempts using the "ALTER" keyword:
alert tcp any any -> any any (msg:"Alert Attempt Using ALTER Keyword"; flow:to_server,established; content:"alter"; nocase; sid:1000018; rev:1;)
- Cảnh báo các User-Agent lạ xuất hiện trong phần header của gói tin. Điều này giúp phát hiện việc kẻ tấn công đang sử dụng các công cụ như sqlmap, nikto, …
# HTTP traffic to suspicious user-agents:
alert tcp any any -> any any (msg:"HTTP Traffic to Suspicious User-Agent"; flow:to_server,established; content:"User-Agent|3A 20|"; http_header; pcre:"/(\\b(BlackWidow|bot|crawler|scanner|spider|wget|nikto|sqlmap|metasploit|curl|libwww-perl)\\b)/i"; sid:1000019; rev:1;)
- Sử dụng công cụ sqlmap để khai thác lỗ hổng SQL Injection
sqlmap -u 'http://192.168.16.128/DVWA/vulnerabilities/sqli/?id=1&Submit=Submit#' --cookie='input_cookie_here' --batch --dbs --dump
Sử dụng Burp Suite bắt request → lấy cookie thay vào payload bên trên để thực hiện tấn công.

- Log nhận được:

Xem log được lưu trữ
Mở tệp server.conf, tại phần output sẽ có nhiều loại định dạng cho ta lưu lại log, bỏ dấu # để chọn định dạng log.
# unified2
# Recommended for most installs
# output unified2: filename merged.log, limit 128, nostamp, mpls_event_types, vlan_event_types
# Additional configuration for specific types of installs
# output alert_unified2: filename snort.alert, limit 128, nostamp
# output log_unified2: filename snort.log, limit 128, nostamp
# syslog
# output alert_syslog: LOG_AUTH LOG_ALERT
# pcap
# output log_tcpdump: tcpdump.log
Theo document từ Snort:
“Unified2 có thể hoạt động ở một trong ba chế độ, ghi nhật ký gói, ghi nhật ký cảnh báo hoặc ghi nhật ký hợp nhất thực sự. Ghi nhật ký gói bao gồm việc chụp toàn bộ gói và được chỉ định bằng log_unified2. Tương tự như vậy, việc ghi nhật ký cảnh báo sẽ chỉ ghi lại các sự kiện và được chỉ định bằng alert_unified2. Để bao gồm cả hai kiểu ghi nhật ký trong một tệp hợp nhất, chỉ cần chỉ định Unified2.”
Mình test thử một vài loại thì rút ra được kết luận như sau:
- Nếu không chỉnh phần output, ta sẽ nhận được tệp có format
snort.log.xxxx
root@vmware:/var/log/snort# ls -l snort.log.1729272137
-rw------- 1 root root 480 Oct 19 00:22 snort.log.1729272137
root@vmware:/var/log/snort# file snort.log.1729272137
snort.log.1729272137: pcap capture file, microsecond ts (little-endian) - version 2.4 (Ethernet, capture length 1514)
Để xem được tệp với định dạng pcap, ta sử dụng tcpdump như sau:
tcpdump -r snort.log.1729272137 > log1.txt
root@vmware:/var/log/snort# tcpdump -r snort.log.1729272137 > log1.txt
reading from file snort.log.1729272137, link-type EN10MB (Ethernet), snapshot length 1514
root@vmware:/var/log/snort# cat log1.txt
00:22:20.697193 IP 192.168.16.132 > 192.168.16.128: ICMP echo request, id 60845, seq 1, length 64
00:22:20.697288 IP 192.168.16.128 > 192.168.16.132: ICMP echo reply, id 60845, seq 1, length 64
00:22:21.706495 IP 192.168.16.132 > 192.168.16.128: ICMP echo request, id 60845, seq 2, length 64
00:22:21.706669 IP 192.168.16.128 > 192.168.16.132: ICMP echo reply, id 60845, seq 2, length 64
- Chọn định dạng output là
log_unified2:
root@vmware:/var/log/snort# ls -l snort.log
-rw------- 1 root root 536 Oct 19 00:27 snort.log
root@vmware:/var/log/snort# file snort.log
snort.log: Adobe Photoshop Color swatch, version 0, 2 colors; 1st RGB space (0), w 0x7e, x 0, y 0, z 0; 2nd HSB space (1), w 0x6712, x 0x9a90, y 0x6712, z 0x9a90
Khác với định dạng ở trên, ta sẽ thu được tệp log dạng Adobe Photoshop Color. Tệp này chỉ lưu lại log ở phiên vừa kết thúc, nếu bắt đầu một phiên mới, tệp này sẽ ghi lại log từ đầu.
Để xem được tệp, ta sử dụng u2pewfoo như sau:
root@vmware:/var/log/snort# u2spewfoo snort.log > log2.txt
root@vmware:/var/log/snort# cat log2.txt
Packet
sensor id: 0 event id: 1 event second: 1729272464
packet second: 1729272464 packet microsecond: 53349
linktype: 1 packet_length: 98
[ 0] 00 0C 29 8F 3C 3A 00 0C 29 DA 08 CB 08 00 45 00 ..).<:..).....E.
[ 16] 00 54 DD E0 40 00 40 01 BA 73 C0 A8 10 84 C0 A8 .T..@.@..s......
[ 32] 10 80 08 00 90 0A F7 CE 00 01 8F 9A 12 67 00 00 .............g..
[ 48] 00 00 08 51 07 00 00 00 00 00 10 11 12 13 14 15 ...Q............
[ 64] 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 .......... !"#$%
[ 80] 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 &'()*+,-./012345
[ 96] 36 37 67
Packet
sensor id: 0 event id: 2 event second: 1729272464
packet second: 1729272464 packet microsecond: 53558
linktype: 1 packet_length: 98
[ 0] 00 0C 29 DA 08 CB 00 0C 29 8F 3C 3A 08 00 45 00 ..).....).<:..E.
[ 16] 00 54 53 63 00 00 80 01 44 F1 C0 A8 10 80 C0 A8 .TSc....D.......
[ 32] 10 84 00 00 98 0A F7 CE 00 01 8F 9A 12 67 00 00 .............g..
[ 48] 00 00 08 51 07 00 00 00 00 00 10 11 12 13 14 15 ...Q............
[ 64] 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 .......... !"#$%
[ 80] 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 &'()*+,-./012345
[ 96] 36 37 67
- Chọn định dạng output là
tcp_dump:
root@vmware:/var/log/snort# ls -l tcpdump.log.1729272818
-rw------- 1 root root 480 Oct 19 00:33 tcpdump.log.1729272818
root@vmware:/var/log/snort# file tcpdump.log.1729272818
tcpdump.log.1729272818: pcap capture file, microsecond ts (little-endian) - version 2.4 (Ethernet, capture length 1514)
Để xem được tệp với định dạng pcap, ta sử dụng tcpdump như sau:
root@vmware:/var/log/snort# tcpdump -r tcpdump.log.1729272818 > log3.txt
reading from file tcpdump.log.1729272818, link-type EN10MB (Ethernet), snapshot length 1514
root@vmware:/var/log/snort# cat log3.txt
00:33:41.510789 IP 192.168.16.132 > 192.168.16.128: ICMP echo request, id 768, seq 1, length 64
00:33:41.510955 IP 192.168.16.128 > 192.168.16.132: ICMP echo reply, id 768, seq 1, length 64
00:33:42.511717 IP 192.168.16.132 > 192.168.16.128: ICMP echo request, id 768, seq 2, length 64
00:33:42.512109 IP 192.168.16.128 > 192.168.16.132: ICMP echo reply, id 768, seq 2, length 64
Vậy là sau các bước thực hiện như trên, ta đã hoàn thành việc cấu hình hệ thống phát hiện xâm nhập Snort giúp phát hiện và ngăn chặn các mối đe dọa an ninh mạng trong hệ thống của chúng ta.



