CCSDS_study project
This commit is contained in:
24
netzob-030/test/resources/files/UDP_example/UDP_automata.zdl
Normal file
24
netzob-030/test/resources/files/UDP_example/UDP_automata.zdl
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
from netzob.all import (Automata, OpenChannelTransition,
|
||||
Protocol, State)
|
||||
|
||||
# Load symbols from ZDL file
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
format_zdl = os.path.join(path, "UDP_format.zdl")
|
||||
symbols = Protocol.load_format(format_zdl)
|
||||
|
||||
# Specify the states
|
||||
s0 = State(name="Initial state")
|
||||
s1 = State(name="Channel opened")
|
||||
# s2 = State(name="Channel closed")
|
||||
|
||||
# Specify the transitions
|
||||
openTransition = OpenChannelTransition(startState=s0, endState=s1, name="Open")
|
||||
|
||||
# closeTransition = CloseChannelTransition(startState=s1,
|
||||
# endState=s2,
|
||||
# name="Closed")
|
||||
|
||||
# Specify the main automaton structure
|
||||
automata = Automata(s0, list(symbols.values()))
|
||||
34
netzob-030/test/resources/files/UDP_example/UDP_format.zdl
Normal file
34
netzob-030/test/resources/files/UDP_example/UDP_format.zdl
Normal file
@@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from bitarray import bitarray
|
||||
from netzob.all import (AbstractType, UnitSize, BitArray, Field, uint16,
|
||||
InternetChecksum, IPv4, Raw, Size, Symbol)
|
||||
|
||||
# Reference: https://www.ietf.org/rfc/rfc768.txt
|
||||
|
||||
# UDP header fields
|
||||
udp_sport = Field(uint16(), "udp.sport")
|
||||
udp_dport = Field(uint16(), "udp.dport")
|
||||
udp_length = Field(bitarray('0000000000000000'), "udp.length")
|
||||
udp_checksum = Field(bitarray('0000000000000000'), "udp.checksum")
|
||||
udp_payload = Field(Raw(), "udp.payload")
|
||||
|
||||
udp_header = [udp_sport, udp_dport, udp_length, udp_checksum, udp_payload]
|
||||
|
||||
# Update UDP length field
|
||||
udp_length.domain = Size(udp_header, dataType=uint16(), factor=1./8)
|
||||
|
||||
# Pseudo IP header to compute the UDP checksum
|
||||
pseudo_ip_src = Field(IPv4(), "udp.pseudoIP.saddr")
|
||||
pseudo_ip_dst = Field(IPv4(), "udp.pseudoIP.daddr")
|
||||
pseudo_ip_proto = Field(Raw(b'\x00\x11'), "udp.pseudoIP.proto")
|
||||
pseudo_ip_length = Field(Size(udp_header, dataType=uint16(), factor=1./8), "udp.pseudoIP.length")
|
||||
|
||||
pseudo_ip_header = Field(name="udp.pseudoIP", isPseudoField=True)
|
||||
pseudo_ip_header.fields = [pseudo_ip_src, pseudo_ip_dst, pseudo_ip_proto, pseudo_ip_length]
|
||||
|
||||
udp_checksum.domain = InternetChecksum([pseudo_ip_header] + udp_header, dataType=Raw(nbBytes=2, unitSize=UnitSize.SIZE_16))
|
||||
|
||||
# UDP symbol
|
||||
symbol_udp = Symbol(name="udp", fields=(udp_header + [pseudo_ip_header]))
|
||||
symbols = [symbol_udp]
|
||||
Reference in New Issue
Block a user