Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$has_disclaimer is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_lock is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_meta_box_present is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_send_notification is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_modify_title_and_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_heading is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_category is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_blz_affiliation_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_content_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_speciali is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskw is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_linkdex is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_content_score is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskeywords is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_keywordsynonyms is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_estimated-reading-time-minutes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$response_body is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_indexnow_last_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_oembed_e09dfbacd4614167781fd37aedac2c93 is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_oembed_time_e09dfbacd4614167781fd37aedac2c93 is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_oembed_820f53898f99cfda6dd08f608c07850b is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_oembed_time_820f53898f99cfda6dd08f608c07850b is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
tcpdump: guida completa allo sniffing del traffico di rete su Linux e altri sistemi | IlSoftware.it

tcpdump: guida completa allo sniffing del traffico di rete su Linux e altri sistemi

tcpdump è uno strumento da riga di comando essenziale per intercettare e analizzare pacchetti di rete su sistemi Unix-like. Utilizzando la libreria libpcap e filtri BPF, permette di monitorare traffico TCP, UDP, HTTP e molto altro. Ecco, in breve, come funziona.

Nel vasto arsenale degli strumenti per la diagnostica e l’analisi delle reti TCP/IP, tcpdump si distingue per potenza, versatilità e leggerezza. Nonostante l’aspetto spartano, questo tool da riga di comando è una risorsa fondamentale per chiunque voglia intercettare, filtrare e analizzare il traffico di rete in tempo reale su sistemi Unix-like. In questo articolo presentiamo il funzionamento di tcpdump, i suoi principali utilizzi, esempi avanzati, casi reali e limiti.

Cos’è tcpdump e come funziona

tcpdump è un packet sniffer che consente di catturare e visualizzare i pacchetti che transitano su un’interfaccia di rete. Sfrutta libpcap (packet capture library), che fornisce l’accesso a basso livello ai pacchetti di rete. Funziona in modalità promiscua, consentendo di verificare tutto il traffico che passa sulla rete, non solo quello destinato all’host.

I pacchetti sono catturati e confrontati con eventuali filtri BPF (Berkeley Packet Filter): in caso di corrispondenza, sono analizzati e mostrati nel terminale o salvati su file .pcap.

A seconda della distribuzione Linux utilizzata, la sintassi per installare tcpdump cambia. Nel caso di macOS basta ricorrere a Homebrew:

sudo apt install tcpdump (Debian/Ubuntu)

sudo yum install tcpdump (RHEL/CentOS)

brew install tcpdump (macOS)

Cattura di base

La cattura di pacchetti con tcpdump è il primo passo fondamentale per analizzare il traffico di rete. In modo molto semplice, è possibile aprire una finestra del terminale e iniziare a catturare tutto ciò che passa su una specifica interfaccia di rete (nell’esempio eth0):

sudo tcpdump -i eth0

Il comando avvia la cattura su eth0 mostrando in tempo reale i pacchetti che transitano. Tuttavia, spesso è necessario restringere la cattura a determinati protocolli, porte o indirizzi IP per evitare inutili sovraccarichi e rendere immediatamente leggibile quanto prodotto da tcpdump.

Nella tabella che segue riassumiamo alcuni comandi di cattura di base e i rispettivi scopi:

Comando Descrizione
tcpdump -i eth0 Cattura tutto il traffico sull’interfaccia eth0
tcpdump -i eth0 port 80 Cattura solo il traffico HTTP (porta 80)
tcpdump -i eth0 host 192.168.1.10 Cattura solo i pacchetti da o verso l’host 192.168.1.10
tcpdump -i eth0 tcp Cattura solo i pacchetti TCP
tcpdump -i eth0 udp Cattura solo i pacchetti UDP
tcpdump -i eth0 -c 100 Interrompe la cattura dopo 100 pacchetti

Per eseguire correttamente tcpdump, potrebbe essere necessario anteporre il comando sudo oppure acquisire preventivamente i diritti di root con sudo -i.

È anche possibile salvare un dump da passare ad applicazioni come Wireshark utilizzando il seguente comando: tcpdump -i eth0 -w cattura.pcap

Limitazioni e considerazioni

È importante tenere presente che tcpdump non è pensato per l’analisi automatizzata a lungo termine. I file .pcap possono infatti diventare rapidamente molto grandi e l’utilità non integra le capacità di decodifica profonda proprie di Wireshark. Per un’analisi all’impronta e verificare cosa sta avvenendo interno della rete locale, tcpdump si conferma un valido alleato.

Va evidenziato che tcpdump non funziona bene all’interno di WSL 2 (Windows Subsystem for Linux) perché il software Microsoft non ha accesso diretto alla scheda di rete fisica del sistema Windows. Inoltre, anche se tcpdump la richiede, WSL 2 non consente di abilitare la modalità promiscua sull’interfaccia virtuale. L’uso dell’apposito flag PROMISC non ha alcun effetto reale nel contesto di WSL.

Nulla vieta, comunque, di usare tcpdump per catturare e analizzare il traffico generato all’interno di WSL.

Cosa si può fare realisticamente con tcpdump

Avvalendosi di uno strumento “pronto per l’uso” come tcpdump è possibile vedere in diretta i pacchetti che transitano su una specifica interfaccia, diagnosticare connessioni sospette, verificare il traffico generato da un’applicazione, osservare handshake TCP o negoziazioni TLS.

Grazie ai filtri BPF, si ha la possibilità di isolare il traffico che interessa, in modo da effettuare il debug di applicazioni client/server, identificare endpoint remoti e analizzare il comportamento di tunnel o reverse proxy.

Ovviamente, tcpdump può essere usato in combinazione con altri comandi Linux, in modo da stilare eventualmente pipeline decisamente complesse. Ad esempio, si può usare con:

  • grep, awk, sed, cut per analisi testuale
  • cron o systemd per raccolte periodiche
  • logrotate per log di lunga durata
  • ssh per sniffing su server remoti

Di molti di questi comandi abbiamo spesso parlato nelle pagine de IlSoftware.it.

Ti consigliamo anche

Link copiato negli appunti