当前位置: 首页 > 工具软件 > Guardian > 使用案例 >

使用Snort+Guardian建立轻量级入侵测系统和主动防火墙

夏高朗
2023-12-01

Snort 是一个开源的轻量级入侵监测系统,可以监测网络上的异常情况,给出报告;
Guardian是基于Snort+IPTables的一个主动防火墙,它分析Snort的日志文件,根据一定的判据自动将某些恶意的IP自动加入IPTables的输入链,将其数据报丢弃。


安装步骤:
1.下载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

2.安装Snort:
*将上述文件拷贝至/opt
[root@game snort]# rpm -qa | grep pcre   #确认系统是否安装了pcre,Snort依赖于pcre的支持,如果系统没有安装pcre,Snort编译将会失败
pcre-devel-3.9-10
pcre-3.9-10

*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
*cp /etc/snort/rules/snort.conf /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 210.75.18.32/29

同时,可以选择将类似
include $RULE_PATH/local.rules
等,前面的#号去掉,设置自己的规则集

* /usr/local/bin/snort -D -l /var/log/snort -c /etc/snort.conf &

* 将上一条命令写入/etc/rc.d/rc.local

3. 安装guardian  #注:需要perl支持
* cd /opt
* 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有时会自动退出,可以使用如下脚本解决:
#!/usr/bin/perl
use Proc::ProcessTable;

$found=0;
$t = new Proc::ProcessTable;
$g = "guardian.pl";
foreach $p ( @{$t->table} ){
$f=($p->cmndline =~ m/guardian/);
if($f==1)
{$found=1;
last;
}
}
if($found == 1)
{
print "guardian is alive!/n";
}
else
{
print "guardian is dead!/n";
print "restart guardian now ... /n";
system "/usr/local/bin/guardian.pl -c /etc/guardian.conf";
}
将上述脚本存为testguardian,放置到/etc/cron.hourly下,意思为:每1小时检测guardian是否存活,如果已经死亡就重新启动guardian


chmod +x /etc/cron.hourly/testguardian

同时,编辑/etc/crontab
在path一行加入/usr/local/bin

 


脚本: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';

}

参考http://bbs.chinaunix.net/forum/viewtopic.php?t=484898&show_type=&postdays=0&postorder=asc&start=0

 类似资料: