利用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
相关推荐
三三有猫5 小时前
代理IP:按流量还是按IP/时长计费更划算?
网络·网络协议·tcp/ip
未来转换6 小时前
计算机网络之HTTP协议详解
网络协议·计算机网络·http
初中就开始混世的大魔王10 小时前
3.1 DDS 层-Core
开发语言·c++·网络协议·tcp/ip·信息与通信
有代理ip12 小时前
聚焦性价比:便宜动态IP在网络优化中的应用技巧
网络·网络协议·tcp/ip
wanhengidc12 小时前
云手机 流畅稳定 操作简单
服务器·网络·网络协议·安全·智能手机
zl_dfq12 小时前
计算机网络 之 【https协议】(数字摘要、密钥、数字证书)
网络协议·计算机网络·https
北京耐用通信13 小时前
工业协议转换新选择:耐达讯自动化CC-Link I转EtherCAT网关深度解析
人工智能·科技·物联网·网络协议·自动化·信息与通信
弹简特14 小时前
【JavaSE-网络部分05】TCP 可靠性 + 高性能的三大核心机制:滑动窗口・流量控制・拥塞控制
网络·网络协议·tcp/ip
Highcharts.js14 小时前
数据更新方案对比|HTTP轮询 vs WebSocket,如何为你的图表选择最佳方案
websocket·网络协议·http·数据更新·highcharts·http轮询·图表数据更新
李庆政37014 小时前
modbus协议四 rtu Over tcp & mbslave & CRC校验码计算方法
网络协议·tcp/ip·modbus·rtu over tcp