json - 使用Tshark查看JSON数据

标签 json wireshark tcpdump tshark

当我使用tshark像这样解码capfile时

 tshark -V -r test.cap  -Y 'http>0'

我有
...
JavaScript Object Notation: application/json
    Object
        Member Key: "ret"
            Number value: 99
        Member Key: "message"
            String value:test

问题是如何使用tshark获得类似的json数据
...
{"ret":99,"message":"test"}

最佳答案

有类似的问题。
仅使用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)
}

关于json - 使用Tshark查看JSON数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22295281/

相关文章:

用于唯一源/目标 IP 和协议(protocol)的 Wireshark 显示过滤器

ssl - 如何在 Wireshark (Cisco CUCM 10.5) 中通过 TLS 解密 SIP

linux - 几个数据包后 telnet/nc 无法发送数据包

linux - 如何在使用 tcpdump 的 bash 脚本中处理 SIGKILL

json - WebScraper 和 Json 格式

http - Wireshark 的简单 Http 替代方案

javascript - 如何使用特定值将 json 数组转换为 javascript 数组

endianness - pcap 文件和字节顺序

android - 按日期对 ListView 进行排序?

json - 将 json.RawMessage 转换为结构的正确方法是什么?