Skip to contentSkip to conversation

my system is under syn-flood attack

DISCUSSION Peter.Chen 5 participants 6 messages Sep 23, 2002

lore
Share & tools
lore

Peter.Chen

author
#0 lore raw

my box is redhat 7.3 apache 1.3.26

from last week . some guys use syn-flood and ping death to attack my system

i use flowing script:
#!/bin/sh

IPTABLES="/sbin/iptables"

echo "Flushing rules..."
$IPTABLES -F
$IPTABLES -X

#Set default policies to DROP
$IPTABLES -F INPUT
$IPTABLES -F OUTPUT
$IPTABLES -F FORWARD
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT

LOOP_IF="lo"

###########################################################################
#----Set network sysctl options-----#
echo "--Setting sysctl options--"

echo "Disabling IP Spoofing attacks"
echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter

echo "Disabling respond to broadcast pings" echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

echo "Blocking source routing"
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route

echo "Kill timestamps"
echo 0 > /proc/sys/net/ipv4/tcp_timestamps

echo "Enable SYN Cookies"
echo 1 > /proc/sys/net/ipv4/tcp_syncookies

echo "Kill redirects"
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects

echo "Enabling bad error message protection"
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses

echo "Logging martians (packets with impossible addresses)" echo 1 > /proc/sys/net/ipv4/conf/all/log_martians

echo "Reducing DoS'ing ability by reducing timeouts" echo 60 > /proc/sys/net/ipv4/tcp_fin_timeout echo 2400 > /proc/sys/net/ipv4/tcp_keepalive_time echo 0 > /proc/sys/net/ipv4/tcp_window_scaling echo 0 > /proc/sys/net/ipv4/tcp_sack
echo "Done..."

#########################################################################
echo "--Setting up standard rules--"

echo "Allow unlimited traffic on the loopback interface" $IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT

echo "Enabling SYN-FLOODING PROTECTION"
$IPTABLES -N syn-flood
$IPTABLES -A INPUT -p tcp --syn -j syn-flood
$IPTABLES -A syn-flood -m limit --limit 1/s --limit-burst 4 -j RETURN $IPTABLES -A syn-flood -j DROP

echo "Making sure NEW tcp connections are SYN packets" $IPTABLES -A INPUT -p tcp ! --syn -m state --state NEW -j DROP

echo "Logging fragments caught"
$IPTABLES -N fragments
$IPTABLES -A INPUT -f -j fragments
$IPTABLES -A fragments -j LOG --log-prefix "IPTABLES FRAGMENTS:" $IPTABLES -A fragments -j DROP

echo "Refusing spoofed packets pretending to be from your IP address" #$IPTABLES -A INPUT -s $NET_IPADDR -j DROP
echo "Done..."

but it's no use how can i protect my system from syn flood?? i have no hardware firewall a

#1 lore raw

Please try to implement the syn-flood rule in prerouting chain:
please goto the following web site for reference:

http://www.samag.com/documents/s=1824/sam0201h/0201h_s1.htm

Quoted 88 lines

my box is redhat 7.3 apache 1.3.26

from last week . some guys use syn-flood and ping death to attack my system

i use flowing script:
#!/bin/sh

IPTABLES="/sbin/iptables"

echo "Flushing rules..."
$IPTABLES -F
$IPTABLES -X

#Set default policies to DROP
$IPTABLES -F INPUT
$IPTABLES -F OUTPUT
$IPTABLES -F FORWARD
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT

LOOP_IF="lo"

###########################################################################
#----Set network sysctl options-----#
echo "--Setting sysctl options--"

echo "Disabling IP Spoofing attacks"
echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter

echo "Disabling respond to broadcast pings" echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

echo "Blocking source routing"
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route

echo "Kill timestamps"
echo 0 > /proc/sys/net/ipv4/tcp_timestamps

echo "Enable SYN Cookies"
echo 1 > /proc/sys/net/ipv4/tcp_syncookies

echo "Kill redirects"
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects

echo "Enabling bad error message protection"
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses

echo "Logging martians (packets with impossible addresses)" echo 1 > /proc/sys/net/ipv4/conf/all/log_martians

echo "Reducing DoS'ing ability by reducing timeouts" echo 60 > /proc/sys/net/ipv4/tcp_fin_timeout echo 2400 > /proc/sys/net/ipv4/tcp_keepalive_time echo 0 > /proc/sys/net/ipv4/tcp_window_scaling echo 0 > /proc/sys/net/ipv4/tcp_sack
echo "Done..."

