利用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
相关推荐
阿珊和她的猫11 小时前
HTTP 状态码 404:深入解析与实践应对
网络·网络协议·http
jinxinyuuuus14 小时前
局域网文件传输:连接逻辑的回归——基于“广播域”而非“身份认证”的P2P架构
网络协议·架构·p2p
_星辰大海乀16 小时前
TCP 协议
网络·网络协议·tcp/ip·tcp
q***51891 天前
Node.js实现WebSocket教程
websocket·网络协议·node.js
重启的码农1 天前
enet源码解析(4)多通道机制 (Channels)
c++·网络协议
重启的码农1 天前
enet源码解析(3)数据包 (ENetPacket)
c++·网络协议
nvd111 天前
如何为 GCE 上的 Envoy 代理启用 HTTPS (使用 Google Cloud Load Balancer)
网络协议·https
拾忆,想起1 天前
Dubbo跨机房调用实战:从原理到架构的完美解决方案
服务器·网络·网络协议·tcp/ip·架构·dubbo
辻戋1 天前
HTTP的血泪进化史
网络·网络协议·http
拾忆,想起1 天前
Dubbo网络延迟全链路排查指南:从微服务“快递”到光速传输
网络·网络协议·微服务·架构·php·dubbo