[OpenBSD] Regles Packet Filter
Le
Olivier Pernet
Je viens de terminer mes règles pour PF. Pourriez-vous y jeter un oeil, au cas où j'aurais laissé de gros trous ? Merci.
Le routeur qui utilise PF est aussi utilisé comme serveur pour différents réseaux de peer-to-peer, d'où les ports ouverts.
Il a 3 interfaces réseau :
- une reliée à l'internet ($extif)
- une reliée au LAN câblé ($intif)
- une reliée à un point d'accès wireless ($wirelessif).
On autorise tout le trafic venant du LAN mais on interdit les mails sortants du WLAN (protection spam).
Et voilà le script :
#######################
# PF Ruleset
# 17/08/2004
#######################
############# Macros/tables #######################
# RFC 1918/3330
table <nonroutable> const { 192.168.0.0/16, 127.0.0.0/8, 172.16.0.0/12, \
10.0.0.0/8, 0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24, \
224.0.0.0/3, 255.255.255.255/32 }
##########
extif = "tun0"
intif = "sis0"
wirelessif = "ne4"
unsafe = "{$external, $wireless}"
##########
# TCP services allowed in
# 22 : SSH 1214 : FastTrack
# 1412 : DirectConnect 2234 : SoulSeek
# 4662 : eDonkey2000 4663 : Overnet
# 6347 : Gnutella2 6699 : OpenNap
# 6881 : BitTorrent
tcpserv = { 22,1214,1412,2234,4662,4663,6347,6699,6881 }
# UDP services allowed in
# 1412 : DirectConnect 4663 : Overnet
# 4672 : eDonkey2000 6347 : Gnutella2
udpserv = { 1412,4663,4672,6347 }
###################################################
# Normalize packets, and reassemble fragmented ones.
scrub in all
# NAT for LAN and WLAN.
nat on $intif from $intif:network to any -> $extif
nat on $wirelessif from $wirelessif:network to any -> $extif
set block-policy return
######### Filtering rules ##########################
# Default deny policy.
block all
#####
# Traffic to/from loopback is allowed without restriction.
pass quick on lo0 all
#####
# Drop spoofing attemps.
block drop in quick on $extif from <nonroutable> to any
block drop out quick on $extif from any to <nonroutable>
#####
# Allow access to the upper-definied TCP and UDP services.
pass in quick on $extif inet proto tcp from any to ($extif) \
port $tcpserv flags S/SA synproxy state
pass in quick on $extif inet proto udp from any to ($extif) \
port $udpserv keep state
##### LAN
# Allow all incoming/responding traffic from the LAN (trusted).
pass in quick on $intif from $int_if:network to any keep state
# Allow all outgoing traffic to the LAN.
pass out quick on $intif from any to $intif:network keep state
##### WLAN
# Block sending mails from to WLAN (spam threat).
block in quick on $wirelessif from $wirelessif:network to any \
inet proto tcp port 25
pass in quick on $wirelessif from $wirelessif:network to any keep state
pass out quick on $wirelessif from any to $wirelessif:network keep state
#####
# Block access from the WLAN to the LAN.
block in quick on $wirelessif from $wirelessif:network \
to $intif:network
#####
# Allow external connections from our networks to the Internet.
pass out quick on $ext_if proto tcp all modulate state flags S/SA
pass out on $ext_if proto { udp, icmp } all keep state
###################################################
Merci d'avance de votre aide !
Olivier
Le routeur qui utilise PF est aussi utilisé comme serveur pour différents réseaux de peer-to-peer, d'où les ports ouverts.
Il a 3 interfaces réseau :
- une reliée à l'internet ($extif)
- une reliée au LAN câblé ($intif)
- une reliée à un point d'accès wireless ($wirelessif).
On autorise tout le trafic venant du LAN mais on interdit les mails sortants du WLAN (protection spam).
Et voilà le script :
#######################
# PF Ruleset
# 17/08/2004
#######################
############# Macros/tables #######################
# RFC 1918/3330
table <nonroutable> const { 192.168.0.0/16, 127.0.0.0/8, 172.16.0.0/12, \
10.0.0.0/8, 0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24, \
224.0.0.0/3, 255.255.255.255/32 }
##########
extif = "tun0"
intif = "sis0"
wirelessif = "ne4"
unsafe = "{$external, $wireless}"
##########
# TCP services allowed in
# 22 : SSH 1214 : FastTrack
# 1412 : DirectConnect 2234 : SoulSeek
# 4662 : eDonkey2000 4663 : Overnet
# 6347 : Gnutella2 6699 : OpenNap
# 6881 : BitTorrent
tcpserv = { 22,1214,1412,2234,4662,4663,6347,6699,6881 }
# UDP services allowed in
# 1412 : DirectConnect 4663 : Overnet
# 4672 : eDonkey2000 6347 : Gnutella2
udpserv = { 1412,4663,4672,6347 }
###################################################
# Normalize packets, and reassemble fragmented ones.
scrub in all
# NAT for LAN and WLAN.
nat on $intif from $intif:network to any -> $extif
nat on $wirelessif from $wirelessif:network to any -> $extif
set block-policy return
######### Filtering rules ##########################
# Default deny policy.
block all
#####
# Traffic to/from loopback is allowed without restriction.
pass quick on lo0 all
#####
# Drop spoofing attemps.
block drop in quick on $extif from <nonroutable> to any
block drop out quick on $extif from any to <nonroutable>
#####
# Allow access to the upper-definied TCP and UDP services.
pass in quick on $extif inet proto tcp from any to ($extif) \
port $tcpserv flags S/SA synproxy state
pass in quick on $extif inet proto udp from any to ($extif) \
port $udpserv keep state
##### LAN
# Allow all incoming/responding traffic from the LAN (trusted).
pass in quick on $intif from $int_if:network to any keep state
# Allow all outgoing traffic to the LAN.
pass out quick on $intif from any to $intif:network keep state
##### WLAN
# Block sending mails from to WLAN (spam threat).
block in quick on $wirelessif from $wirelessif:network to any \
inet proto tcp port 25
pass in quick on $wirelessif from $wirelessif:network to any keep state
pass out quick on $wirelessif from any to $wirelessif:network keep state
#####
# Block access from the WLAN to the LAN.
block in quick on $wirelessif from $wirelessif:network \
to $intif:network
#####
# Allow external connections from our networks to the Internet.
pass out quick on $ext_if proto tcp all modulate state flags S/SA
pass out on $ext_if proto { udp, icmp } all keep state
###################################################
Merci d'avance de votre aide !
Olivier

