利用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
相关推荐
Sheffield3 天前
Docker的跨主机服务与其对应的优缺点
linux·网络协议·docker
YuMiao7 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
Jony_10 天前
高可用移动网络连接
网络协议
chilix10 天前
Linux 跨网段路由转发配置
网络协议
gihigo199812 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
白太岁12 天前
通信:(5) 电路交换、报文交换与分组交换
运维·服务器·网络·网络协议
EasyGBS12 天前
国标安全升级:GB28181平台EasyGBS支持GB35114协议的应用场景与核心优势
网络协议·安全·gb28181·gb35114
凯酱12 天前
Windows防火墙入站规则IP白名单
windows·网络协议·tcp/ip
稻草猫.12 天前
TCP与UDP:传输层协议深度解析
笔记·后端·网络协议
科技块儿12 天前
如何用离线库秒筛“数据中心”IP段并自动封号?
网络·网络协议·tcp/ip