#########################################################################
echo "--Setting up standard rules--"

echo "Allow unlimited traffic on the loopback interface" $IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT

echo "Enabling SYN-FLOODING PROTECTION"
$IPTABLES -N syn-flood
$IPTABLES -A INPUT -p tcp --syn -j syn-flood
$IPTABLES -A syn-flood -m limit --limit 1/s --limit-burst 4 -j RETURN $IPTABLES -A syn-flood -j DROP

echo "Making sure NEW tcp connections are SYN packets" $IPTABLES -A INPUT -p tcp ! --syn -m state --state NEW -j DROP

echo "Logging fragments caught"
$IPTABLES -N fragments
$IPTABLES -A INPUT -f -j fragments
$IPTABLES -A fragments -j LOG --log-prefix "IPTABLES FRAGMENTS:" $IPTABLES -A fragments -j DROP

echo "Refusing spoofed packets pretending to be from your IP address" #$IPTABLES -A INPUT -s $NET_IPADDR -j DROP
echo "Done..."

but it's no use how can i protect my system from syn flood?? i have no hardware firewall a

#2 lore raw
Quoted 5 lines · Patrick

Please try to implement the syn-flood rule in prerouting chain:
please goto the following web site for reference:

http://www.samag.com/documents/s=1824/sam0201h/0201h_s1.htm

Please do not do as the above link suggests.
The above link suggests putting DoS attack detection in the nat table, which IMHO is a very bad idea.

The nat table should be used to changes soruce and destination of packets - no more.

The mangle table should be used to change packets only, e.g TOS settings.

The filter tables shoyld be used to accept and drop packets (filter packets). This tables is the one must people should use.

As for the flood attack, What do you mean by "it's no use"? (I do understand that you think it does not work, but could you elaborate on that). Are no packets dropped because of it?

Regards
Anders

#3 lore raw
Quoted 3 lines
Quoted 2 lines

http://www.samag.com/documents/s=1824/sam0201h/0201h_s1.htm

Please do not do as the above link suggests.

I agree, it has been discussed some time ago, that nat table is not for filtering. (That is why, the REJECT target is not valid in PREROUTING)

I have once experimented with SYN floods, i wrote a script to generated spoofed SYN packets and flood the host. Linux 2.2 & 2.4 with syn_cookies turned on worked fine, so did w2k boxes and HP-UX. I belive that what is going on is that your hosts can not issue any connections without huge delays, which is rather caused by the eaten bandwith by SYN floods, not their connection table memory consuming habits.

Regards,
Maciej

#4 lore raw
In reply to Anders Fugmann
Quoted 4 lines · Anders Fugmann

Please do not do as the above link [deleted to avoid repeating bad advice] suggests.
The above link suggests putting DoS attack detection in the nat table, which IMHO is a very bad idea.

Seconded. nat tables are *not* for filtering. Mass confusion and broken
firewalls result when people start doing that.

Quoted 7 lines

The nat table should be used to changes soruce and destination of packets - no more.

The mangle table should be used to change packets only, e.g TOS settings.

The filter tables shoyld be used to accept and drop packets (filter packets). This tables is the one must people should use.

This is a good message to be repeated whenever someone suggests misusing the tables - there's no good reason for it that I've come across yet, and it does cause significant problems.

Quoted 3 lines

As for the flood attack, What do you mean by "it's no use"? (I do understand that you think it does not work, but could you elaborate on that). Are no packets dropped because of it?

Bear in mind that the original poster had a default ACCEPT policy on his
INPUT and FORWARD chains. I don't think that would be helping him...

Antony.

Signature · 3 lines
90% of network problems are routing problems.
9 of the remaining 10% are routing problems in the other direction.
The remaining 1% might be something else, but check the routing anyway.
#5 lore raw
In reply to Peter.Chen
Quoted 7 lines · Peter.Chen

my box is redhat 7.3 apache 1.3.26

from last week . some guys use syn-flood and ping death to attack my system

#Set default policies to DROP

Good idea.

Quoted 5 lines

$IPTABLES -F INPUT
$IPTABLES -F OUTPUT
$IPTABLES -F FORWARD
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT

Why have you not set the default INPUT and FORWARD policies to DROP ?

Antony.

Signature · 3 lines
Documentation is like sex:
when it's good, it's very very good;
when it's bad, it's still better than nothing.