操纵系统:Centos6.9
snort版本:2.9.90
daq 版本: 2.0.6 数据采集
barnyard 版本:2-1.9 Barnyard2的作用是读取snort产生的二进制事件文件并存储到MySQL
rules版本:snortrules-snapshot-2990
libdnet 通过yum 安装或者编译安装,编译参数 –with-pic
首先将其解压,然后将其编译到/usr/local/ 下
tar -zxvf snort-2.9.9.0.tar.gz
tar -zxvf daq-2.0.6.tar.gz
编译daq:
./configure && make && make install -j 2
编译snort :
./configure --enable-sourcefire && make && make install -j 2
#error dnet header not found 安装 apt-get install libdumbnet-dev
# error daq_static library not found
ldconfig几个需要注意的地方!
1. 往/lib和/usr/lib里面加东西,是不用修改/etc/ld.so.conf的,但是完了之后要调一下ldconfig,不然这个library会找不到
2. 想往上面两个目录以外加东西的时候,一定要修改/etc/ld.so.conf,然后再调用ldconfig,不然也会找不到
比 如安装了一个mysql到/usr/local/mysql,mysql有一大堆library在/usr/local/mysql/lib下面,这时就 需要在/etc/ld.so.conf下面加一行/usr/local/mysql/lib,保存过后ldconfig一下,新的library才能在程 序运行时被找到。
3. 如果想在这两个目录以外放lib,但是又不想在/etc/ld.so.conf中加东西(或者是没有权限加东西)。那也可以,就是export一个全局变 量LD_LIBRARY_PATH,然后运行程序的时候就会去这个目录中找library。一般来讲这只是一种临时的解决方案,在没有权限或临时需要的时 候使用。
4. ldconfig做的这些东西都与运行程序时有关,跟编译时一点关系都没有。编译的时候还是该加-L就得加,不要混淆了。
5. 总之,就是不管做了什么关于library的变动后,最好都ldconfig -v /usr/local/lib一下,不然会出现一些意想不到的结果。不会花太多的时间,但是会省很多的事
编译完成后会在编译目录中生成config.log文件,该文件记录这有关编译信息。
编译的默认目录在/usr/local/下。
在/etc/创建snort目录,然后将解压目录中的配置cp 过来:cp /root/snort-2.9.9.0/etc/* .
ls /etc/snort
attribute_table.dtd file_magic.conf Makefile Makefile.in snort.conf unicode.map
classification.config gen-msg.map Makefile.am reference.config threshold.conf
在/etc/snort中执行对snortrules的解压操作
tar -xf snortrules-snapshot-2990.tar.gz -C /etc/snort/
创建规则:
touch /etc/snort/rules/white_list.rules /etc/snort/rules/black_list.rules
至此:配置文件在/etc/snort中,而规则在/etc/snort/rules中 。
使用root 用户执行该程序
修改配置文件:
在/etc/snort/snort.conf 的40-120行。
如果你监控的主机为192.168.1.0/24 那么:
var RULE_PATH /etc/snort/rules
ipvar HOME_NET 192.168.1.0/24
ipvar EXTERNAL_NET !$HOME_NET
var SO_RULE_PATH /etc/snort/so_rules
var PREPROC_RULE_PATH /etc/snort/preproc_rules
var WHITE_LIST_PATH /etc/snort/rules
var BLACK_LIST_PATH /etc/snort/rules
config logdir : /var/log/snort
创建启动,停止的脚本文件:
在/root/snort-2.9.9.0/rpm中,有一个snortd ,可以将其复制到/etc/init.d/snort 中,给予合适的权限,当作脚本文件使用。
添加启动项,并设置开机启动: chkconfig –add snort chkconfig snort on
添加snort的命令行工具到/usr/bin/下,方便快捷使用:
ln -s /usr/local/snort/bin/snort /usr/local/bin/snort
在/etc/sysconfig下添加snort的sysconfig配置信息。
cat snort
# /etc/sysconfig/snort
# $Id: snort.sysconfig,v 1.8 2003/09/19 05:18:12 dwittenb Exp $
#### General Configuration
INTERFACE=eth0
CONF=/etc/snort/snort.conf
PASS_FIRST=0
#### Logging & Alerting
LOGDIR=/var/log/snort
ALERTMODE=fast
DUMP_APP=1
BINARY_LOG=1
NO_PACKET_LOG=0
PRINT_INTERFACE=0
测试:
snort -T -i eth0 -u snort -g snort -c /etc/snort/snort.conf
报错:
ERROR: snort_stream5_tcp.c(906) Could not initialize tcp session memory pool.
Fatal Error, Quitting..
修改:
vi /etc/snort/snort.conf
preprocessor stream5_global: track_tcp yes, \
track_udp yes, \
track_icmp no, \
max_tcp 162144, \
max_udp 131072, \
max_active_responses 2, \
min_response_seconds 5
新建一条测试规则:
alert icmp any any -> $HOME_NET any (msg:”Ping”;sid:1000003;rev:1;)
snort -i eth0 -c /etc/snort/snort.conf -A fast-l /var/log/snort/
所有ping命令均会触发报警。
在tail -f /var/log/snort/alert 查看警告信息
11/29-16:11:50.036879 [**] [1:1000003:1] Ping [**] [Priority: 0] {ICMP} 120.26.48.161 -> 172.17.36.79
11/29-16:11:50.036931 [**] [1:1000003:1] Ping [**] [Priority: 0] {ICMP} 172.17.36.79 -> 120.26.48.161
11/29-16:11:51.037137 [**] [1:1000003:1] Ping [**] [Priority: 0] {ICMP} 120.26.48.161 -> 172.17.36.79</
安装数据库和barnyard
下载barnyard 软件,解压。
安装数据库及相关:
yum install -y mysql-server mysql-devel php-mysql php-adodb php-pear php-gd libtool php-imapphp-ldap php-mbstring php-odbc php-pear php-xml php-pecl-apc
登陆数据库,创建snort 库,默认字符集为utf8
create database snort default character set utf8;
use snort;
source /root/barnyard2-1.9/schemas/create_mysql;
#将barnyard2表结构存储过程刷入snort库中。
show tables;
+------------------+
| Tables_in_snort |
+------------------+
| data |
| detail |
| encoding |
| event |
| icmphdr |
| iphdr |
| opt |
| reference |
| reference_system |
| schema |
| sensor |
| sig_class |
| sig_reference |
| signature |
| tcphdr |
| udphdr |
+------------------+
安装barnyard2
./configure –with-mysql
报错:
unable to find mysqlclient library (libmysqlclient.*)
错误产生原因是:
问题是64位系统中 libmysqlclient 默认安装到了 /usr/lib64/mysql/ 目录下
而/usr/lib 目录下没有相应文件,但是php编译时,要去 /usr/lib目录下查找
解决方法:
ln -s /usr/lib64/mysql/libmysqlclient.so.15.0.0/usr/lib/libmysqlclient.so
或者是:
直接指定--with-mysql-libraries=/usr/lib64/mysql
编译安装barnyard2:
./configure --with-mysql --with-mysql-libraries=/usr/lib64/mysql
make && make install -j 2
cp barnyard2的配置到/etc/snort中
cp etc/barnyard2.conf /etc/snort/
cp /etc/snort/etc/sid-msg.map /etc/snort
编辑barnyard2.conf
config hostname: localhost
config interface: eth0
config waldo_file:/var/log/snort/barnyard2.waldo
output database: log,mysql,user=root password=Ginkgo+007 dbname=snort host=localhost
config logdir: /var/log/barnyard
mkdir /var/log/barnyard -p
touch /var/log/snort/barnyard2.waldo
@@@@http://blog.csdn.net/u013816144/article/details/53729153