{"id":1322,"date":"2016-09-12T10:49:30","date_gmt":"2016-09-12T08:49:30","guid":{"rendered":"http:\/\/clark.tipistrani.it\/?p=1322"},"modified":"2020-10-31T10:27:18","modified_gmt":"2020-10-31T09:27:18","slug":"portsentry-un-valido-aiuto-al-firewall","status":"publish","type":"post","link":"http:\/\/clark.tipistrani.it\/?p=1322","title":{"rendered":"Portsentry un valido aiuto al firewall"},"content":{"rendered":"<p>Rifacendomi a questo <a href=\"http:\/\/clark.tipistrani.it\/?p=1317\">articolo<\/a> e vedendo che la faccenda continua e si \u00e8 spostata sulla porta superiore e quindi vogliono proprio sfondarmi ho deciso di passare al pi\u00f9 presto possibile all&#8217;autenticazione ssh con certificati, una &#8220;breve&#8221; burocrazia e al pi\u00f9 presto possibile lo far\u00f2.<br \/>\nPer il momento per\u00f2 ho deciso di rendere ancora pi\u00f9 difficile la vita a quel\/quei &#8220;CENSURA&#8221; che hanno deciso di rovinarmi la macchina.<br \/>\nRiflettendo sul come rompere le scatole ai rompiscatole m&#8217;\u00e8 venuto in mente il buon vecchio portsentry.<br \/>\nPortsentry nato in psionic.com assorbita poi da Cisco, \u00e8 un programma che analizza le scansioni delle porte e quindi a seconda di come \u00e8 istruito reagisce di conseguenza.<br \/>\nAl 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.<br \/>\nPer default portsentry non blocca nulla bisogna istruirlo su cosa fare e, al solito la directory dove ci sono le configurazioni \u00e8 \/etc\/ in cui si trova la subdirectory portsentry.<br \/>\nAll&#8217;interno ci sono 3 files<br \/>\nportsentry.conf che contiene tutte le configurazioni e che \u00e8 il file su cui lavorare.<br \/>\nportsentry.ignore che viene generato dinamicamente<br \/>\nportsentry.ignore.static dovve aggiungere quegli IP\/classi che non devono essere processati.<br \/>\nVediamo In breve come configurare i parametri in portsentry.conf<\/p>\n<p>#######################<br \/>\n# Port Configurations #<br \/>\n#######################<br \/>\n# Un-comment these if you are really anal:<br \/>\nTCP_PORTS=&#8221;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&#8243;<br \/>\nUDP_PORTS=&#8221;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&#8243;<br \/>\n#<br \/>\n# Use these if you just want to be aware:<br \/>\n#TCP_PORTS=&#8221;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&#8243;<br \/>\n#UDP_PORTS=&#8221;1,7,9,69,161,162,513,635,640,641,700,37444,34555,31335,32770,32771,32772,32773,32774,31337,54321&#8243;<br \/>\n#<br \/>\n# Use these for just bare-bones<br \/>\n#TCP_PORTS=&#8221;1,11,15,110,111,143,540,635,1080,1524,2000,12345,12346,20034,32771,32772,32773,32774,49724,54320&#8243;<br \/>\n#UDP_PORTS=&#8221;1,7,9,69,161,162,513,640,700,32770,32771,32772,32773,32774,31337,54321&#8243;<br \/>\n###########################################<br \/>\n# Advanced Stealth Scan Detection Options #<br \/>\n###########################################<br \/>\nADVANCED_PORTS_TCP=&#8221;1024&#8243;<br \/>\nADVANCED_PORTS_UDP=&#8221;1024&#8243;<br \/>\n# Default TCP ident and NetBIOS service<br \/>\nADVANCED_EXCLUDE_TCP=&#8221;113,139&#8243;<br \/>\n# Default UDP route (RIP), NetBIOS, bootp broadcasts.<br \/>\nADVANCED_EXCLUDE_UDP=&#8221;520,138,137,67&#8243;<br \/>\n######################<br \/>\n# Configuration Files#<br \/>\n######################<br \/>\n#<br \/>\n# Hosts to ignore<br \/>\nIGNORE_FILE=&#8221;\/etc\/portsentry\/portsentry.ignore&#8221;<br \/>\n# Hosts that have been denied (running history)<br \/>\nHISTORY_FILE=&#8221;\/var\/lib\/portsentry\/portsentry.history&#8221;<br \/>\n# Hosts that have been denied this session only (temporary until next restart)<br \/>\nBLOCKED_FILE=&#8221;\/var\/lib\/portsentry\/portsentry.blocked&#8221;<\/p>\n<p>##############################<br \/>\n# Misc. Configuration Options#<br \/>\n##############################<br \/>\n#<br \/>\n# DNS Name resolution &#8211; Setting this to &#8220;1&#8221; will turn on DNS lookups<br \/>\n# for attacking hosts. Setting it to &#8220;0&#8221; (or any other value) will shut<br \/>\n# it off.<br \/>\nRESOLVE_HOST = &#8220;1&#8221;<\/p>\n<p>##################<br \/>\n# Ignore Options #<br \/>\n##################<br \/>\n# 0 = Do not block UDP\/TCP scans.<br \/>\n# 1 = Block UDP\/TCP scans.<br \/>\n# 2 = Run external command only (KILL_RUN_CMD)<\/p>\n<p>BLOCK_UDP=&#8221;1&#8243;<br \/>\nBLOCK_TCP=&#8221;1&#8243;<\/p>\n<p>###################<br \/>\n# Dropping Routes:#<br \/>\n###################<br \/>\n# This command is used to drop the route or add the host into<br \/>\n# a local filter table.<br \/>\n#<br \/>\n# The gateway (333.444.555.666) should ideally be a dead host on<br \/>\n# the *local* subnet. On some hosts you can also point this at<br \/>\n# localhost (127.0.0.1) and get the same effect. NOTE THAT<br \/>\n# 333.444.555.66 WILL *NOT* WORK. YOU NEED TO CHANGE IT!!<br \/>\n#<br \/>\n# ALL KILL ROUTE OPTIONS ARE COMMENTED OUT INITIALLY. Make sure you<br \/>\n# uncomment the correct line for your OS. If you OS is not listed<br \/>\n# here and you have a route drop command that works then please<br \/>\n# mail it to me so I can include it. ONLY ONE KILL_ROUTE OPTION<br \/>\n# CAN BE USED AT A TIME SO DON&#8217;T UNCOMMENT MULTIPLE LINES.<br \/>\n#<br \/>\n# NOTE: The route commands are the least optimal way of blocking<br \/>\n# and do not provide complete protection against UDP attacks and<br \/>\n# will still generate alarms for both UDP and stealth scans. I<br \/>\n# always recommend you use a packet filter because they are made<br \/>\n# for this purpose.<br \/>\n# iptables support for Linux with limit and LOG support. Logs only<br \/>\n# a limited number of packets to avoid a denial of service attack.<br \/>\nKILL_ROUTE=&#8221;\/sbin\/iptables -I INPUT -s $TARGET$ -j DROP &amp;&amp; \/sbin\/iptables -I INPUT -s $TARGET$ -m limit &#8211;limit 3\/minute &#8211;limit-burst 5 -j LOG &#8211;log-level DEBUG &#8211;log-prefix &#8216;Portsentry: dropping: &#8216;&#8221;<\/p>\n<p>###<br \/>\n# TCP Wrappers#<br \/>\n###############<br \/>\n# This text will be dropped into the hosts.deny file for wrappers<br \/>\n# to use. There are two formats for TCP wrappers:<br \/>\nKILL_HOSTS_DENY=&#8221;ALL: $TARGET$ : DENY&#8221;<br \/>\n###################<br \/>\n# External Command#<br \/>\n###################<br \/>\n# This is a command that is run when a host connects, it can be whatever<br \/>\n# you want it to be (pager, etc.). This command is executed before the<br \/>\n# route is dropped or after depending on the KILL_RUN_CMD_FIRST option below<br \/>\nKILL_RUN_CMD_FIRST = &#8220;0&#8221;<br \/>\n# for examples see \/usr\/share\/doc\/portsentry\/examples\/<br \/>\nKILL_RUN_CMD=&#8221;\/usr\/local\/bin\/scan-detect<br \/>\n#####################<br \/>\n# Scan trigger value#<br \/>\n#####################<br \/>\n# Enter in the number of port connects you will allow before an<br \/>\n# alarm is given. The default is 0 which will react immediately.<br \/>\n# A value of 1 or 2 will reduce false alarms. Anything higher is<br \/>\n# probably not necessary. This value must always be specified, but<br \/>\n# generally can be left at 0.<br \/>\n#<br \/>\n# NOTE: If you are using the advanced detection option you need to<br \/>\n# be careful that you don&#8217;t make a hair trigger situation. Because<br \/>\n# Advanced mode will react for *any* host connecting to a non-used<br \/>\n# port below your specified range, you have the opportunity to<br \/>\n# really break things. (i.e someone innocently tries to connect to<br \/>\n# you via SSL [TCP port 443] and you immediately block them). Some<br \/>\n# of you may even want this though. Just be careful.<br \/>\n#<br \/>\nSCAN_TRIGGER=&#8221;0&#8243;<br \/>\nridotto questo \u00e8 il file di configurazione.<br \/>\nAdesso il passo successivo e&#8217; 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).<br \/>\nUltimo step, in \/etc\/portsentry\/portsentry.ignore.static andiamo ad aggiungere uno per riga<br \/>\nIP.Di.Casa.per.connessione.remota<br \/>\n1\u00b0 IP.DI.CHI.ci.fa.assistenza<br \/>\n2\u00b0 IP.DI.CHI.ci.fa.assistenza<br \/>\nquesto perch\u00e8 pu\u00f2 essere utile dare il permesso a qualcuno di fare scansione per capire cosa succede in caso di problemi<br \/>\n\/etc\/init.d\/portsentry restart e il gioco \u00e8 fatto.<br \/>\nIn seguito ad un nmap in syslog possiamo trovare qualcosa di simile:<\/p>\n<p><code> 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<br \/>\ne facendo un cat di \/etc\/hosts.deny troveremo<br \/>\n...<br \/>\n<\/code><\/p>\n<pre>ALL: 10.9.8.8 : DENY<\/pre>\n<p>Quindi adesso il rompiscatole di turno ha la vita un po pi\u00f9 difficile, e io un po meno patema d&#8217;animo.<\/p>\n<p><code>\u00a0<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rifacendomi a questo articolo e vedendo che la faccenda continua e si \u00e8 spostata sulla porta superiore e quindi vogliono proprio sfondarmi ho deciso di passare al pi\u00f9 presto possibile all&#8217;autenticazione ssh con certificati, una &#8220;breve&#8221; burocrazia e al pi\u00f9 presto possibile lo far\u00f2. Per il momento per\u00f2 ho deciso di rendere ancora pi\u00f9 difficile [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[110,8,14,6],"tags":[112,103],"class_list":["post-1322","post","type-post","status-publish","format-standard","hentry","category-ids","category-linux","category-networking","category-work","tag-ids","tag-iptables"],"_links":{"self":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/1322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1322"}],"version-history":[{"count":4,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/1322\/revisions"}],"predecessor-version":[{"id":1326,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/1322\/revisions\/1326"}],"wp:attachment":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1322"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}