Snort 是一个开源的轻量级入侵监测系统,可以监测网络上的异常情况,给出报告.
Guardian是基于Snort IPTables的一个主动防火墙,它分析Snort的日志文件,根据一定的判据自动将某些恶意的IP自动加入IPTables的输入链,将其数据包丢弃.
我自使用Snort Guardian以来,每天可以看到很多的恶意行为被终止.
安装步骤:
1.安装Snort:
*现在Snort & Guardian,目前下载地址为:
http://www.snort.org/dl/snort-2.3.0RC2.tar.gz
http://www.snort.org/dl/contrib/other_tools/guardian/guardian-1.6.tar.gz
*将上述文件拷贝至/tmp
*tar zxvf *.tgz
*cd snort-2.3.0RC2
*./configure
*make
*make install
*mkdir /etc/snort
*cd /etc/snort
*wget http://www.snort.org/dl/rules/snortrules-snapshot-CURRENT.tar.gz
* tar zxvf snortrules-snapshot-CURRENT.tar.gz
*mkdir /var/log/snort
*cd /etc
*vi snort.conf
修改后一些关键设置如下:
var HOME_NET yournetwork
var RULE_PATH /etc/snort/rules
preprocessor http_inspect: global iis_unicode_map /etc/snort/rules/unicode.map 1252
include /etc/snort/rules/reference.config
include /etc/snort/rules/classification.config
如:yournetwork 220.8.0.0/16
同时,可以选择将类似 include $RULE_PATH/local.rules等,前面的#号去掉,设置自己的规则集.
* /usr/local/bin/snort -D -l /var/log/snort -c /etc/snort.conf
* 将上一条命令写入/etc/rc.d/rc.local
2.安装guardian---需要perl支持
* cd /tmp
* tar zxvf guardian-1.6.tar.gz
* cd guardian-1.6
* echo > /etc/guardian.ignore
* cp guardian.pl /usr/local/bin/.
* cp scripts/iptables_block.sh /usr/local/bin/guardian_block.sh
* cp scripts/iptables_unblock.sh /usr/local/bin/guardian_unblock.sh
* cp guardian.conf /etc/.
* vi /etc/guardian.conf
如下:
HostGatewayByte 1
# guardian的日志文件
LogFile /var/log/guardian.log
#guardian从何处读取snort的日志
AlertFile /var/log/snort/alert
#将你需要忽略的IP放在此文件中
IgnoreFile /etc/guardian.ignore
# 封锁IP的最长时间,99999999为没有时限
TimeLimit 86400
* /usr/bin/perl /usr/local/bin/guardian.pl -c /etc/guardian.conf
* 将上一条命令加入 /etc/rc.d/rc.local
至此,完成设置.
注意:
1)snort的规则文件经常更新,可以使用如下脚本自动更新:
#!/bin/sh
cd /etc/snort
wget http://www.snort.org/dl/rules/snortrules-snapshot-CURRENT.tar.gz
tar zxvf snortrules-snapshot-CURRENT.tar.gz
exit 0
*将上述脚本存为snortupdate,并放置到/etc/cron.daily/下,可以每天更新一次.
2)guardian有时会自动退出,可以使用如下脚本解决:
#!/bin/sh
/usr/local/bin/killguardian
/usr/local/bin/guardian.pl -c /etc/guardian.conf
exit 0
将上述脚本存为restartguardian,放置到/usr/local/bin .
同时,crontab -e,加入如下一句:
* */6 * * * /usr/local/bin/restartguardian
意思为:每6小时重新启动guardian.
脚本:killguardian
#!/usr/bin/perl
#杀死当前guardian.pl进程,需要安装perl module Proc::ProcessTable
#访问http://www.cpan.org可以获得上述module
use Proc::ProcessTable;
$t = new Proc::ProcessTable;
foreach $p (@{$t->table})
{
kill 9, $p->pid if $p->cmndline =~ 'guardian.pl';
}
Garfield
A lazy, fat CAT I am!