KEMBAR78
Introduction to tcpdump | PDF
tcpdump
capturing network traffic

      Lev Walkin
      @levwalkin
What is tcpdump?

Capture
[Save]
Filter
Show and explain
Why tcpdump?

Universal file format (.pcap)
Universal filter expression
Can work on remote hosts
Quick start

     “No DNS”                 “Hex dump”
    faster display           display payload

tcpdump -n -s 1500 -X
                     “Packet size”
                     fuller capture
Header    tcpdump -Xns0


HEX                       ASCII
(-X)                       (-A)




...next
Workflow 1:
     Online analysis

Fast (-n), full (-s0), with dump
(-X), ...and filter:
tcpdump -Xns0 port 80
Workflow 2:
          Offline analysis
Full (-s0), write to a file (-w),
then read:
tcpdump -s0 -w abc.pcap port 80
tcpdump -nXr abc.pcap host nweb30
Architecture
  tcpdump          tcpdump.exe

  libpcap.so       BPF     libpcap.a

  /dev/bpf0              ???

BPF   BSD Kernel   $OS Kernel
BPF: Berkeley Packet Filter

 The human readable filter is
 converted to a bytecode (-d),
 sent to kernel. Efficient.
 http://www.tcpdump.org/
 papers/bpf-usenix93.pdf
Filter language

and, or
port 80
host nweb30
‘src host localhost and dst port 80’
Timestamp                          L3 protocol
 (-tt, -ttt, -tttt)   Output        (IP, GRE, etc)
                              Relative TCP
                              ack number
src host       src port       dst host & port
    TCP Flags      Relative TCP      Advertised TCP
     (S, F, R)  sequence number
    1343949078.196214 IP               window size
    216.218.215.245.61966 > 50.18.0.102.80:
    Flags [P.], seq 1:473, ack 1, win 8265,
    options [nop,nop,TS val 808617737 ecr
    1091126708], length 472

          List of TCP             Payload length
      options (e.g. wscale)
WTFs (0/3)

tcpdump: no suitable device
found
Use sudo or check /dev/bpf*
permissions
WTFs (1/3)

Output is laggy?
Disable DNS resolution (-n)
Or save to a file (-w)
WTFs (2/3)


Nothing happens?
Select a proper interface
(-i ppp0)
WTFs (3/3)


Want to cut-n-paste HTML?
Use ASCII output (-A), or save
to .pcap (-r) and fire up vim.
RFCs

IP: RFC791
TCP: RFC793, 1122
DNS: RFC1034, 1035
Many short overviews exist!
See also
WireShark (GUI)
SSLdump (decrypt HTTPS)
tcpflow (split by TCP flow)
libpcap (C interface)
lionet.info/ipcad
RTFM

man pcap-filter
man tcpdump
man pcap
man bpf
Questions?

Introduction to tcpdump