And Thus Spake [EMAIL PROTECTED] (on Fri, 5 Sep 2003 20:12:31 +0200): > Question 1: > ---------- > Est-il correct d'écrire dans /etc/hosts, pour reprendre par exemple les > adresses à bloquer citées par Godwin: > 0.0.0.0 10.0.0.0/8 > 0.0.0.0 172.16.0.0/12 > ... > ou bien faut-il écrire: > 0.0.0.0 http://10.0.0.0/8 > 0.0.0.0 http://172.16.0.0/12 > ... > et si ce n'est ni l'un ni l'autre, comment faut-il faire?
Là, il faudrait se reporter à la doc IPCop pour prendre connaissance de la syntaxe autorisée. Si les scripts de démarrage font appel à iptables, il es possible que la syntaxe à base de CIDR fonctionne. En aucun cas celle avec les "http://" ne devrait fonctionner car on ne cherche pas à ne bloquer que le protocole HTTP, mais toute intrusion à partir de ces adresses IP. > Question 2: > ---------- > Ce qui m'ennuie, c'est que l'adresse qui devrait être bloquée en > priorité, c'est: 127.0.0.1:80. Or c'est aussi celle du loopback! Justement, iptables permet de spécifier sur quelle interface on veut bloquer les paquets avec cette adresse dans l'entête - et je réitère qu'on ne cherche pas à bloquer seulement le HTTP. Par exemple : iptables -A INPUT -i ppp0 -s 127.0.0.0/8 -j DROP Cette commande a pour effet de bloquer les paquets s'annonçant de 127.0.0.0/8 mais arrivant par l'interface "ppp0" et n'auront aucun effet sur ceux circulant à l'intérieur de la machine par l'interface "lo" (loopback). Si IPCop ne permet pas d'affiner les règles de pare-feu de la sorte, il serait peut-être temps d'envisager une distrib qui le permet... En ce qui me concerne j'ai une machine tournant sous Slackware 8.0 qui remplit cette même fonction de pare-feu/passerelle (mais aussi serveur web, ssh et smtp). Voici mon script de "protection" (quelques éléments supprimés) : #!/bin/bash # A few useful declares: IPT="/usr/sbin/iptables" EXT_IF="ppp0" INT_IF="eth0" LO_IF="lo" LOOPBACK="127.0.0.0/8" CLASS_A="10.0.0.0/8" CLASS_B="172.16.0.0/12" CLASS_C="192.168.0.0/16" CLASS_D_MULTICAST="224.0.0.0/4" CLASS_E_RESERVED="240.0.0.0/5" BROADCAST_SRC="0.0.0.0" BROADCAST_DEST="255.255.255.255" MY_SUBNET="192.168.0.0/23" MY_SUBNET_MASK="255.255.254.0" PRIVPORTS="0:1023" UNPRIVPORTS="1024:65535" # Have a go at the ipv4 routing... cd /proc/sys/net/ipv4 /bin/echo "1" > icmp_echo_ignore_all /bin/echo "0" > icmp_echo_ignore_broadcasts /bin/echo "0" > conf/all/accept_source_route /bin/echo "0" > conf/all/accept_redirects /bin/echo "1" > icmp_ignore_bogus_error_responses /bin/echo "1" > ip_forward for interface in conf/*/rp_filter; do /bin/echo "1" > ${interface} done # Now remove all rules and user-defined chains in the "filter" and "nat" # tables $IPT -t filter -F $IPT -t filter -X $IPT -t filter -Z $IPT -t nat -F # Disallow connections from spoofed external addresses $IPT -t filter -A INPUT -i $EXT_IF -s $CLASS_A -j DROP $IPT -t filter -A INPUT -i $EXT_IF -s $CLASS_B -j DROP $IPT -t filter -A INPUT -i $EXT_IF -s $CLASS_C -j DROP $IPT -t filter -A INPUT -i $EXT_IF -s $CLASS_D_MULTICAST -j DROP $IPT -t filter -A INPUT -i $EXT_IF -s $CLASS_E_RESERVED -j DROP # Disallow communication with hosts with spoofed addresses $IPT -t filter -A OUTPUT -o $EXT_IF -d $CLASS_A -j DROP $IPT -t filter -A OUTPUT -o $EXT_IF -d $CLASS_B -j DROP $IPT -t filter -A OUTPUT -o $EXT_IF -d $CLASS_C -j DROP $IPT -t filter -A OUTPUT -o $EXT_IF -d $CLASS_D_MULTICAST -j DROP $IPT -t filter -A OUTPUT -o $EXT_IF -d $CLASS_E_RESERVED -j DROP # Disallow connections from a$$wipes on the net: # HTTP requests from cyveillance.com $IPT -t filter -A INPUT -i $EXT_IF -s 63.148.99.224/27 -j DROP $IPT -t filter -A INPUT -i $EXT_IF -s 65.118.41.192/27 -j DROP # Lock out inktomi.com scumbags $IPT -t filter -A INPUT -i $EXT_IF -s 66.196.64.0/18 -j DROP # Lock out nameprotect.com $IPT -t filter -A INPUT -i $EXT_IF -s 12.148.209.192/26 -j DROP # Since connections outside but claiming to be from within my # subnet will already have been dropped by the CLASS_C # rejection rules, any request seen thus far can only be from # the inside, so let it through. # Allow full traffic between local IP and my subnet echo "Allowing full local traffic..." $IPT -t filter -A INPUT -i $INT_IF -s $MY_SUBNET -j ACCEPT $IPT -t filter -A OUTPUT -o $INT_IF -d $MY_SUBNET -j ACCEPT # Now that this is done we can set the default policy to "DROP" echo "Setting default policy to DROP..." $IPT -t filter -P INPUT DROP $IPT -t filter -P FORWARD DROP $IPT -t filter -P OUTPUT DROP # Allow access to tcp ports 443 and 80 from the outside echo "Unlocking ports 443 (https) and 80 (http)" $IPT -t filter -A INPUT -p tcp -i $EXT_IF --dport 443 -j ACCEPT $IPT -t filter -A INPUT -p tcp -i $EXT_IF --dport 80 -j ACCEPT $IPT -t filter -A OUTPUT -p tcp -o $EXT_IF --sport 443 -j ACCEPT $IPT -t filter -A OUTPUT -p tcp -o $EXT_IF --sport 80 -j ACCEPT # Allow http requests FROM this machine (dyndns.org update requires it) $IPT -t filter -A INPUT -i $EXT_IF -p tcp --sport 80 ! --syn -j ACCEPT $IPT -t filter -A OUTPUT -o $EXT_IF -p tcp --dport 80 -j ACCEPT # Allow access to ssh echo "Allowing access to port 22 (sshd)" $IPT -t filter -A INPUT -p tcp -i $EXT_IF --dport 22 -j ACCEPT $IPT -t filter -A OUTPUT -p tcp -o $EXT_IF --sport 22 -j ACCEPT # Open up the MTA to the outside echo "Opening the MTA..." $IPT -t filter -A INPUT -p tcp -i $EXT_IF --dport 25 -j ACCEPT $IPT -t filter -A OUTPUT -p tcp -o $EXT_IF --sport 25 -j ACCEPT # Open the POP3 server to the outside echo "Opening POP3 server..." $IPT -t filter -A INPUT -p tcp -i $EXT_IF --dport 110 -j ACCEPT $IPT -t filter -A OUTPUT -p tcp -o $EXT_IF --sport 110 -j ACCEPT # Allow this machine to do whois lookups echo "Allowing whois lookups..." $IPT -t filter -A INPUT -p tcp -i $EXT_IF ! --syn --sport 43 -j ACCEPT $IPT -t filter -A OUTPUT -p tcp -o $EXT_IF --dport 43 -j ACCEPT # Allow this host to do NTP and netdate lookups. $IPT -t filter -A INPUT -p tcp -i $EXT_IF ! --syn --sport 37 -j ACCEPT $IPT -t filter -A OUTPUT -p tcp -o $EXT_IF --dport 37 -j ACCEPT $IPT -t filter -A INPUT -p udp -i $EXT_IF --sport 37 -j ACCEPT $IPT -t filter -A OUTPUT -p udp -o $EXT_IF --dport 37 -j ACCEPT $IPT -t filter -A INPUT -p tcp -i $EXT_IF ! --syn --sport 123 -j ACCEPT $IPT -t filter -A OUTPUT -p tcp -o $EXT_IF --dport 123 -j ACCEPT $IPT -t filter -A INPUT -p udp -i $EXT_IF --sport 123 -j ACCEPT $IPT -t filter -A OUTPUT -p udp -o $EXT_IF --dport 123 -j ACCEPT # Allow masquerading echo "Setting up IPv4 MASQUERADING..." $IPT -t filter -A FORWARD -s $MY_SUBNET -i $INT_IF -o $EXT_IF -j ACCEPT $IPT -t filter -A FORWARD -i $EXT_IF -d $MY_SUBNET -o $INT_IF -j ACCEPT # Allow unlimited loopback traffic echo "Allowing loopback traffic..." $IPT -t filter -A INPUT -i $LO_IF -j ACCEPT $IPT -t filter -A OUTPUT -o $LO_IF -j ACCEPT # Allow this machine to do DNS with the outside echo "Opening DNS communication..." $IPT -t filter -A INPUT -p udp -i $EXT_IF --sport 53 --dport $UNPRIVPORTS -j ACCEPT $IPT -t filter -A INPUT -p tcp -i $EXT_IF --sport 53 --dport $UNPRIVPORTS -j ACCEPT $IPT -t filter -A OUTPUT -p udp -o $EXT_IF --sport $UNPRIVPORTS --dport 53 -j ACCEPT $IPT -t filter -A OUTPUT -p tcp -o $EXT_IF --sport $UNPRIVPORTS --dport 53 -j ACCEPT # Allow some ICMP traffic with the outside echo "Allowing limited ICMP traffic..." $IPT -t filter -A INPUT -i $EXT_IF -p icmp --icmp-type 0 -j ACCEPT $IPT -t filter -A INPUT -i $EXT_IF -p icmp --icmp-type 3 -j ACCEPT $IPT -t filter -A INPUT -i $EXT_IF -p icmp --icmp-type 4 -j ACCEPT $IPT -t filter -A INPUT -i $EXT_IF -p icmp --icmp-type 11 -j ACCEPT $IPT -t filter -A INPUT -i $EXT_IF -p icmp --icmp-type 12 -j ACCEPT $IPT -t filter -A OUTPUT -o $EXT_IF -p icmp -j ACCEPT # Allow me to send e-mail (sendmail needs this!) echo "Enabling remote SMTP..." $IPT -t filter -A OUTPUT -o $EXT_IF -p tcp --dport 25 -j ACCEPT $IPT -t filter -A INPUT -i $EXT_IF -p tcp --sport 25 -j ACCEPT # Finally, allow other machines on the net to share my connection echo "MASQUERADE'ing NAT table..." $IPT -t nat -A POSTROUTING -o $EXT_IF -j MASQUERADE echo "Setting up Proxy hijack logging..." IPTI="$IPT -t filter -I INPUT 1 -i $EXT_IF -p tcp ! -s 193.252.22.0/24 --dport" IPLG="--log-level notice" JLOG="-j LOG --log-prefix" $IPTI 1080 $JLOG "Proxy 1080: " $IPLG $IPTI 3128 $JLOG "Proxy 3128: " $IPLG $IPTI 8080 $JLOG "Proxy 8080: " $IPLG $IPTI 6588 $JLOG "Proxy 6588: " $IPLG $IPTI 6589 $JLOG "Proxy 6589: " $IPLG $IPT -t filter -I INPUT 1 -i $EXT_IF -p udp --dport 135 $JLOG "UDP 135: " $IPLG echo "Firewall up!" -- G. Stewart -- [EMAIL PROTECTED] -- [EMAIL PROTECTED] Registered Linux user #284683 (Slackware 9.0) --------------------------------------------------------------- Shin, n. : a device for finding furniture in the dark. Linux-Azur : http://www.linux-azur.org Désinscriptions: http://www.linux-azur.org/liste.php3 **** Pas de message au format HTML, SVP ****
