黑帽联盟

 找回密码
 会员注册
查看: 1241|回复: 0
打印 上一主题 下一主题

[脚本语言] shell防ddos攻击脚本

[复制链接]

852

主题

38

听众

3177

积分

白金VIP

Rank: 8Rank: 8

  • TA的每日心情
    开心
    2024-3-7 12:52
  • 签到天数: 1538 天

    [LV.Master]伴坛终老

      最近服务器经常受到攻击,并且还大多数是晚上,实在是受不了晚上起来处理,直接从网上搜了个写得不错的shell封ddos脚本,这个脚本是老外写的,我觉得效果还不错,发给大家看看吧.

       系统:centos 5.9 64位

    脚本内容:
    vi ipdrop.sh
    1. #!/bin/bash

    2. #Collecting list of ip addresses connected to port 80

    3. netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1 > /root/iplist

    4. #Limit the no of connections
    5. LIMIT=100;

    6. for ip in `cat /root/iplist |awk '{print $2}'`;do

    7. if [ `grep $ip /root/iplist | awk '{print $1}'` -gt $LIMIT ]
    8. then
    9. echo "100 connection from $ip... `grep $ip /root/iplist | awk '{print $1}'` number of connections... Blocking $ip";

    10. #Blocking the ip ...

    11. /etc/rc.d/init.d/iptables save > /dev/null;
    12. CHECK_IF_LOCALIP=0;
    13. /sbin/ifconfig | grep $ip > /dev/null;
    14. if [ $? -ne $CHECK_IF_LOCALIP ]
    15. then
    16. {
    17. FLAG=0;
    18. grep $ip /etc/sysconfig/iptables | grep DROP > /dev/null;
    19. if [ $? -ne $FLAG ]
    20. then
    21. iptables -I INPUT -s $ip -j DROP;
    22. else
    23. echo " Ipaddress $ip is already blocked ";
    24. fi
    25. }
    26. else
    27. echo " Sorry, the ip $ip cannot be blocked since this is a local ip of the server ";
    28. fi
    29. fi
    30. done
    复制代码
    帖子永久地址: 

    黑帽联盟 - 论坛版权1、本主题所有言论和图片纯属会员个人意见,与本论坛立场无关
    2、本站所有主题由该帖子作者发表,该帖子作者与黑帽联盟享有帖子相关版权
    3、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和黑帽联盟的同意
    4、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任
    5、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
    6、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
    7、黑帽联盟管理员和版主有权不事先通知发贴者而删除本文

    勿忘初心,方得始终!
    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部