根据web日志或者或者网络连接数,监控当某个IP并发连接数或者短时内PV达到100,即调用防火墙命令封掉对应的IP,监控频率每隔3分钟。防火墙命令为:iptables -I INPUT -s 10.0.1.10 -j DROP。这个脚本是基于IPTABLES的周末将firewalld的防火墙脚本写好分享给大家

#!/bin/sh

#

[ -f /etc/init.d/functions ] && . /etc/init.d/functions

IP_file="/server/scripts/ddos.txt"

IP_filter_command="iptables -I INPUT -j DROP -s"

IP_recover_command="iptables -D INPUT -j DROP -s"

function IP_check(){

grep "EST" ${IP_file}|awk -F "[ |:]+" '{print $6}'|sort |uniq -c|sort -rn -k1 > /server/scripts/ip.txt

}

function IP_filter(){

exec < /server/scripts/ip.txt

while read line

do

IP_count=`echo $line|awk '{print $1}'`

IP=`echo $line|awk '{print $2}'`

IP_fil=`iptables -L -n|grep "${IP}"|wc -l`

if [ ${IP_count} -gt 25 -a ${IP_fil} -eq 0 ];then

${IP_filter_command} ${IP}

echo "${IP}" >> /server/scripts/ip_filtered.txt

action "Filter ${IP}" /bin/true

fi

done

}

function IP_recover(){

exec < /server/scripts/ip.txt

while read line

do

IP_count=`echo $line|awk '{print $1}'`

IP=`echo $line|awk '{print $2}'`

IP_fil=`iptables -L -n|grep "${IP}"|wc -l`

if [ ${IP_count} -le 25 -a ${IP_fil} -eq 1 ];then

${IP_recover_command} ${IP}

echo "${IP}" >> /server/scripts/ip_filtered.txt

action "Recover ${IP}" /bin/true

fi

done

}

function main(){

case "$1" in

filter)

IP_check

echo "$(date +%F-%H:%M:%S) filtered by $(whoami)" >> /server/scripts/ip_filtered.txt

IP_filter

;;

recover)

IP_check

echo "$(date +%F-%H:%M:%S) recovered by $(whoami)" >> /server/scripts/ip_filtered.txt

IP_recover

;;

*)

echo "USAGE:$0 {filter|recover}"

exit 1

esac

}

main $*

shell日常实战防dos攻击的更多相关文章

  1. shell脚本-实战防dos攻击

    根据web日志或者或者网络连接数,监控当某个IP并发连接数或者短时内PV达到100,即调用防火墙命令封掉对应的IP,监控频率每隔3分钟.防火墙命令为:iptables -I INPUT -s 10.0 ...

  2. 运维派 企业面试题6 防dos攻击

    Linux运维必会的实战编程笔试题(19题) 企业实战题6:请用至少两种方法实现! 写一个脚本解决DOS攻击生产案例 提示:根据web日志或者或者网络连接数,监控当某个IP并发连接数或者短时内PV达到 ...

  3. nginx防DOS攻击

    将 timeout 设低来防止 DOS 攻击 client_body_timeout 10; client_header_timeout 10; keepalive_timeout 5 5; send ...

  4. shell日常实战练习——通过监视用户登陆找到入侵者

    #!/usr/bin/bash #用户检测入侵工具 AUTHLOG=/var/log/secure if [[ -n $1 ]];then AUTHLOG=$1 echo "Using Lo ...

  5. 防DOS攻击-网络连接法

    #!/bin/bash netstat -antup | grep SYN_RECV | awk '{print $5}' |awk -F: '{print $1}'|sort|uniq -c > ...

  6. 企业Shell面试题5:解决DOS攻击生产案例

    企业Shell面试题5:解决DOS攻击生产案例 写一个Shell脚本解决DOS攻击生产案例. 请根据web日志或者或者网络连接数,监控当某个IP并发连接数或者短时内PV达到100(读者根据实际情况设定 ...

  7. Linux系统防CC攻击自动拉黑IP增强版Shell脚本 《Linux系统防CC攻击自动拉黑IP增强版Shell脚本》来自张戈博客

    前天没事写了一个防CC攻击的Shell脚本,没想到这么快就要用上了,原因是因为360网站卫士的缓存黑名单突然无法过滤后台,导致WordPress无法登录!虽然,可以通过修改本地hosts文件来解决这个 ...

  8. shell解决DOS攻击生产案例

    解决DOS攻击生产案例企业实战题5:请用至少两种方法实现!写一个脚本解决DOS攻击生产案例.提示:根据web日志或者或者网络连接数,监控当某个IP并发连接数或者短时内PV达到100,即调用防火墙命令封 ...

  9. 真实故事:网站遭遇DOS攻击

     网站遭遇DOS攻击 一个.事件背景 长假对于IT人员来说是个短暂的休整时期,可IT系统却一时也不能停.越是节假日,越可能出大问题,以下要讲述的就是一起遭受DOS攻击的案例. 春节长假刚过完,小李 ...

随机推荐

  1. PHP工厂模式demo

    <?php//工厂模式 interface operstion{ function oper($a,$b);}//加class add implements operstion{ functio ...

  2. 2017-2018 ACM-ICPC Latin American Regional Programming Contest D.Daunting device

    题意:一个数组n个操作每次先查询p颜色的数量然后求出区间,区间染色成x,然后求最大染色数 题解:odt裸题,多维护一个color个数数组就好了 //#pragma comment(linker, &q ...

  3. hdu 1257 LIS (略坑5

    ---恢复内容开始--- 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...

  4. Leetcode 120

    class Solution { public: int minimumTotal(vector<vector<int>>& triangle) { ) ][]; tr ...

  5. 元类应用ORM实现

    首先看下一个简单的例子 # 需求 import numbers class Field: pass class IntField(Field): # 数据描述符 def __init__(self, ...

  6. 学习Spring Security OAuth认证(一)-授权码模式

    一.环境 spring boot+spring security+idea+maven+mybatis 主要是spring security 二.依赖 <dependency> <g ...

  7. poj1002 大数的 n的m次

    import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(S ...

  8. ActiveMQ 中的链表

    ActiveMQ 中的消息在内存中时,以链表形式保存,以 PendingList 表示,每一个消息是 PendingNode. PendingList 主要有2种实现:OrderedPendingLi ...

  9. 使用外置的Servlet容器

    嵌入式Servlet容器: 优点:简单.便捷 缺点:默认不支持JSP.优化定制比较复杂(使用定制器[ServerProperties.自定义EmbeddedServletContainerCustom ...

  10. POJ 2243 Knight Moves(BFS)

    POJ 2243 Knight Moves A friend of you is doing research on the Traveling Knight Problem (TKP) where ...