Poser une question


Apparement, il n'empêche pas de poster 5 fois le même message... :-)
Sinon, 2 remarques:
- le script n'empêche pas l'intrusion d'une machine qui "emprunterait"
votre adresse IP.
- tous les icmp sont rejetés, ce qui n'est pas une bonne chose.
--
MP
Si tu as une ip dynamique il vaut mieux mettre les parenthèses à ton
interface externe. Comme ça par exemple :
nat on $ext_if from $int_if:network to any -> ($ext_if)
--
Serge
partir de Google Groups qui ne répondait pas après l'envoi du
message...
Une question à propos de ce que disait Michel toutefois :
Si j'ai bien compris, il faudrait ajouter quelque chose pour bloquer
les paquets entrants qui portent mon adresse IP publique comme source
? Comme ça
block in drop quick from ($extif) to any
Mais j'ai peur que comme ça, tout le trafic entrant soit bloqué, non ?
Olivier
Ah oui, c'est même carrement heretique. Une machine disposant de
connectivité IP doit pouvoir envoyer et recevoir des paquets ICMP.
--
Emmanuel Dreyfus
Publicité subliminale: achetez ce livre!
http://www.eyrolles.com/Informatiqu...re-bsd.php
hérétique ? je pense pas, tu peux l'activer avec proto ICMP, mais persos
j'évite le ICMP moi aussi pour divers pb. si tu l'active, oublie pas de
bien configurer la chose pour qu'il ne reponde pas à des ICMP broadcast
par exemple, tu risque de noyer ton réseau. bon après ce n'est qu'une
question de choix : moi je prefere faire un ping avec un telnet, je
m'explique : mon ipf bloque les ICMP, soit, mais j'autorise au minimum
un service à tourner avec son port accessible (ex: openssh sur 8080). un
simple "telnet [IP] 8080" me permet de tester la connectivité du monstre.
si ça répond pas : soit la machine est out, soit le service à planté,
auquel faut se déplacer :)