Abbiamo visto come installare e configurare un firewall iptables su server ubuntu linux, vediamo adesso come aggiungere una blacklist di indirizzi IP.

Su internet possiamo trovare varie fonti che detengono liste di IP bannati, ma nel nostro caso vogliamo bannare solo una serie di ip conosciuti perchè utilizzati per attaccare determinati servizi Es. ssh, apache.

In questo modo se non gestiamo un server di posta possiamo limitare il numero di regole da aggiungere al nostro firewall. Infatti la maggior parte degli indirizzi IP bannati sono conosciuti per azioni di spam.

Blocklist.de è una buona fonte e fornisce liste di IP bannati suddivisi per servizio.

http://www.blocklist.de/lists/

Come possiamo vedere il file relativo alla porta 25 (server mail smtp) è quello più fornito.

Vediamo come integrare tali liste per aggiungerle nuove regole di DROP al nostro firewall

creiamo un nuovo script vi /etc/init.d/firewall-blacklist

 

 Bash |  copy code |? 
01
#! /bin/sh
02
### BEGIN INIT INFO
03
# Provides: scriptname
04
# Required−Start: $remote_fs $syslog
05
# Required−Stop: $remote_fs $syslog
06
# Default−Start: 2 3 4 5
07
# Default−Stop: 0 1 6
08
# Short−Description: Start daemon at boot time
09
# Description: Enable service provided by daemon.
10
### END INIT INFO
11
start(){
12
echo "start"
13
BLACKLIST=/usr/local/etc/blacklist.txt
14
BLOCKLIST_URL=http://www.blocklist.de/lists/22.txt
15
wget $BLOCKLIST_URL −O $BLACKLIST
16
if [ $? −eq 0 ]
17
then
18
for x in `grep −v ^# $BLACKLIST | awk '{print $1}'`; do
19
 echo "Denying $x..."
20
 /sbin/iptables −D INPUT −t filter −s $x −j DROP
21
 /sbin/iptables −A INPUT −t filter −s $x −j DROP
22
done
23
else
24
 echo "$BLOCKLIST_URL ERROR"
25
fi
26
}
27
 
28
stop(){
29
echo "stop"
30
#/sbin/iptables −F INPUT
31
}
32
 
33
restart(){
34
 stop
35
 sleep 5
36
 start
37
}
38
 
39
 
40
 
41
 
42
case "$1" in
43
 start)
44
 start
45
 ;;
46
 stop)
47
 stop
48
 ;;
49
 restart)
50
 restart
51
 ;;
52
 *)
53
 echo "Usage: firewall {start|stop|restart}"
54
 exit 1
55
esac
56
 
57
exit 0





 

utilizzando

/etc/init.d/firewall-blacklist start

verrà scaricato il file degli indirizzi IP ed inseriti nelle rule di iptables se non già presenti.

inseriamolo adesso sulla crontab per aggiornare la lista degli ip regolarmente

crontab -e

0 2 * * * (/etc/init.d/firewall-blacklist start)

Lascia un Commento

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *

*

È possibile utilizzare questi tag ed attributi XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>