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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM