Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
6001CEM/defend.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
28 lines (28 sloc)
936 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description : SYN Flood Prevention using iptables against Scapy SYN packets generated | |
> /var/log/DDOS_IP.log | |
> /tmp/test1.txt | |
> /tmp/test2.txt | |
trap "echo ;echo Caught EXIT signal;iptables -F;echo Iptables entries cleared;echo HaX0R SVP" EXIT | |
while true; | |
do | |
date >> /var/log/DDOS_IP.log | |
netstat | grep -E "ssh|www" | grep -iv ESTABLISHED | awk '{print $5}' | cut -d : -f 1 | sort | uniq -c >> /var/log/DDOS_IP.log | |
for pip in `netstat | grep -E "ssh|www" | grep -iv ESTABLISHED | awk '{print $5}' | cut -d : -f 1 | sort | uniq` | |
do | |
conntrack=`netstat | grep -E "ssh|www" | grep -iv ESTABLISHED | awk '{print $5}' | cut -d : -f 1 | grep $pip | wc -l`; | |
while read line | |
do | |
if [ "$line" = "$pip" ] | |
then | |
continue 2 | |
fi | |
done < /tmp/test2.txt | |
if [ "$conntrack" -gt "25" ] | |
then | |
iptables -I INPUT -s $pip -p tcp -j REJECT --reject-with tcp-reset | |
echo "$pip" >> /tmp/test1.txt | |
fi | |
done | |
cat /tmp/test1.txt | sort | uniq > /tmp/test2.txt | |
sleep $1 | |
done |