autour de la libpcap [width=.8]tcpdump
Post on 08-May-2022
5 Views
Preview:
TRANSCRIPT
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Autour de la libpcap
2016
2016
1 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Plan
1 Les outils autour de tcpdump2 Programmer3 Pourquoi programmer en libpcap?
2 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
• Libpcap et tcpdump : http://tcpdump.org• Utilisation par la galaxie tshark/ wireshark• Beaucoup d’autres logiciels (voire plus)• Utilisation par programmation en C
3 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Plan
1 Les outils autour de tcpdump2 Programmer3 Pourquoi programmer en libpcap?
4 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Les outils
• Driftnet ; capture des images et fichiers sonores• Chaosreader : capture des sessions TCP• Dsniff : voir page suivante• . . .
5 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
dsniff• arpspoof : réponses ARP• dnsspoof : sur le réseau local ;• dsniff : écoute de mots de passe• filesnarf : NFS, sauvegarde des fichiers sélectionnés ;• macof : inonde d’adresses MAC aléatoires ;• mailsnarf : écoute les courriels et créé la mbox ;• msgsnarf : messageries instantanées ;• sshmitm : SSH monkey-in-the-middle• sshow : analyse de trafic SSH ;• tcpkill : tue les connexions TCP spécifiées ;• tcpnice : ralentit les connexions TCP spécifiées• urlsnarf : affiche les URL écoutées• webmitm : monkey-in-the-middle HTTP/HTTPS• webspy : URL écoutées vers un navigateur
6 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Driftnet
• https://github.com/deiv/driftnet• Capture les images et la vidéo• Affiche ou enregistre• Peut extraire à partir d’une capture tcpdump (à
distance)
7 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Driftnet
# driftnet -i eth0.106 -vMon Mar 21 14:09:33 2016 [driftnet] info:
using temporary file directory /tmp/drifnet-EssNOfstarted display child, pid 9569listening on eth0.106 in promiscuous modenew connection: 10.3.30.6:36634 -> 10.33.106.3:22new connection: 10.33.106.3:22 -> 10.3.30.6:36634connection closing: 10.3.30.6:36634 -> 10.33.106.3:22, 3085 bytes transferredconnection closing: 10.33.106.3:22 -> 10.3.30.6:36634, 2084 bytes transferrednew connection: 10.3.30.6:36634 -> 10.33.106.3:22new connection: 10.3.30.6:53440 -> 10.33.106.2:22new connection: 10.33.106.2:22 -> 10.3.30.6:53440new connection: 10.3.30.6:53440 -> 10.33.106.2:22caught signal 2
8 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Premières images
[driftnet] info: received imagedriftnet-56eff57019495cff.png of size 4463
[driftnet] info: received imagedriftnet-56eff6ef2ae8944a.png of size 4959
[driftnet] info: received imagedriftnet-56eff6ef625558ec.png of size 469
9 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Driftnet
10 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Driftnet
11 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Chaosreader
• http://chaosreader.sf.net• Sessions TCP :
• telnet• http• ftp• . . .
• Capture• les images• Les sessions• Crée un script Perl
12 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Chaosreader
13 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Chaosreader
14 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Chaosreader
15 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
dsniff
• http://www.monkey.org/~dugsong/dsniff• Collection d’outils• Test de webspy
• webspy adresseIP• Connexion X-Window• Affiche sur un descendant de Netscape
16 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Analyse
• Autour de tcpdump (pas tshark !)• Trafic en clair :
• Pédagogie de la sécurité• Rapidement limité
• Vieillots :• Bugs• Fonctionnalités manquantes• Pas de ssl• Pas d’adaptation aux sites virtuels d’apache
• Exemples de programmes• Temps pour discriminer utiles/ inutiles et prise en main :
⇒ Concours César ?
17 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Plan
1 Les outils autour de tcpdump2 Programmer3 Pourquoi programmer en libpcap?
18 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Programmer la libpcap
Séquence libpcap1 déterminer l’interface (par défaut ?)2 Initialiser la libpcap sur quelle(s) interface(s)3 Éventuellement, filtrer le trafic4 Boucle principale d’attente (callback)5 Terminer la session (Génération du rapport)
Gestion des erreurs :• Code de retour• char errbuf[PCAP_ERRBUF_SIZE];
19 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Pcap : interface par défaut
char * interfacepardefaut (){char * dev;char errbuf[PCAP_ERRBUF_SIZE];
dev = pcap_lookupdev(errbuf);if (dev == NULL) {fprintf(stderr,
"Couldn’t find default device: %s\n",errbuf);
return("");}return(dev);
}
20 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Pcap : Initialisation de l’interface
printf("Interface: %s\n", dev);
handle = pcap_open_live(dev,BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {fprintf(stderr,"Err init %s car %s\n",dev, errbuf);
return(-1);}
return(0);
21 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Pcap : Boucle
handle = pcap_open_live(dev,BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {fprintf(stderr, "echec ouverture %s car %s\n",
dev, errbuf);return(-1);
}
res = pcap_loop(handle,10 ,traitepaquet,NULL);
22 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Pcap : Callback
void traitepaquet(u_char *args,const struct pcap_pkthdr *header,const u_char *packet)
{printf ("ping \n");
}
header • Longueur du paquet• Longueur du paquet capturé• date de la capture (approximative)
paquet les octets transmis (attention aux querellespetit/grands boutistes)
23 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Pcap : Filtre
handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
pcap_compile(handle, &fp, filter_exp, 0, mask) ;
pcap_setfilter(handle, &fp) == -1) ;
fp le filtre compiléfilter_exp syntaxe tcpdump
Optimisation ? ? ? ? 0
24 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Pcap : Interruptions
void sig_handler(int signo){
if (signo == SIGINT)printf("\nRéception de SIGINT\n");
}...mainif (signal(SIGINT, sig_handler) == SIG_ERR)
fprintf(stderr,"\nErreur: impossible de récupérer SIGINT\n");
Termine souvent par un CTRL-C
25 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Nombre et taille de paquetsvoid traitepaquet(u_char *args, const struct pcap_pkthdr *header,
const u_char *packet){
static int packet_cnt = 1;static int packet_orig;struct timeval ts;bpf_u_int32 caplen;bpf_u_int32 len;ts= header->ts;caplen = header->caplen;len = header-> len;
if (packet_cnt == 1){packet_orig = ts.tv_sec;}printf ("paquet %d (%d s) %d/ %d\n",
packet_cnt,(int)ts.tv_sec - packet_orig,
caplen,len);
packet_cnt++;}
26 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Pcap : Ethernet
eptr = (struct ether_header *) packet;printf("Ethernet type= %d(%d) IP:%d\n",
ntohs (eptr->ether_type),eptr->ether_type,ETHERTYPE_IP);
printf(" Source: %s -> Destination: %s \n",mac2s(eptr->ether_shost),mac2s(eptr->ether_dhost));
• Vérifier le type de liaison• Afficher les adresses mac
27 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Pcap : TCP/IP
• IP : pointeur = pointeurethernet + 14• TCP : Pointeur IP + longueur (variable) en-tête IP• Payload : TCP + longueur en tête TCP
Wireshark le fera mieux...
28 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Boutistes
• Attention à l’ordre des octets :uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);
29 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Plan
1 Les outils autour de tcpdump2 Programmer3 Pourquoi programmer en libpcap?
30 / 31
LibPcap
2016
Introduction
OutilsDriftnet
Chaosreader
Programmer
Quellesapplications ?
Quelles applications ?
• Analyse (au sens pédagogie R&T)⇒Wireshark• Analyse réseau pour trouver un bug⇒ tsharkS,
tcpdumpS• Mesure de la charge de trafic de mon serveur Icinga :
s,m,h,j• Mesure du temps complet pour charger une page• Mesure de l’équité de traitement lors d’un capes
documentaliste• . . .
31 / 31
top related