Retour dstlimit
Filtre du p2p Reject personaliss darcs-hash:20050131155802-41617-7c5019e6b396b6dd08f6cabb8e4ff431d628bd1b.gz
This commit is contained in:
parent
ef3a05e196
commit
bd0aff0589
1 changed files with 42 additions and 12 deletions
|
@ -67,12 +67,14 @@ class firewall_komaz :
|
|||
table filter :
|
||||
FORWARD (policy par defaut : ACCEPT)
|
||||
1) passage par BLACKLIST
|
||||
2) ce qui a pour source les serveurs de serveurs_crans est dirigé vers SERVEURS_VERS_EXT
|
||||
3) ce qui a pour destination les serveurs de serveurs_crans est dirigé EXT_VERS_SERVEURS
|
||||
4) tout ce qui vient de l'interface externe est dirigé vers EXT_VERS_CRANS
|
||||
5) ce qui a pour source les serveurs de serveurs_crans est dirigé vers EXT_VERS_CRANS
|
||||
2) passage pas FILTRE_P2P (REJECT sur tout le trafic p2p)
|
||||
3) ce qui a pour source les serveurs de serveurs_crans est dirigé vers SERVEURS_VERS_EXT
|
||||
4) ce qui a pour destination les serveurs de serveurs_crans est dirigé EXT_VERS_SERVEURS
|
||||
5) tout ce qui vient de l'interface externe est dirigé vers EXT_VERS_CRANS
|
||||
6) ce qui a pour source les serveurs de serveurs_crans est dirigé vers EXT_VERS_CRANS
|
||||
|
||||
BLACKLIST fitre des ip blacklistées (reject)
|
||||
FILTRE_P2P filtre le traffic de p2p
|
||||
EXT_VERS_CRANS et CRANS_VERS_EXT
|
||||
ACCEPT pour les paquets vers les machines du crans (test port-ip)
|
||||
REJECT pour le reste
|
||||
|
@ -92,7 +94,8 @@ class firewall_komaz :
|
|||
|
||||
limit = " -m limit --limit 10/s --limit-burst 10 "
|
||||
log_template = '-m limit --limit 1/s --limit-burst 1 -j LOG --log-level notice --log-prefix '
|
||||
filtre_flood = '-m hashlimit --hashlimit 20 --hashlimit-mode srcip-dstip --hashlimit-name flood'
|
||||
#filtre_flood = '-m hashlimit --hashlimit 20 --hashlimit-mode srcip,dstip --hashlimit-name flood'
|
||||
filtre_flood = '-m dstlimit --dstlimit 20 --dstlimit-mode srcip-dstip --dstlimit-name flood'
|
||||
|
||||
liste_reseaux_non_routables = [ '1.0.0.0/8','2.0.0.0/8','5.0.0.0/8','7.0.0.0/8',\
|
||||
'10.0.0.0/8','14.0.0.0/8','23.0.0.0/8','27.0.0.0/8','31.0.0.0/8','36.0.0.0/8',\
|
||||
|
@ -114,6 +117,11 @@ class firewall_komaz :
|
|||
|
||||
ports_virus = { 'tcp' : [ 135, 445 ] , 'udp' : [] }
|
||||
|
||||
# Filtrage du peer to peer
|
||||
filtres_p2p = [ '-p tcp -m ipp2p --ipp2p --bit --apple --soul --winmx' ,
|
||||
'-p tcp -m ipp2p --ipp2p-data' ]
|
||||
ports_p2p = [ '412', '1214', '4662:4665' , '6346:6347', '6699', '6881:6889' ]
|
||||
|
||||
machines = []
|
||||
debug = 1
|
||||
|
||||
|
@ -173,7 +181,7 @@ class firewall_komaz :
|
|||
# Remplisage
|
||||
for tache in [ self.log_chaines, self.test_virus_flood, self.reseaux_non_routables,
|
||||
self.blacklist , self.serveurs_vers_ext, self.ext_vers_serveurs,
|
||||
self.crans_vers_ext, self.ext_vers_crans, self.test_mac_ip ] :
|
||||
self.crans_vers_ext, self.ext_vers_crans, self.test_mac_ip, self.filtre_p2p ] :
|
||||
self.__exception_catcher(tache)
|
||||
|
||||
# On peux router
|
||||
|
@ -181,13 +189,15 @@ class firewall_komaz :
|
|||
warn = ''
|
||||
for cmd in [ 'echo 1 > /proc/sys/net/ipv4/ip_forward' ,
|
||||
'echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max' ,
|
||||
'modprobe ip_conntrack_ftp' ] :
|
||||
'modprobe ip_conntrack_ftp' ,
|
||||
'modprobe ip_conntrack_h323',
|
||||
'modprobe ip_conntrack_irc' ] :
|
||||
status,output=getstatusoutput(cmd)
|
||||
if status :
|
||||
warn += output +'\n'
|
||||
if warn :
|
||||
print WARNING
|
||||
if debug :
|
||||
if self.debug :
|
||||
print warn
|
||||
else :
|
||||
print OK
|
||||
|
@ -213,13 +223,14 @@ class firewall_komaz :
|
|||
print OK
|
||||
|
||||
self.anim = anim(' Structure de la table filter')
|
||||
for chaine in [ 'EXT_VERS_SERVEURS', 'SERVEURS_VERS_EXT' , 'EXT_VERS_CRANS', 'CRANS_VERS_EXT', 'BLACKLIST_SRC', 'BLACKLIST_DST' ] :
|
||||
for chaine in [ 'EXT_VERS_SERVEURS', 'SERVEURS_VERS_EXT' , 'EXT_VERS_CRANS', 'CRANS_VERS_EXT', 'BLACKLIST_SRC', 'BLACKLIST_DST' , 'FILTRE_P2P' ] :
|
||||
iptables('-N %s' % chaine)
|
||||
|
||||
iptables("-A FORWARD -i lo -j ACCEPT")
|
||||
iptables("-A FORWARD -p icmp -j ACCEPT")
|
||||
iptables("-A FORWARD -i %s -j BLACKLIST_DST" % self.eth_ext )
|
||||
iptables("-A FORWARD -o %s -j BLACKLIST_SRC" % self.eth_ext )
|
||||
iptables("-A FORWARD -j FILTRE_P2P")
|
||||
iptables("-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT")
|
||||
iptables("-A FORWARD -i %s -d %s -j EXT_VERS_SERVEURS" % (self.eth_ext, self.zone_serveur) )
|
||||
iptables("-A FORWARD -o %s -s %s -j SERVEURS_VERS_EXT" % (self.eth_ext, self.zone_serveur) )
|
||||
|
@ -253,10 +264,12 @@ class firewall_komaz :
|
|||
""" Construction de la chaîne TEST_VIRUS """
|
||||
iptables('-t nat -F TEST_VIRUS_FLOOD')
|
||||
self.anim = anim(' Filtrage virus et floods')
|
||||
|
||||
for proto, ports in self.ports_virus.items() :
|
||||
for port in ports :
|
||||
iptables('-t nat -A TEST_VIRUS_FLOOD -p %s --dport %s -j LOG_VIRUS' % (proto, port) )
|
||||
self.anim.cycle()
|
||||
|
||||
iptables('-t nat -A TEST_VIRUS_FLOOD %s -j RETURN' % self.filtre_flood) # Les limites en négatif ca ne marche pas.
|
||||
self.anim.cycle()
|
||||
iptables('-t nat -A TEST_VIRUS_FLOOD -j LOG_FLOOD')
|
||||
|
@ -432,12 +445,29 @@ class firewall_komaz :
|
|||
blacklist+=entite.machines()
|
||||
|
||||
for machine in blacklist:
|
||||
iptables("-A BLACKLIST_DST -d %s -j REJECT" % machine.ip())
|
||||
iptables("-A BLACKLIST_SRC -s %s -j REJECT" % machine.ip())
|
||||
iptables("-A BLACKLIST_DST -d %s -j REJECT --reject-with icmp-host-prohibited" % machine.ip())
|
||||
iptables("-A BLACKLIST_SRC -s %s -j REJECT --reject-with icmp-host-prohibited" % machine.ip())
|
||||
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def filtre_p2p(self):
|
||||
""" Construit la chaines de filtrage du p2p (FILTRE_P2P) """
|
||||
self.anim = anim(" Filtrage p2p")
|
||||
iptables('-F FILTRE_P2P')
|
||||
|
||||
for port in self.ports_p2p :
|
||||
iptables('-A FILTRE_P2P -p tcp --dport %s -j REJECT --reject-with icmp-admin-prohibited' % port )
|
||||
iptables('-A FILTRE_P2P -p udp --dport %s -j REJECT --reject-with icmp-admin-prohibited' % port )
|
||||
self.anim.cycle()
|
||||
|
||||
for filtre in self.filtres_p2p :
|
||||
iptables('-A FILTRE_P2P %s -j REJECT --reject-with icmp-admin-prohibited' % filtre)
|
||||
self.anim.cycle()
|
||||
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def port_maj(self,ip_list) :
|
||||
""" Mise à jour des ports pour les ip fournies """
|
||||
# Note : système bourrin (on efface les chaines et on refait)
|
||||
|
@ -555,7 +585,7 @@ if __name__ == '__main__' :
|
|||
global chaines
|
||||
chaines = [ 'log_chaines' , 'test_virus_flood', 'reseaux_non_routables',
|
||||
'test_mac_ip' , 'blacklist' , 'ext_vers_serveurs' , 'serveurs_vers_ext',
|
||||
'ext_vers_crans', 'crans_vers_ext' ]
|
||||
'ext_vers_crans', 'crans_vers_ext' , 'filtre_p2p' ]
|
||||
|
||||
def __usage(txt=None) :
|
||||
if txt!=None : cprint(txt,'gras')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue