summaryrefslogtreecommitdiff
path: root/doc/note/tcpdump/tcpdump.txt
blob: 71ffb0246cbc565c7c0d4054f37a6d433688a25e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

Tcpdump
================


## Realtime Download:

  scriptlee -W OcChunkDownload.lua -n OC_PROJ --scan-delay 10 --workdir ../../../../../tmp --pod-pattern 'houston.%d' --file-pattern 'houston.STAGE.tcp.*gz' --skip 1

  RNG="{001,002,003}"; TS="20230907-100235"; ocprod exec -i "$(ocprod get pods|grep houston-[1-9]|cut -f1 -d' ')" -- sh -c 'true && cd /tmp && tar c houston-prod-tcp-'"${TS:?}"'.pcap'"${RNG:?}"'.gz && rm houston-prod-tcp-'"${TS:?}
"'.pcap'"${RNG:?}"'.gz' | tar x



## Base (inclusive blacklist brox, fluentd, ...):

redis=6379, brox=7022, fluentd=7099

  cd /usr/local/vertx/houston-storage-file && timeout --foreground -s INT 180 tcpdump -ni any -C 50M -W 999 -w houston-STAGE-tcp-`date -u +%Y%m%d-%H%M%S`.pcap "not port 443 and not port 6379 and not port 7022 and not port 7099" -z gzip

  cd /tmp && timeout --foreground -s INT 180 tcpdump -ni any -C 50M -W 999 -w houston-prod-tcp-`date -u +%Y%m%d-%H%M%S`.pcap "not port 443 and not port 6379 and not port 7022 and not port 7099" -z gzip

  ocprod exec -i "$(ocprod get pods|egrep ston-[1-9]|cut -f1 -d' ')" -- sh -c 'cd /tmp && tar c "houston-prod-tcp-20231114-165243.pcap*.gz"' > houston-prod-tcp-20231114-165243.pcap.gz.tar

  ocprod exec -ti "$(ocprod get pods|egrep ston-[1-9]|cut -f1 -d' ')" -- sh -c 'cd /tmp && watch ls -Ahl'


## pcap cli PreProcessing

Tips: "https://chrissanders.org/2018/06/large-captures4-filter-whittling/"

  mergecap.exe -a -w OUTFILE INFILES_GLOB

  -Y 'http.request.uri.query contains "expand"'
  -Y 'http.time < 2.0 or http.request'



## Local dumps isa-only filter

  "portrange 6000-9999 and not port 7778"


## Accept HTTP POST requests:

  "tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504F5354"



## Copy result to local machine (the boring way)

  oc rsync <pod-name>:/remote/dir/filename .



## Special filters

  "tcp[tcpflags] & (tcp-syn|tcp-ack|tcp-fin|tcp-rst) != 0"

  "ip 1.2.3.4"

  "net 172.18.0.0/16"


## Filter kube-probes "GET /houston/server/info" or '{"name":"houston",'

  tcpdump -nni any -w /tmp/houston-${PAISA_ENV:?}-tcp-$(date -u +%Y%m%d-%H%M%SZ)-%s.pcap -C 8M -W 99 -G 600 "(tcp[((tcp[12:1]&0xf0)>>2)+0:4] = 0x47455420 && tcp[((tcp[12:1]&0xf0)>>2)+4:4] = 0x2F686F75 && tcp[((tcp[12:1]&0xf0)>>2)+8:4] = 0x73746F6E && tcp[((tcp[12:1]&0xf0)>>2)+12:4] = 0x2F736572 && tcp[((tcp[12:1]&0xf0)>>2)+16:4] = 0x7665722F && tcp[((tcp[12:1]&0xf0)>>2)+20:4] = 0x696E666F && tcp[((tcp[12:1]&0xf0)>>2)+24:1] = 0x20) or (tcp[((tcp[12:1]&0xf0)>>2)+115:4] = 0x7B226E61 && tcp[((tcp[12:1]&0xf0)>>2)+119:4] = 0x6D65223A && tcp[((tcp[12:1]&0xf0)>>2)+123:4] = 0x22686F75 && tcp[((tcp[12:1]&0xf0)>>2)+127:4] = 0x73746F6E && tcp[((tcp[12:1]&0xf0)>>2)+131:2] = 0x222C)"


## Try dump kube-probes fully

  timeout --foreground 900 tcpdump -nni any -w /tmp/houston-${PAISA_ENV:?}-tcp-$(date -u +%Y%m%d-%H%M%SZ)-%s.pcap -C 42M -W 42 -G 600 "host 10.127.73.1 and port 7012"


## Extract hosts file from DNS traffic

Not perfect because needs manual fine-tuning. But can be helpful anyway.

  -Y 'dns.a and dns.resp.name' -Tfields -edns.a -edns.resp.name

Vielleicht auch mal option "-zhosts" ausprobieren. Sollte auch sowas tun.


[man tcpdump](https://www.tcpdump.org/manpages/tcpdump.1.html)
[no name port numbers rhel patch](https://superuser.com/a/587304/1123359)
[complex filter by byte contents](https://security.stackexchange.com/a/121013/179017)