simon / tcpdump

Last active 1 month ago

simon revised this gist 1 month ago · 105e352

1 file changed, 61 insertions

tcpdump.md (file created)
@@ -0,0 +1,61 @@
1 + # tcpdump
2 +
3 + * capture HTTPS ClientHello packets and use tshark to extract Hostnames:
4 +
5 + ```
6 + tcpdump "tcp port 443 and (tcp[((tcp[12] & 0xf0) >>2)] = 0x16) && (tcp[((tcp[12] & 0xf0) >>2)+5] = 0x01)" -w output.pcap
7 +
8 + tshark -r output.pcap -Tfields -e tls.handshake.extensions_server_name -Y 'tls.handshake.extension.type == 0' | sort | uniq
9 + ```
10 +
11 + * capture HTTP (80) traffic and print headers
12 +
13 + ```
14 + tcpdump -A -s 10240 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' | egrep --line-buffered "^........(GET |HTTP\/|POST |HEAD )|^[A-Za-z0-9-]+: " | sed -r 's/^........(GET |HTTP\/|POST |HEAD )/\n\1/g'
15 + ```
16 +
17 + * filter packets with a TTL less than 32 (TTL is the 8th byte in the header):
18 +
19 + ```
20 + tcpdump -v ip and 'ip[8]<32'
21 + ```
22 +
23 + * summarise IPs from a pcap:
24 +
25 + ```
26 + tcpdump -ntr file.pcap | awk '{print $2}' | tr . ' ' | awk '{print $1"."$2"."$3"."$4}' | sort | uniq -c | awk ' {print $2}'
27 + ```
28 +
29 + * summarise IPs from a pcap (with packet count per IP):
30 +
31 + ```tcpdump
32 + ```
33 +
34 + ## capture traffic encapsulated IPIP traffic based on IP address
35 +
36 + * first convert the IP to hex [here](https://www.browserling.com/tools/ip-to-hex)
37 + * then run:
38 +
39 + ```
40 + tcpdump -l ip[32:4] = 0x0a6fc802 or ip[36:4] = 0x0a6fc802”
41 + ```
42 +
43 + ## capture traffic and send it to a remote location:
44 +
45 + * listen on port 12345 on the remote:
46 +
47 + ```
48 + nc -l -p 12345 > /home/user/somefile.pcap
49 + ```
50 +
51 + * tcpdump and pipe it to the remote with netcat (or nc):
52 +
53 + ```
54 + # nc
55 +
56 + tcpdump -n -U -s 0 -i <interface> not port 12345 -w - | nc <remote IP> 12345
57 +
58 + # ncat
59 +
60 + tcpdump -n -U -s 0 -i <interface> not port 12345 -w - | ncat <remote IP> 12345
61 + ```