Linux运维常用网络抓包工具tcpdump的介绍和使用

98 篇文章 1 订阅
82 篇文章 3 订阅

Linux运维常用网络抓包工具tcpdump的介绍和使用

前言

tcpdump是一个用于截取网络分组,并输出分组内容的工具。tcpdump凭借强大的功能和灵活的截取策略,使其成为类UNIX系统下用于网络分析和问题排查的首选工具。
tcpdump提供了源代码,公开了接口,因此具备很强的可扩展性,对于网络维护和入侵者都是非常有用的工具。tcpdump存在于基本的Linux系统中,由于它需要将网络界面设置为混杂模式,普通用户不能正常执行,但具备root权限的用户可以直接执行它来获取网络上的信息。因此系统中存在网络分析工具主要不是对本机安全的威胁,而是对网络上的其他计算机的安全存在威胁。

概述

顾名思义,tcpdump可以将网络中传送的数据包的“头”完全截获下来提供分析。它支持针对网络层、协议、主机、网络或端口的过滤,并提供and、or、not等逻辑语句来帮助你去掉无用的信息。

[root@test ~]# tcpdump -vv
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
11:57:07.477212 IP (tos 0x10, ttl 64, id 41116, offset 0, flags [DF], proto TCP (6), length 188)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x3207 (incorrect -> 0x7648), seq 3550446765:3550446913, ack 2337647144, win 136, length 148
11:57:07.477532 IP (tos 0x0, ttl 64, id 21864, offset 0, flags [DF], proto UDP (17), length 71)
    192.168.5.95.54801 > public1.114dns.com.domain: [bad udp cksum 0xab30 -> 0x55dc!] 1634+ PTR? 3.241.77.122.in-addr.arpa. (43)
11:57:07.477570 IP (tos 0x10, ttl 64, id 41117, offset 0, flags [DF], proto TCP (6), length 188)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x3207 (incorrect -> 0x2044), seq 148:296, ack 1, win 136, length 148
11:57:07.509891 IP (tos 0x4, ttl 41, id 11461, offset 0, flags [DF], proto TCP (6), length 40)
    122.77.241.3.36783 > 192.168.5.95.ssh: Flags [.], cksum 0x1fed (correct), seq 1, ack 296, win 16342, length 0
11:57:07.527134 IP (tos 0x0, ttl 144, id 0, offset 0, flags [none], proto UDP (17), length 130)
    public1.114dns.com.domain > 192.168.5.95.54801: [udp sum ok] 1634 NXDomain q: PTR? 3.241.77.122.in-addr.arpa. 0/1/0 ns: 77.122.in-addr.arpa. SOA a.in-addr.cn. ipas.cnnic.cn. 2008102201 10800 900 2419200 86400 (102)
11:57:07.527359 IP (tos 0x0, ttl 64, id 21865, offset 0, flags [DF], proto UDP (17), length 71)
    192.168.5.95.57699 > public1.114dns.com.domain: [bad udp cksum 0xab30 -> 0x0042!] 60668+ PTR? 95.5.168.192.in-addr.arpa. (43)
11:57:07.556141 IP (tos 0x0, ttl 144, id 0, offset 0, flags [none], proto UDP (17), length 106)
    public1.114dns.com.domain > 192.168.5.95.57699: [udp sum ok] 60668 NXDomain* q: PTR? 95.5.168.192.in-addr.arpa. 0/1/0 ns: 168.192.in-addr.arpa. SOA 168.192.in-addr.arpa. . 0 28800 7200 604800 86400 (78)
11:57:07.556904 IP (tos 0x0, ttl 64, id 21866, offset 0, flags [DF], proto UDP (17), length 74)
    192.168.5.95.46903 > public1.114dns.com.domain: [bad udp cksum 0xab33 -> 0x648d!] 21178+ PTR? 114.114.114.114.in-addr.arpa. (46)
11:57:07.556990 IP (tos 0x10, ttl 64, id 41118, offset 0, flags [DF], proto TCP (6), length 348)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x32a7 (incorrect -> 0x3db7), seq 296:604, ack 1, win 136, length 308
11:57:07.585982 IP (tos 0x0, ttl 144, id 0, offset 0, flags [none], proto UDP (17), length 106)
    public1.114dns.com.domain > 192.168.5.95.46903: [udp sum ok] 21178 q: PTR? 114.114.114.114.in-addr.arpa. 1/0/0 114.114.114.114.in-addr.arpa. PTR public1.114dns.com. (78)
11:57:07.586308 IP (tos 0x10, ttl 64, id 41119, offset 0, flags [DF], proto TCP (6), length 1488)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [.], cksum 0x371b (incorrect -> 0xf637), seq 604:2052, ack 1, win 136, length 1448
11:57:07.586320 IP (tos 0x10, ttl 64, id 41120, offset 0, flags [DF], proto TCP (6), length 804)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x346f (incorrect -> 0x9d17), seq 2052:2816, ack 1, win 136, length 764
11:57:07.586373 IP (tos 0x10, ttl 64, id 41121, offset 0, flags [DF], proto TCP (6), length 556)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x3377 (incorrect -> 0x8662), seq 2816:3332, ack 1, win 136, length 516
11:57:07.586410 IP (tos 0x10, ttl 64, id 41122, offset 0, flags [DF], proto TCP (6), length 332)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x3297 (incorrect -> 0xf760), seq 3332:3624, ack 1, win 136, length 292
11:57:07.586439 IP (tos 0x10, ttl 64, id 41123, offset 0, flags [DF], proto TCP (6), length 332)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x3297 (incorrect -> 0xa701), seq 3624:3916, ack 1, win 136, length 292
11:57:07.586466 IP (tos 0x10, ttl 64, id 41124, offset 0, flags [DF], proto TCP (6), length 332)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x3297 (incorrect -> 0x7625), seq 3916:4208, ack 1, win 136, length 292
11:57:07.618691 IP (tos 0x4, ttl 41, id 11463, offset 0, flags [DF], proto TCP (6), length 40)
    122.77.241.3.36783 > 192.168.5.95.ssh: Flags [.], cksum 0x17db (correct), seq 1, ack 2052, win 16652, length 0
11:57:07.618713 IP (tos 0x4, ttl 41, id 11464, offset 0, flags [DF], proto TCP (6), length 40)
.......
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x3297 (incorrect -> 0xb4aa), seq 10340264:10340556, ack 1769, win 136, length 292
11:58:44.486792 IP (tos 0x10, ttl 64, id 7519, offset 0, flags [DF], proto TCP (6), length 332)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x3297 (incorrect -> 0x6926), seq 10340556:10340848, ack 1769, win 136, length 292
11:58:44.486819 IP (tos 0x10, ttl 64, id 7520, offset 0, flags [DF], proto TCP (6), length 332)
    192.168.5.95.ssh > 122.77.241.3.36783: Flags [P.], cksum 0x3297 (incorrect -> 0xd156), seq 10340848:10341140, ack 1769, win 136, length 292
11:58:44.497791 IP (tos 0x4, ttl 41, id 16466, offset 0, flags [DF], proto TCP (6), length 92)
    122.77.241.3.36783 > 192.168.5.95.ssh: Flags [P.], cksum 0xbe53 (correct), seq 1769:1821, ack 10338288, win 16652, length 52
^C
36391 packets captured
36391 packets received by filter
0 packets dropped by kernel
[root@test ~]# 

不带参数的tcpdump会收集网络中所有的信息包头,数据量巨大,必须过滤。

选项介绍

  • -A 以ASCII格式打印出所有分组,并将链路层的头最小化。
  • -c 在收到指定的数量的分组后,tcpdump就会停止。
  • -C 在将一个原始分组写入文件之前,检查文件当前的大小是否超过了参数file_size 中指定的大小。如果超过了指定大小,则关闭当前文件,然后在打开一个新的文件。参数 file_size 的单位是兆字节(是1,000,000字节,而不是1,048,576字节)。
  • -d 将匹配信息包的代码以人们能够理解的汇编格式给出。
  • -dd 将匹配信息包的代码以c语言程序段的格式给出。
  • -ddd 将匹配信息包的代码以十进制的形式给出。
  • -D 打印出系统中所有可以用tcpdump截包的网络接口。
  • -e 在输出行打印出数据链路层的头部信息。
  • -E 用spi@ipaddr algo:secret解密那些以addr作为地址,并且包含了安全参数索引值spi的IPsec ESP分组。
  • -f 将外部的Internet地址以数字的形式打印出来。
  • -F 从指定的文件中读取表达式,忽略命令行中给出的表达式。
  • -i 指定监听的网络接口。
  • -l 使标准输出变为缓冲行形式,可以把数据导出到文件。
  • -L 列出网络接口的已知数据链路。
  • -m 从文件module中导入SMI MIB模块定义。该参数可以被使用多次,以导入多个MIB模块。
  • -M 如果tcp报文中存在TCP-MD5选项,则需要用secret作为共享的验证码用于验证TCP-MD5选选项摘要(详情可参考RFC 2385)。
  • -b 在数据-链路层上选择协议,包括ip、arp、rarp、ipx都是这一层的。
  • -n 不把网络地址转换成名字。
  • -nn 不进行端口名称的转换。
  • -N 不输出主机名中的域名部分。例如,‘nic.ddn.mil‘只输出’nic‘。
  • -t 在输出的每一行不打印时间戳。
  • -O 不运行分组分组匹配(packet-matching)代码优化程序。
  • -P 不将网络接口设置成混杂模式。
  • -q 快速输出。只输出较少的协议信息。
  • -r 从指定的文件中读取包(这些包一般通过-w选项产生)。
  • -S 将tcp的序列号以绝对值形式输出,而不是相对值。
  • -s 从每个分组中读取最开始的snaplen个字节,而不是默认的68个字节。
  • -T 将监听到的包直接解释为指定的类型的报文,常见的类型有rpc远程过程调用)和snmp(简单网络管理协议;)。
  • -t 不在每一行中输出时间戳。
  • -tt 在每一行中输出非格式化的时间戳。
  • -ttt 输出本行和前面一行之间的时间差。
  • -tttt 在每一行中输出由date处理的默认格式的时间戳。
  • -u 输出未解码的NFS句柄。
  • -v 输出一个稍微详细的信息,例如在ip包中可以包括ttl和服务类型的信息。
  • -vv 输出详细的报文信息。
  • -w 直接将分组写入文件中,而不是不分析并打印出来。

tcpdump的表达式介绍

表达式是一个正则表达式,tcpdump利用它作为过滤报文的条件,如果一个报文满足表 达式的条件,则这个报文将会被捕获。如果没有给出任何条件,则网络上所有的信息包 将会被截获。
在表达式中一般如下几种类型的关键字:

第一种是关于类型的关键字,主要包括host,net,port,例如 host 210.27.48.2, 指明 210.27.48.2是一台主机,net 202.0.0.0指明202.0.0.0是一个网络地址,port 23 指明端口号是23。如果没有指定类型,缺省的类型是host。
第二种是确定传输方向的关键字,主要包括src,dst,dst or src,dst and src, 这些关键字指明了传输的方向。举例说明,src 210.27.48.2 ,指明ip包中源地址是 210.27.48.2 , dst net 202.0.0.0 指明目的网络地址是202.0.0.0。如果没有指明 方向关键字,则缺省是src or dst关键字。
第三种是协议的关键字,主要包括fddi,ip,arp,rarp,tcp,udp等类型。Fddi指明是在FDDI (分布式光纤数据接口网络)上的特定的网络协议,实际上它是”ether”的别名,fddi和ether 具有类似的源地址和目的地址,所以可以将fddi协议包当作ether的包进行处理和分析。 其他的几个关键字就是指明了监听的包的协议内容。如果没有指定任何协议,则tcpdump 将会 监听所有协议的信息包。

除了这三种类型的关键字之外,其他重要的关键字如下:gateway, broadcast,less, greater,
还有三种逻辑运算,取非运算是 ‘not ’ ‘! ‘, 与运算是’and’,’&&’;或运算是’or’ ,’||’;
这些关键字可以组合起来构成强大的组合条件来满足人们的需要。

输出结果介绍

下面我们介绍几种典型的tcpdump命令的输出信息
(1) 数据链路层头信息
使用命令:

tcpdump --e host ICE

ICE 是一台装有linux的主机。它的MAC地址是0:90:27:58:AF:1A H219是一台装有Solaris的SUN工作站。它的MAC地址是8:0:20:79:5B:46; 上一条命令的输出结果如下所示:
引用
21:50:12.847509 eth0 < 8:0:20:79:5b:46 0:90:27:58:af:1a ip 60: h219.33357 > ICE. telne t 0:0(0) ack 22535 win 8760 (DF)
21:50:12是显示的时间, 847509是ID号,eth0 <表示从网络接口eth0接收该分组, eth0 >表示从网络接口设备发送分组, 8:0:20:79:5b:46是主机H219的MAC地址, 它表明是从源地址H219发来的分组. 0:90:27:58:af:1a是主机ICE的MAC地址, 表示该分组的目的地址是ICE。 ip 是表明该分组是IP分组,60 是分组的长度, h219.33357 > ICE. telnet 表明该分组是从主机H219的33357端口发往主机ICE的 TELNET(23)端口。 ack 22535 表明对序列号是222535的包进行响应。 win 8760表明发 送窗口的大小是8760。
(2) ARP包的tcpdump输出信息
使用命令:

tcpdump arp

得到的输出结果是:
引用
22:32:42.802509 eth0 > arp who-has route tell ICE (0:90:27:58:af:1a)
22:32:42.802902 eth0 < arp reply route is-at 0:90:27:12:10:66 (0:90:27:58:af:1a)
22:32:42是时间戳, 802509是ID号, eth0 >表明从主机发出该分组,arp表明是ARP请求包, who-has route tell ICE表明是主机ICE请求主机route的MAC地址。 0:90:27:58:af:1a是主机 ICE的MAC地址。
(3) TCP包的输出信息
用tcpdump捕获的TCP包的一般输出信息是:
引用
src > dst: flags data-seqno ack window urgent options
src > dst:表明从源地址到目的地址, flags是TCP报文中的标志信息,S 是SYN标志, F (FIN), P (PUSH) , R (RST) “.” (没有标记); data-seqno是报文中的数据 的顺序号, ack是下次期望的顺序号, window是接收缓存的窗口大小, urgent表明 报文中是否有紧急指针。 Options是选项。
(4) UDP包的输出信息
用tcpdump捕获的UDP包的一般输出信息是:
引用
route.port1 > ICE.port2: udp lenth
UDP十分简单,上面的输出行表明从主机route的port1端口发出的一个UDP报文 到主机ICE的port2端口,类型是UDP, 包的长度是lenth。

举例

(1) 想要截获所有192.168.5.85 的主机收到的和发出的所有的分组:

#tcpdump host 192.168.5.85
[root@test ~]# tcpdump host 192.168.5.85
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
14:49:57.413801 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [P.], seq 1884170244:1884170284, ack 255292485, win 215, options [nop,nop,TS val 172762855 ecr 4294793410], length 40
14:49:57.415789 IP 192.168.5.85.ssh > 192.168.5.95.56931: Flags [P.], seq 1:41, ack 40, win 362, options [nop,nop,TS val 4294859237 ecr 172762855], length 40
14:49:57.415805 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [.], ack 41, win 215, options [nop,nop,TS val 172762857 ecr 4294859237], length 0
14:49:57.642953 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [P.], seq 40:80, ack 41, win 215, options [nop,nop,TS val 172763084 ecr 4294859237], length 40
14:49:57.644324 IP 192.168.5.85.ssh > 192.168.5.95.56931: Flags [P.], seq 41:81, ack 80, win 362, options [nop,nop,TS val 4294859466 ecr 172763084], length 40
14:49:57.644341 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [.], ack 81, win 215, options [nop,nop,TS val 172763085 ecr 4294859466], length 0
14:49:57.794525 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [P.], seq 80:120, ack 81, win 215, options [nop,nop,TS val 172763235 ecr 4294859466], length 40
14:49:57.795831 IP 192.168.5.85.ssh > 192.168.5.95.56931: Flags [P.], seq 81:121, ack 120, win 362, options [nop,nop,TS val 4294859618 ecr 172763235], length 40
14:49:57.795851 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [.], ack 121, win 215, options [nop,nop,TS val 172763237 ecr 4294859618], length 0
14:49:58.035351 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [P.], seq 120:160, ack 121, win 215, options [nop,nop,TS val 172763476 ecr 4294859618], length 40
14:49:58.036710 IP 192.168.5.85.ssh > 192.168.5.95.56931: Flags [P.], seq 121:161, ack 160, win 362, options [nop,nop,TS val 4294859859 ecr 172763476], length 40
14:49:58.036724 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [.], ack 161, win 215, options [nop,nop,TS val 172763478 ecr 4294859859], length 0
......
14:50:05.235253 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [P.], seq 680:720, ack 681, win 215, options [nop,nop,TS val 172770676 ecr 4294866700], length 40
14:50:05.236640 IP 192.168.5.85.ssh > 192.168.5.95.56931: Flags [P.], seq 681:721, ack 720, win 362, options [nop,nop,TS val 4294867059 ecr 172770676], length 40
14:50:05.236652 IP 192.168.5.95.56931 > 192.168.5.85.ssh: Flags [.], ack 721, win 215, options [nop,nop,TS val 172770678 ecr 4294867059], length 0
^C
54 packets captured
54 packets received by filter
0 packets dropped by kernel

