Wireshark 在 macOS 上使用及问题解决_wireshark mac
wireshark概述
Wireshark 是被广泛使用的免费开源网络协议分析软件(network protocol analyzer)或网络数据包分析工具,它可以让你在微观层面上查看网络上发生的事情。它的主要功能是截取网络数据包,并尽可能详细地展示网络数据包信息内容。
项目地址:https://github.com/wireshark/wireshark
本篇文章主要讲述在 Mac 使用 Wireshark 时可能遇到的一些问题,并通过一个实例介绍详细的抓包手法。
常见问题
抓包报错
报错信息
You do not have permission to capture on device \"bridge100\". ((cannot open BPF device) /dev/bpf0: Permission denied)
解决办法
查看 /dev/bpf* 文件的权限
ls -l /dev/bpf*
更新 /dev/bpf* 文件权限和组权限
sudo chmod g+r /dev/bpf* && sudo chgrp admin /dev/bpf*
网卡太多
使用 ifconfig
命令可以查看到 Mac 中的所有网络接口,可能会出现数量繁多,不清楚选哪个的问题。
先来看看我的网卡信息。
$ ifconfiglo0: flags=8049 mtu 16384 options=1203 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 nd6 options=201gif0: flags=8010 mtu 1280stf0: flags=0 mtu 1280anpi1: flags=8863 mtu 1500 options=400 ether e2:5d:00:2d:ee:ec media: none status: inactiveanpi0: flags=8863 mtu 1500 options=400 ether e2:5d:00:2d:ee:eb media: none status: inactiveen3: flags=8863 mtu 1500 options=400 ether e2:5d:00:2d:ee:cb nd6 options=201 media: none status: inactiveen4: flags=8863 mtu 1500 options=400 ether e2:5d:00:2d:ee:cc nd6 options=201 media: none status: inactiveen1: flags=8963 mtu 1500 options=460 ether 36:b2:2d:e4:95:80 media: autoselect status: inactiveen2: flags=8963 mtu 1500 options=460 ether 36:b2:2d:e4:95:84 media: autoselect status: inactivebridge0: flags=8863 mtu 1500 options=63 ether 36:b2:2d:e4:95:80 Configuration: id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0 maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200 root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0 ipfilter disabled flags 0x0 member: en1 flags=3 ifmaxaddr 0 port 8 priority 0 path cost 0 member: en2 flags=3 ifmaxaddr 0 port 9 priority 0 path cost 0 nd6 options=201 media: status: inactiveap1: flags=8802 mtu 1500 options=400 ether 3e:57:dc:50:21:95 media: autoselecten0: flags=8863 mtu 1500 options=6460 ether 1c:57:dc:50:21:95 inet6 fe80::493:9294:92cb:962d%en0 prefixlen 64 secured scopeid 0xc inet 10.201.102.126 netmask 0xffffe000 broadcast 10.201.127.255 nd6 options=201 media: autoselect status: activeawdl0: flags=8843 mtu 1500 options=6460 ether ce:41:0d:0a:06:8b inet6 fe80::cc41:dff:fe0a:68b%awdl0 prefixlen 64 scopeid 0xd nd6 options=201 media: autoselect status: activellw0: flags=8863 mtu 1500 options=400 ether ce:41:0d:0a:06:8b inet6 fe80::cc41:dff:fe0a:68b%llw0 prefixlen 64 scopeid 0xe nd6 options=201 media: autoselect status: inactiveutun0: flags=8051 mtu 1380 inet6 fe80::bbb3:6daa:deb9:6132%utun0 prefixlen 64 scopeid 0xf nd6 options=201utun1: flags=8051 mtu 2000 inet6 fe80::a590:7109:be1b:f900%utun1 prefixlen 64 scopeid 0x10 nd6 options=201utun2: flags=8051 mtu 1000 inet6 fe80::ce81:b1c:bd2c:69e%utun2 prefixlen 64 scopeid 0x11 nd6 options=201utun3: flags=8051 mtu 1500 inet6 fe80::4562:973c:823c:162d%utun3 prefixlen 64 scopeid 0x12 nd6 options=201utun4: flags=8051 mtu 9000 inet 198.18.0.1 --> 198.18.0.1 netmask 0xfffe0000vmenet0: flags=8963 mtu 1500 ether 3e:64:95:b7:62:33 media: autoselect status: activebridge100: flags=8a63 mtu 1500 options=3 ether 1e:57:dc:05:87:64 inet 192.168.64.1 netmask 0xffffff00 broadcast 192.168.64.255 inet6 fe80::1c57:dcff:fe05:8764%bridge100 prefixlen 64 scopeid 0x15 inet6 fd93:45e9:560c:404:1020:f068:469e:d583 prefixlen 64 autoconf secured Configuration: id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0 maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200 root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0 ipfilter disabled flags 0x0 member: vmenet0 flags=3 ifmaxaddr 0 port 20 priority 0 path cost 0 nd6 options=201 media: autoselect status: active(base)
如何选网卡
在众多网卡中,重点关注 en0
和 bridge100
这两个接口,其他多数可以忽略。
lo0
active
en0
10.201.102.126
active
bridge100
192.168.64.1
active
awdl0
active
utun*
active
vmenet0
active
en1/en2/en3...
anpi0/anpi1
抓包实例
本例用于分析在漏洞复现或攻击检测中捕获的数据流量,步骤如下:
确定靶机 IP
可以通过查看靶机(如虚拟机)中的 IP 地址获取。
判断哪个网卡可以访问靶机
在本机 ifconfig
中找到能访问靶机 IP 的网卡,一般为 bridge100
。
在 Wireshark 中选择该网卡进行抓包
启动 Wireshark,选择对应的 bridge100
网卡,点击开始抓包即可。
如图这是我抓的工具攻击的流量数据,这样就可以单独拿出来分析了。
wireshrk命令速查
IP 地址过滤
- ip.src == 192.168.1.107:来源 IP 是 192.168.1.107
- ip.dst == 192.168.1.107:目标 IP 是 192.168.1.107
- ip.addr == 192.168.1.107:来源或目标 IP 是该地址
端口过滤
- tcp.port == 80:来源或目标 TCP 端口为 80
- tcp.srcport == 80:来源端口为 80
- tcp.dstport == 80:目标端口为 80
- udp.port == 15000:UDP 任意端口为 15000
- tcp.port >= 1 and tcp.port <= 80:TCP 端口范围过滤
协议过滤
- tcp/ udp/ icmp/ http/ dns/ ftp/ ssl
- not arp/!arp:排除 ARP 包
MAC 地址过滤
- eth.src == A0:00:00:04:C5:84:来源 MAC
- eth.dst == A0:00:00:04:C5:84:目标 MAC
- eth.addr == A0:00:00:04:C5:84:任意 MAC(源或目的)
包长度过滤
- udp.length == 26:UDP 数据长度
- tcp.len >= 7:TCP 负载长度
- ip.len == 94:IP 层长度
- frame.len == 119:整个数据帧长度
HTTP 过滤
按方法
- http.request.method == “GET”
- http.request.method == “POST”
按内容
- http contains “GET”:包含 GET 字符串
- http contains “HTTP/1.1 200 OK”:HTTP 成功响应
TCP 参数过滤
- tcp.flags.syn == 1:TCP SYN 包
- tcp.window_size == 0 and tcp.flags.reset != 1
数据内容过滤(进阶)
UDP:
- udp[8:3] == 20:21:22:UDP payload 前3字节为指定值
- udp contains 7c:7c:7d:7d:包含任意位置匹配内容
TCP:
- tcp[20:3] == 47:45:54:等价于 tcp[20:3] == “GET”(ASCII)
- tcp[20:] matches “^GET.*HTTP/1.1\\x0d\\x0a”:用正则匹配完整 GET 请求
正则匹配语法速查
\\d
\\D
\\w
\\s
.
.*
^
$
例子:
tcp[20:] matches \"^GET.*\"
:匹配以 GET 开头的 TCP 数据udp[8:] matches \"\\\\x14\\\\x05\"
:匹配特定字节序列