FAQ tcpdump

Creation: 20 avril 2013
Mise à jour: 16 mai 2013
Version: 1.1
Author: Jean-Louis Bicquelet-Salaün
Location: http://jlbicquelet.free.fr
Copyright: (c) 2013 Jean-Louis BICQUELET-SALAÜN

TCPDUMP Frequently-Asked Questions

Pour plus d'information au sujet de cette faq, contactez Jean-Louis BICQUELET

Cette FAQ a été réalisée sous AIX. L'interface à utiliser sous AIX est enx (en0, en1, en2 ...). Il est facile de transposer sous linux Redhat, debian ou ubuntu en utilisant les interfaces ethx (eth0, eth1, eth2 ...).


FAQ Revised: Saturday 18 May 2013 09:27:32


Table of Contents

1. presentation
2. utilisation
3. traces tcpdump

1. presentation

1.1. c'est quoi tcpdump ?
TCPdump est un analyseur de paquet en ligne de commande très puissant et très répendu. Il doit être lancé en tant que root ou avec des pouvoirs de super-utilisateur pour être sur d'avoir des privilèges suffisants sur une socket ou une carte réseau.

1.2. Est-ce qu'il existe une version graphique ?
Wireshark (auparavant cecui-ci s'appelait ethereal) est un outil mais doté d'une interface graphique comparable à TCPdump. Wireshark peut être aussi utilisé pour lire des journaux capturé par TCPdump. On peut trouver Wireshark sur ce site openmaniak.com.

1.3. Ou trouve-t-on tcpdump sous AIX ?
Sous AIX, depuis la version 5.3 au moins, tcpdump est inclus dans le systême dans le fileset bos.net.tcp.server.
# which tcpdump
/usr/sbin/tcpdump
# lslpp -w /usr/sbin/tcpdump
  File                                        Fileset               Type
  ----------------------------------------------------------------------------
  /usr/sbin/tcpdump                           bos.net.tcp.server    File


1.4. Ou trouve-t-on tcpdump sous ubuntu ?
Sous ubuntu il existe sour forme de package (sous debian aussi) Si il n'est pas installé, on peut l'installer:
#apt-get install tcpdump
Les dépendances de TCPdump sont:
#apt-cache depends tcpdump
tcpdump
   Depends: libc6
   Depends: libpcap0.8
   Depends: libssl0.9.8
Pour voir la version installée de TCPdump:
#apt-cache policy tcpdump
tcpdump:
   Installed: 3.9.4-2ubuntu0.1
   Candidate: 3.9.4-2ubuntu0.1
   Version table:
  *** 3.9.4-2ubuntu0.1 0
            500 http://security.ubuntu.com dapper-security/main Packages
            100 /var/lib/dpkg/status
         3.9.4-2 0
            500 http://ch.archive.ubuntu.com dapper/main Packages

Il y a eu à un moment besoin du rpm de l'AIX TOOLBOX libpcap.


2. utilisation

2.1. comment lister les cartes réseaux?
tcpdump -D
1.en10
2.en11
3.en12
4.lo0


2.2. Comment utiliser tcpdump ?
# tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en10, link-type 1, capture size 96 bytes
10:50:15.614350 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
10:50:15.614351 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
10:50:15.930023 802.1d unknown version
10:50:16.252558 802.1d unknown version
10:50:16.549961 IP SERVEUR001.mondomain.frp > 172.228.0.20
10:50:16.550015 IP SERVEUR001.mondomain.frp > 172.228.0.20
10:50:16.553005 IP SERVEUR002.mondomain.frp > 172.228.0.20
10:50:16.553010 IP SERVEUR002.mondomain.frp > 172.228.0.20
10:50:16.614334 ARP, Request who-has SERVEUR002.mondomain.fr tell 192.168.134.14, length 46
10:50:16.614335 ARP, Request who-has SERVEUR002.mondomain.fr tell 192.168.134.14, length 46
10:50:16.614344 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
10:50:16.614345 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
10:50:17.614386 ARP, Request who-has SERVEUR002.mondomain.fr tell 192.168.134.14, length 46
10:50:17.614388 ARP, Request who-has SERVEUR002.mondomain.fr tell 192.168.134.14, length 46
10:50:17.614400 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
10:50:17.614401 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
10:50:17.930170 802.1d unknown version

17 packets received by filter
0 packets dropped by kernel
TCPdump génére une ligne par paquet IP. Avec les options par défaut, une ligne ressemble à:
  • l'heure d'arrivée du paquet
    10:50:16.549961 IP SERVEUR001.mondomain.frp > 172.228.0.20
    
  • Le protocole de transmition ici IP, cela peut être aussi ARP, IGMP, GRE ...)
    10:50:16.549961 IP SERVEUR001.mondomain.frp > 172.228.0.20
    
  • serveur source (suivi éventuellement du port exemple .22)
    10:50:16.549961 IP SERVEUR001.mondomain.frp > 172.228.0.20
    
  • serveur destination (suivi éventuellement du port)
    10:50:16.549961 IP SERVEUR001.mondomain.frp  >172.228.0.20
    

