tcpdump¶
A Linux/Unix tool for sniffing packets
See your interfaces with ifconfig
output format¶
22:27:09.121959 IP video-edge-65e942.hkg06.justin.tv.https > b162.m5.ntu.edu.tw.57341: Flags [.], seq 14518649:14520097, ack 194005, win 1687, options [nop,nop,TS val 3701151147 ecr 3117567374], length 1448
win & length in bytes
packet flags¶
tcpflags are some combination of S (SYN), F (FIN), P (PUSH), R (RST), U (URG), W (ECN CWR), E (ECN-Echo) or . (ACK), or none if no flags are set.
command flags¶
-i en0select interfaceen0-rread-w traces.trwrite totraces.tr-c 5capture only 5 packets-nshow ip instead of domain name
read¶
read packets
read 5 packets
read from file
write¶
write output to file
write output to file but limit to 1MB
over 1MB -> save to output.tr1expressions¶
add expression directly
use expressions in expression.exp
get start & end packets
get ACK packets
examples
Expressions:types
tcpdump -r tmp.tr -c 2 host nslab.ee.ntu.edu.tw
tcpdump -r tmp.tr -c 2 net 140.112.154
tcpdump -r tmp.tr -c 2 net 140.112.154.128/25
tcpdump -r tmp.tr -c 2 net 140.112.154.128 mask 255.255.255.128
tcpdump -r tmp.tr -c 2 port 80
tcpdump -r tmp.tr -c 2 port http
tcpdump -r tmp.tr -c 2 port ssh
Expressions:directions
tcpdump -r tmp.tr -c 2 src or dst host nslab.ee.ntu.edu.tw
tcpdump -r tmp.tr -c 2 dst net 140.112.154
tcpdump -r tmp.tr -c 2 dst port 80
Expressions:protocols
tcpdump -r tmp.tr -c 2 ip src or dst host nslab.ee.ntu.edu.tw
tcpdump -r tmp.tr -c 2 arp dst net 140.112.154
tcpdump -r tmp.tr -c 2 tcp dst port 80
tcpdump -r tmp.tr -c 2 udp
tcpdump -r tmp.tr -c 2 broadcast
Expressions:others
tcpdump -r tmp.tr -c 2 greater 100
tcpdump -r tmp.tr -c 2 less 100
Expressions:operands
tcpdump -r tmp.tr -c 2 dst host nslab.ee.ntu.edu.tw and tcp
tcpdump -r tmp.tr -c 2 dst host nslab.ee.ntu.edu.tw \&\& tcp
tcpdump -r tmp.tr -c 2 dst host nslab.ee.ntu.edu.tw and \(tcp or udp\)
Expressions:in a separate file
tcpdump -r tmp.tr -c 2 -F test.exp
Troubleshooting¶
permission¶
If you run it in Ubuntu, it might say you don't have permission. Do the followings to fix it
If it said tcpdump (enforce), make it in complain mode by
You can install aa-complain by
See https://blog.karatos.in/a?ID=01100-68ee7a10-9f07-412a-aa93-e67032182326