(2) 想要截获主机192.168.5.95 和主机192.168.5.6或192.168.5.172的通信,使用命令(注意:括号前的反斜杠是必须的):

[root@test ~]# tcpdump host 192.168.5.95 and \(192.168.5.6 or 192.168.5.172\)
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
15:02:17.610810 IP 192.168.5.95 > 192.168.5.6: ICMP echo request, id 13076, seq 59, length 64
15:02:17.612465 IP 192.168.5.6 > 192.168.5.95: ICMP echo reply, id 13076, seq 59, length 64
15:02:18.612643 IP 192.168.5.95 > 192.168.5.6: ICMP echo request, id 13076, seq 60, length 64
15:02:18.614285 IP 192.168.5.6 > 192.168.5.95: ICMP echo reply, id 13076, seq 60, length 64
15:02:23.267843 IP 192.168.5.95 > 192.168.5.172: ICMP echo request, id 13078, seq 1, length 64
15:02:23.269671 IP 192.168.5.172 > 192.168.5.95: ICMP echo reply, id 13078, seq 1, length 64
15:02:24.269857 IP 192.168.5.95 > 192.168.5.172: ICMP echo request, id 13078, seq 2, length 64
15:02:24.271147 IP 192.168.5.172 > 192.168.5.95: ICMP echo reply, id 13078, seq 2, length 64
15:02:25.271438 IP 192.168.5.95 > 192.168.5.172: ICMP echo request, id 13078, seq 3, length 64
15:02:25.272730 IP 192.168.5.172 > 192.168.5.95: ICMP echo reply, id 13078, seq 3, length 64
15:02:28.284987 ARP, Request who-has 192.168.5.95 tell 192.168.5.172, length 28
15:02:28.285009 ARP, Reply 192.168.5.95 is-at fa:16:3e:ef:d6:d2 (oui Unknown), length 28
^C
12 packets captured
12 packets received by filter
0 packets dropped by kernel
[root@test ~]# 

(3) 如果想要获取主机192.168.5.95除了和主机192.168.5.6之外所有主机通信的ip包,使用命令:

#tcpdump ip host 192.168.5.95 and ! 192.168.5.6
[root@test ~]# tcpdump ip  host 192.168.5.95 and ! 192.168.5.6 
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
15:12:56.399113 IP 192.168.5.95.ssh > ecs-117-78-49-132.compute.hwclouds-dns.com.50420: Flags [P.], seq 1480510225:1480510437, ack 4113213748, win 137, length 212
15:12:56.399470 IP 192.168.5.95.46226 > public1.114dns.com.domain: 58734+ PTR? 132.49.78.117.in-addr.arpa. (44)
15:12:56.428869 IP public1.114dns.com.domain > 192.168.5.95.46226: 58734 1/0/0 PTR ecs-117-78-49-132.compute.hwclouds-dns.com. (100)
15:12:56.429089 IP 192.168.5.95.42321 > public1.114dns.com.domain: 37164+ PTR? 95.5.168.192.in-addr.arpa. (43)
15:12:56.455952 IP ecs-117-78-49-132.compute.hwclouds-dns.com.50420 > 192.168.5.95.ssh: Flags [.], ack 212, win 511, length 0
15:12:56.457803 IP public1.114dns.com.domain > 192.168.5.95.42321: 37164 NXDomain* 0/1/0 (78)
15:12:56.458036 IP 192.168.5.95.37343 > public1.114dns.com.domain: 55708+ PTR? 114.114.114.114.in-addr.arpa. (46)
15:12:56.458126 IP 192.168.5.95.ssh > ecs-117-78-49-132.compute.hwclouds-dns.com.50420: Flags [P.], seq 212:440, ack 1, win 137, length 228
15:12:56.483624 IP public1.114dns.com.domain > 192.168.5.95.37343: 55708 1/0/0 PTR public1.114dns.com. (78)
15:12:56.483919 IP 192.168.5.95.ssh > ecs-117-78-49-132.compute.hwclouds-dns.com.50420: Flags [P.], seq 440:1436, ack 1, win 137, length 996
15:12:56.483966 IP 192.168.5.95.ssh > ecs-117-78-49-132.compute.hwclouds-dns.com.50420: Flags [P.], seq 1436:1632, ack 1, win 137, length 196
15:12:56.483993 IP 192.168.5.95.ssh > ecs-117-78-49-132.compute.hwclouds-dns.com.50420: Flags [P.], seq 1632:1828, ack 1, win 137, length 196
15:12:56.484023 IP 192.168.5.95.ssh > ecs-117-78-49-132.compute.hwclouds-dns.com.50420: Flags [P.], seq 1828:2024, ack 1, win 137, length 196

