Snort的架设

:安装Apache,Mysql,Php5,Linux(CentOS)

yum install httpd mysql mysql-server php php-devel php-mysql

安装好并测试完毕就行,这里不多加赘述.

:安装Snort:

http://www.snort.org/下载最新的Snort安装包,并注册账号下载官网提供的最新的规则包

https://www.snort.org/snort-rules/?

我们把文件下载至/usr/local/snortfile

cd  /usr/local/snortfile

tar zxvf snortrules-snapshot-2930.tar.gz

tar zxvf snort-2.9.3.1.tar.gz

cd  snor-2.9.3.1

./configure  --enable-zlib

在这里会出现错误,提示说需要各种其他的文件,包括daqaprncursespcreflexlibdnetlibpcaptcpdumpzlibbisonapr-util.apr-iconv,libxml2可能还需要gcc cmake make  g++等等 可以根据错误提示谷歌搜索都会得到答案.

PS:有时候装了也不行,可以yum安装和用二进制文件安装,二者都试一下。

make

make  install

mkdir /etc/snort

mkdir /etc/snort/rules

mkdir /etc/snort/preproc_rules

mkdir /etc/snort/so_rules

mkdir /usr/local/lib/snort_dynamicrules

mkdir /var/log/snort

把安装文件etc目录的文件全部复制到/etc/snort里面

cp /usr/local/snortfile/snort-2.9.3.1/etc/* /etc/snort/

rule文件拷贝至/etc/snort/下面

cd /usr/local/snortfile/rules

cp *  /etc/snort/rules

cd /usr/local/snortfile/so_rules

cp *  /etc/snort/so_rules

cd /usr/local/snortfile/ preproc_rules

cp *  /etc/snort/ preproc_rules

cd /usr/local/snortfile/so_rules/precompiled/Centos-5-4/i386/2.9.3.0

cp * /usr/local/lib/snort_dynamicrules

Snort.conf的配置

下面重点是snort.conf的配置

snort.conf分为9部分

1Set the network variables

2Configure the decoder

3Configure the base detection engine

4Configure dynamic loaded libraries

5Configure preprocessors

6Configure output plugins

7Customize your rule set

8Customize preprocessor and decoder rule set

9Customize shared object rule set

第一部分:

a.最新的snort版本支持ipv6,如果你的网络没有ipv6的话,把ipvar都改成var

b.把变量HOME_NET改为自己的网络  192.168.0.1/24

c.EXTERNAL_NET改为!$HOME_NET

d.修改RULE_PATH,建议改为绝对路径

var RULE_PATH /etc/snort/rules

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 注意:去掉前面的#

第三部分:不需要修改

第四部分:不需要修改

第五部分:不需要修改

第六部分:配置输入插件,注意同时只能有一个插件同时存在,一般情况下保留第一个即把第一个output取消注释

output unified2: filename merged.log, limit 128

取消include classification.config and include reference.config 前面的注释

第七部分:这里主要是配置snort启动时候需要读取哪些规则文件,这里根据实际情况决定是否保留,刚开始建议注释掉除local.rules之外所有的规则文件。

第八部分:取消注释所有

第九部分:: 取消注释所有

至此snort安装并配置完毕,下面说下barnyard2的安装和配置

 

三:安装Barnyard2:

http://www.securixlive.com/barnyard2/download.php 下载文件至/usr/local/snortfile/

cd  /usr/local/snortfile

tar zxvf barnyard2-1.9.tar.gz

cd barnyard2-1.9

# ./configure --with-mysql

# make

# make install

复制barnyard2.conf文件至/etc/snort

cp /usr/local/snortfile/barnyard2-1.9/etc/barnyard2.conf  /etc/snort/

建立barnyard2日志目录

mkdir /var/log/barnyard

使这个目录可写

chmod 666 /var/log/barnyard2

建立一个barnyard2需要的空白文件

touch /var/log/snort/barnyard2.waldo

重要:拷贝sid-msg.map/etc/snort里面 该文件在snortrules-snapshot-2930.tar.gz包里面的etc目录

cp  etc/sid-msg.map /etc/snort/

Barnyard2.conf的配置:

这里也有三部分:

1configure the variable declarations

2setup the input plugins

3 setup the output plugins

第一部分:

config reference_file: /etc/snort/reference.config

config classification_file: /etc/snort/classification.config

config gen_file: /etc/snort/gen-msg.map

config sid_file: /etc/snort/sid-msg.map

这些文件是否存在

然后找到下面的行,取消注释并修改配置如下:

config logdir: /var/log/barnyard2

config hostname: localhost

config interface: eth0

config waldo_file: /var/log/snort/barnyard2.waldo

第二部分:不需要修改

第三部分:注释掉alert_fast

在最后新增

output database: log, mysql, user=snort password=snortpass dbname=snort host=localhost

PS密码不需要加引号

至此Barnyard2安装完成,接下来安装BASE

四:BASE的安装

1:首先下载BASE ADODB

http://adodb.sourceforge.net/#download

http://sourceforge.net/projects/secureideas/files/latest/download

然后解压这些文件并把他们放在apache 网站的目录内

tar -xzvf base-1.4.5.tar.gz

tar -xzvf adodb517.tgz

cp *  /var/www/html/base

cp *  /var/www/html/adodb5

接下来打开浏览求按照步骤配置base

2:面为base安装图形插件用来绘制图形

pear install image_graph-alpha

pear install Numbers_Roman

pear install Numbers_Words-beta

pear install image_canvas-alpha

以上为Snort+Barnyard2+BASE安装及配置的过程。

五:使用方法

snort有三种工作模式 嗅探器,日志记录和IDS

嗅探器相当于sniffer

日志记录模式会把记录写到文件内

IDS模式会把获取的包根据规则来匹配然后进行操作

barnyard2会读取日志文件在把他内容写入数据库,BASE通过读取数据库然后再网页上显示出来。

六:测试

首先在snort.conf中注释掉除local.rules之外所有的规则

编辑local.rules添加

alert icmp any any -> any any (msg:"ICMP Testing Rule"; sid:1000001;)

然后打开一个终端,输入

barnyard2 -c /etc/snort/barnyard2.conf -d /var/log/snort -f snort.log -w /var/log/snort/barnyard2.waldo

在打开一个终端输入:

snort  -A console -u snor -g snort  -q  -c /etc/snort/snort.conf  -q可省略

这时候用一台机器ping另外一个,2个终端会弹出log记录,同时BASE也会更新数据。

    alert tcp any any -> 192.168.1.0/24 111 (content:"|00 01 86 a5|"; msg: "mountd access";)

   动作协议源ip目标ip地址与网络掩码,以及源和目标端口信息