tcpdump 与 抓包分析

在Windows下一般使用WireShark 抓包软件,tcpdump 是 Linux 系统的抓包软件。它可以抓取 TCP/IP 协议族的数据包,支持针对网络层、协议、主机、端口的过滤,并提供 and、or、not 等逻辑语句来过滤无用的信息。

root@h # tcpdump -h
tcpdump version 4.9.2
libpcap version 1.8.1
OpenSSL 1.1.1  11 Sep 2018
Usage: tcpdump [-aAbdDefhHIJKlLnNOpqStuUvxX#] [ -B size ] [ -c count ]
		[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]
		[ -i interface ] [ -j tstamptype ] [ -M secret ] [ --number ]
		[ -Q in|out|inout ]
		[ -r file ] [ -s snaplen ] [ --time-stamp-precision precision ]
		[ --immediate-mode ] [ -T type ] [ --version ] [ -V file ]
		[ -w file ] [ -W filecount ] [ -y datalinktype ] [ -z postrotate-command ]
		[ -Z user ] [ expression ]

 常用的命令列表:

1.查看当前可用的的网口列表

  tcpdump -D

2. 指定一个网口

  tcpdump -i enp0s3

3. 指定一个网口和网段

  tcpdump -i enp0s3 net 192.168.225

4. 指定监听报文,端口号,发送源,详细信息

  tcpdump -nn -i enp0s3 tcp and src 192.168.225.5 and port 54620 -vv

5. 查看报文的所有数据 

  tcpdump -nn -i enp0s3 tcp and src 192.168.225.5 -e -XX -S -s 0 -vv

分析TCP报文:

07:18:19.872797 40:00:00:aa:00:60 > 3c:52:82:d7:1d:ef, ethertype IPv4 (0x0800), length 70: (tos 0x0, ttl 64, id 10141, offset 0, flags [DF], proto TCP (6), length 56)
192.168.225.5.49384 > 192.168.225.1.13411: Flags [P.], cksum 0x37c2 (correct), seq 402706124:402706140, ack 2009259232, win 229, length 16

        源IP地址                        目的IP地址                                                                      

中括号表示 : [ IP 头]     + {TCP头} +{TCP}

0x0000: [  3c52 82d7 1def4000 00aa 0060 0800 4500          <R....@....`..E.

               目的mac地址    源mac地址     报文类型 4:IPv4 5:IP头部长度

0x0010: 0038 279d ]  { 4000 4006 cfca c0a8 e105 c0a8          .8'.@.@.........

       总报文长度0x38        0x6:TCP
0x0020: e101 c0e8 3463 1800 cecc 77c2 dce0 5018         ....4c....w...P.
0x0030: 00e5 37c2 0000 } 0201 0100 0000 0000 0000        ..7.............

               Data 开始的地方

0x0040: 0000 0000 0000

参考资料:

1、UDP头

0      7 8     15 16    23 24    31
 +--------+--------+--------+--------+
 |     Source      |   Destination   |
 |      Port       |      Port       |
 +--------+--------+--------+--------+
 |                 |                 |
 |     Length      |    Checksum     |
 +--------+--------+--------+--------+
 |                                   |
 |              DATA ...             |
 +-----------------------------------+

2. TCP头

3. IP 头

 tcpdump -nn -e -XX -S -s 0 -vv -w /free_emmc/file.pcap -i ravb0 udp and src 192.168.1.50

参考连接:

http://www.tcpdump.org/manpages/tcpdump.1.html

https://www.cnblogs.com/bakari/p/10748721.html

https://blog.csdn.net/qq_25453065/article/details/89786943

原文地址:https://www.cnblogs.com/hutiann/p/11993726.html