Wireshark抓包

过滤器

1.1、捕获过滤器

捕获过滤器表达式作用在wireshark开始捕获数据包之前,只捕获符合条件的数据包

表达式语法

协议列表
tcp
udp
arp
tcp
ip
ip6
逻辑关键字
----------
or
and
取反关键字
----------
no

案例

  1. 协议是tcp并且端口号是443
    tcp port 443
    # 或
    tcp port https
    
  2. 协议是tcp并且端口号不是443
    tcp and not port 443
    
  3. 域名是baidu.com
    host baidu.com
    # 或
    host 220.181.38.148
    
  4. 网卡的mac地址
    ether host 00:00:5e:00:53:10
    

1.2、显示过滤器

显示过滤器表达式作用在在wireshark捕获数据包之后,从已捕获的所有数据包中显示出符合条件的数据包,隐藏不符合条件的数据包。

表达式语法

逻辑关键字
||
&&
取反关键字
----------
!

案例

  1. IP地址是
    106.152.175.199
    
    并且端口号是
    56147
    
    ip.addr == 106.152.175.199 && tcp.port == 56147
    
  2. IP地址是
    106.152.175.199
    
    并且端口号
    不是
    56147
    
    ip.addr == 106.152.175.199 && tcp.port != 56147
    
  3. 目标IP地址是
    106.152.175.199
    
    并且源IP地址是
    16.52.175.199
    
    ip.dst == 106.52.175.199 && ip.src == 16.52.175.199
    
  4. url中包含.js的http数据包
    http.request.uri contains ".js"
    
  5. 内容包含username的http数据包
    http contains "username"
    

2、捕获HTTPS数据(MacOS)

  1. 命令行启动谷歌浏览器,并指定
    ssl-key-log-file=/tmp/.ssl-key.log
    
    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/tmp/chrome --ssl-key-log-file=/tmp/.ssl-key.log
    
  2. 配置Wireshark,依次打开首选项->protocol->TLS
  3. 在输入框内输入/tmp/.ssl-key.log

    4.在新开启的浏览器窗口,访问要抓取的内容
    5.案列一个

主机是 api.baidu.com 并且 请求的url中包含 login 并且 请求的类型是POST或GET , (?!)是正则的不区分大小写
http.host contains "api.baidu.com" && http.request.full_uri matches "login" && http.request.method matches "(?i)post|get"

3、Wireshark 过滤语句中常用的过滤规则

关键字:

eq,== 等于
ne,!= 不等于
gt,> 比… 大
lt,<比… 小 ge,>= 大于等于
le,<= 小于等于 and,|| 且 or,&& 或 not,! 取反
另外还有 contains 和 matches 两个不常用的关键字,过滤效果不错。
“contains” 过滤包含指定字符串的数据包。例如:

http.request.uri contains “/dll/test.htm?”
// 过滤 http 请求的 uri 中含有 / dll/test.htm? 字段的请求信息

udp contains 81:60:03
// 过滤包含 81:60:03 的 udp 数据包

http.request.uri matches “V4=..1″
//matches 匹配过滤条件中给定的正则表达式,支持与 Perl 兼容的正则表达式(PCRE)。

http.host==magentonotes.com
http.host contains magentonotes.com
// 过滤经过指定域名的 http 数据包,这里的 host 值不一定是请求中的域名

http.response.code==302
// 过滤 http 响应状态码为 302 的数据包

http.response==1
// 过滤所有的 http 响应包

http.request==1
// 过滤所有的 http 请求,貌似也可以使用 http.request

http.request.method==POST
//[wireshark](https://so.csdn.net/so/search?q=wireshark&spm=1001.2101.3001.7020) 过滤所有请求方式为 POST 的 http 请求包,注意 POST 为大写

http.cookie contains guid
// 过滤含有指定 cookie 的 http 数据包

http.request.uri==”/online/setpoint”
// 过滤请求的 uri,取值是域名后的部分

http.request.full_uri==” http://task.browser.360.cn/online/setpoint”
// 过滤含域名的整个 url 则需要使用 http.request.full_uri

http.server contains “nginx”
// 过滤 http 头中 server 字段含有 nginx 字符的数据包

http.content_type == “text/html”
// 过滤 content_type 是 text/html 的 http 响应、post 包,即根据文件类型过滤 http 数据包

http.content_encoding == “gzip”
// 过滤 content_encoding 是 gzip 的 http 包

http.transfer_encoding == “chunked”
// 根据 transfer_encoding 过滤

http.content_length == 279
http.content_length_header == “279″
// 根据 content_length 的数值过滤

http.server
// 过滤所有含有 http 头中含有 server 字段的数据包

http.request.version == “HTTP/1.1″
// 过滤 HTTP/1.1 版本的 http 包,包括请求和响应

http.response.phrase == “OK”
// 过滤 http 响应中的 phrase

Wireshark 捕获 UDP 数据包

UDP 协议分析常用过滤条件

