有类似的问题。仅使用wireshark/tshark 选项无法解决它。下面是我从 cap 文件中提取原始 json 和 xml的解决方法。
# 1. convert to pdml with DISABLED json and xml dissectors
tshark -r "wireshark.cap" -2 -R "http" --disable-protocol json --disable-protocol xml -V -T pdml > "wireshark.cap.pdml.xml"
# 2. get hex encoded raw data from media.type pdml element
# 3. perform hex decode
我在步骤 2 和 3 中使用了groovy脚本
import groovy.xml.*
...
def String hexDecode(String s) {
if ( null == s || 0 == s.length() ) {
return null
}
def res = ""
for (int i = 0; i < s?.length(); i += 2) {
res += (Character)((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16))
}
return res
}
...
def xmlFile = new File("wireshark.cap.pdml.xml")
def pdml = new XmlParser().parseText( xmlFile.text )
pdml.packet.each{ packet->
def media = packet.proto.find{ "media"==it.@name }
def hex = media?.field.find{"media.type"==it.@name }?.@value
def raw = hexDecode(hex)
}