tcpdump 用法

1. 原文链接

本文原文来自: A tcpdump Tutorial with Examples — 50 Ways to Isolate Traffic

2. TCPDUMP 简介

TCPDUMP 在一个界面中既提供了强大的功能又简单易用,无疑已经是网络分析工具中的老大。

本教程将介绍如何以各种方式隔离流量:从IP,端口到协议,再到应用层流量。以确使用者保能够尽快找到所需内容。

3. 查看所有流量

查看指定接口上的所有流量

tcpdump -i eth0

查看所有接口上的所有流量

tcpdump -i any

4. 通过IP找流量

这是最常用的查询之一,使用 host 指定主机,就会看到 从指定IP的进流量和出流量

tcpdump host 1.1.1.1 -i ens33

5. 通过源地址和/或目的地址进行过滤

如果你只想一个方向上的流量,可以使用 srcdst 指定。

tcpdump src 192.168.27.100 -i ens33
tcpdump dst 192.168.27.100 -i ens33

6. 通过网段过滤流量

使用 net 选项查看进出一个网段或子网的进出流量。

tcpdump net 1.2.3.0/24

7. 使用十六进制输出流量包的内容

当要对一些包进行仔细审查其内容的时候,使用十六进制输出的方式来查看包就很有用了。

tcpdump -c 1 -X icmp -i ens33
tcpdump -c 1 -X tcp port 443 -i ens33

-c 1 是指定只抓取一个包。

[root@centos7 ~]#tcpdump -c 1 -X icmp -i ens33        
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
15:25:37.519985 IP ming-machine > centos7-scm: ICMP echo request, id 40906, seq 1154, length 64
        0x0000:  4500 0054 61af 4000 4001 20c8 c0a8 1b7d  E..Ta.@.@......}
        0x0010:  c0a8 1b64 0800 5ec2 9fca 0482 007a f35c  ...d..^......z.\
        0x0020:  0000 0000 3547 0d00 0000 0000 1011 1213  ....5G..........
        0x0030:  1415 1617 1819 1a1b 1c1d 1e1f 2021 2223  .............!"#
        0x0040:  2425 2627 2829 2a2b 2c2d 2e2f 3031 3233  $%&'()*+,-./0123
        0x0050:  3435 3637                                4567
1 packet captured
2 packets received by filter
0 packets dropped by kernel
[root@centos7-scm ~]#tcpdump -c 1 -X tcp port 443 -i ens33
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
15:25:40.084912 IP ming-machine.53006 > tsa03s01-in-f14.1e100.net.https: Flags [S], seq 908528803, win 29200, options [mss 1460,sackOK,TS val 4054248663 ecr 0,nop,wscale 7], length 0
        0x0000:  4500 003c 747a 4000 4006 48f3 c0a8 1b7d  E..<tz@.@.H....}
        0x0010:  d83a c8ee cf0e 01bb 3627 0ca3 0000 0000  .:......6'......
        0x0020:  a002 7210 668e 0000 0204 05b4 0402 080a  ..r.f...........
        0x0030:  f1a6 ecd7 0000 0000 0103 0307            ............
1 packet captured
1 packet received by filter
0 packets dropped by kernel
[root@centos7-scm ~]#

8. 查看指定端口上的流量

通过 port 选项,可以找到指定端口上的进出流量。

tcpdump port 3389 -i ens33   # 3389 是 windows 远程链接的端口
tcpdump src port 1025 -i ens33

9. 查看指定协议类型的流量

如果想要查看某一种类型协议的流量,可以通过 tcpudpicmo 或其他协议类型。

tcpdump icmp

10. 只查看 IPv6 流量

https://hauweele.net/~gawen/blog/?p=1053

tcpdump src fe80::1e55:bb34:ae1:fd08 -i ens33
tcpdump dst fe80::1e55:bb34:ae1:fd08 -i ens33

抓包示例

[root@centos7 ~]#tcpdump -nn dst fe80::1e55:bb34:ae1:fd08 -i ens33 -c 2
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
16:04:08.318748 IP6 fe80::20c:29ff:fe20:a3f5 > fe80::1e55:bb34:ae1:fd08: ICMP6, echo request, seq 250, length 64
16:04:09.342193 IP6 fe80::20c:29ff:fe20:a3f5 > fe80::1e55:bb34:ae1:fd08: ICMP6, echo request, seq 251, length 64
2 packets captured
2 packets received by filter
0 packets dropped by kernel

使用 ipv6 地址ping使用的是 ping6 命令
命令格式为

ping6 ipv6地址%网卡名     #要通过 "%" 指定网卡名
ping -6 ipv6地址%网卡名   #要通过 "%" 指定网卡名, ping -6 在ubuntu上无效,需要使用ping6

示例

[root@centos7 ~]#ping6 fe80::20c:29ff:fe20:a3f5%ens33
PING fe80::20c:29ff:fe20:a3f5%ens33(fe80::20c:29ff:fe20:a3f5%ens33) 56 data bytes
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq=1 ttl=64 time=0.265 ms
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq=2 ttl=64 time=0.319 ms
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq=3 ttl=64 time=0.510 ms
[root@centos7 ~]#ping -6 fe80::20c:29ff:fe20:a3f5%ens33 -c 2
PING fe80::20c:29ff:fe20:a3f5%ens33(fe80::20c:29ff:fe20:a3f5%ens33) 56 data bytes
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq=1 ttl=64 time=0.231 ms
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq=2 ttl=64 time=0.402 ms

11. 通过端口范围过滤

tcpdump portrange 21-23

12. 查看指定大小的数据包

可以查看指定大小的数据包,指定数据包的大小的时候还可以使用比较运算符。

tcpdump less 32 
tcpdump greater 64 
tcpdump <= 128

13. 读/写抓取的信息从/到文件

将抓取到的数据包信息存储到文件以便将来进行分析是很必要的。文件格式为 PCAP (PEE-cap) files格式。这种文件可以被众多的应用程序解析,包括网络分析工具、入侵检测系统、当然还有tcpdump自己。

13.1. 保存抓包信息到文件

使用 -w 选项写入文件(后缀是 .cap 就可以使用 wireshark 识别分析)

sudo tcpdump -i eth0 -c 100 -w catcher.cap
$ sudo tcpdump -i eth0 -c 100 -w catcher.cap
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
100 packets captured
213 packets received by filter
0 packets dropped by kernel
$ 

13.2. 从文件中读取抓包信息

使用 -r 选项从文件中读取,在读取文件的时候,我们可以像正常抓包时一样使用tcpdump.需要注意的是,文件中不存在的数据是抓取不到和解析的。

tcpdump -r capture_file

示例

tcpdump -r capture_file dst 192.168.27.125
tcpdump -r capture_file src 192.168.27.100 
tcpdump -r capture_file -i ens33 icmp6

14. 以下是进阶内容

下面是 tcpdump 的一些其他进阶选项,工抓包时候进行进一步调整。

  • -A : Print each packet (minus its link level header) in ASCII. Handy for capturing web pages.
  • -X : 十六进制的ASCII编码方式输出显示包内容
  • -XX : 同 -X , 但是同时显示一台帧头部信息。
  • -D : 显示可用的接口列表。
  • -l : 显示行号输出。
  • -q : 静默输出(显示最少的信息)。
  • -t : 输出的时间戳为人类可读格式(经实验无时间戳输出)。
  • -tttt : 输出最详细的时间戳为人类可读格式。
  • -i eth0 : 监听 eth0 网卡抓包。
  • -vv : 比 -v 有更详细的输出。
  • -c : 指定的抓包的数量,之后停止。
  • -s : 指定每个抓取的数据包的字节长度,默认是262144字节. 使用 -s0 获取整个数据包的内容。
  • -S : 输出绝对数据包的绝对序列号。
  • -e : 同时获取以太帧头信息。
  • -E : 通过给定的密钥解密 IPSEC 数据流。

15. 关于组合(或与非)

tcpdump 除了支持上面的单独的功能,还提供了更加强大的组合功能,可以让我们创造出各种组合形式来得到我们想要的结果。如果学习果编程,你会发现下面的内容似曾相识。

  • AND:and or &&
  • OR:or or ||
  • EXCEPT:not or !

16. 裸视图输出

下面的组合输出的是:没有主机名和端口解析、使用绝对序号、人类可读时间戳的详细输出。

[root@centos7 ~]#tcpdump -ttnnvvS -i ens33 -c 1
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
1559468718.414926 IP (tos 0x10, ttl 64, id 35965, offset 0, flags [DF], proto TCP (6), length 216)
    192.168.27.100.22 > 192.168.27.2.14154: Flags [P.], cksum 0xb881 (incorrect -> 0x7999), seq 580563511:580563687, ack 2138271063, win 339, length 176

17. 指定源IP和目的端口的流量

tcpdump -nnvvS src 10.5.2.3 and dst port 3389

18. 网段到网段的流量

下面阿组合输出为:从源为192.168.0.0/16目的为10.0.0.0/8或172.16.0.0/16、不解析主机名、十六进制格式、详细级别为-v级别的抓包信息。

tcpdump -nvX src net 192.168.0.0/16 and dst net 10.0.0.0/8 or 172.16.0.0/16

19. 到指定地址的非ICMP的流量

tcpdump dst 192.168.0.2 and src net and not icmp

20. 指定源主机和排除目的端口的流量

下面的输出为:源为指定的主机 mars, 目的端口不是 22 端口的流量信息。

tcpdump -vv src mars and not dst port 22

21. 关于分组的小结

我们可以看到,通过合理的组合,我们就可以得到任何想要的结果,关键是要搞清楚想要的信心,并且构建合适的查询语法。

在构建复杂查询时,可能必须使用单引号对选项进行分组,在下例中是在“()”括号下面。单引号用于告诉tcpdump忽略某些特殊字符。同样的技术也可以用于使用其他表达式(如host、port、net等)进行分组。

tcpdump 'src 10.0.2.4 and (dst port 3389 or 22)'

22. 隔离指定TCP标记的流量

22.1. TCP 报头

# TCP 报头简图 ,一个 TCP 头为 20 字节
 0                            15                              31
-----------------------------------------------------------------
|          source port          |       destination port        |
-----------------------------------------------------------------
|                        sequence number                        |
-----------------------------------------------------------------
|                     acknowledgment number                     |
-----------------------------------------------------------------
|  HL   | rsvd  |C|E|U|A|P|R|S|F|        window size            |
-----------------------------------------------------------------
|         TCP checksum          |       urgent pointer          |
-----------------------------------------------------------------

# 下面是标志位的部分,位置处在包头20字节中的第 13 字节的位置。
 0             7|             15|             23|             31
----------------|---------------|---------------|----------------
|  HL   | rsvd  |C|E|U|A|P|R|S|F|        window size            |
----------------|---------------|---------------|----------------
|               |  13th octet   |               |               |

通过二进制计算可以得到

  • FIN 的值为 1 (2^0)
  • SYN 的值为 2 (2^1)
  • RST 的值为 4 (2^2)
  • PSH 的值为 8 (2^3)
  • ACK 的值为 16(2^4)
  • URG 的值为 32(2^5)
  • ECE 的值为 64(2^6)
  • CWR 的值为 128(2^7)

22.2. TCP RST 标记的隔离

tcpdump 'tcp[13] & 4!=0'
tcpdump 'tcp[tcpflags] == tcp-rst'

22.3. TCP SYN 标记的隔离

tcpdump 'tcp[13] & 2!=0'
tcpdump 'tcp[tcpflags] == tcp-syn'

22.4. TCP ACK 和 SYN 标记的隔离

tcpdump 'tcp[13]=18'

22.5. TCP URG 标记的隔离

tcpdump 'tcp[13] & 32!=0'
tcpdump 'tcp[tcpflags] == tcp-urg'

22.6. TCP ACK 标记的隔离

tcpdump 'tcp[13] & 16!=0'
tcpdump 'tcp[tcpflags] == tcp-ack'

22.7. TCP PSH 标记的隔离

tcpdump 'tcp[13] & 8!=0'
tcpdump 'tcp[tcpflags] == tcp-psh'

22.8. TCP FIN 标记的隔离

tcpdump 'tcp[13] & 1!=0'
tcpdump 'tcp[tcpflags] == tcp-fin'

22.9. 快速过滤 TCP FLAG

可以通过上文中计算出的各个标志位的对应值,直接计算出组合的值来设置组合对应的值。

