zoukankan      html  css  js  c++  java
  • shell解决DOS攻击生产案例

    解决DOS攻击生产案例
    企业实战题5:请用至少两种方法实现!写一个脚本解决DOS攻击生产案例。
    提示:根据web日志或者或者网络连接数,监控当某个IP并发连接数或者短时内PV达到100,即调用防火墙命令封掉对应的IP,监控频率每隔3分钟。防火墙命令为:iptables -A INPUT -s 10.0.1.10 -j DROP。

    #!/bin/bash
    log=/tmp/tmp.log
    [ -f $log ] || touch $log
    function add_iptables(){
        while read line
            do
              ip=`echo $line|awk '{print $2}'`
              count=`echo $line|wc -l`
                if [ $count -gt 100 ] && [`iptables -L -n|grep "$ip"|wc -l` -lt 1 ]
                 then
                    iptables -I INPUT -s $ip -jDROP
                    echo "$line isdropped" >>/tmp/droplist.log
                fi
            done<$log
    }
    function main(){
        while true
               do
                 netstat -an|grep EST|awk '{print $(NF-1)}'|awk -F '[:]' '{print $1}'|sort|uniq -c >$log
                 add_iptables
                 sleep 180
        done
    }
     
    main
  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    iOS开发系列--IOS程序开发概览
    iOS开发系列—Objective-C之Foundation框架
  • 原文地址:https://www.cnblogs.com/sunziying/p/6556470.html
Copyright © 2011-2022 走看看