Cài đặt và cấu hình Snort trên CentOS
|
GIỚI THIỆU: Snort là một dạng IDS (Instruction Detection System). IDS là một hệ thống được cài đặt trên mạng làm nhiệm vụ giám sát những packet vào ra hệ thống mạng. Khi Snort phát hiện một cuộc tấn công thì nó có thể phản ứng bằng nhiều cách khác nhau tùy thuộc vào cấu hình mà người quản trị mạng thiết lập, chẳng hạn như nó có thể gởi thông điệp cảnh báo đến nhà quản trị hay loại bỏ gói tin khi phát hiện có sự bất thường trong các gói tin đó.
Snort hoạt động dựa trên các luật – rule xây dựng sẵn và phải được cập nhật thường xuyên. Mỗi luật đại diện cho một cuộc tấn công. Khi có một packet đến hệ thống nó sẽ được áp vào tập luật, nếu có sự so trùng snort sẽ phản ứng.
Ví dụ về 1 rule:
alert tcp !192.168.1.0/24 any -> 192.168.1.0/24 111 (content: "|00 01 86 a5|"; msg: "external mountd access"; )
Phần đầu của luật mô tả cách hành động (rule's action) là alert, giao thức (tcp) và địa chỉ IP nguồn, đích cũng như thông tin về port. Phần này gọi là “rule header”.
Phần còn lại của luật, được biết như “rule option”, chứa thông điệp báo động và thông tin sẽ được snort sử dụng để kiểm tra xem liệu luật đó có phù hợp (match) với gói tin không.
Mô Hình:
Snort server: cài phần mềm snort
Client: sử dụng phần mềm nmap tiến hành quét port trên máy snort
Lần lượt cài các gói phụ thuộc sau:
mysql-bench, mysql-server, mysql-devel, yum-utils, php-mysql, httpd, gcc, pcre-devel, php-gd, gd , distcache-devel, mod_ssl, glib2-devel, gcc-c++, libpcap-devel, php, php-pear
Trường hợp các hàm thư viện và các gói phần mềm cần thiết chưa được cài bạn có thể thực hiệc các bước sau cho nhanh:
b1. tạo thư mục trong root:
mkdir media/CentOS
b2. mount dvd vào thư mục:
mount dev/cdrom /media/CentOS
b3. import key PGP:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
b4. cài đặt yum với 4 gói sau đây:
yum --disablerepo=\* --enablerepo=c5-media groupinstall "Development Tools"
yum --disablerepo=\* --enablerepo=c5-media groupinstall "Development Libraries" yum --disablerepo=\* --enablerepo=c5-media groupinstall "MySQL Database"
Sau đó kiểm tra nếu thiếu gói nào thì cài thêm gói đó
1.2. Cài đặt Snort:
Chép snort vào /snort
cd /soft
Giải nén snort
tar -zxvf snort-2.8.4.1.tar.gz
cd snort-2.8.4.1
Lần lượt thực hiện các sau để cài đặt snort
#./configure --with-mysql --enable-dynamicplugin
#make
#make install
1.3. Cấu hình snort:
- Tạo các thư mục hoạt động cho snort
mkdir /etc/snort
mkdir /etc/snort/rules mkdir /var/log/snort
- Chép các file cấu hình
cd etc/
cp * /etc/snort
- Tạo nhóm & người dùng cho snort
groupadd snort
useradd -g snort snort -s /sbin/nologin
- Set quyền sở hữu và cho phép Snort ghi log vào thư mục chứa log
chown snort:snort /var/log/snort/
2. Cài đặt tập rule cho SNORT
- Tải rule mới nhất từ
- Giải nén
tar -xzvf snortrules-snapshot-2.8.tar.gz
cd rules cp * /etc/snort/rules 3. Cấu hình snort
File cấu hình /etc/snort/snort.conf
- Sửa dòng 46
var HOME_NET 192.168.9.0/24
- Sửa dòng 49
var EXTERNAL_NET !$HOME_NET
Sửa dòng:
110: var RULE_PATH /etc/snort/rules
688: output database: log, mysql, user=snort password=123456 dbname=snort host=localhost
Save lại
Thiết Lập Snort khởi động cùng hệ thống:
Tạo một liên kết mềm (symbolic link) của file snort binary đến /usr/sbin/snort
ln -s /usr/local/bin/snort /usr/sbin/snort
Snort cung cấp các scrip để khởi động trong thư mục rpm/ ; (thư mục giải nén snort)
cp /snort/snort-2.8.4.1/rpm/snortd /etc/init.d/
cp /snort/snort-2.8.4.1/rpm/snort.sysconfig /etc/sysconfig/snort
Đặt quyền lại cho file snortd :
chmod 755 /etc/init.d/snortd
chkconfig snortd on service snortd start
Để khởi động snort ở chế độ debug nếu bạn muốn kiểm tra lỗi:
/snort/snort-2.8.4.1/src/snort -u snort -g snort -d -c /etc/snort/snort.conf
Quản lý snort bằng webmin:
(bước này có thể bỏ qua làm tiếp phần 4)
- Cài webmin
- Tích hợp snort vào webmin:
chép snort-1.1.wbm vào thư mục bung snort
vào http:/localhost:10000
-> Webmin, chọn Webmin Configuration, Webmin Modules, From uploaded file, chỉ đến thư mục chứa snort-1.1.wbm
Tiến hành cài đặt
4. Tạo CSDL snort với MySQL: #service mysqld start
Trước tiên ta cần set password cho root trong MySQL.
#mysqladmin -u root password 123456
#mysql -p
Tạo password cho tài khoản snort.
mysql> use mysql;
mysql> CREATE USER 'snort'@'localhost' IDENTIFIED BY '123456';
Tạo CSDL cho snort.
mysql> create database snort;
mysql> GRANT CREATE, INSERT, SELECT, DELETE, UPDATE ON snort.* to snort@localhost; mysql> flush privileges; mysql> exit
Tạo các table từ /snort/snort-2.8.4.1/schemas/create_mysql cho database snort (thư mục gải nén snort)
mysql -u root -p < /snort/snort-2.8.4.1/schemas/create_mysql snort
mysql -p show databases; use snort; show tables;
Quan sát các tables
5. Cài đặt BASE và ADODB
Web server và PHP đã cài đặt sẵn ta cần cài thêm vài gói pear cho PHP.
cd snort/snort-2.8.4.1
pear install Image_Graph-alpha Image_Canvas-alpha Image_Color Numbers_Roman ; (máy phải online)
Cài đặt ADODB
Tải ADODB tại:
http://nchc.dl.sourceforge.net/sourceforge/adodb/
cp adodb480.tgz /var/www/html/ cd /var/www/html/ tar -xzvf adodb480.tgz Cài BASE
Tải BASE tại:
http://nchc.dl.sourceforge.net/sourc...e-1.4.2.tar.gz
#cp /snort/base-1.4.4.tar.gz /var/www/html/ #tar -zxvf base-1.4.4.tar.gz #mv base-1.4.4/ base/ #cd base #cp base_conf.php.dist base_conf.php #vi base_conf.php
Sửa các dòng sau:
57 $BASE_urlpath = '/base';
79 $DBlib_path = '/var/www/html/adodb'; 101 $alert_dbname = 'snort'; 105 $alert_password = '123456'; 108 $archive_exists = 1; # Set this to 1 if you have an archive DB 109 $archive_dbname = 'snort'; 112 $archive_user = 'snort'; 113 $archive_password = '123456'; 355 $external_whois_link = 'index.php'; 382 $external_dns_link = 'index.php'; 385 $external_all_link = 'index.php';
Save lại
#service snortd restart
#service httpd restart 6. Kiểm tra:
Tại máy Client chạy Nmap, nhập địa chỉ máy Linux 192.168.1.10 để tiến hành do thám
Mở IE truy cập Snort: 192.168.1.10/bass
Cửa sổ hiện thị thông tin tóm tắt về các cảnh báo mà Snort bắt được
Chọn Most recent 15 Unique Alerts xem 15 cảnh báo gần đây nhất
Source addres: Số lượng host tham gia cuộc tấn công
Trong trường hợp này là 1, chọn số 1
Src IP address: địa chỉ máy thực hiệc cuộc do thám 192.168.1.2
|
Tham khảo thêm:
Snort is a signature based network intrusion detection system (NIDS) which has become a defacto standard for NIDS. In addition to being used as a NIDS, Snort may also be used as a simple network traffic packet sniffer or logger.
A number of Snort dynamic preprocessors are available which enables the development of rules to attack detection.
Snort is an open source product and available for most popular network operating systems. Snort rules are also available commercially from Sourcefire.
The following instruction detail the installation of Snort 2.9.4 on a CentOS 6.3 64bit host. The installation instructions include the installation of Snort rules available to registered Snort users, as well as third party rules available from EmergingThreats.
Installation:
- Install dependencies
- yum -y update
- yum -y install gcc flex bison wget make
- yum -y install zlib zlib-devel
- yum -y install libpcap libpcap-devel
- yum -y install pcre pcre-devel
- rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm #(or rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm for 32 bit machines)
- yum -y update
- yum -y install libdnet libdnet-devel
- Download and install DAQ
- cd /root/
- wget http://www.snort.org/downloads/2216 -O daq-2.0.0.tar.gz
- tar zxvf daq-2.0.0.tar.gz
- cd daq-2.0.0
- ./configure
- make
- make install
- Download and install Snort
- wget http://www.snort.org/downloads/2225 -O snort-2.9.4.1.tar.gz
- tar zxvf snort-2.9.4.1.tar.gz
- cd snort-2.9.4.1
- ./configure --enable-sourcefire
- make
- make install
- Download and install Snort Rules
- mkdir -p /etc/snort/rules
- mkdir -p /var/log/snort
- cd /etc/snort
- Manually download the rules file to /etc/snort/ (You need to be signed in to get the registered user rules). In this case it was snortrules-snapshot-2940.tar.gz
- tar zxvf snortrules-snapshot-2940.tar.gz
- mv ./etc/* /etc/snort/
- rmdir /etc/snort/etc
- OPTIONAL: Download and install Emerging Threats rules
- wget http://rules.emergingthreats.net/open/snort-2.9.0/emerging.rules.tar.gz -O emerging.rules.tar.gz
- tar zxvf emerging.rules.tar.gz
- Create Snort accounts
- groupadd snort
- useradd snort -g snort -d /var/log/snort -s /sbin/nologin -m
- chown -R snort:snort /etc/snort
- chown -R snort:snort /var/log/snort
- Edit the Snort configuration file
- vi /etc/snort/snort.conf
- ipvar HOME_NET x.x.x.x/x/
- ipvar EXTERNAL_NET !$HOME_NET
- var RULE_PATH rules
- var SO_RULE_PATH so_rules
- var PREPROC_RULE_PATH preproc_rules
- var WHITE_LIST_PATH rules
- var BLACK_LIST_PATH rules
- OPTIONAL: include $RULES_PATH/emerging.conf
- Test the Snort installation
- snort -u snort -g snort -c /etc/snort/snort.conf -T
- If all goes well you should see this
Snort exiting
I plan to have a subsequent blog post to record instructions for installing and configuring barnyard, oinkmaster and BASE. Instructions in a previous post using an older version of Snort and CentOS can be found at http://nkush.blogspot.com.au/2011/10/installing-snort-2912-on-centos-57.html
References
- http://fedoraproject.org/wiki/EPEL
- http://snort.org/docs
- http://nkush.blogspot.com.au/2011/10/installing-snort-2912-on-centos-57.html
- ERROR: /etc/snort/snort.conf(253) Could not stat dynamic module path "/usr/local/lib/snort_dynamicrules": No such file or directory.
- mkdir -p /usr/local/lib/snort_dynamicrules
- ERROR: /etc/snort/snort.conf(511) => Unable to open address file /etc/snort/rules/white_list.rules, Error: No such file or directory
- touch /etc/snort/rules/white_list.rules
- ERROR: /etc/snort/snort.conf(511) => Unable to open address file /etc/snort/rules/black_list.rules, Error: No such file or directory
- touch /etc/snort/rules/black_list.rules
Không có nhận xét nào:
Đăng nhận xét