Both SYN and RST Set

  • SYN 的值为 2 (2^1)
  • RST 的值为 4 (2^2)
tcpdump 'tcp[13] = 6'

23. 过滤 HTTP的 User Agents

tcpdump -vvAls0 -i ens33| grep 'User-Agent:'
[root@centos7-scm ~]#curl --head www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 277
Content-Type: text/html
Date: Sun, 02 Jun 2019 10:42:35 GMT
Etag: "575e1f60-115"
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
[root@centos7-scm ~]#tcpdump -vvAls0 -i ens33| grep 'User-Agent:'
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
        User-Agent: curl/7.29.0
User-Agent: curl/7.29.0

24. 过滤 HTTP的 明文 HTTP 请求头

tcpdump -vvAls0 -i ens33 | grep 'GET'
[root@centos7-scm ~]#curl -X GET www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
[root@centos7-scm ~]#tcpdump -vvAls0 -i ens33 | grep 'GET'
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
        GET / HTTP/1.1
E..u@|@.@......dg..'...P601.....P...r...GET / HTTP/1.1

25. 过滤 HTTP的 Hosts

tcpdump -vvAls0 -i ens33 | grep 'Host:'
[root@centos7-scm ~]#curl -I www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 277
Content-Type: text/html
Date: Sun, 02 Jun 2019 10:48:40 GMT
Etag: "575e1f60-115"
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
[root@centos7-scm ~]#tcpdump -vvAls0 -i ens33 | grep 'Host:'
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
        Host: www.baidu.com
Host: www.baidu.com

26. 过滤 HTTP Cookies

tcpdump -vvAls0 -i ens33 | grep -E 'Set-Cookie:|Host:|Cookie:'
[root@centos7-scm ~]#wget  www.baidu.com         
--2019-06-02 19:34:49--  http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 220.181.38.149, 220.181.38.150
Connecting to www.baidu.com (www.baidu.com)|220.181.38.149|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html.5’

100%[==================================================================>] 2,381       --.-K/s   in 0s      

2019-06-02 19:34:49 (191 MB/s) - ‘index.html.5’ saved [2381/2381]
[root@centos7-scm ~]#tcpdump -vvAls0 -i ens33 | grep -E 'Set-Cookie:|Host:|Cookie:'
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
        Host: www.baidu.com
Host: www.baidu.com
        Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/

27. 过滤 SSH Connections

This one works regardless of what port the connection comes in on, because it’s getting the banner response.

tcpdump 'tcp[(tcp[12]>>2):4] = 0x5353482D' -i ens33
[root@centos7 ~]#tcpdump 'tcp[(tcp[12]>>2):4] = 0x5353482D' -i ens33
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
18:36:23.490464 IP gateway.fronet > centos7.ssh: Flags [P.], seq 960612390:960612432, ack 497953643, win 2053, length 42
18:36:23.502672 IP centos7.ssh > gateway.fronet: Flags [P.], seq 1:22, ack 42, win 229, length 21

28. 过滤 DNS 流量

tcpdump -vvAs0 port 53 -i ens33
[root@centos7-scm ~]#ping www.google.com
PING www.google.com (74.86.235.236) 56(84) bytes of dat
[root@centos7-scm ~]#tcpdump -vvAs0 port 53 -i ens33
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
19:39:12.520747 IP (tos 0x0, ttl 64, id 6789, offset 0, flags [DF], proto UDP (17), length 60)
    centos7-scm.40966 > google-public-dns-a.google.com.domain: [bad udp cksum 0xec55 -> 0xbfb1!] 9453+ A? www.google.com. (32)
