这个页面是为了方便实时看路由器的flow--ip流的流量,以便快速分析攻击,如果有很多外网ip同时访问内网一个ip(内网有大量服务器,平时访问不会那么集中),那么该网页会有颜色提示,方便快速定位和排查攻击
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum -y install nfdump httpd php
mkdir -p /usr/local/nfdump/test
mkdir /flow
chown apache.apache /flow
setfacl -d --set g:apache:rwx /flow
setfacl -d --set u:apache:rwx /flow
nfcapd -z -w -D -l /usr/local/nfdump/test -p 9996 -S 0 -t 60 -T all -s 2000
chkconfig httpd on && service httpd restart
vim /etc/rc.local 最下面加入下面这行
nfcapd -z -w -D -l /usr/local/nfdump/test -p 9996 -S 0 -t 60 -T all -s 2000
iptables放开80和udp的9996端口,关闭selinux
vim /flow/flow.sh 按a,然后粘贴下面代码
#!/bin/bash
nfdump -r `find /usr/local/nfdump/test -name nfcapd.cu*` 'router ip '$1' and if '$2'' -o fmt:%sa" ->"%da" --- "%byt -s record/bytes -q -n 60 > $3
vim /flow/top.sh 按a,然后粘贴下面代码
#!/bin/bash
if [[ `cat $1 |awk '{print $3}'|sort|uniq -c|awk '{print $1}'|sort -nr|head -1` -ge 40 ]];then
echo "1" > $2
else
echo "0" > $2
fi
vim /var/www/html/index.php 主页,按a,然后粘贴下面代码,其中1.php等是每个链路的单独页面,请自行添加
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Refresh" content="187">
</head>
<body>
<div style="text-align:left;padding:50px;">
<iframe width="400" height="485" frameborder="1" scrolling="yes" src="1.php"></iframe>
<iframe width="400" height="485" frameborder="1" scrolling="yes" src="2.php"></iframe>
<iframe width="400" height="485" frameborder="1" scrolling="yes" src="3.php"></iframe>
</div>
</body>
</html>
vim /var/www/html/1.php 按a,然后粘贴下面代码,其中链路名和路由器ip和snmp接口号要自己改
<h2>链路名</h2>
<?php
$a="/flow/1.txt";
$b="/flow/1";
system("sh /flow/flow.sh 路由器ip snmp接口号 $a");
$f=file("$a");
foreach($f as &$line) echo $line.'<br />';
system("sh /flow/top.sh $a $b");
if (`cat $b` == 1) {
$c="background-color:#93FF93";
}else{
$c="";
}
?>
<html>
<body style='<?php echo $c?>'>
<meta http-equiv="Refresh" content="58">
</body>
</html>
访问 http://服务器ip/index.php 即可显示1分钟刷新的top60