LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices

Reply
 
LinkBack Search this Thread
Old 03-26-2009, 03:30 AM   #1
mosesdel
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Rep: Reputation: 0
Security with iptables


Dear all:

I have make iptables in my server like this...

#!/bin/sh

# Kernel monitoring support
# More information:
# /usr/src/linux-`uname -r`/Documentation/networking/ip-sysctl.txt
# http://www.linuxgazette.com/book/view/1645
# http://www.spirit.com/Network/net0300.html

# Drop ICMP echo-request messages sent to broadcast or multicast addresses
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

# Drop source routed packets
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route

# Enable TCP SYN cookie protection from SYN floods
echo 1 > /proc/sys/net/ipv4/tcp_syncookies

# Don't accept ICMP redirect messages
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects

# Don't send ICMP redirect messages
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects

# Enable source address spoofing protection
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter

# Log packets with impossible source addresses
echo 1 > /proc/sys/net/ipv4/conf/all/log_martians

# Flush all chains
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT


iptables -A INPUT -p tcp -m multiport --dport 20,21,22,25,53,110,143,80,5222,9090,10000 -m state --state NEW -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT

#iptables -A INPUT -p icmp --icmp-type echo-request -s 192.168.1.102 -d 192.168.1.10 -m limit --limit 1/m --limit-burst 10 -j ACCEPT
#iptables -A INPUT -p icmp --icmp-type echo-request -s 192.168.1.102 -d 192.168.1.10 -m limit --limit 1/m --limit-burst 10 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -s 192.168.1.102 -d 192.168.1.10 -m limit --limit 1/m --limit-burst 10 -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -s 192.168.1.10 -d 192.168.1.102 -j ACCEPT


#iptables -A INPUT -p icmp -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT


#LOG
iptables -A FORWARD -m limit --limit 2/m --limit-burst 2 -j LOG --log-prefix '** FORWARD DROP**' --log-level debug
iptables -A INPUT -m limit --limit 2/m --limit-burst 2 -j LOG --log-prefix '** INPUT DROP**' --log-level debug
iptables -A OUTPUT -m limit --limit 2/m --limit-burst 2 -j LOG --log-prefix '** OUTPUT DROP**' --log-level debug


iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP


HOw about your opinion, is good configuration??
 
Old 03-26-2009, 03:38 AM   #2
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
If port 10000 is open for the webmin service, I would seriously consider removing that port from the list. If you need access to that port through an untrusted network, then I would use ssh port forwarding to attach to it through the localhost interface. If any vulnerabilities are ever uncovered in the webmin httpd service, you're protecting it from unauthorized access with only a minor inconvenience of having to ssh to the box first.

What is 5222,9090 for?
 
Old 03-26-2009, 03:50 AM   #3
reptiler
Member
 
Registered: Mar 2009
Location: Hong Kong
Distribution: Fedora
Posts: 184

Rep: Reputation: 41
Personally I don't like using DROP as a policy for the default chains.
Dropping packets makes it too obvious that you're filtering.

It doesn't add any security but it follows the RFCs for "proper network communication" to use REJECT with the proper options.

Thus, I reject TCP-packets with a tcp-reset, UDP-packets with an icmp-port-unreachable and everything else with icmp-proto-unreachable.
That's the way an unfiltered box will react if packets are received on closed ports/unavailable protocols.

As said, it doesn't add to the security, but it also doesn't lessen it.

Edit: Why do you add any rules to the FORWARD-chain? Do you route anything through that box? If not, which I suspect, these rules are useless.

Last edited by reptiler; 03-26-2009 at 03:51 AM.
 
Old 03-27-2009, 06:16 AM   #4
mosesdel
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by reptiler View Post
Personally I don't like using DROP as a policy for the default chains.
Dropping packets makes it too obvious that you're filtering.

It doesn't add any security but it follows the RFCs for "proper network communication" to use REJECT with the proper options.

Thus, I reject TCP-packets with a tcp-reset, UDP-packets with an icmp-port-unreachable and everything else with icmp-proto-unreachable.
That's the way an unfiltered box will react if packets are received on closed ports/unavailable protocols.

As said, it doesn't add to the security, but it also doesn't lessen it.

Edit: Why do you add any rules to the FORWARD-chain? Do you route anything through that box? If not, which I suspect, these rules are useless.

thanks for all contribution
Now I have change like this..

I create two files ddos.sh to protect form DDOS
this is the script

#!/bin/bash
FILE="/tmp/drop.lasso"
URL="http://www.spamhaus.org/drop/drop.lasso"
cd /tmp
wget $URL
#iptables policy di hapus
iptables -F
#jalankan policy yang sudah ada
/root/iptables/netfilter.sh
blocks=$(cat $FILE | egrep -v '^;' | awk '{ print $1}')
iptables -N droplist
for ipblock in $blocks
do
iptables -A droplist -s $ipblock -j LOG --log-prefix "DROP List Block"
iptables -A droplist -s $ipblock -j DROP
done
iptables -I INPUT -j droplist
iptables -I OUTPUT -j droplist
iptables -I FORWARD -j droplist
echo "...Done"
/bin/rm -f $FILE


And netfilter.sh like this

# Flush all chains
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT



iptables -A INPUT -p tcp -m multiport --dport 25,53,110,143,80 -m state --state NEW -j ACCEPT

iptables -A INPUT -p tcp -m multiport -s 119.235.20.42 -d 119.235.20.119 --dport 20,21,22,9090,10000 -m state --state NEW -j ACCEPT

iptables -A INPUT -p udp --dport 53 -j ACCEPT

#iptables -A INPUT -p icmp --icmp-type echo-request -s 192.168.1.102 -d 192.168.1.10 -m limit --limit 1/m --limit-burst 10 -j ACCEPT
#iptables -A INPUT -p icmp --icmp-type echo-request -s 192.168.1.102 -d 192.168.1.10 -m limit --limit 1/m --limit-burst 10 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -s 0/0 -d 119.235.20.242 -m limit --limit 1/m --limit-burst 10 -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -s 0/0 -d 119.235.20.242 -j ACCEPT


#iptables -A INPUT -p icmp -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT


#LOG
iptables -A FORWARD -m limit --limit 2/m --limit-burst 2 -j LOG --log-prefix '** FORWARD DROP**' --log-level debug
iptables -A INPUT -m limit --limit 2/m --limit-burst 2 -j LOG --log-prefix '** INPUT DROP**' --log-level debug
iptables -A OUTPUT -m limit --limit 2/m --limit-burst 2 -j LOG --log-prefix '** OUTPUT DROP**' --log-level debug


iptables -P INPUT REJECT
iptables -P OUTPUT REJECT
iptables -P FORWARD REJECT


# not port 9090 for wildfire

is it secure if I implemented in my server???
 
  


Reply

Tags
iptables


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables security devenix Linux - Security 2 07-24-2007 11:52 AM
security policy iptables Ammad Linux - Security 2 11-14-2005 06:15 AM
sendmail, iptables and security Tigger Linux - Security 3 11-25-2003 09:14 PM
sendmail, iptables and security Tigger Linux - General 2 05-27-2003 08:45 AM
IPTABLES and checking its security.... ankscorek Linux - Networking 3 04-09-2003 05:52 AM


All times are GMT -5. The time now is 02:03 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration