4 069
contributi
(20 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 236: | Riga 236: | ||
# 8980 - OpenNMS - Server Monitor - LAN | # 8980 - OpenNMS - Server Monitor - LAN | ||
$IPT -A INPUT -p tcp --dport 8980 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | $IPT -A INPUT -p tcp --dport 8980 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | ||
$IPT -A INPUT -p udp --dport 8980 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
# 9000 - 9200 - 9300 - GrayLOG - LOG Monitor - LAN | # 9000 - 9200 - 9300 - 8514 - GrayLOG - LOG Monitor - LAN | ||
$IPT -A INPUT -p tcp --dport 9000 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | $IPT -A INPUT -p tcp --dport 9000 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | ||
$IPT -A INPUT -p tcp --dport 9200 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | $IPT -A INPUT -p tcp --dport 9200 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | ||
$IPT -A INPUT -p tcp --dport 9300 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | $IPT -A INPUT -p tcp --dport 9300 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | ||
$IPT -A INPUT -p tcp --dport 8514 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 9000 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 9200 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 9300 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 8514 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
# 5353 mDNS - LAN | # 5353 mDNS - LAN | ||
Riga 247: | Riga 253: | ||
# 67-68 DHCP - LAN | # 67-68 DHCP - LAN | ||
$IPT -A INPUT -p udp -m udp --dport 67 --sport 68 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | $IPT -A INPUT -p udp -m udp --dport 67 --sport 68 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | ||
# 4200 - Shell in a Box - LAN | |||
$IPT -A INPUT -p tcp --dport 4200 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 4200 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
# 173 - 138 - 139 - 445 - 389 - 901 - Samba - LAN | |||
$IPT -A INPUT -p tcp --dport 137 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 137 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p tcp --dport 138 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 138 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p tcp --dport 139 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 139 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p tcp --dport 445 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 445 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p tcp --dport 389 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 389 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p tcp --dport 901 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
$IPT -A INPUT -p udp --dport 901 -m state --state NEW -s 10.0.0.0/24 -j ACCEPT | |||
Riga 337: | Riga 361: | ||
pre-up /etc/iptables-firewall.sh | pre-up /etc/iptables-firewall.sh | ||
</pre> | </pre> | ||
== Impostare il ban di IP ostili == | |||
Per impostare il blocco di un IP è sempre possibile agire manualmente, in questo modo: | |||
<pre> | |||
# iptables -I INPUT -s 192.168.1.100 -j DROP | |||
</pre> | |||
ma l'amministrazione e la gestione manuale dei ban agli indirizzi IP ostili non è praticabile. | |||
<br/> | |||
A questo scopo ci può venire in aiuto uno strumento disponibile nei repository ufficiali di Debian: | |||
<pre> | |||
# apt-get install ipset | |||
</pre> | |||
Una volta installato, occorre creare la lista, che chiameremo ''blacklist'': | |||
<pre> | |||
# ipset create blacklist hash:net maxelem 1000000 | |||
</pre> | |||
Con il comando: | |||
<pre> | |||
# ipset list | |||
</pre> | |||
possiamo vedere l'elenco delle liste già create. | |||
<br/> | |||
A questo punto è possibile aggiungere a mano il primo IP da bannare: | |||
<pre> | |||
# ipset add blacklist 1.1.2.0/24 | |||
# ipset add blacklist 1.1.3.0/24 | |||
</pre> | |||
Controlliamo se i due IP sono stati aggiunti alla lista di ban: | |||
<pre> | |||
# ipset list | |||
Name: blacklist | |||
Type: hash:net | |||
Revision: 6 | |||
Header: family inet hashsize 1024 maxelem 1000000 | |||
Size in memory: 472 | |||
References: 0 | |||
Number of entries: 2 | |||
Members: | |||
1.1.3.0/24 | |||
1.1.2.0/24 | |||
</pre> | |||
Aggiungere a mano tutti gli IP da bannare è un'impresa titanica; meglio affidarsi a liste già costruite, come quelle utilizzate qui di seguito, disponibili sotto licenza GPL. | |||
<br/> | |||
Per prima cosa installiamo un tool per convertire le liste di iBlockList nel formato accettato da Ipset. | |||
<pre> | |||
# apt-get install python-pip curl | |||
</pre> | |||
Quindi recuperiamo uno script che ci permetterà di mantenere aggiornata la nostra lista di IP ostili: | |||
<pre> | |||
# wget -O /usr/local/sbin/update-blacklist.sh https://raw.githubusercontent.com/trick77/ipset-blacklist/master/update-blacklist.sh | |||
# chmod +x /usr/local/sbin/update-blacklist.sh | |||
# mkdir -p /etc/ipset-blacklist | |||
# wget -O /etc/ipset-blacklist/ipset-blacklist.conf https://raw.githubusercontent.com/trick77/ipset-blacklist/master/ipset-blacklist.conf | |||
</pre> | |||
Quindi salviamo l'attuale configurazione di ipset: | |||
<pre> | |||
# ipset save > /etc/ipset-blacklist/ip-blacklist.restore | |||
</pre> | |||
Modifichiamo il file di configurazione adattandolo alle nostre necessità: | |||
<pre> | |||
# nano /etc/ipset-blacklist/ipset-blacklist.conf | |||
</pre> | |||
Impostiamo un cronjob che ogni domenica a mezzanotte aggiornerà le nostre liste: | |||
<pre> | |||
crontab -e | |||
0 0 * * 7 /usr/local/sbin/update-blacklist.sh /etc/ipset-blacklist/ipset-blacklist.conf | |||
</pre> | |||
Aggiungiamo la nuova regola al nostro script iptables: | |||
<pre> | |||
# nano /etc/iptables-firewall.sh | |||
# Imposto le regole ipset | |||
iptables -I INPUT -m set --match-set blacklist src -j DROP | |||
iptables -I FORWARD -m set --match-set blacklist src -j DROP | |||
</pre> | |||
e facciamo in modo che ipset sia impostato correttamente dopo un riavvio, aggiungendo la direttiva: | |||
<pre> | |||
pre-up ipset restore -! < /etc/ipset-blacklist/ip-blacklist.restore | |||
</pre> | |||
alla sezione della scheda di rete principale nel file <tt>/etc/network/interfaces</tt>, stando attenti a inserirla '''''prima''''' della direttiva <tt>pre up</tt> impostata in precedenza per l'avvio dello script di iptables. | |||
<br/> | |||
<br/> | |||
== Sitografia == | == Sitografia == |