pysap.utils.fields module

class pysap.utils.fields.ASN1F_CHOICE_SAFE(name, default, *args, **kwargs)[source]

Bases: scapy.asn1fields.ASN1F_CHOICE

m2i(pkt, s)[source]

Try to safely extract an ASN1_Packet from the choices list.

Raises:ASN1_Error – if unable to parse the packet using any of the given choices
class pysap.utils.fields.AdjustableFieldLenField(name, default, length_of=None)[source]

Bases: scapy.fields.Field

addfield(pkt, s, val)[source]

Add an internal value to a string

Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.

adjust
count_of
getfield(pkt, s)[source]

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

i2m(pkt, x)[source]

Convert internal value to machine value

length_of
class pysap.utils.fields.ByteMultiEnumKeysField(name, default, enum, depends_on, fmt='H')[source]

Bases: scapy.fields.MultiEnumField

MultiEnumField that picks a reduced number of values. Used for fuzzing Byte fields with reduced number of values.

randval()[source]

Return a volatile object whose value is both random and suitable for this field

class pysap.utils.fields.IntToStrField(name, default, length=11)[source]

Bases: scapy.fields.Field

Custom field from int to str values, with a variable length

format
i2count(pkt, x)[source]

Convert internal value to a number of elements usable by a FieldLenField. Always 1 except for list fields

i2m(pkt, x)[source]

Convert internal value to machine value

length
m2i(pkt, x)[source]

Convert machine value to internal value

class pysap.utils.fields.LESignedByteField(name, default)[source]

Bases: scapy.fields.Field

class pysap.utils.fields.LESignedLongField(name, default)[source]

Bases: scapy.fields.Field

class pysap.utils.fields.LESignedShortField(name, default)[source]

Bases: scapy.fields.Field

class pysap.utils.fields.MutablePacketField(name, default, length_from, get_class, evaluators=None)[source]

Bases: scapy.fields.StrLenField

Packet field that mutates the class according to a list of evaluators. The evaluators are run against the packet and given to a class getter.

If the class can’t be found, the field is treated as a StrLenField.

evaluators
get_class(pkt)[source]
i2m(pkt, i)[source]

Convert internal value to machine value

length_from
m2i(pkt, m)[source]

Convert machine value to internal value

class pysap.utils.fields.PacketListStopField(name, default, cls, count_from=None, length_from=None, stop=None)[source]

Bases: scapy.fields.PacketListField

Custom field that contains a list of packets until a ‘stop’ condition is met.

count_from
getfield(pkt, s)[source]

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

length_from
stop
class pysap.utils.fields.PacketNoPadded(_pkt='', post_transform=None, _internal=0, _underlayer=None, **fields)[source]

Bases: scapy.packet.Packet

Regular scapy packet with no padding.

aliastypes = [<class 'pysap.utils.fields.PacketNoPadded'>, <class 'scapy.packet.Packet'>]
extract_padding(s)[source]

DEV: to be overloaded to extract current layer’s padding.

Parameters:s (str) – the current layer
Returns:a couple of strings (actual layer, padding)
class pysap.utils.fields.RandByteReduced[source]

Bases: scapy.volatile.RandNum

RandByte that only returns random values between 0 and x2a. Used while performing some fuzz to reduce the test cases space.

class pysap.utils.fields.StrEncodedPaddedField(name, default, encoding='utf-16', padd='x0c', fmt='H', remain=0)[source]

Bases: scapy.fields.StrField

addfield(pkt, s, val)[source]

Add an internal value to a string

Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.

encoding
getfield(pkt, s)[source]

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

h2i(pkt, x)[source]

Convert human value to internal value

i2h(pkt, x)[source]

Convert internal value to human value

padd
remain
class pysap.utils.fields.StrFixedLenPaddedField(name, default, length=None, length_from=None, padd=' ')[source]

Bases: scapy.fields.StrFixedLenField

Packet field that has a fixed length and is padded with a given character.

addfield(pkt, s, val)[source]

Add an internal value to a string

Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.

getfield(pkt, s)[source]

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

length_from
padd
class pysap.utils.fields.StrNullFixedLenField(name, default, length=None, length_from=None, max_length=None, null_terminated=None)[source]

Bases: scapy.fields.StrFixedLenField

Packet field that has a fixed length and is conditionally null-terminated.

addfield(pkt, s, val)[source]

Add an internal value to a string

Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.

getfield(pkt, s)[source]

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

i2repr(pkt, v)[source]

Convert internal value to a nice representation

length_from
max_length
null_terminated
randval()[source]

Return a volatile object whose value is both random and suitable for this field

class pysap.utils.fields.StrNullFixedLenPaddedField(name, default, length=None, length_from=None, padd=' ')[source]

Bases: scapy.fields.StrFixedLenField

Packet field that has a fixed length and is padded with a given character and null terminated.

addfield(pkt, s, val)[source]

Add an internal value to a string

Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.

getfield(pkt, s)[source]

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

length_from
padd
class pysap.utils.fields.TimestampField(name, default)[source]

Bases: scapy.fields.LongField

Timestamp field

i2h(pkt, x)[source]

Convert internal value to human value

pysap.utils.fields.saptimestamp_to_datetime(timestamp)[source]

Converts a timestamp in “SAP format” to a datetime object. Time zone looks to be fixed at GMT+1.