如何根据数据包长度过滤tcpdump输出

26
我一直在尝试根据数据包长度过滤tcpdump输出,但是没有成功。这是一个命令的简单输出:

tcpdump -n -i eth0 dst port 443 -A

17:03:30.866890 IP 192.168.0.149.45104 > 62.75.148.60.443: Flags [S], seq 2685064927, win 14600, options [mss 1460,sackOK,TS val 7028787 ecr 0,nop,wscale 4], length 0
E..<..@.@.......>K.<.0...
........9............
.k@3........


17:03:30.867658 IP 192.168.0.149.45104 > 62.75.148.60.443: Flags [.], ack 2285019097, win 913, options [nop,nop,TS val 7028787 ecr 974439509], length 0
E..4..@.@.......>K.<.0...
...2.............
.k@3:..U


17:03:30.867928 IP 192.168.0.149.45104 > 62.75.148.60.443: Flags [P.], seq 0:171, ack 1, win 913, options [nop,nop,TS val 7028787 ecr 974439509], length 171
E.....@.@..f....>K.<.0...
...2.............
.k@3:..U...........Opw2.....l..".T.7.q.]h..8W..%.....H...
.......9.8.......5...   .....E.D.3.2...........A...../.........
...1.........alice.sni.velox.ch.
.................#..


17:03:30.869712 IP 192.168.0.149.45104 > 62.75.148.60.443: Flags [.], ack 1319, win 1078, options [nop,nop,TS val 7028788 ecr 974439511], length 0
E..4..@.@.......>K.<.0...
...2.....6.......
.k@4:..W


17:03:30.870724 IP 192.168.0.149.45104 > 62.75.148.60.443: Flags [P.], seq 171:178, ack 1319, win 1078, options [nop,nop,TS val 7028788 ecr 974439511], length 7
E..;..@.@.......>K.<.0...
...2.....6.......
.k@4:..W......0

我希望只看到长度超过100字节的数据包,对于这种情况,只有第3个数据包。
选项[nop,nop,TS val 7028787 ecr 974439509],长度171
我查看了tcpdump的man页面,但没有找到任何有用的参数。这里提到了一个表达式“greater length”,http://www.ethereal.com/docs/man-pages/tcpdump.8.html,但我也无法使用该表达式。
$ tcpdump -n -i eth0 dst port 443 -A -x greater 100
tcpdump: syntax error

感谢任何帮助。

1个回答

41

greater length works, but you have to use it as part of a complete filter expression, and the filter expression has to come after all the command-line flag arguments.

Working example:

tcpdump -n -i eth0 -A -x dst port 443 and greater 100

应该可以工作 - dst port 443 and greater 100 是一个完整的过滤表达式,它检查被发送到 TCP 或 UDP 端口 443 的数据包,并且具有大于 100 的长度(包括链路层、IP 和 TCP 头!)。

不工作的示例:

tcpdump -n -i eth0 dst port 443 -A -x greater 100

不起作用 - 在“dst port 443”中的“dst”被视为筛选表达式的开头,这意味着它与其后的所有内容(包括“A”和“-x”)都被视为筛选表达式的一部分,但“A”和“-x”不是筛选表达式的有效组成部分。它们可能旨在作为命令行选项,因此必须放在所有非标志参数(包括筛选表达式的组件)之前。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接