利用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
相关推荐
FPGA_Linuxer3 天前
FPGA 40 DAC线缆和光模块带光纤实现40G UDP差异
网络协议·fpga开发·udp
real 13 天前
传输层协议UDP
网络·网络协议·udp
hsjkdhs3 天前
网络编程之UDP广播与粘包问题
网络·网络协议·udp
yzx9910133 天前
接口协议全解析:从HTTP到gRPC,如何选择适合你的通信方案?
网络·人工智能·网络协议·flask·pygame
板鸭〈小号〉4 天前
UDP-Server(3)chat聊天室
网络·网络协议·udp
weixin_456904274 天前
使用HTTPS 服务在浏览器端使用摄像头的方式解析
网络协议·http·https
疯狂的维修4 天前
关于Gateway configration studio软件配置网关
网络协议·c#·自动化·gateway
wow_DG4 天前
【WebSocket✨】入门之旅(五):WebSocket 的安全性
网络·websocket·网络协议
拷贝码农卡卡东4 天前
pre-commit run --all-files 报错:http.client.RemoteDisconnected
网络·网络协议·http