我先看下实例代码:
?
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
1.常见参数
tcpdump -i eth0 -nn -s0 -v port 80
-i 选择监控的网卡
-nn 不解析主机名和端口号,捕获大量数据,名称解析会降低解析速度
-s0 捕获长度无限制
-v 增加输出中显示的详细信息量
port 80 端口过滤器,只捕获80端口的流量,通常是http
2.
tcpdump -a -s0 port 80
-a 输出ascii数据
-x 输出十六进制数据和ascii数据
3.
tcpdump -i eth0 udp
udp 过滤器,只捕获udp数据
proto 17 协议17等效于udp
proto 6 等效于tcp
4.
tcpdump -i eth0 host 10.10.1.1
host 过滤器,基于ip地址过滤
5.
tcpdump -i eth0 dst 10.105.38.204
dst 过滤器,根据目的ip过滤
src 过滤器,根据来源ip过滤
6.
tcpdump -i eth0 -s0 -w test.pcap
-w 写入一个文件,可以在wireshark中分析
7.
tcpdump -i eth0 -s0 -l port 80 | grep server:
-l 配合一些管道命令的时候例如grep
8.
组合过滤
and or &&
or or ||
not or !
9.
快速提取http ua
tcpdump -nn -a -s1500 -l | grep “user-agent:”
使用egrep 匹配 ua和host
tcpdump -nn -a -s1500 -l | egrep -i user-agent:|host:
10.
匹配get的数据包
tcpdump -s 0 -a -vv tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420
匹配post包,post的数据可能不在包里
tcpdump -s 0 -a -vv tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354
11.
匹配http请求头
tcpdump -s 0 -v -n -l | egrep -i “post /|get /|host:”
匹配一些post的数据
tcpdump -s 0 -a -n -l | egrep -i “post /|pwd=|passwd=|password=|host:”
匹配一些cookie信息
tcpdump -nn -a -s0 -l | egrep -i set-cookie|host:|cookie:
12.
捕获dns请求和响应
tcpdump -i eth0 -s0 port 53
13.
使用tcpdump捕获并在wireshark中查看
使用ssh远程连接服务器执行tcpdump命令,并在本地的wireshark分析
ssh root@remotesystem tcpdump -s0 -c 1000 -nn -w – not port 22 | wireshark -k -i –
ssh ubuntu@115.159.28.111 sudo tcpdump -s0 -c 1000 -nn -w – not port 22 | wireshark -k -i –
14.
配合shell获取最高的ip数
tcpdump -nnn -t -c 200 | cut -f 1,2,3,4 -d . | sort | uniq -c | sort -nr | head -n 20
15.捕获dhcp的请求和响应
tcpdump -v -n port 67 or 68