利用tshark从pcap中解析http流量

使用tshark解析

安装tshark

bash 复制代码
apt install tshark
# 测试
tshark -r gitlab.pcap -T fields -Y http -e        tcp.stream -e   http.request.method -e          http.request.uri -e     http.request.version -e    http.request.line -e    http.response.version -e        http.response.code -e   http.response.phrase -e         http.response.line -e   http.file_data 

工具

简易脚本pcap2http.sh

需要安装apt install xmlstarlet gawk

bash 复制代码
#!/bin/bash
FIELDS=(
  tcp.stream
  http.request.method http.request.uri http.request.version
  http.request.line
  http.response.version http.response.code http.response.phrase
  http.response.line
  http.file_data
)
tshark -r $1 -T fields -Y http ${FIELDS[@]/#/-e$IFS} |
  awk -v FS=$'\t' '
{
  output = $1 ".http";
  n = $2 ? 2 : 6
  if (OUTPUTS[output]) printf("") >> output;
  else {printf("") > output; OUTPUTS[output] = 1; }
  printf("%s %s %s\n", $n, $(n+1), $(n+2)) >> output;
  printf("%s\n", gensub("(\\\\r\\\\n,?)+", "\n", "g", $(n+3))) >> output;
  if (substr($10,1,1) == "<") {
    fflush(output);
    close(output);
    xmlstarlet = "xmlstarlet fo - >> "output;
    printf("%s\n", gensub("\\\\n", "\n", "g", $10)) | xmlstarlet;
    close(xmlstarlet);
    printf("") >> output;
  }
  else
    printf("%s\n", $10) >> output;
  printf("\n--\n\n") >> output;
  close(output);
}
'

使用方法

bash 复制代码
./pcap2http.sh xxx.pcap
相关推荐
xx~t8 小时前
嵌入式——Linux软件编程——网络1
linux·c语言·网络·vscode·网络协议
MyFreeIT10 小时前
Let‘s Encrypt SSL 製作免費證書
网络协议·https·ssl
爱研究的小梁11 小时前
打破时延‑带宽悖论|乾元通 QMP‑UDP,为无人载具提供低延时高带宽原生通信方案
网络·网络协议·udp
xie0510_12 小时前
TCP socket
linux·网络协议·tcp/ip
恋恋西风12 小时前
TCP 三次握手 / 四次挥手 讲解
网络·网络协议·tcp/ip
00后程序员张12 小时前
Android证书绑定抓包失败?Android SSL Pinning绕过实战指南
android·网络协议·计算机网络·网络安全·adb·https·ssl
比兔代理13 小时前
动态 IP 代理深度讲解:IP 地址轮换机制与会话保持方案
网络·网络协议·tcp/ip
一直C13 小时前
Linux应用软件编程|TCP协议与Socket全套编程(三次握手、四次挥手、报文头部、核心机制)
linux·网络协议·tcp/ip·wireshark·vim·visual studio
隔窗听雨眠14 小时前
大模型实时通信协议深度对比:SSE、WebSocket与gRPC的选型指南与实战解析
网络·websocket·网络协议
唐古乌梁海15 小时前
传输协议https-TCP
网络协议·tcp/ip·https