tshark怎样在命令行分析pcap文件

联启 网络工具 14

本文目录导读:

tshark怎样在命令行分析pcap文件-第1张图片-电脑手机工具软件下载 - 免费实用工具合集 | 联启科技

  1. 基础查看
  2. 过滤数据包
  3. 格式化输出
  4. 统计分析
  5. 特定协议分析
  6. 时间分析
  7. 写入文件
  8. 高级分析示例
  9. 实用脚本示例

tshark 是 Wireshark 的命令行版本,功能非常强大,以下是一些常用的命令行分析方法:

基础查看

# 查看文件基本信息
tshark -r file.pcap -q -z io,phs
# 查看统计信息
tshark -r file.pcap -q -z io,stat,1
# 列出所有支持的协议
tshark -G protocols

过滤数据包

# 按 IP 过滤
tshark -r file.pcap ip.addr==192.168.1.1
# 按端口过滤
tshark -r file.pcap tcp.port==80
# 复合过滤
tshark -r file.pcap "ip.src==192.168.1.1 and tcp.port==443"
# 使用显示过滤器(更详细)
tshark -r file.pcap -Y "http.request"

格式化输出

# 基本字段输出
tshark -r file.pcap -T fields -e ip.src -e ip.dst -e tcp.port
# CSV 格式输出
tshark -r file.pcap -T fields -E header=y -e frame.number -e ip.src -e ip.dst
# 自定义输出格式
tshark -r file.pcap -T fields -e frame.time -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport -e data

统计分析

# 会话统计
tshark -r file.pcap -z conv,tcp
# HTTP 请求统计
tshark -r file.pcap -z http,tree
# 端点统计
tshark -r file.pcap -z endpoints,ip
# 协议分层统计
tshark -r file.pcap -q -z io,phs

特定协议分析

# HTTP 请求分析
tshark -r file.pcap -Y "http.request" -T fields -e http.host -e http.request.uri -e http.request.method
# DNS 查询分析
tshark -r file.pcap -Y "dns" -T fields -e dns.qry.name
# SSL/TLS 握手分析
tshark -r file.pcap -Y "tls.handshake.type==1" -T fields -e tls.handshake.ciphersuites
# TCP 流重组
tshark -r file.pcap -z follow,tcp,ascii,0

时间分析

# 显示时间戳
tshark -r file.pcap -T fields -e frame.time_relative -e frame.time_delta
# 按时间范围过滤
tshark -r file.pcap -Y "frame.time >= \"2024-01-01 00:00:00\" and frame.time <= \"2024-01-02 00:00:00\""

写入文件

# 导出过滤后的数据包
tshark -r input.pcap -Y "http" -w filtered.pcap
# 导出特定字段到文本文件
tshark -r input.pcap -T fields -e ip.src -e ip.dst > output.txt

高级分析示例

# 查找重传包
tshark -r file.pcap -Y "tcp.analysis.retransmission"
# 查找 SYN 扫描
tshark -r file.pcap -Y "tcp.flags.syn==1 and tcp.flags.ack==0"
# 分析 DNS 响应时间
tshark -r file.pcap -Y "dns.flags.response==1" -T fields -e frame.time -e dns.qry.name -e dns.resp.ttl
# 导出 HTTP 对象
tshark -r file.pcap --export-objects "http,extracted_files"

实用脚本示例

# 分析最活跃的 IP
tshark -r file.pcap -T fields -e ip.src | sort | uniq -c | sort -rn | head -10
# 分析端口使用情况
tshark -r file.pcap -T fields -e tcp.dstport | sort | uniq -c | sort -rn | head -10
# 监视实时流量(类似 wireshark)
tshark -i eth0 -Y "http" -T fields -e frame.time -e ip.src -e http.host

这些命令可以组合使用,根据需要选择合适的参数来分析 pcap 文件,如果网络流量很大,建议先使用 -Y 过滤器减少数据量,再进行分析。

标签: pcap分析

抱歉,评论功能暂时关闭!