E..<..@.@.4....d.......5.(.U$............www.google.com.....
19:39:12.521795 IP (tos 0x0, ttl 64, id 6790, offset 0, flags [DF], proto UDP (17), length 66)
    centos7-scm.59105 > google-public-dns-a.google.com.domain: [bad udp cksum 0xec5b -> 0x3a7d!] 55476+ PTR? 8.8.8.8.in-addr.arpa. (38)
E..B..@.@.4     ...d.......5...[.............8.8.8.8.in-addr.arpa.....
19:39:12.537071 IP (tos 0x0, ttl 60, id 27911, offset 0, flags [DF], proto UDP (17), length 76)
    google-public-dns-a.google.com.domain > centos7-scm.40966: [udp sum ok] 9453 q: A? www.google.com. 1/0/0 www.google.com. A 74.86.235.236 (48)
E..Lm.@.<..}.......d.5...8G.$............www.google.com.................JV..
19:39:12.537087 IP (tos 0x0, ttl 48, id 0, offset 0, flags [none], proto UDP (17), length 76)
    google-public-dns-a.google.com.domain > centos7-scm.40966: [udp sum ok] 9453 q: A? www.google.com. 1/0/0 www.google.com. A 69.63.186.30 (48)
E..L....0..........d.5...8~.$............www.google.com.................E?..

29. 过滤 FTP 流量

tcpdump -vvAs0 port ftp or ftp-data -i ens33

30. 过滤NTP流量

tcpdump -vvAs0 port 123 -i ens33

31. 过滤明文密码

tcpdump port http or port ftp or port smtp or port imap or port pop3 or port telnet -lA | egrep -i -B5 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd= |password=|pass:|user:|username:|password:|login:|pass |user '
test@machine:~$ curl -X GET  http://www.baidu.com/?pass=123456
<!DOCTYPE html>
<!--STATUS OK--><html> ... </html>
test@machine:~$ sudo tcpdump port http or port ftp or port smtp or port imap or port pop3 or port telnet -lA | egrep -i -B5 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd= |password=|pass:|user:|username:|password:|login:|pass |user '
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
.Q.!........
19:49:57.328294 IP 103.235.46.39.http > 192.168.27.125.47334: Flags [S.], seq 2439930931, ack 2291696402, win 8192, options [mss 1440,sackOK,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,wscale 5], length 0
E..<d*@.,.xZg..'...}.P...nd3...... ..O......................
19:49:57.328365 IP 192.168.27.125.47334 > 103.235.46.39.http: Flags [.], ack 1, win 229, length 0
E..(d+@.@.dm...}g..'...P.....nd4P...rR..
19:49:57.328474 IP 192.168.27.125.47334 > 103.235.46.39.http: Flags [P.], seq 1:90, ack 1, win 229, length 89: HTTP: GET /?pass=123456 HTTP/1.1
E...d,@.@.d....}g..'...P.....nd4P...r...GET /?pass=123456 HTTP/1.1

32. 过滤包含"邪恶位"的包

IP 包头中有 3个bit的标志位(Flag),3bit的标识字段每一位都有特定的含义,该字段主要用来分片和重组。第1个bit为保留位(Reserved Bit),一般置位0。第2个bit为不分片位(Don’t ragment),该位在置1时表示不分片。第3个bit为更多片位(More Fragment),该位表示后面是否还有更多的分片,置位1时表示后面还有,所以除了最后一片报文,其他分片报文该位全部置1。

这里指的邪恶位就是第一个bit的位置。 处在IP包头中的第6个字节位置。

tcpdump 'ip[6] & 128 != 0'

33. 几种重要流量的抓取

本节内容参考自 tcpdump简明教程: https://github.com/mylxsw/growing-up/blob/master/doc/tcpdump简明教程.md

这里有一些重要的代码片段你可能需要,它们用于过滤指定的流量,例如畸形的或者恶意的流量。

33.1. 过滤同时设置SYN和RST标识的包(这在正常情况下不应该发生)

tcpdump 'tcp[13] = 6'

33.2. 过滤明文的HTTP GET请求

tcpdump 'tcp[32:4] = 0x47455420'

33.3. 通过横幅文本过滤任意端口的SSH连接

tcpdump 'tcp[(tcp[12]>>2):4] = 0x5353482D'

33.4. 过滤TTL小于10的包(通常情况下是存在问题或者在使用traceroute)

tcpdump 'ip[8] < 10'

33.5. 过滤恶意的包

tcpdump 'ip[6] & 128 != 0'

34. 可能出现问题的解决

在RHEL7下,如果不用-i参数指定网络接口,则会报如下错误:
tcpdump: Bluetooth link-layer type filtering not implemented

posted @ 2019-03-02 20:33  scm1911  阅读(2284)  评论(0编辑  收藏  举报
/** ####################################################################### */