ip.addr==192.168.0.1 // 过滤 ip 地址
data.len==8 // 过滤 data 部分长度为 8 的数据包
data.data == 00:08:30:03:00:00:00:00 // 过滤指定内容的数据包
udp.srcport == 10092 // 过滤经过本机 10092 端口的 udp 数据包
udp.dstport == 80 // 过滤目标机器 10092 端口的 udp 数据包
udp.port==10092 // 过滤本机或目标机器 10092 端口的数据包
udp.length == 20 // 过滤指定长度的 UDP 数据包
UDP 校验和过滤条件
udp.checksum == 0x250f
udp.checksum_good == 0 //Boolean 类型
udp.checksum_bad == 0
进程相关的过滤条件
以下过滤条件不支持 Windows,因为需要特殊的驱动。
udp.proc.dstcmd // 过滤目标进程名
udp.proc.dstpid // 过滤目标进程 PID
udp.proc.dstuid // 过滤目标进程的用户 ID
udp.proc.dstuname // 过滤目标进程的用户名
udp.proc.srccmd // 过滤源进程名
udp.proc.srcpid // 过滤源进程 PID
udp.proc.srcuid // 过滤源进程的用户 ID
udp.proc.srcuname // 过滤源进程的用户名

Wireshark 中根据 MAC 地址 / 物理地址过滤数据包

#### Wireshark 捕获过滤中过滤 MAC 地址 / 物理地址
ether host 00:11:22:33:44:55 // 过滤目标或源地址是 00:11:22:33:44:55 的数据包
ether dst host 00:11:22:33:44:55 // 过滤目标地址是 00:11:22:33:44:55 的数据包
ether src host 00:11:22:33:44:55 // 过滤源地址是 00:11:22:33:44:55 的数据包

#### Wireshark 显示过滤中过滤 MAC 地址 / 物理地址
eth.addr== 00:11:22:33:44:55 // 过滤目标或源地址是 00:11:22:33:44:55 的数据包
eth.src== 00:11:22:33:44:55 // 过滤源地址是 00:11:22:33:44:55 的数据包
eth.dst== 00:11:22:33:44:55 // 过滤目标地址是 00:11:22:33:44:55 的数据包

Wireshark 捕获经过指定 ip 的数据包

捕捉过滤抓包前在 capture option 中设置,仅捕获符合条件的包,可以避免产生较大的捕获文件和内存占用,但不能完整的复现测试时的网络环境。

host 192.168.0.1 // 抓取 192.168.0.1 收到和发出的所有数据包
src host 192.168.0.1 // 源地址,192.168.0.1 发出的所有数据包
dst host 192.168.0.1 // 目标地址,192.168.0.1 收到的所有数据包
src host hostname // 根据主机名过滤
ether host 80:05:09:03:E4:35 // 根据 MAC 地址过滤
net 192.168.0 // 网络过滤,过滤整个网段
src net 192.168
dst net 192

使用 “非 / 且 / 或” 建立组合过滤条件可以获得更精确的捕获

非: ! or “not” (去掉双引号)
且: && or “and”
或: || or “or”

wirershark 过滤指定 ip 收发数据包示例:

抓取所有目的地址是 192.168.0.2 或 192.168.0.3 端口是 80 的 TCP 数据
(tcp port 80) and ((dst host 192.168.0.2) or (dst host192.168.0.3)) // 捕获过滤
tcp.port==80&&(ip.dst==192.168.0.2||ip.dst==192.168.0.3) // 显示过滤

抓取所有目标 MAC 地址是 80:05:09:03:E4:35 的 ICMP 数据
(icmp) and ((ether dst host 80:05:09:03:E4:35))icmp && eth.dst==80:05:09:03:E4:35

抓取所有目的网络是 192.168,但目的主机不是 192.168.0.2 的 TCP 数据
(tcp) and ((dst net 192.168) and (not dst host 192.168.0.2)) 
tcp&&ip.src==192.168.0.0/16&&!(ip.src==192.168.0.2)

捕获主机 192.168.0.1 和主机 192.168.0.2 或 192.168.0.3 的通信
host 192.168.0.1 and (192.168.0.2 or 192.168.0.3) 
ip.addr==192.168.0.1&&(ip.addr==192.168.0.2||ip.addr==192.168.0.3)

获取主机 192.168.0.1 除了和主机 192.168.0.2 之外所有主机通信的数据包
host 192.168.0.1 and ! 192.168.0.2
ip.addr==192.168.0.1&&!ip.addr==192.168.0.2

获取主机 192.168.0.1 接收或发出的 telnet 包,telnet 使用 tcp 23 端口
tcp port 23 and host 192.168.0.1
tcp.port==23&&ip.addr==192.168.0.1

原文地址:http://www.magentonotes.com/
原文地址:https://blog.csdn.net/chenzhisi/article/details/49814769

posted @ 2023-09-27 18:24  Journey&Flower  阅读(196)  评论(0)    收藏  举报