利用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
相关推荐
陈橘又青1 天前
开创性的初创企业利用 Amazon SageMaker孵化器释放企业价值
人工智能·网络协议·学习·ai·编辑器
Evan芙1 天前
TCP/IP传输访问数据流如何进出主机原理总结
网络·网络协议·tcp/ip
爱尔兰极光1 天前
计算机网络--IP地址和子网划分
网络协议·tcp/ip·计算机网络
Neolnfra1 天前
华为无线网络AC+AP完整配置指南
网络协议·华为·wireshark·信息与通信
liangshanbo12151 天前
JSON-RPC 2.0 协议详解
网络协议·rpc·json
橘子真甜~1 天前
C/C++ Linux网络编程15 - 网络层IP协议
linux·网络·c++·网络协议·tcp/ip·计算机网络·网络层
CodeByV1 天前
【网络】UDP 协议深度解析:从五元组标识到缓冲区
网络·网络协议·udp
车载测试工程师1 天前
CAPL学习-AVB交互层-概述
网络协议·tcp/ip·以太网·capl·canoe
鲸鱼电台分台1 天前
工业应用通信协议:IEC104
网络协议
无敌最俊朗@2 天前
WebSocket与Webhook:实时通信技术对比
网络·websocket·网络协议