(4) 如果想要获取主机192.168.5.95接收或发出的ssh包,并且不转换主机名使用如下命令:

[root@tcpdump ~]# tcpdump -nn -n src host 192.168.5.95 and port 22 and tcp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
15:22:48.315164 IP 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 1970378770, win 314, options [nop,nop,TS val 174734130 ecr 1863215], length 0
15:22:48.316764 IP 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 201, win 313, options [nop,nop,TS val 174734132 ecr 1863217], length 0
15:22:48.318307 IP 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 385, win 312, options [nop,nop,TS val 174734133 ecr 1863218], length 0
15:22:48.319858 IP 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 569, win 311, options [nop,nop,TS val 174734135 ecr 1863220], length 0
15:22:48.321381 IP 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 753, win 310, options [nop,nop,TS val 174734136 ecr 1863221], length 0
15:22:48.322930 IP 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 937, win 309, options [nop,nop,TS val 174734138 ecr 1863223], length 0
......
15:22:48.803803 IP 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 52841, win 315, options [nop,nop,TS val 174734619 ecr 1863704], length 0
15:22:48.805393 IP 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 53025, win 315, options [nop,nop,TS val 174734620 ecr 1863705], length 0
^C
289 packets captured
290 packets received by filter
0 packets dropped by kernel
[root@tcpdump ~]# 

(5) 获取主机192.168.228.246接收或发出的ssh包,并把mac地址也一同显示:

[root@tcpdump ~]# tcpdump -e -n -nn src host 192.168.5.95 and port 22 and tcp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
15:27:48.643645 fa:16:3e:ef:d6:d2 > fa:16:3e:e3:b4:f7, ethertype IPv4 (0x0800), length 66: 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 1970522266, win 328, options [nop,nop,TS val 175034458 ecr 2163543], length 0
15:27:48.645284 fa:16:3e:ef:d6:d2 > fa:16:3e:e3:b4:f7, ethertype IPv4 (0x0800), length 66: 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 265, win 326, options [nop,nop,TS val 175034460 ecr 2163545], length 0
15:27:48.646845 fa:16:3e:ef:d6:d2 > fa:16:3e:e3:b4:f7, ethertype IPv4 (0x0800), length 66: 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 529, win 324, options [nop,nop,TS val 175034462 ecr 2163547], length 0
15:27:48.648409 fa:16:3e:ef:d6:d2 > fa:16:3e:e3:b4:f7, ethertype IPv4 (0x0800), length 66: 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 793, win 322, options [nop,nop,TS val 175034463 ecr 2163548], length 0
......
15:27:48.960391 fa:16:3e:ef:d6:d2 > fa:16:3e:e3:b4:f7, ethertype IPv4 (0x0800), length 66: 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 46217, win 329, options [nop,nop,TS val 175034775 ecr 2163860], length 0
15:27:48.961935 fa:16:3e:ef:d6:d2 > fa:16:3e:e3:b4:f7, ethertype IPv4 (0x0800), length 66: 192.168.5.95.56932 > 192.168.5.85.22: Flags [.], ack 46481, win 329, options [nop,nop,TS val 175034777 ecr 2163862], length 0
15:27:48.962455 fa:16:3e:ef:d6:d2 > fa:16:3e:e3:b4:f7, ethertype IPv4 (0x0800), length 106: 192.168.5.95.56932 > 192.168.5.85.22: Flags [P.], seq 40:80, ack 46481, win 329, options [nop,nop,TS val 175034777 ecr 2163862], length 40
^C
178 packets captured
178 packets received by filter
0 packets dropped by kernel
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值