服务器 频道

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

    安装完成检查一下表的显示
    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、flags、dsize、ttl等;第二类是规则本身相关一些说明选项,比如:reference、sid、classtype、priority等;第三类是规则匹配后的动作选项,比如:msg、resp、react、session、logto、tag等;第四类是选项是对某些选项的修饰,比如从属于content的nocase、offset、depth、regex等。由于snort的规则语言语法非常简单,所以可以对新发现的攻击作出快速的反应,迅速开发新的snort规则。编写新的规则,最重要的是知道新攻击的特征码。要得到一个新的攻击的特征码,一般的方法就是进行实际的测试。对一个测试网络进行攻击,使用snort记录在攻击主机和测试网络之间的数据流。然后,对记录的数据进行分析得到其唯一的特征码,最后把得到的特征码加入到规则中。下面是IMAP缓冲区溢出攻击被记录下的数据包:
    --------------------------------------------------------------------------
    052499-22:27:58.403313 192.168.1.4:1034 -> 192.168.1.3:143
    TCP TTL:64 TOS:0x0 DF
    ***PA* Seq: 0x5295B44E Ack: 0x1B4F8970 Win: 0x7D78
    90 90 90 90 90 90 90 90 90 90 90 90 90 90 EB 3B ...............;
    5E 89 76 08 31 ED 31 C9 31 C0 88 6E 07 89 6E 0C ^.v.1.1.1..n..n.
    B0 0B 89 F3 6E 08 89 E9 6E 0C 89 EA CD 80 .....n....n.....
    31 DB 89 D8 40 CD 80 90 90 90 90 90 90 90 90 90 1...@...........
    90 90 90 90 90 90 90 90 90 90 90 E8 C0 FF FF FF ................
    2F 62 69 6E 2F 73 68 90 90 90 90 90 90 90 90 90 /bin/sh.........
    ---------------------------------------------------------------------------
    这个攻击的特征码就是/bin/sh字符串及其前面的机器代码。这实际上是一个shellcode。四用这些信息可以很快开发出一条新的规则:
    alert tcp any any -> 192.168.1.0/24 143 (content:"|E8C0 FFF FF|/bin/sh";
    msg:"New IMAP Buffer Overflow detected!"
    其中的特征码含有文本和16进制两种形式,它们以|分割,snort运行时都被转换为二进制形式。

    至此,FREEBSD 下的Snort 安装建立成功。结果可以直接从WEB界面上看到,一套完整的IDS系统就可以正常运行了。

    由于个人水平所限,本文难免会有遗漏和错误之处,希望大家不吝指正。

0
相关文章