Clark's Home page

Tecnicismi vari di un Sysadmin Linux ma anche qualcosa della sua vita

Portsentry un valido aiuto al firewall —

Rifacendomi a questo articolo e vedendo che la faccenda continua e si è spostata sulla porta superiore e quindi vogliono proprio sfondarmi ho deciso di passare al più presto possibile all’autenticazione ssh con certificati, una “breve” burocrazia e al più presto possibile lo farò.
Per il momento però ho deciso di rendere ancora più difficile la vita a quel/quei “CENSURA” che hanno deciso di rovinarmi la macchina.
Riflettendo sul come rompere le scatole ai rompiscatole m’è venuto in mente il buon vecchio portsentry.
Portsentry nato in psionic.com assorbita poi da Cisco, è un programma che analizza le scansioni delle porte e quindi a seconda di come è istruito reagisce di conseguenza.
Al solito parliamo di macchina Debian in questo caso una oldstable (7.x) e quindi apt-get install portsentry che si porta dietro le dipendenze relative.
Per default portsentry non blocca nulla bisogna istruirlo su cosa fare e, al solito la directory dove ci sono le configurazioni è /etc/ in cui si trova la subdirectory portsentry.
All’interno ci sono 3 files
portsentry.conf che contiene tutte le configurazioni e che è il file su cui lavorare.
portsentry.ignore che viene generato dinamicamente
portsentry.ignore.static dovve aggiungere quegli IP/classi che non devono essere processati.
Vediamo In breve come configurare i parametri in portsentry.conf

#######################
# Port Configurations #
#######################
# Un-comment these if you are really anal:
TCP_PORTS=”1,7,9,11,15,70,79,80,109,110,111,119,138,139,143,512,513,514,515,540,635,1080,1524,2000,2001,4000,4001,5742,6000,6001,6667,12345,12346,20034,27665,30303,32771,32772,32773,32774,31337,40421,40425,49724,54320″
UDP_PORTS=”1,7,9,66,67,68,69,111,137,138,161,162,474,513,517,518,635,640,641,666,700,2049,31335,27444,34555,32770,32771,32772,32773,32774,31337,54321″
#
# Use these if you just want to be aware:
#TCP_PORTS=”1,11,15,79,111,119,143,540,635,1080,1524,2000,5742,6667,12345,12346,20034,27665,31337,32771,32772,32773,32774,40421,49724,54320″
#UDP_PORTS=”1,7,9,69,161,162,513,635,640,641,700,37444,34555,31335,32770,32771,32772,32773,32774,31337,54321″
#
# Use these for just bare-bones
#TCP_PORTS=”1,11,15,110,111,143,540,635,1080,1524,2000,12345,12346,20034,32771,32772,32773,32774,49724,54320″
#UDP_PORTS=”1,7,9,69,161,162,513,640,700,32770,32771,32772,32773,32774,31337,54321″
###########################################
# Advanced Stealth Scan Detection Options #
###########################################
ADVANCED_PORTS_TCP=”1024″
ADVANCED_PORTS_UDP=”1024″
# Default TCP ident and NetBIOS service
ADVANCED_EXCLUDE_TCP=”113,139″
# Default UDP route (RIP), NetBIOS, bootp broadcasts.
ADVANCED_EXCLUDE_UDP=”520,138,137,67″
######################
# Configuration Files#
######################
#
# Hosts to ignore
IGNORE_FILE=”/etc/portsentry/portsentry.ignore”
# Hosts that have been denied (running history)
HISTORY_FILE=”/var/lib/portsentry/portsentry.history”
# Hosts that have been denied this session only (temporary until next restart)
BLOCKED_FILE=”/var/lib/portsentry/portsentry.blocked”

##############################
# Misc. Configuration Options#
##############################
#
# DNS Name resolution – Setting this to “1” will turn on DNS lookups
# for attacking hosts. Setting it to “0” (or any other value) will shut
# it off.
RESOLVE_HOST = “1”

##################
# Ignore Options #
##################
# 0 = Do not block UDP/TCP scans.
# 1 = Block UDP/TCP scans.
# 2 = Run external command only (KILL_RUN_CMD)

BLOCK_UDP=”1″
BLOCK_TCP=”1″

