当前位置:操作系统 > Unix/Linux >>

Freebsd构建小型的入侵检测系统

1.Snort简介

  Snort 是一个强大的轻量级的网络入侵检测系统。它具有实时数据流量分析和日志IP 网络数据包的能力,能够进行协议分析,对内容进行搜索/匹配。它能够检测各种不同的攻击方式,对攻击进行实时报警。更重要的它是免费的,在中小企业中很好的适应网络环境,不需要太多的资源和资金就能建立起一个优秀的IDS系统。

  2.系统平台

  安装平台选择FreeBSD 4.9 ,本身足够安全,坚固;特性喜欢PORTS安装起来少了不少麻烦。

  Hawk# uname -a

  FreeBSD hawk.the9 4.9-RELEASE FreeBSD 4.9-RELEASE

  3.需要软件

  Mysql-server-3.23.58 http://mysql.secsup.org

  Snort2.0.6 http://www.snort.org

  Apache-2.0.47 http://www.apache.org

  mod_php4-4.3.3,1 http://www.php.net

  adodb-3.60_1 http://phplens.com

  acid-0.9.6b23 http://acidlab.sourceforge.net

  Jpgraph-1.12.2 http://jpgraph.techuk.com

  4.安装SNORT

  1)安装mysql

  hawk# cd /usr/ports/databases/mysql323-server

  hawk# make install

  2)安装apache

  hawk# cd /usr/ports/www/apache2/

  hawk# make install

  3)安装PHP

  hawk # cd /usr/ports/www/mod_php4

  hawk # make install

  4)配置APACHE

  编辑httpd.conf (/usr/local/etc/apache2)

  DocumentRoot "/usr/local/www/snort"

  LoadModule php4_module modules/libphp4.so

  AddType application/x-httpd-php .php

  5)安装SNORT

  hawk# mkdir /etc/snorthawk# mkdir /var/log/snorthawk# tar -zxvf snort-2.0.6.tar.gzhawk# mv snort-2.0.6 /etc/snorthawk# ./configure --with-mysqlhawk# makehawk# make installhawk# cd /etc/snort/etchawk# cp snort.conf /etc/snort/hawk# cp *.config /etc/snort

  6) 安装SNORT的规则库

  可以在SNORT站点上下载标准规则库,基本够用了。2.0.0.x的SNORT使用STABLE rules,而2.0.1.x的SNORT使用CURRENT rules。

  

  hawk# mkdir /etc/snort/etchawk# wget http://www.snort.org/dl/rules/snortrules-stable.tar.gzhawk# tar xvfz snortrules-stable.tar.gz

  7)配置SNORT

  修改snort.conf (/etc/snort/snort.conf)

  var HOME_NET 172.18.0.0/22 (修改为你的内部网网络地址)

  var EXTERNAL_NET any #外网,关键字any这里表示HOME_NET之外的所有地址

  var DNS_SERVERS 202.197.32.12 #DNS 服务器

  var RULE_PATH ../rules 修改为 var RULE_PATH /etc/snort/etc/rules

  改变记录日志数据库:

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

  设置snort启动

  hawk# vi /usr/local/etc/rc.d/snort.sh#!/bin/shcase "$1" instart)/usr/local/bin/snort -Dqc /etc/snort/snort.conf > /dev/null && echo -n " snort";;stop)kill `cat /var/run/snort_*.pid`;;restart)killall -1 `cat /var/run/snort_*.pid`;;*)echo "Usage: snort.sh [start|stop|restart]";;esac

  不过建议是手动启动,我在使用中发现自动启动有一点问题,等系统完全启动完了再启动SNORT就一切正常。

  9)在mysql中建立数据库

  先建立SNORT使用的数据库

  mysql>create database snort;

  mysql>grant INSERT,SELECT on root.* to snort@localhost;

  mysql>quit;

  进入snort安装目录:

  mysql -p <./contrib/create_mysql snort

  >Enter password:

  安装DB表:(在contrib目录)

  zcat snortdb-extra.gz | mysql -p snort

  >Enter password:

  安装完成检查一下表的显示

  mysql>show databases;+------------+| Database+------------+| mysql| snort| test+------------+3 rows in set (0.00 sec)mysql>use snort;

  mysql>show tables; 将会有这些:

  +------------------+| Tables_in_snort |+------------------+| data| detail| encoding| event| flags| icmphdr| iphdr| opt| protocols| reference| reference_system| schema| sensor| services| sig_class| sig_reference| signature| tcphdr| udphdr+------------------+19 rows in set (0.00 sec)mysql>exit

  

  5.安装配置Web接口

  1)先安装GD库

  hawk# cd /usr/ports/graphics/gd

  hawk# make install

  2) 安装 jpgraph-1.12.2

  hawk# cd /usr/ports/graphics/jpgraph

  hawk# make install

  3)安装adodb-3.60_1

  hawk# cd /usr/ports/databases/adodb

  hawk# make install

  4 )安装acid-0.9.6b23

  hawk# cd /usr/ports/security/acid

  hawk# make install

  5)配置 acid

  hawk# mv /usr/local/www/data.default/php/adodb /usr/local/www/snort/

  hawk# mv /usr/local/www/data.default/php/acid /usr/local/www/snort/

  编辑acid_conf.php,修改相关配置如下:

  $DBlib_path = "/usr/local/www/snort/adodb";/* The type of underlying alert database** MySQL : "mysql"* PostgresSQL : "postgres"* MS SQL Server : "mssql"*/$DBtype = "mysql";/* Alert DB connection parameters* - $alert_dbname : MySQL database name of Snort alert DB* - $alert_host : host on which the DB is stored* - $alert_port : port on which to access the DB* - $alert_user : login to the database with this user* - $alert_password : password of the DB user** This information can be gleaned from the Snort database* output plugin configuration.*/$alert_dbname = "snort";$alert_host = "localhost";$alert_port = "";$alert_user = "root";$alert_password = "Your_Password";/* Archive DB connection parameters */$archive_dbname = "snort";$archive_host = "localhost";$archive_port = "";$archive_user = "root";$archive_password = "Your_Password ";

  6)可以进入进入web界面:

  http://172.18.5.198/acid/acid_main.php

  点"Setup Page"链接 ->Create Acid AG

  然后访问http:// 172.18.5.198/acid将会看到ACID界面。

  

  6.最后测试

  重新启动系统进入系统,启动SNORT。然后用NMAP,XSCAN,SSS来扫描一下,看看是不是有结果了。我用的是Retina。下面是成功后的界面。

  7.SNORT规则编写简介

  一条Snort规则可以分为前后两个部分,规则头和后面的选项部分。规则头包含有匹配后的动作命令、协议类型、以及选择流量的四元组(源目的IP及源目的端口)。规则的选项部分是由一个或几个选项的符合,所有主要选项之间是与的关系。选项之间可能有一定的依赖关系,选项主要可以分为四类,第一类是数据包相关各种特征的描述选项,比如:content、fla

  gs、dsize、ttl等;第二类是规则本身相关一些说明选项,比如:reference、sid、classtype、priority等;第三类是规则匹配后的动作选项,比如:msg、resp、react、session、logto、tag等;第四类是选项是对某些选项的修饰,比如从属于content的nocase、offset、depth、regex等。由于snort的规则语言语法非常简单,所以可以对新发现的攻击作出快速的反应,迅速开发新的snort规则。编写新的规则,最重要的是知道新攻击的特征码。要得到一个新的攻击的特征码,一般的方法就是进行实际的测试。对一个测试网络进行攻击,使用snort记录在攻击主机和测试网络之间的数据流。然后,对记录的数据进行分析得到其唯一的特征码,最后把得到的特征码加入到规则中。下面是IMAP缓冲区溢出攻击被记录下的数据包:

  ---------------------------------------
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,