利用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
相关推荐
汤愈韬9 小时前
ACL概述、ACL原理、基本ACL应用及配置
网络·网络协议·网络安全
haluhalu.15 小时前
Linux网络编程------网络基础
网络·网络协议
坐怀不乱杯魂15 小时前
Linux网络 - HTTP协议
网络·网络协议·http
ipooipoo118816 小时前
动态住宅IP的定义、核心优势与技术场景应用
网络·网络协议·tcp/ip
pythonchashaoyou19 小时前
静态住宅ip是什么,静态住宅IP选型全解
网络·网络协议·tcp/ip
科技块儿1 天前
如何定期向监管部门报送IP属地统计报表?
网络·网络协议·tcp/ip
win x1 天前
UDP Socket
网络·网络协议·udp
小李独爱秋1 天前
计算机网络经典问题透视:RTS/CTS是强制使用还是选择使用?
网络协议·计算机网络·网络安全·信息与通信·信号处理
hoududubaba1 天前
ORAN C平面传输和基本功能——C平面消息的ACK/NACK过程
网络·网络协议
坐怀不乱杯魂1 天前
Linux 网络 - HTTP -cookie session
网络·网络协议·http