###################
# Dropping Routes:#
###################
# This command is used to drop the route or add the host into
# a local filter table.
#
# The gateway (333.444.555.666) should ideally be a dead host on
# the *local* subnet. On some hosts you can also point this at
# localhost (127.0.0.1) and get the same effect. NOTE THAT
# 333.444.555.66 WILL *NOT* WORK. YOU NEED TO CHANGE IT!!
#
# ALL KILL ROUTE OPTIONS ARE COMMENTED OUT INITIALLY. Make sure you
# uncomment the correct line for your OS. If you OS is not listed
# here and you have a route drop command that works then please
# mail it to me so I can include it. ONLY ONE KILL_ROUTE OPTION
# CAN BE USED AT A TIME SO DON’T UNCOMMENT MULTIPLE LINES.
#
# NOTE: The route commands are the least optimal way of blocking
# and do not provide complete protection against UDP attacks and
# will still generate alarms for both UDP and stealth scans. I
# always recommend you use a packet filter because they are made
# for this purpose.
# iptables support for Linux with limit and LOG support. Logs only
# a limited number of packets to avoid a denial of service attack.
KILL_ROUTE=”/sbin/iptables -I INPUT -s $TARGET$ -j DROP && /sbin/iptables -I INPUT -s $TARGET$ -m limit –limit 3/minute –limit-burst 5 -j LOG –log-level DEBUG –log-prefix ‘Portsentry: dropping: ‘”

###
# TCP Wrappers#
###############
# This text will be dropped into the hosts.deny file for wrappers
# to use. There are two formats for TCP wrappers:
KILL_HOSTS_DENY=”ALL: $TARGET$ : DENY”
###################
# External Command#
###################
# This is a command that is run when a host connects, it can be whatever
# you want it to be (pager, etc.). This command is executed before the
# route is dropped or after depending on the KILL_RUN_CMD_FIRST option below
KILL_RUN_CMD_FIRST = “0”
# for examples see /usr/share/doc/portsentry/examples/
KILL_RUN_CMD=”/usr/local/bin/scan-detect
#####################
# Scan trigger value#
#####################
# Enter in the number of port connects you will allow before an
# alarm is given. The default is 0 which will react immediately.
# A value of 1 or 2 will reduce false alarms. Anything higher is
# probably not necessary. This value must always be specified, but
# generally can be left at 0.
#
# NOTE: If you are using the advanced detection option you need to
# be careful that you don’t make a hair trigger situation. Because
# Advanced mode will react for *any* host connecting to a non-used
# port below your specified range, you have the opportunity to
# really break things. (i.e someone innocently tries to connect to
# you via SSL [TCP port 443] and you immediately block them). Some
# of you may even want this though. Just be careful.
#
SCAN_TRIGGER=”0″
ridotto questo è il file di configurazione.
Adesso il passo successivo e’ quello di modificare in /etc/default da tcp e udp in atcp e audp in modo da portare il funzionamento in modo avanzato/reverse (man portsentry per un approfondimento).
Ultimo step, in /etc/portsentry/portsentry.ignore.static andiamo ad aggiungere uno per riga
IP.Di.Casa.per.connessione.remota
1° IP.DI.CHI.ci.fa.assistenza
2° IP.DI.CHI.ci.fa.assistenza
questo perchè può essere utile dare il permesso a qualcuno di fare scansione per capire cosa succede in caso di problemi
/etc/init.d/portsentry restart e il gioco è fatto.
In seguito ad un nmap in syslog possiamo trovare qualcosa di simile:

Sep 10 16:11:33 sangiorgio portsentry[4077]: attackalert: TCP SYN/Normal scan from host: 10.9.8.8/10.9.8.8 to TCP port: 135 Sep 10 16:11:33 sangiorgio portsentry[4077]: attackalert: Ignoring TCP response per configuration file setting. Sep 10 16:11:33 sangiorgio portsentry[4077]: attackalert: TCP SYN/Normal scan from host: 10.9.8.8/10.9.8.8 to TCP port: 53 Sep 10 16:11:33 sidlol portsentry[4077]: attackalert: Host: 10.9.8.8/10.9.8.8 is already blocked Ignoring
e facendo un cat di /etc/hosts.deny troveremo
...

ALL: 10.9.8.8 : DENY

Quindi adesso il rompiscatole di turno ha la vita un po più difficile, e io un po meno patema d’animo.

 


Categorised as: IDS | Linux | Networking | Work

Comments are disabled on this post


Comments are closed.