Simulating a shell script to resolve Dos attacks

Source: Internet
Author: User
Tags iptables

Method 1:

#!/bin/sh

While True

Do

awk ' {print $} '. Access.log|grep–v "^$" |sort|uniq–c >/tmp/access.log

#netstat –an|grep est|awk–f ' [:]+ ' {print $6} ' |sort|uniq–c >/tmp/access.log determine network Connections

EXEC </tmp/access.log

While Read line

Do

Ip= ' echo $line |awk ' {print $} '

Count= ' echo $line |awk ' {print $} '

If [$count –gt] && [' Iptables–l-n|grep ' $ip "|wc–l '-LT 1]

Then

Iptables–a input–s $ip-j DROP

echo "$line is dropped" >>/tmp/droplist.log

Fi

Done

Sleep 180

Done

Method 2:

#!/bin/sh

If [$#-ne 1];then

echo "Usage:$0 ARG"

Exit

Fi

IPT () {

awk ' {print '} ' $ |sort|uniq-c|sort-rn-k1 >/tmp/access.log

EXEC </tmp/access.log

While Read line

Do

Ip= ' echo $line |awk ' {print $} '

Count= ' echo $line |awk ' {print $} '

If ["$count"-gt 100-a ' iptables-l-n|grep "$ip" |wc-l '-lt 1];then

Iptables-i input-s "$ip"-j DROP

echo "$ip" >>/tmp/ip_$ (date +%f). log

Fi

Done

}

Del () {

touch/tmp/ip_$ (date +%f-d ' -1day '). Log

EXEC </tmp/ip_$ (date +%f-d ' -1day '). Log

While Read line

Do

If [' Iptables-l-n|grep ' $line "|wc-l '-le 1];then

iptables-d input-s $line-j DROP

Fi

Done

}

Main () {

While True

Do

IPT $

Sleep 5

Del

Done

}

Main $*

Simulating a shell script to resolve Dos attacks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.