Pour trouver le numero de port correspondant au nom du port, on va regarder le fichier /etc/services.

2.3. Comment capturer les paquets qui passent ?
tcpdump -A
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en10, link-type 1, capture size 96 bytes
09:38:28.128815 802.1d unknown version
BB.....<...#........+..&Q.%A...........
09:38:28.585654 ARP, Request who-has SERVEUR001-02-HSRP-VLAN1034.mondomain.fr tell 192.168.134.14, length 46
..........%{+\................................
09:38:28.585665 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
..........%{+\......%{+\......................
09:38:28.585716 ARP, Request who-has SERVEUR001-02-HSRP-VLAN1034.mondomain.fr tell 192.168.134.14, length 46
..........%{+\................................
09:38:28.585719 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:11:11 (oui Unknown), length 46
..........%{+\......%{+\......................

5 packets received by filter
0 packets dropped by kernel

C'est de cette manière que l'on peut facilement intercepté les mots de passe FTP car il sont envoyés en clair vers le serveur. On peut spécifier une interface donnée (en0 sous AIX, eth0 sous linux):

tcpdump -A -i en0
tcpdump -A -i eth0


2.4. Comment afficher les paquets capturés en hexadécimal?
tcpdump -A -c2 -XX -i en0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en0, link-type 1, capture size 96 bytes
11:54:53.589057 IP frlohfedb2tpa01-mgt.ssh > wrumlms02.38394: P 171042357:171042409(52) ack 496084802 win 65535
        0x0000:  0000 0c9f f002 0af4 7f54 7403 0800 4510  .........Tt...E.
        0x0010:  005c 2cdb 4000 3c06 f301 80ab 1345 80ab  .\,.@.<......E..
        0x0020:  0a14 0016 95fa 0a31 e635 1d91 a742 5018  .......1.5...BP.
        0x0030:  ffff 0000 0000 b73a c136 471b eaf6 9c37  .......:.6G....7
        0x0040:  6887 dd7d 8f9b e033 1c30 c2db f658 2457  h..}...3.0...X$W
        0x0050:  e408 7235 54d0 b3e6 67df 4286 f965 6c1d  ..r5T...g.B..el.
11:54:53.589082 IP frlohfedb2tpa01-mgt.ssh > wrumlms02.38394: P 52:216(164) ack 1 win 65535
        0x0000:  0000 0c9f f002 0af4 7f54 7403 0800 4510  .........Tt...E.
        0x0010:  00cc 2cdc 4000 3c06 f290 80ab 1345 80ab  ..,.@.<......E..
        0x0020:  0a14 0016 95fa 0a31 e669 1d91 a742 5018  .......1.i...BP.
        0x0030:  ffff 0000 0000 1be8 70f8 292d c709 32b2  ........p.)-..2.
        0x0040:  5a5e d119 b440 5555 cd15 acc5 6698 de21  Z^...@UU....f..!
        0x0050:  bdb8 bcdb 2cd5 4c65 19ca aaa8 d2df a21a  ....,.Le........
16 packets received by filter
0 packets dropped by kernel


2.5. Comment capturer les paquets udp ?
tcpdump udp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en10, link-type 1, capture size 96 bytes
09:48:22.576884 IP SERVEUR001.mondomain.frs > 192.168.6.255.netbios-ns: UDP, length 50
09:48:22.576889 IP SERVEUR001.mondomain.frs > 192.168.6.255.netbios-ns: UDP, length 50
09:48:22.576894 IP SERVEUR001.mondomain.frs > 192.168.6.255.netbios-ns: UDP, length 50
09:48:22.576895 IP SERVEUR001.mondomain.frs > 192.168.6.255.netbios-ns: UDP, length 50
09:48:22.577068 IP SERVEUR003.mondomain.fr > 192.168.6.255.netbios-ns: UDP, length 50
09:48:22.577071 IP SERVEUR003.mondomain.fr > 192.168.6.255.netbios-ns: UDP, length 50
09:48:22.577082 IP SERVEUR003.mondomain.fr > 192.168.6.255.netbios-ns: UDP, length 50
09:48:22.577084 IP SERVEUR003.mondomain.fr > 192.168.6.255.netbios-ns: UDP, length 50
09:48:23.084253 IP SERVEUR004.mondomain.fr > 176.228.10.1
09:48:23.084254 IP SERVEUR004.mondomain.fr > 176.228.10.1
09:48:23.086668 IP GSERVEUR005.mondomain.fr > 176.228.10.1
09:48:23.086680 IP GSERVEUR005.mondomain.fr > 176.228.10.1

22 packets received by filter
0 packets dropped by kernel


2.6. Comment utiliser tcpdump avec un filtre préconfiguré ?
On créé un fichier où le filtre est configuré, ici le port ssh TCP 22.
port 22
On lance ainsi tcpdump:
#tcpdump -F file_name


2.7. Comment capturer les paquets tcp ?
# tcpdump tcp tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on en10, link-type 1, capture size 96 bytes 59 packets received by filter 0 packets dropped by kernel

2.8. Comment capturer les paquets http ?
# tcpdump http

2.9. Comment capturer un nombre de paquets donné ?
Il faut utiliser l'option -c suivi du nombre voulu.
#tcpdump -c 10


2.10. Comment effiche seulement les paquets qui ont pour adresse une source ou destination donnée?
On utilise l'option host
tcpdump host www.google.fr


2.11. Comment effiche seulement les paquets qui ont pour adresse une destination donnée?
tcpdump dst www.google.fr


2.12. Comment capturer les paquets sur une interface particulière provenant d'un host donné ?
#  tcpdump -i en1 host 192.100.28.1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en12, link-type 1, capture size 96 bytes
08:45:00.099209 IP SERVEUR001.mondomain.fr.63037 > SERVEUR002.mondomain.fr.ssh: S 4267097698:4267097698(0) win 65535 wscale 12,nop,nop,timestamp 1383246626 0,nop,nop,sackOK>
08:45:00.099261 IP SERVEUR002.mondomain.fr.ssh > SERVEUR001.mondomain.fr.63037: S 779894081:779894081(0) ack 4267097699 win 65535 wscale 12,nop,nop,timestamp 1372291888 1383246626,nop,nop,sackOK>
08:45:00.100196 IP RSERVEUR001.mondomain.fr.63037 > SERVEUR002.mondomain.fr.ssh: . ack 1 win 40959 
08:45:00.100219 IP SERVEUR002.mondomain.fr.ssh > SERVEUR001.mondomain.fr.63037: . ack 1 win 40959 

On remarquera dans l'exemple, le facteur d'echelle correspondant à des grandes fenetres TCPIP (rfc1323).

On peut ajouter l'option -n pour éviter la résolution de nom.

2.13. Comment afficher les données de tcpdump avec des adresses IP numériques ?
#tcpdump -n
exemple avec 4 paquets sur l'inteface en1 :
tcpdump -n  -c 4 -i  en1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en1, link-type 1, capture size 96 bytes
11:57:49.692472 IP 192.16819.69.22 > 192.16810.20.38394: P 171408605:171408657(52) ack 496097138 win 65535
11:57:49.692508 IP 192.16819.69.22 > 192.16810.20.38394: P 52:216(164) ack 1 win 65535
11:57:49.692696 IP 192.16819.69.22 > 192.16810.20.38394: P 216:364(148) ack 1 win 65535
11:57:49.692718 IP 192.16819.69.22 > 192.16810.20.38394: P 364:496(132) ack 1 win 65535
4 packets received by filter
0 packets dropped by kernel
On peut noter que les mis en oeuvre son 22 (ssh) et 38394.

2.14. Comment etre verbeux ?
Il faut utiliser l'option -v

2.15. Comment afficher des paquets avec un timestamp lisible ?
tcpdump -n -tttt -i en10
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en10, link-type 1, capture size 96 bytes
2013-05-16 12:09:51.645814 ARP, Reply 192.168.134.14 is-at 00:11:25:77:22:55, length 46
2013-05-16 12:09:51.645815 ARP, Reply 192.168.134.14 is-at 00:11:25:77:22:55, length 46
2013-05-16 12:09:52.111149 802.1d unknown version
2013-05-16 12:09:52.395830 802.1d unknown version
2013-05-16 12:09:52.645774 ARP, Request who-has 192.168.134.1 tell 192.168.134.14, length 46
2013-05-16 12:09:52.645781 ARP, Request who-has 192.168.134.1 tell 192.168.134.14, length 46


2.16. Comment afficher des paquets répondant à plusieures critères ?
Il est possible de sélectionner des paquets répondant à plusieurs critères. On peut utiliser une syntaxe utilisant les opérateurs and, or et ( ).
tcpdump -i en12 hostSERVEUR001 and port ssh



3. traces tcpdump

3.1. comment capturer dans un fichier les traces tcpdump?
 tcpdump -w capture.log
tcpdump: listening on en10, link-type 1, capture size 96 bytes

14 packets received by filter
0 packets dropped by kernel

Une autre façon de faire est:

tcpdump -i en0 host SERVEUR001.mondomain.fr > traces.log

3.2. comment relire un fichier les traces tcpdump?
tcpdump -r capture.log
reading from file capture.log, link-type 1
09:42:21.587125 ARP, Request who-has SERVEUR001_VLAN1034.mondomain.fr tell 192.168.134.14, length 46
09:42:21.587126 ARP, Request who-has SERVEUR001_VLAN1034.mondomain.fr tell 192.168.134.14, length 46
09:42:21.587137 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
09:42:21.587138 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
09:42:21.766819 802.1d unknown version
09:42:21.866766 IP SERVEUR002-VLAN1022.mondomain.fr > 176.228.10.1
09:42:21.866812 IP SERVEUR002-VLAN1022.mondomain.fr > 176.228.10.1
09:42:21.869142 IP SERVEUR003-VLAN1023.mondomain.fr > 176.228.10.1
09:42:21.869170 IP SERVEUR003-VLAN1023.mondomain.fr > 176.228.10.1
09:42:22.138371 802.1d unknown version
09:42:22.587099 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
09:42:22.587101 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
09:42:23.587075 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46
09:42:23.587157 ARP, Reply 192.168.134.14 is-at 00:11:25:7b:22:22 (oui Unknown), length 46



Copyright (c) 2013 Jean-Louis BICQUELET

This list of questions and answers was generated by makefaq.