简体   繁体   English

船尾嗅和解码直径

[英]scapy sniff and decode diameter

i am trying to do scapy/python sniffer for Diameter messages and parse Diameter part to get AVP's from Raw.load. 我正在尝试为Diameter消息做scapy / python嗅探器并解析Diameter部分以从Raw.load获取AVP。 After some fails i get back to basic python/scapy script like this: from scapy.all import * 在失败之后,我回到像这样的基本python / scapy脚本:从scapy.all import *

def pkt_diam(pkt):
    raw = pkt.getlayer(Raw).load
    print raw
    # pkt.show()

sniff(iface="eth0", filter="port 3868", store=0, prn=pkt_diam)

By printing raw.load i have received just some AVP's but very unreadable. 通过打印raw.load,我只收到了一些AVP,但是非常不可读。 If i use pkt.show() i receive whole packet, Ethernet, IP, TCP and Raw part but Raw.load i almost unusable. 如果我使用pkt.show(),则会收到整个数据包,以太网,IP,TCP和Raw部分,但是Raw.load几乎无法使用。

###[ Raw ]###
        load      = '\x01\x00\x00\xec@\x00\x01/\x01\x00\x00\x00\x07K\x12\xca\x07K\x12\xca\x00\x00\x01\x07@\x00\x00 00000001;000001;61de2650\x00\x00\x01\x04@\x00\x00 \x00\x00\x01\n@\x00\x00\x0c\x00\x00(\xaf\x00\x00\x01\x02@\x00\x00\x0c\x01\x00\x00\x00\x00\x00\x01\x15@\x00\x00\x0c\x00\x00\x00\x01\x00\x00\x01\x08@\x00\x00\x1dtest.a-server.org\x00\x00\x00\x00\x00\x01(@\x00\x00\x14a-server.org\x00\x00\x01)@\x00\x00 \x00\x00\x01\n@\x00\x00\x0c\x00\x00(\xaf\x00\x00\x01*@\x00\x00\x0c\x00\x00\x13\x89\x00\x00\x02t\x80\x00\x008\x00\x00(\xaf\x00\x00\x01\n@\x00\x00\x0c\x00\x00(\xaf\x00\x00\x02u\x80\x00\x00\x10\x00\x00(\xaf\x00\x00\x00\x01\x00\x00\x02v\x80\x00\x00\x10\x00\x00(\xaf\x00\x00\x00\x05'

I need some help to parse and decode Diameter Raw.load message. 我需要一些帮助来解析和解码Diameter Raw.load消息。 Thx in advance 提前Thx

The best way to do it is to define the Diameter header yourself , following the link that I just gave you which is the section of the main Scapy documentation that details the step-by-step guide on how to build your own protocol type (header). 最好的方法是在我刚刚给您的链接之后, 自己定义Diameter标头 ,这是Scapy主文档的一部分,详细介绍了如何构建自己的协议类型的分步指南(标头) )。

Once you have the Diameter() header defined correctly, dissecting the Diameter packets will become a breeze. 一旦正确定义了Diameter()标头,解剖Diameter数据包将变得轻而易举。

The wikipedia page on the Diameter protocol seems to be a very good reference regarding the Diameter packet header. 关于Diameter协议Wikipedia页面似乎是有关Diameter数据包头的很好参考。

As part of the current Scapy pull requests https://bitbucket.org/secdev/scapy/pull-requests/ , number #109 provides support for the Diameter layer (parsing and generation). 作为当前Scapy拉取请求https://bitbucket.org/secdev/scapy/pull-requests/的一部分 ,编号109为Diameter层提供了支持(解析和生成)。

Download the latest Scapy sources and the diameter.py file which should be placed in the 'contribution' directory (this file will not fully work with the current 2.3.1 Scapy version) 下载最新的Scapy来源和应放置在“贡献”目录中的diameter.py文件(此文件不能与当前的2.3.1 Scapy版本完全兼容)

scapy is very useful. 船尾很有用。

from scapy.all import *

packets = rdpcap('/path/to/rx.pcap')

def generatePacket(): 
 '''
   Generate a packet.
 '''
 IP()/TCP()/DiamG()

def dissectPacket():
 '''
   dissect a packet.
 '''
 packet[0][DiamG]

The above shows the idea. 上面显示了这个想法。 and you can use print(repr(packet[0][DiamG])) to see result. 您可以使用print(repr(packet[0][DiamG]))查看结果。 Of course in order to check the packet is a Diameter packet, you might want to check at first like: 当然,为了检查数据包是否为直径数据包,您可能首先需要像这样检查:

x = packet[0]
while x.payload:
    x = x.payload
    if x.name == 'Diameter' # it has diameter message.
        # dissect it like above.

And how to ensemble and send a Diameter packet, one can check: building diameter message 以及如何集成和发送直径数据包,一个可以检查: 建筑物直径消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM