Snort - Dong Xuan Thinh

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Hướng dẫn cài đặt snort

Sơ đồ:

Sơ đồ còn thiếu, mong các bạn thông cảm!


Link video hướng dẫn cài:
https://www.youtube.com/watch?v=sgdLySA_2hE&t=37s

1. Cài đặt các package cần thiết:


# yum install -y gcc flex bison zlib libpcap pcre libdnet tcpdump
# yum install -y epel-release
# yum install -y libnghttp2

Kiểm tra libdnet có thể truy cập bằng cách tạo liên kết:
# ln -s /usr/lib64/libdnet.so.1.0.1 /lib64/libdnet.1

2. Cài đặt Snort


Cài đặt bằng lệnh yum, lên trang chủ snort.org, kéo xuống dưới chọn Centos, copy
link về để cài đặt:
3. Cấu hình Snort ở chế độ NIDS
# ldconfig
Tạo các thư mục sau:
# mkdir -p /etc/snort/rules
# mkdir /var/log/snort
# mkdir /usr/local/lib/snort_dynamicrules

Cấp quyền cho các thư mục đó


# chmod -R 5775 /etc/snort
# chmod -R 5775 /var/log/snort
# chmod -R 5775 /usr/local/lib/snort_dynamicrules
# chown -R snort:snort /etc/snort
# chown -R snort:snort /var/log/snort
# chown -R snort:snort /usr/local/lib/snort_dynamicrules

Tạo các tệp mới cho danh sách trắng và đen cũng như các quy tắc cục bộ:
# touch /etc/snort/rules/white_list.rules
# touch /etc/snort/rules/black_list.rules
# touch /etc/snort/rules/local.rules
# touch /var/log/snort/snort.log
# sed -i 's/include \$RULE\_PATH/#include \$RULE\_PATH/' /etc/snort/snort.conf

Chỉnh sửa file snort.conf để thay đổi một vài thông số:
# vi /etc/snort/snort.conf

Tìm và chỉnh sửa các dòng như sau:

Tìm dòng sau sửa IP lớp mạng bạn muốn nhận thông tin xâm nhập
# Setup the network addresses you are protecting
ipvar HOME_NET <server public IP>/32

# Set up the external network addresses. Leave as "any" in most situations


ipvar EXTERNAL_NET !$HOME_NET

# Path to your rules files (this can be a relative path)


var RULE_PATH /etc/snort/rules
var SO_RULE_PATH /etc/snort/so_rules
var PREPROC_RULE_PATH /etc/snort/preproc_rules

# Set the absolute path appropriately


var WHITE_LIST_PATH /etc/snort/rules
var BLACK_LIST_PATH /etc/snort/rules

# unified2
# Recommended for most installs
output unified2: filename snort.log, limit 128
Kéo xuống dưới bỏ dấu # của dòng sau:
include $RULE_PATH/local.rules

Sau khi chỉnh sửa xong thì lưu lại

Kiểm tra snort xem có lỗi không:


snort -T -c /etc/snort/snort.conf

Kết quả nhận được:

4. Thử nghiệm
Để kiểm tra xem Snort có ghi nhật ký cảnh báo như dự định hay không, hãy thêm
cảnh báo quy tắc phát hiện tùy chỉnh trên các kết nối ICMP đến vào tệp local.rules:
# vi /etc/snort/rules/local.rules
Thêm dòng sau:
alert icmp any any -> $HOME_NET any (msg:"Phat hien ping"; sid:10000001;
rev:001;)

Bắt đầu Snort với tùy chọn -A console để in cảnh báo ra thiết bị. Cần chọn giao diện
mạng chính xác với địa chỉ IP của máy chủ, ví dụ: ens33
snort -A console -i ens33 -u snort -g snort -c /etc/snort/snort.conf

Một số rules khác:


alert icmp any any -> $HOME_NET 81 (msg:"Scanning Port 81";sid:1000005;rev:1;)
alert tcp any any -> $HOME_NET 22 (msg:"Scanning Port 22"; sid:1000002;rev:1;)
alert icmp any any -> any any (msg:"UDP Tesing Rule"; sid:1000006;rev:1;)
alert tcp any any -> $HOME_NET 80 (msg:"HTTP Test!!!"; classtype:not-suspicious;
sid:1000005; rev:1;)
5. Cấu hình chặn gói
Mở cấu hình snort inline mode trong snort.conf:
# vim /etc/snort/snort.conf

“## Under Step #2:” Thêm dòng sau:


config policy_mode:inline
Cấu hình giá trị biến DAQ để chạy AFPacket trong inline (IPS) mode:
“## Configure DAQ variables for AFPacket”
config daq: afpacket
config daq_mode: inline
config daq_dir: /usr/local/lib/daq
config daq_var: buffer_size_mb=128
Lưu cấu hình. Thêm rule chặn ping và kiểm tra:
drop icmp any any -> any any (itype:0;msg:"-->Da chan
Ping !";gid:1000002;sid:1000002;rev:1;)
# snort -i ens33:ens37 -A console -c /etc/snort/snort.conf -l /var/log/snort/ -Q

Bắt gói tin bằng wireshank:

You might also like