Wireshark渗透常用整理

Wireshark常用搜索命令与渗透分析指南

Wireshark 是一款功能强大的网络封包分析工具,在网络安全领域常用于渗透测试、攻击分析和事件响应。下面按常见分析场景整理其搜索命令与过滤方法。

基本操作与界面介绍

Wireshark 界面主要由以下几个部分组成:

  1. 显示过滤器(Display Filter) - 用来设置过滤条件,筛选数据包列表。
  2. 数据包列表(Packet List Pane) - 展示已捕获的数据包,每行对应一个数据包。
  3. 数据包详细信息(Packet Details Pane) - 查看当前数据包各层协议的详细字段。
  4. 数据包字节视图(Packet Bytes Pane) - 以十六进制和 ASCII 形式查看原始内容。
    小提示: 可以通过 View 菜单调整面板大小,或显示、隐藏特定面板。

Wireshark界面

搜索功能

快捷键:

Ctrl + F

可选择不同的搜索方式:

  • Display Filter - 使用显示过滤器语法搜索
  • Hex Value - 搜索十六进制字节值
  • String - 搜索字符串
  • Packet list - 搜索数据包列表内容
  • Packet details - 搜索数据包详细字段
  • Packet bytes - 搜索原始字节

常用显示过滤器命令

IP地址过滤

# 过滤特定 IP(源或目标)
ip.addr == x.x.x.x

# 源 IP
ip.src == x.x.x.x

# 目标 IP
ip.dst == x.x.x.x

# 排除特定 IP
!(ip.addr == x.x.x.x)

# 过滤一个 IP 范围
ip.addr >= 192.168.1.1 and ip.addr <= 192.168.1.10

协议过滤

# 常见协议
http
https
dns
tcp
udp
icmp
arp
ssl

# 组合协议
http or dns

端口过滤

tcp.port == 80      # HTTP
tcp.port == 443     # HTTPS
tcp.port == 22      # SSH
tcp.port == 21      # FTP
udp.port == 53      # DNS
tcp.port == 4444    # 常见反向 Shell 端口

# 非常见端口的新 TCP 连接
!(tcp.port in {80 443 20 21 22 25 110 143 993 995 3389}) and tcp.flags.syn == 1

组合过滤

# IP 与端口组合
ip.addr == x.x.x.x && tcp.port == 80

tcp.port == 80 || udp.port == 53

# 复杂逻辑
(ip.src == x.x.x.x and tcp.dstport == 80) or
(ip.dst == x.x.x.x and tcp.srcport == 80)

网络渗透分析场景

1. 扫描活动检测

# 端口扫描:大量初始 SYN
tcp.flags.syn == 1 and tcp.flags.ack == 0

# 指定源主机的 SYN
tcp.flags.syn == 1 and tcp.flags.ack == 0 and ip.src == x.x.x.x

# ICMP Echo Request,可用于观察 Ping 扫描
icmp.type == 8

扫描活动检测示意图

攻击者->目标主机A: SYN(端口 80)
攻击者->目标主机A: SYN(端口 443)
攻击者->目标主机A: SYN(端口 22)
攻击者->目标主机B: SYN(端口 80)
攻击者->目标主机B: SYN(端口 443)
Note right of 目标主机B: 典型端口扫描模式

2. 暴力破解检测

# SSH 连接尝试
tcp.port == 22 and tcp.flags.syn == 1

# HTTP Basic Authentication
http.authbasic

# HTTP POST 登录尝试
http.request.method == "POST" and http.request.uri contains "login"

3. 漏洞利用检测

# SQL 注入相关字符串
http.request.uri contains "'" or http.request.uri contains "%27"

http.request.uri contains "union select" or
http.request.uri contains "UNION SELECT"

# 命令注入相关字符
http.request.uri contains ";" or
http.request.uri contains "|" or
http.request.uri contains "`"

# XSS 相关字符串
http.request.uri contains "<script>" or
http.request.uri contains "%3Cscript%3E"

恶意流量识别技巧

1. 数据外泄检测

# 在数据帧中寻找可能的敏感数据模式
frame contains "4[0-9]{15}" or frame contains "5[1-5][0-9]{14}"

# 较大的 TCP 数据传输
tcp.len > 1000 and ip.dst == x.x.x.x

2. 异常连接检测

# 非标准或少见端口
tcp.port not in {80 443 22 25 110 143 53 123 20 21}
and tcp.flags.syn == 1

# 时间间隔异常
tcp.time_delta > 300

3. 流量统计与分析

Wireshark 自带多个统计功能,可辅助发现异常流量:

  • Conversations - Statistics → Conversations
  • Protocol Hierarchy - Statistics → Protocol Hierarchy
  • I/O Graph - Statistics → I/O Graph

隐蔽通道与C2通信检测

攻击者可能通过 DNS、ICMP、HTTP 等方式建立隐蔽通道或 C2 通信。

1. DNS隧道检测

# 查询名异常长
dns.qry.name.len > 50

# 可疑编码或随机性线索
dns.qry.name contains "base64" or dns.qry.name contains "enc"

# 多级子域名
dns.qry.name matches ".*\..*\..*\..*\..*\..*\..*"

# TXT 记录
dns.qry.type == 16

DNS隧道检测流程图

st=>start: 捕获 DNS 流量
op1=>operation: 过滤长度超过 50 的查询
op2=>operation: 检查高熵或随机性域名
cond=>condition: 是否异常?
op3=>operation: 深入分析可疑 DNS 流量
e=>end: 完成分析

st->op1->op2->cond
cond(yes)->op3->e
cond(no)->e

2. ICMP隧道检测

# 较大的 ICMP Echo Request
icmp.type == 8 and frame.len > 100

# ICMP 数据中包含可疑内容
icmp.type == 8 and data.data contains "cmd"

3. HTTP/HTTPS隐蔽通道

# 异常 User-Agent
http.user_agent contains "Python" or
http.user_agent contains "curl" or
http.user_agent contains "wget"

# 排除常见静态资源后的 HTTP 请求
http.request and !(
    http.request.uri contains ".jpg" or
    http.request.uri contains ".png" or
    http.request.uri contains ".css" or
    http.request.uri contains ".js"
)

# 可疑规律性 GET 请求
http.request.method == "GET" and
http.request.uri matches ".*\?id=.*"

常见攻击模式分析

1. 横向移动检测

# SMB
smb or smb2

# RDP
tcp.port == 3389

# 与 PowerShell 相关的 HTTP 请求
http.request.uri contains "powershell"

2. 数据抹除与反取证操作

# SMB2 删除文件相关命令
smb2.cmd == 16

3. Webshell活动

# 可疑文件上传
http.request.method == "POST" and (
    http.request.uri contains ".php" or
    http.request.uri contains ".jsp" or
    http.request.uri contains ".asp"
)

# 可疑命令字段
http.request.uri contains "cmd" or
http.request.uri contains "exec" or
http.request.uri contains "system"

实战案例

案例1:检测网络扫描和初始入侵

假设分析过程中发现可疑主机 10.10.10.15

  1. 使用 SYN 条件查找扫描:
tcp.flags.syn == 1 and
tcp.flags.ack == 0 and
ip.src == 10.10.10.15
  1. 检查对 Web 服务的漏洞探测:
http.request.method == "GET" and
http.request.uri contains "wp-content/plugins"
  1. 继续寻找上传行为:
http.request.method == "POST" and
http.request.uri contains "upload.php"

:::spoiler
案例1分析详情

这个过程体现了一个典型思路:先发现扫描,再追踪漏洞利用,最后检查 Webshell 上传或后续持久化行为。

可以配合 Follow TCP Stream 查看完整会话,进一步确认请求内容和服务端响应。
:::

案例2:检测数据外泄

  1. 查看与可疑外部 IP 的全部通信:
ip.addr == 203.0.113.25
  1. 查看是否存在较大的数据传输:
ip.dst == 203.0.113.25 and tcp.len > 1000
  1. 使用 Follow TCP Stream 进一步检查会话内容,并结合协议、传输方向和流量大小判断是否存在数据外传。

进阶技巧与自动化分析

1. 使用tshark进行大规模分析

tshark 是 Wireshark 的命令行工具,适合处理大型 PCAP 和脚本化分析。

# 提取 HTTP 请求
tshark -r capture.pcap \
-Y "http.request" \
-T fields \
-e http.host \
-e http.request.uri

# 提取 DNS 查询
tshark -r capture.pcap \
-Y "dns.qry.name" \
-T fields \
-e dns.qry.name

# 统计 SSH 新连接来源
tshark -r capture.pcap \
-Y "tcp.port==22 and tcp.flags.syn==1" \
-T fields \
-e ip.src |
sort |
uniq -c |
sort -nr

2. 使用Display Filter Expression按钮

Wireshark 可以通过 Expression 功能辅助构造过滤器:

  • 点击过滤栏附近的 Expression
  • 选择协议和字段
  • 选择匹配条件
  • 填写匹配值

3. 使用颜色规则标记可疑流量

菜单:

View → Coloring Rules

例如可以建立:

  • 名称:可疑DNS隧道
  • 过滤器:dns.qry.name.len > 50
  • 颜色:设置醒目的显示颜色

参考资源

  1. Wireshark 官方文档:https://www.wireshark.org/docs/
  2. Wireshark Display Filter Reference:https://www.wireshark.org/docs/dfref/
  3. SANS 网络安全流量分析资料:https://www.sans.org/reading-room/whitepapers/detection/
  4. MITRE ATT&CK:https://attack.mitre.org/

tags: wireshark 网络安全 渗透测试 封包分析 资安 网络分析
posted @ 2026-09-05 16:15  E诶iY0uwe1  阅读(4)  评论(0)    收藏  举报