May 102014
 

terminal1.jpg

Il server appare piuttosto lento potrebbero essere molte cose dalle configurazioni errate, script e hardware con problemi, ma a volte potrebbe essere perché qualcuno sta inondando il server con traffico conosciuto come DoS (Denial of Service) o DDoS (Distributed Denial of Service).

Attacco denial-of-service (attacco DoS) o attacco Distributed Denial-of-service (DDoS attack) è un tentativo di rendere non disponibile una macchina o risorsa di rete per i suoi utenti previsti. Questo attacco generalmente indirizzato a siti o servizi ospitati sui server web di alto profilo come banche, i gateway di pagamento con carta di credito, e persino i root nameserver. Attacchi DoS sono attuati forzando il computer remoto ad un reset, o consumando le risorse in modo che non possa più fornire i propri servizi o ostacolando i mezzi di comunicazione tra gli utenti e la vittima in modo che essi non possano più comunicare in modo adeguato.

In questo piccolo articolo vedrete come controllare se il server è sotto attacco dal terminale Linux con il comando netstat


Dalla pagina man di netstat “netstat – stampa le connessioni di rete, tabelle di routing, statistiche di interfaccia, connessioni masquerade, e le appartenenze multicast”

Alcuni esempi con spiegazione

netstat -na

Questo mostra tutte le connessioni Internet attive al server e sono incluse solo le connessioni stabilite.

netstat -an | grep :80 | sort

Mostra solo le connessioni Internet attive al server sulla porta 80, questa è la porta http e quindi è utile se si dispone di un server web, e ordina i risultati. Utile per individuare un unico flood, consentendo di riconoscere molte connessioni provenienti da un IP.

netstat -n -p|grep SYN_REC | wc -l

Questo comando è utile per scoprire quanti SYNC_REC attivi ci sono sul server. Il numero dovrebbe essere abbastanza basso, preferibilmente meno di 5. Durante gli incidenti o un attacco DoS o bombe di posta elettronica, il numero può diventare piuttosto alto. Tuttavia, il valore dipende sempre dal sistema, quindi un valore elevato può essere la normalità su un server.

netstat -n -p | grep SYN_REC | sort -u

Elenca tutti gli indirizzi IP coinvolti invece di contarli.

netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'

Elenca tutti gli indirizzi IP univoci del nodo che stanno trasmettendo lo stato della connessione SYN_REC.

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Utilizza il comando netstat per calcolare e conta il numero di connessioni al server per ogni indirizzo IP.

netstat -anp |grep 'tcp|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Elenca il conto del numero di connessioni per gli IP sono collegati al server tramite protocollo TCP o UDP.

netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr

Controlla le connessioni stabilite invece di tutti i collegamenti, e visualizza contando le connessioni per ogni IP.

netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1

Mostra ed elenco gli indirizzi IP ed il numero di connessione che si collegano alla porta 80 del server. La porta 80 è utilizzata principalmente dalle richieste HTTP di una pagina web.

Come mitigare un attacco DOS

Una volta che avete trovato l’IP che sta attaccando il server è possibile utilizzare i seguenti comandi per bloccare la sua connessione al server:

iptables -A INPUT 1 -s $IPADRESS -j DROP/REJECT

Si prega di notare che si deve sostituire a $IPADRESS l’ip con i numeri IP che avete trovato con netstat.
Dopo aver dato il comando precedente, uccidere tutti i collegamenti httpd per pulire il sistema e fare un restart del servizio httpd usando i seguenti comandi:

killall -KILL httpd
 
service httpd start           #For Red Hat systems 
/etc/init/d/apache2 restart   #For Debian systems


Popular Posts:

Flattr this!

  13 Responses to “Come verificare gli attacchi DDOS con il comando netstat dal Terminale linux”

  1. Realy? *Face Palm*

  2. Small typo in your restart command for debian based systems:

    /etc/init/d/apache2 restart #For Debian systems

    Should read:

    /etc/init.d/apache2 restart #For Debian systems

  3. netstat -anp |grep 'tcp|udp'
    on ubuntu needs to be:
    netstat -anp |grep 'tcp\|udp'

  4. Add a null route iinux via bencane.com

    How to add a null route
    In our example we are receiving unwanted SSH login attempts from 192.168.0.195

    root@server:~# netstat -na | grep :22
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
    tcp 0 0 192.168.0.197:22 192.168.0.195:57776 ESTABLISHED
    To add the null route we will use the ip command

    root@server:~# ip route add blackhole 192.168.0.195/32
    To verify the route is in place will will use ip route show

    root@server:~# ip route show
    default via 192.168.0.1 dev eth0 metric 100
    blackhole 192.168.0.195

  5. What do I do if it’s a DDoS? How do I stop them from taking down my server? I’m currently under DDoS, and being hit by over a thousand different IPs. My server normally has several hundred IPs connected simultaneously, so how do I tell which are part of the DDoS and which are real?

    • if your
      netstat -ntu | grep ESTAB | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -nr

      show one or more ips with more than 20 connections and if you run the same command; and the same ips have more connections..
      This ips are the ones ataking you ..
      you can use this script:

      wget http://www.inetbase.com/scripts/ddos/install.sh
      chmod 0700 install.sh
      ./install.sh

  6. How decide which ip attacking on server?

  7. netstat -anp |grep ‘tcp|udp’ in centos this command no working, replace grep by egrep.

  8. Iptables doesn’t work well with CloudFlare. Have you try install vDDoS Protection Reverse Proxy from http://vddos.voduy.com/ Layer 7 Filter Mitigate DOS, DDOS, SYN Floods, or HTTP Floods attack?

  9. netstat -anp |egrep ‘tcp|udp’
    tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2830/cupsd
    tcp 0 0 192.168.1.143:40826 66.196.116.112:443 ESTABLISHED 2587/firefox
    tcp 0 0 192.168.1.143:59992 87.248.118.23:443 ESTABLISHED 2587/firefox
    tcp 0 0 192.168.1.143:52036 63.250.200.41:443 ESTABLISHED 2587/firefox
    tcp 0 0 192.168.1.143:56426 82.196.8.47:80 ESTABLISHED 2587/firefox
    tcp6 0 0 ::1:631 :::* LISTEN 2830/cupsd
    udp 0 0 0.0.0.0:5353 0.0.0.0:* 1495/avahi-daemon:
    udp 0 0 0.0.0.0:42706 0.0.0.0:* 1495/avahi-daemon:
    udp 0 0 0.0.0.0:68 0.0.0.0:* 2405/dhclient
    udp 0 0 127.0.0.1:323 0.0.0.0:* 1560/chronyd
    udp6 0 0 :::5353 :::* 1495/avahi-daemon:
    udp6 0 0 :::40217 :::* 1495/avahi-daemon:
    udp6 0 0 ::1:323 :::* 1560/chronyd

  10. The above code gave me an error. Is this really working?

  11. Hi,

    When I do your command ” netstat -plan|grep :80|awk {‘print $5’}|cut -d: -f 1|sort|uniq -c|sort -nk 1 “, I have :

    ************************
    1 2.152.249.29

    3 90.33.32.1
    3 90.56.121.206
    7 91.179.39.2
    1025
    1 107.167.113.54
    1 109.132.78.156

    2 188.163.86.105
    3 188.7.174.39

    ************************

    Seem to have a problem with “1025” but no ip on the right column.

Leave a Reply to Gerald Drouillard Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*