par omsarath » 03 Sep 2004 11:30
merci beaucoup, avant tout.
commande :
# nmap -v -P0 adresse IP
voici mon script :
où w.x.y.z est mon adresse IP externe, eth0 connecté à freebox, eth1 à mon autre ordi.
(mais les derniers tests que j'ai fait étaient ordi éteint alors normalement iptables n'est pas en cause, je pense plutôt à la freebox, m'enfin si qqch cloche dans mon script, je veux bien le savoir)
#!/bin/sh
# /etc/network/if-pre-up.d/iptables/start
# suppression de toutes les chaines
iptables -t filter -F
iptables -t filter -X
iptables -t nat -F
iptables -t nat -X
# définition des politiques par défaut
iptables -t filter -P INPUT DROP
iptables -t filter -P OUTPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
# loopback
iptables -t filter -A OUTPUT -o lo -j ACCEPT
iptables -t filter -A INPUT -i lo -j ACCEPT
# lan eth1
iptables -A OUTPUT -o eth1 -d 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -i eth1 -s 192.168.0.0/24 -j ACCEPT
# UDP INCOMING TRACEROUTE
# traceroute usually uses -S 32769:65535 -D 33434:33523
iptables -A INPUT -i eth0 -p udp --sport 32769:65535 --dport 33434:33523 -j ULOG --ulog-prefix " traceroute "
iptables -A INPUT -i eth0 -p udp --sport 32769:65535 --dport 33434:33523 -j DROP
# résolution DNS
iptables -A INPUT -i eth0 -p udp --sport 53 -j ACCEPT
iptables -A OUTPUT -o eth0 -p udp --dport 53 -j ACCEPT
# lan
iptables -A FORWARD -p udp -i eth1 --sport 53 -j ACCEPT
iptables -A FORWARD -p udp -o eth1 --dport 53 -j ACCEPT
# internet eth0
iptables -A OUTPUT -o eth0 -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -p tcp --sport 80 -j ACCEPT
iptables -A OUTPUT -o eth0 -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -p tcp --sport 443 -j ACCEPT
# partage de connexion
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# connexion ADSL, problème du MTU.
# le problème vient du fait que le MTU de la liaison entre votre
# fournisseur d'accès et le serveur NAT est un petit peu inférieur au
# MTU de la liaison Ethernet qui relie le serveur NAT aux machines qui
# sont derrière le NAT.
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS -o eth0 --clamp-mss-to-pmtu
# forward
iptables -A FORWARD -i eth1 -o eth0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.0.2:80
# ping
# To prevent denial of service attacks based on ICMP bombs, filter
# incoming Redirect (5) and outgoing Destination Unreachable (3).
# Note, however, disabling Destination Unreachable (3) is not
# advisable, as it is used to negotiate packet fragment size.
# For bi-directional ping.
# Message Types: Echo_Reply (0), Echo_Request (8)
# To prevent attacks, limit the src addresses to your ISP range.
#
# For outgoing traceroute.
# Message Types: INCOMING Dest_Unreachable (3), Time_Exceeded (11)
# default UDP base: 33434 to base+nhops-1
#
# For incoming traceroute.
# Message Types: OUTGOING Dest_Unreachable (3), Time_Exceeded (11)
# To block this, deny OUTGOING 3 and 11
# 0: echo-reply (pong)
# 3: destination-unreachable, port-unreachable, fragmentation-needed, etc.
# 4: source-quench
# 5: redirect
# 8: echo-request (ping)
# 11: time-exceeded
# 12: parameter-problem
iptables -A INPUT -i eth0 -p icmp --icmp-type 0 -d w.x.y.z -j ACCEPT
iptables -A INPUT -i eth0 -p icmp --icmp-type destination-unreachable -d w.x.y.z -j ACCEPT
iptables -A INPUT -i eth0 -p icmp --icmp-type source-quench -d w.x.y.z -j ACCEPT
iptables -A INPUT -i eth0 -p icmp --icmp-type time-exceeded -d w.x.y.z -j ACCEPT
iptables -A INPUT -i eth0 -p icmp --icmp-type parameter-problem -d w.x.y.z -j ACCEPT
iptables -A OUTPUT -o eth0 -p icmp -s w.x.y.z --icmp-type fragmentation-needed -j ACCEPT
iptables -A OUTPUT -o eth0 -p icmp -s w.x.y.z --icmp-type source-quench -j ACCEPT
iptables -A OUTPUT -o eth0 -p icmp -s w.x.y.z --icmp-type 8 -j ACCEPT
iptables -A OUTPUT -o eth0 -p icmp -s w.x.y.z --icmp-type parameter-problem -j ACCEPT
# mails
iptables -A INPUT -i eth0 -p tcp ! --syn --sport 110 -d w.x.y.z --destination-port 1024:65535 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 110 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 1024: -d 213.228.0.176 --dport 25 -m state --state ! INVALID -j ACCEPT
iptables -A INPUT -i eth0 -p tcp -s 213.228.0.176 --sport 25 --dport 1024: -m state --state RELATED,ESTABLISHED -j ACCEPT
# AUTH client (113)
iptables -A OUTPUT -o eth0 -p tcp -s w.x.y.z --sport 1024:65535 --dport 113 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp ! --syn --sport 113 -d w.x.y.z --dport 1024:65535 -j ULOG --ulog-prefix " ok auth "
iptables -A INPUT -i eth0 -p tcp ! --syn --sport 113 -d w.x.y.z --dport 1024:65535 -j ACCEPT
# WHOIS client (43)
iptables -A OUTPUT -o eth0 -p tcp -s w.x.y.z --sport 1024:65535 --dport 43 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp ! --syn --sport 43 -d w.x.y.z --dport 1024:65535 -j ACCEPT
# FTP client (21)
iptables -A INPUT -i eth0 -p tcp --sport 21 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 20 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 20 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
# OUTGOING TRACEROUTE
iptables -A OUTPUT -o eth0 -p udp -s w.x.y.z --sport 32769:65535 --dport 33434:33523 -j ACCEPT
# pas de spoofing
iptables -A INPUT -i eth0 -s 192.168.0.0/24 -j ULOG --ulog-prefix " SPOOFING "
iptables -A INPUT -i eth0 -s 192.168.0.0/24 -j DROP
iptables -A INPUT -i eth0 -s 10.0.0.0/8 -j ULOG --ulog-prefix " SPOOFING "
iptables -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i eth0 -s 172.16.0.0/12 -j ULOG --ulog-prefix " SPOOFING "
iptables -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i eth0 -s 127.0.0.0/8 -j ULOG --ulog-prefix " SPOOFING "
iptables -A INPUT -i eth0 -s 127.0.0.0/8 -j DROP
iptables -A INPUT -i eth0 -s 255.255.255.255 -j ULOG --ulog-prefix " SPOOFING "
iptables -A INPUT -i eth0 -s 255.255.255.255 -j DROP
iptables -A INPUT -i eth0 -d 0.0.0.0 -j ULOG --ulog-prefix " SPOOFING "
iptables -A INPUT -i eth0 -d 0.0.0.0 -j DROP
# samba anti 139
iptables -A INPUT -i eth0 -p tcp --dport 139 -j ULOG --ulog-prefix " connection samba "
iptables -A INPUT -i eth0 -p tcp --dport 139 -j DROP
iptables -A INPUT -i eth0 -p udp --dport 139 -j ULOG --ulog-prefix " connection samba "
iptables -A INPUT -i eth0 -p udp --dport 139 -j DROP
# clés Gnupg
iptables -A OUTPUT -o eth0 -p tcp --dport 11371 -j ACCEPT
# log
iptables -A INPUT -i eth0 -p tcp -j DROP
iptables -A INPUT -i eth0 -p udp --destination-port 0:1023 -j ULOG --ulog-prefix " udp reject "
iptables -A INPUT -i eth0 -p udp --dport 0:1023 -j DROP
iptables -A INPUT -i eth0 -p udp --destination-port 1024:65535 -j ULOG --ulog-prefix " trojan "
iptables -A INPUT -i eth0 -p udp --dport 1024:65535 -j DROP
iptables -A INPUT -i eth0 -p icmp --icmp-type 5 -j ULOG --ulog-prefix " icmp redir "
iptables -A INPUT -i eth0 -p icmp --icmp-type 5 -j DROP
iptables -A INPUT -i eth0 -p icmp -j ULOG --ulog-prefix " autres icmp "
iptables -A INPUT -i eth0 -p icmp -j DROP
#forget all other icmp
# --icmp-type 13:255 -j DROP
iptables -A OUTPUT -o eth0 -j ULOG --ulog-prefix " output "
iptables -A OUTPUT -o eth0 -j REJECT