scapy.contrib.http2

http2 Module Implements packets and fields required to encode/decode HTTP/2 Frames and HPack encoded headers

class scapy.contrib.http2.AbstractUVarIntField(name, default, size)

Bases: scapy.fields.Field

AbstractUVarIntField represents an integer as defined in RFC7541

addfield(pkt, s, val)

An AbstractUVarIntField prefix always consumes the remaining bits of a BitField;if no current BitField is in use (no tuple in entry) then the prefix length is 8 bits and the whole byte is to be consumed

Parameters
  • pkt (packet.Packet|None) – the packet containing this field. Probably unused.

  • int, long) s (str|(str,) – the string to append this field to. A tuple indicates that some bits were already generated by another bitfield-compatible field. This MUST be the case if “size” is not 8. The int is the number of bits already generated in the first byte of the str. The long is the value that was generated by the previous bitfield-compatible fields.

  • val (int) – the positive or null value to be added.

Returns

str: s concatenated with the machine representation of this field.

Raises

AssertionError

any2i(pkt, x)

A “x” value as a string is parsed as a binary encoding of a UVarInt. An int is considered an internal value. # noqa: E501 None is returned as is.

Parameters
  • pkt (packet.Packet|None) – the packet containing this field; probably unused. # noqa: E501

  • x (str|int|None) – the value to convert.

Returns

int|None: the converted value.

Raises

AssertionError

getfield(pkt, s)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field; probably unused.

  • int) s (str|(str,) – the input value to get this field value from. If size is 8, s is a string, else it is a tuple containing the value and an int indicating the number of bits already consumed in the first byte of the str. The number of remaining bits to consume in the first byte must be equal to “size”.

Returns

(str, int): the remaining bytes of s and the parsed value.

Raises

AssertionError

h2i(pkt, x)
Parameters
  • pkt (packet.Packet|None) – unused.

  • x (int|None) – the value to convert.

Returns

int|None: the converted value.

Raises

AssertionError

i2h(pkt, x)
Parameters
  • pkt (packet.Packet|None) – unused.

  • x (int|None) – the value to convert.

Return:

int|None: the converted value.

i2len(pkt, x)
Parameters
  • pkt (packet.Packet|None) – unused.

  • x (int) – the positive or null value whose binary size if requested. # noqa: E501

Raises

AssertionError

i2m(pkt, x)
Parameters
  • pkt (packet.Packet|None) – unused.

  • x (int) – the value to convert.

Returns

str: the converted value.

Raises

AssertionError

i2repr(pkt, x)
Parameters
  • pkt (packet.Packet|None) – probably unused.

  • x – int|None: the positive, null or none value to convert.

Returns

str: the representation of the value.

m2i(pkt, x)

A tuple is expected for the “x” param only if “size” is different than 8. If a tuple is received, some bits # noqa: E501 were consumed by another field. This field consumes the remaining bits, therefore the int of the tuple must # noqa: E501 equal “size”.

Parameters
  • pkt (packet.Packet|None) – unused.

  • int) x (str|(str,) – the string to convert. If bits were consumed by a previous bitfield-compatible field. # noqa: E501

Raises

AssertionError

randval()
Returns

volatile.VolatileValue: a volatile value for this field “long”-compatible internal value. # noqa: E501

rev
size
class scapy.contrib.http2.EOS

Bases: object

Simple “marker” to designate the End Of String symbol in the huffman table

class scapy.contrib.http2.FieldUVarLenField(name, default, size, length_of, adjust=<function FieldUVarLenField.<lambda>>)

Bases: scapy.contrib.http2.AbstractUVarIntField

addfield(pkt, s, val)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance. This parameter must not be # noqa: E501 None if the val parameter is.

  • int, long) s (str|(str,) – the string to append this field to. A tuple indicates that some bits were already # noqa: E501 generated by another bitfield-compatible field. This MUST be the case if “size” is not 8. The int is the # noqa: E501 number of bits already generated in the first byte of the str. The long is the value that was generated by the # noqa: E501 previous bitfield-compatible fields.

  • val (int|None) – the positive or null value to be added. If None, the value is computed from pkt. # noqa: E501

Returns

str: s concatenated with the machine representation of this field. # noqa: E501

Raises

AssertionError

i2m(pkt, x)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance. This parameter must not be # noqa: E501 None if the x parameter is.

  • x (int|None) – the positive or null value to be added. If None, the value is computed from pkt. # noqa: E501

Returns

str

Raises

AssertionError

class scapy.contrib.http2.H2AbstractHeadersFrame

Bases: scapy.contrib.http2.H2FramePayload

Superclass of all variants of HTTP/2 Header Frame Packets. May be used for type checking.

aliastypes
class scapy.contrib.http2.H2ContinuationFrame

Bases: scapy.contrib.http2.H2FramePayload

H2ContinuationFrame implements the RFC 7540 par6.10

END_HEADERS_FLAG = 2
aliastypes
fields_desc
H2ContinuationFrame fields

hdrs

PacketListField

[]

flags = {2: MultiFlagEntry(short='EH', long='End Headers')}
type_id = 9
class scapy.contrib.http2.H2DataFrame

Bases: scapy.contrib.http2.H2FramePayload

H2DataFrame implements RFC7540 par6.1 This packet is the Data Frame to use when there is no padding.

END_STREAM_FLAG = 0
PADDED_FLAG = 3
aliastypes
fields_desc
H2DataFrame fields

data

StrField

b''

flags = {0: MultiFlagEntry(short='ES', long='End Stream'), 3: MultiFlagEntry(short='P', long='Padded')}
type_id = 0
class scapy.contrib.http2.H2ErrorCodes

Bases: object

H2ErrorCodes is an enumeration of the error codes defined in RFC7540 par7. This enumeration is not part of any frame because the error codes are in common with H2ResetFrame and H2GoAwayFrame.

CANCEL = 8
COMPRESSION_ERROR = 9
CONNECT_ERROR = 10
ENHANCE_YOUR_CALM = 11
FLOW_CONTROL_ERROR = 3
FRAME_SIZE_ERROR = 6
HTTP_1_1_REQUIRED = 13
INADEQUATE_SECURITY = 12
INTERNAL_ERROR = 2
NO_ERROR = 0
PROTOCOL_ERROR = 1
REFUSED_STREAM = 7
SETTINGS_TIMEOUT = 4
STREAM_CLOSED = 5
literal = {0: 'No error', 1: 'Protocol error', 2: 'Internal error', 3: 'Flow control error', 4: 'Settings timeout', 5: 'Stream closed', 6: 'Frame size error', 7: 'Refused stream', 8: 'Cancel', 9: 'Compression error', 10: 'Control error', 11: 'Enhance your calm', 12: 'Inadequate security', 13: 'HTTP/1.1 required'}
class scapy.contrib.http2.H2Frame

Bases: scapy.packet.Packet

H2Frame implements the frame structure as defined in RFC 7540 par4.1

This packet may have a payload (one of the H2FramePayload) or none, in some rare cases such as settings acknowledgement)

aliastypes
extract_padding(s)
Parameters

s (str) – the string from which to tell the padding and the payload data apart # noqa: E501

Returns

(str, str): the padding and the payload data strings

Raises

AssertionError

fields_desc
H2Frame fields

len

X3BytesField

None

type

EnumField

None

flags

MultiFlagsField (8 bits)

set()

reserved

BitField (1 bit)

0

stream_id

BitField (31 bits)

0

guess_payload_class(payload)

guess_payload_class returns the Class object to use for parsing a payload This function uses the H2Frame.type field value to decide which payload to parse. The implement cannot be # noqa: E501 performed using the simple bind_layers helper because sometimes the selection of which Class object to return # noqa: E501 also depends on the H2Frame.flags value.

Parameters

payload

Return:

payload_guess

Possible sublayers: H2ContinuationFrame, H2DataFrame, H2GoAwayFrame, H2HeadersFrame, H2PaddedDataFrame, H2PaddedHeadersFrame, H2PaddedPriorityHeadersFrame, H2PaddedPushPromiseFrame, H2PingFrame, H2PriorityFrame, H2PriorityHeadersFrame, H2PushPromiseFrame, H2ResetFrame, H2SettingsFrame, H2WindowUpdateFrame

post_build(p, pay)
Parameters
  • p (str) – the stringified packet

  • pay (str) – the stringified payload

Returns

str: the stringified packet and payload, with the packet length field “patched” # noqa: E501

Raises

AssertionError

class scapy.contrib.http2.H2FramePayload

Bases: scapy.packet.Packet

H2FramePayload is an empty class that is a super class of all Scapy HTTP/2 Frame Packets

aliastypes
class scapy.contrib.http2.H2GoAwayFrame

Bases: scapy.contrib.http2.H2FramePayload

H2GoAwayFrame implements the RFC 7540 par6.8

aliastypes
fields_desc
H2GoAwayFrame fields

reserved

BitField (1 bit)

0

last_stream_id

BitField (31 bits)

0

error

EnumField

0

additional_data

StrField

b''

type_id = 7
class scapy.contrib.http2.H2HeadersFrame

Bases: scapy.contrib.http2.H2AbstractHeadersFrame

H2HeadersFrame implements RFC 7540 par6.2 Headers Frame when there is no padding and no priority information

The choice of decomposing into four classes is probably preferable to having # noqa: E501 numerous conditional fields based on the underlayer :/

END_HEADERS_FLAG = 2
END_STREAM_FLAG = 0
PADDED_FLAG = 3
PRIORITY_FLAG = 5
aliastypes
fields_desc
H2HeadersFrame fields

hdrs

PacketListField

[]

flags = {0: MultiFlagEntry(short='ES', long='End Stream'), 2: MultiFlagEntry(short='EH', long='End Headers'), 3: MultiFlagEntry(short='P', long='Padded'), 5: MultiFlagEntry(short='+', long='Priority')}
type_id = 1
class scapy.contrib.http2.H2PaddedDataFrame

Bases: scapy.contrib.http2.H2DataFrame

H2DataFrame implements RFC7540 par6.1 This packet is the Data Frame to use when there is padding.

aliastypes
fields_desc
H2PaddedDataFrame fields

padlen

FieldLenField

None

data

StrLenField

b''

padding

StrLenField

b''

get_data_len()

get_data_len computes the length of the data field

To do this computation, the length of the padlen field and the actual padding is subtracted to the string that was provided to the pre_dissect # noqa: E501 fun of the pkt parameter :return: int; length of the data part of the HTTP/2 frame packet provided as parameter # noqa: E501 :raises: AssertionError

pre_dissect(s)

pre_dissect is filling the s_len property of this instance. This property is later used during the getfield call of the “data” field when # noqa: E501 trying to evaluate the length of the StrLenField! This “trick” works because the underlayer packet (H2Frame) is assumed to override the “extract_padding” method and to only provide to this packet the data necessary for this packet. Tricky, tricky, will break some day probably! # noqa: E501

s_len
class scapy.contrib.http2.H2PaddedHeadersFrame

Bases: scapy.contrib.http2.H2AbstractHeadersFrame

H2PaddedHeadersFrame is the variant of H2HeadersFrame where padding flag is set and priority flag is cleared

aliastypes
fields_desc
H2PaddedHeadersFrame fields

padlen

FieldLenField

None

hdrs

PacketListField

[]

padding

StrLenField

b''

get_hdrs_len()

get_hdrs_len computes the length of the hdrs field

To do this computation, the length of the padlen field and the actual padding is subtracted to the string that was provided to the pre_dissect # noqa: E501 fun of the pkt parameter. :return: int; length of the data part of the HTTP/2 frame packet provided as parameter # noqa: E501 :raises: AssertionError

pre_dissect(s)

pre_dissect is filling the s_len property of this instance. This property is later used during the parsing of the hdrs PacketListField when trying to evaluate the length of the PacketListField! This “trick” works because the underlayer packet (H2Frame) is assumed to override the # noqa: E501 “extract_padding” method and to only provide to this packet the data necessary for this packet. Tricky, tricky, will break some day probably! # noqa: E501

s_len
class scapy.contrib.http2.H2PaddedPriorityHeadersFrame

Bases: scapy.contrib.http2.H2AbstractHeadersFrame

H2PaddedPriorityHeadersFrame is the variant of H2HeadersFrame where both priority and padding flags are set

aliastypes
fields_desc
H2PaddedPriorityHeadersFrame fields

padlen

FieldLenField

None

exclusive

BitField (1 bit)

0

stream_dependency

BitField (31 bits)

0

weight

ByteField

0

hdrs

PacketListField

[]

padding

StrLenField

b''

get_hdrs_len()

get_hdrs_len computes the length of the hdrs field

To do this computation, the length of the padlen field, the priority information fields and the actual padding is subtracted to the string that was provided to the pre_dissect fun of the pkt parameter. :return: int: the length of the hdrs field :raises: AssertionError

pre_dissect(s)

pre_dissect is filling the s_len property of this instance. This property is later used during the parsing of the hdrs PacketListField when trying to evaluate the length of the PacketListField! This “trick” works because the underlayer packet (H2Frame) is assumed to override the # noqa: E501 “extract_padding” method and to only provide to this packet the data necessary for this packet. Tricky, tricky, will break some day probably! # noqa: E501

s_len
class scapy.contrib.http2.H2PaddedPushPromiseFrame

Bases: scapy.contrib.http2.H2PushPromiseFrame

H2PaddedPushPromiseFrame implements RFC7540 par6.6. This packet is the variant to use when the underlayer padding flag is set

aliastypes
fields_desc
H2PaddedPushPromiseFrame fields

padlen

FieldLenField

None

reserved

BitField (1 bit)

0

stream_id

BitField (31 bits)

0

hdrs

PacketListField

[]

padding

StrLenField

b''

get_hdrs_len()

get_hdrs_len computes the length of the hdrs field

To do this computation, the length of the padlen field, reserved, stream_id and the actual padding is subtracted to the string that was provided to the pre_dissect fun of the pkt parameter. :return: int: the length of the hdrs field :raises: AssertionError

pre_dissect(s)

pre_dissect is filling the s_len property of this instance. This property is later used during the parsing of the hdrs PacketListField when trying to evaluate the length of the PacketListField! This “trick” works because the underlayer packet (H2Frame) is assumed to override the # noqa: E501 “extract_padding” method and to only provide to this packet the data necessary for this packet. Tricky, tricky, will break some day probably! # noqa: E501

s_len
class scapy.contrib.http2.H2PingFrame(*args, **kwargs)

Bases: scapy.contrib.http2.H2FramePayload

H2PingFrame implements the RFC 7540 par6.7

ACK_FLAG = 0
aliastypes
fields_desc
H2PingFrame fields

opaque

LongField

0

flags = {0: MultiFlagEntry(short='A', long='ACK')}
type_id = 6
class scapy.contrib.http2.H2PriorityFrame

Bases: scapy.contrib.http2.H2FramePayload

H2PriorityFrame implements RFC 7540 par6.3

aliastypes
fields_desc
H2PriorityFrame fields

exclusive

BitField (1 bit)

0

stream_dependency

BitField (31 bits)

0

weight

ByteField

0

type_id = 2
class scapy.contrib.http2.H2PriorityHeadersFrame

Bases: scapy.contrib.http2.H2AbstractHeadersFrame

H2PriorityHeadersFrame is the variant of H2HeadersFrame where priority flag is set and padding flag is cleared

aliastypes
fields_desc
H2PriorityHeadersFrame fields

exclusive

BitField (1 bit)

0

stream_dependency

BitField (31 bits)

0

weight

ByteField

0

hdrs

PacketListField

[]

s_len
class scapy.contrib.http2.H2PushPromiseFrame

Bases: scapy.contrib.http2.H2FramePayload

H2PushPromiseFrame implements RFC7540 par6.6. This packet is the variant to use when the underlayer padding flag is cleared

END_HEADERS_FLAG = 2
PADDED_FLAG = 3
aliastypes
fields_desc
H2PushPromiseFrame fields

reserved

BitField (1 bit)

0

stream_id

BitField (31 bits)

0

hdrs

PacketListField

[]

flags = {2: MultiFlagEntry(short='EH', long='End Headers'), 3: MultiFlagEntry(short='P', long='Padded')}
type_id = 5
class scapy.contrib.http2.H2ResetFrame

Bases: scapy.contrib.http2.H2FramePayload

H2ResetFrame implements RFC 7540 par6.4

aliastypes
fields_desc
H2ResetFrame fields

error

EnumField

0

type_id = 3
class scapy.contrib.http2.H2Seq

Bases: scapy.packet.Packet

H2Seq is a helper packet that contains several H2Frames and their payload. This packet can be used, for instance, while reading manually from a TCP socket.

aliastypes
fields_desc
H2Seq fields

frames

PacketListField

[]

guess_payload_class(payload)
class scapy.contrib.http2.H2Setting

Bases: scapy.packet.Packet

H2Setting implements a setting, as defined in RFC7540 par6.5.1

SETTINGS_ENABLE_PUSH = 2
SETTINGS_HEADER_TABLE_SIZE = 1
SETTINGS_INITIAL_WINDOW_SIZE = 4
SETTINGS_MAX_CONCURRENT_STREAMS = 3
SETTINGS_MAX_FRAME_SIZE = 5
SETTINGS_MAX_HEADER_LIST_SIZE = 6
aliastypes
fields_desc
H2Setting fields

id

EnumField

0

value

IntField

0

guess_payload_class(payload)
class scapy.contrib.http2.H2SettingsFrame(*args, **kwargs)

Bases: scapy.contrib.http2.H2FramePayload

H2SettingsFrame implements RFC7540 par6.5

ACK_FLAG = 0
aliastypes
fields_desc
H2SettingsFrame fields

settings

PacketListField

[]

flags = {0: MultiFlagEntry(short='A', long='ACK')}
type_id = 4
class scapy.contrib.http2.H2WindowUpdateFrame(*args, **kwargs)

Bases: scapy.contrib.http2.H2FramePayload

H2WindowUpdateFrame implements the RFC 7540 par6.9

aliastypes
fields_desc
H2WindowUpdateFrame fields

reserved

BitField (1 bit)

0

win_size_incr

BitField (31 bits)

0

type_id = 8
class scapy.contrib.http2.HPackDynamicSizeUpdate

Bases: scapy.contrib.http2.HPackHeaders

HPackDynamicSizeUpdate implements RFC 7541 par6.3

aliastypes
fields_desc
HPackDynamicSizeUpdate fields

magic

HPackMagicBitField (3 bits)

1

max_size

UVarIntField

0

class scapy.contrib.http2.HPackHdrEntry(name, value)

Bases: collections.abc.Sized, typing.Generic

HPackHdrEntry is an entry of the HPackHdrTable helper

Each HPackHdrEntry instance is a header line (name and value). Names are normalized (lowercase), according to RFC 7540 par8.1.2

name()
size()

size returns the “length” of the header entry, as defined in RFC 7541 par4.1.

value()
class scapy.contrib.http2.HPackHdrString

Bases: scapy.packet.Packet

HPackHdrString is a packet that that is serialized into a RFC7541 par5.2 string literal repr.

aliastypes
fields_desc
HPackHdrString fields

type

BitEnumField (1 bit)

None

len

FieldUVarLenField

None

data

HPackStrLenField

<scapy.contrib.http2.HPackLiteralString object at 0x7f50d181be08>

guess_payload_class(payload)
self_build(field_pos_list=None)

self_build is overridden because type and len are determined at build time, based on the “data” field internal type

class scapy.contrib.http2.HPackHdrTable(dynamic_table_max_size=4096, dynamic_table_cap_size=4096)

Bases: collections.abc.Sized, typing.Generic

HPackHdrTable is a helper class that implements some of the logic associated with indexing of headers (read and write operations in this “registry”. THe HPackHdrTable also implements convenience functions to easily # noqa: E501 convert to and from textual representation and binary representation of a HTTP/2 requests

gen_txt_repr(hdrs, register=True)

gen_txt_repr returns a “textual” representation of the provided headers. The output of this function is compatible with the input of parse_txt_hdrs.

Parameters
  • of HPackHeaders hdrs (H2Frame|list) – the list of headers to convert to textual representation.

  • bool – whether incremental headers should be added to the dynamic table as we generate the text representation

Returns

str: the textual representation of the provided headers

Raises

AssertionError

get_idx_by_name(name)

get_idx_by_name returns the index of a matching registered header

This implementation will prefer returning a static entry index whenever possible. If multiple matching header name are found in the static table, there is insurance that the first entry (lowest index number) will be returned. If no matching header is found, this method returns None.

get_idx_by_name_and_value(name, value)

get_idx_by_name_and_value returns the index of a matching registered header

This implementation will prefer returning a static entry index whenever possible. If multiple matching headers are found in the dynamic table, the lowest index is returned If no matching header is found, this method returns None.

classmethod init_static_table()
parse_txt_hdrs(s, stream_id=1, body=None, max_frm_sz=4096, max_hdr_lst_sz=0, is_sensitive=<function HPackHdrTable.<lambda>>, should_index=<function HPackHdrTable.<lambda>>, register=True)

parse_txt_hdrs parses headers expressed in text and converts them into a series of H2Frames with the “correct” flags. A body can be provided # noqa: E501 in which case, the data frames are added, bearing the End Stream flag, instead of the H2HeadersFrame/H2ContinuationFrame. The generated frames may respect max_frm_sz (SETTINGS_MAX_FRAME_SIZE) and max_hdr_lst_sz (SETTINGS_MAX_HEADER_LIST_SIZE) if provided. The headers are split into multiple headers fragment (and H2Frames) to respect these limits. Also, a callback can be provided to tell if a header should be never indexed (sensitive headers, such as cookies), and another callback say if the header should be registered into the index table at all. For an header to be registered, the is_sensitive callback must return False AND the should_index callback should return True. This is the default behavior.

Parameters
  • s (str) – the string to parse for headers

  • stream_id (int) – the stream id to use in the generated H2Frames

  • body (str|None) – the eventual body of the request, that is added to the generated frames

  • max_frm_sz (int) – the maximum frame size. This is used to split the headers and data frames according to the maximum frame size negotiated for this connection.

  • max_hdr_lst_sz (int) – the maximum size of a “header fragment” as defined in RFC7540

  • is_sensitive (callable) – callback that returns True if the provided header is sensible and must be stored in a header packet requesting this header never to be indexed

  • should_index (callable) – callback that returns True if the provided header should be stored in a header packet requesting indexation in the dynamic header table.

  • register (bool) – whether to register new headers with incremental indexing as we parse them

Raises

Exception

recap(nc)

recap changes the maximum size limit of the dynamic table. It also proceeds to a resize(), if the new size is lower than the previous one. :param int nc: the new cap of the dynamic table (that is the maximum-maximum size) # noqa: E501 :raises: AssertionError

register(hdrs)

register adds to this table the instances of HPackLitHdrFldWithIncrIndexing provided as parameters.

A H2Frame with a H2HeadersFrame payload can be provided, as much as a python list of HPackHeaders or a single HPackLitHdrFldWithIncrIndexing instance. :param HPackLitHdrFldWithIncrIndexing|H2Frame|list of HPackHeaders hdrs: the header(s) to register # noqa: E501 :raises: AssertionError

resize(ns)

Resize the dynamic table. If the new size (ns) must be between 0 and the cap size. If the new size is lower than the current size of the dynamic table, entries are evicted. :param int ns: the new size of the dynamic table :raises: AssertionError

class scapy.contrib.http2.HPackHeaders

Bases: scapy.packet.Packet

HPackHeaders uses the “dispatch_hook” trick of Packet_metaclass to select the correct HPack header packet type. For this, the first byte of the string # noqa: E501 to dissect is snooped on.

aliastypes
classmethod dispatch_hook(s=None, *_args, **_kwds)

dispatch_hook returns the subclass of HPackHeaders that must be used to dissect the string.

guess_payload_class(payload)
class scapy.contrib.http2.HPackIndexedHdr

Bases: scapy.contrib.http2.HPackHeaders

HPackIndexedHdr implements RFC 7541 par6.1

aliastypes
fields_desc
HPackIndexedHdr fields

magic

HPackMagicBitField (1 bit)

1

index

UVarIntField

2

class scapy.contrib.http2.HPackLitHdrFldWithIncrIndexing

Bases: scapy.contrib.http2.HPackHeaders

HPackLitHdrFldWithIncrIndexing implements RFC 7541 par6.2.1

aliastypes
fields_desc
HPackLitHdrFldWithIncrIndexing fields

magic

HPackMagicBitField (2 bits)

1

index

UVarIntField

0

hdr_name

PacketField (Cond)

None

hdr_value

PacketField

None

class scapy.contrib.http2.HPackLitHdrFldWithoutIndexing

Bases: scapy.contrib.http2.HPackHeaders

HPackLitHdrFldWithIncrIndexing implements RFC 7541 par6.2.2 and par6.2.3

aliastypes
fields_desc
HPackLitHdrFldWithoutIndexing fields

magic

HPackMagicBitField (3 bits)

0

never_index

BitEnumField (1 bit)

0

index

UVarIntField

0

hdr_name

PacketField (Cond)

None

hdr_value

PacketField

None

class scapy.contrib.http2.HPackLiteralString(s)

Bases: scapy.contrib.http2.HPackStringsInterface

HPackLiteralString is a string. This class is used as a marker and implements an interface in common with HPackZString

origin()
class scapy.contrib.http2.HPackMagicBitField(name, default, size)

Bases: scapy.fields.BitField

HPackMagicBitField is a BitField variant that cannot be assigned another value than the default one. This field must not be used where there is potential for fuzzing. OTOH, this field makes sense (for instance, if the magic bits are used by a dispatcher to select the payload class)

addfield(pkt, s, val)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused. # noqa: E501

  • int, long) s (str|(str,) – either a str if 0 == size%8 or a tuple with the string to add this field to, the # noqa: E501 number of bits already generated and the generated value so far.

  • val (int) – unused; must be equal to default value

Returns

str|(str, int, long): the s string extended with this field machine representation # noqa: E501

Raises

AssertionError

any2i(pkt, x)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused # noqa: E501

  • x (int) – unused; must be equal to default value

Returns

int; default value

Raises

AssertionError

getfield(pkt, s)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused. # noqa: E501

  • int) s (str|(str,) – either a str if size%8==0 or a tuple with the string to parse from and the number of # noqa: E501 bits already consumed by previous bitfield-compatible fields.

Returns

(str|(str, int), int): Returns the remaining string and the parsed value. May return a tuple if there # noqa: E501 are remaining bits to parse in the first byte. Returned value is equal to default value # noqa: E501

Raises

AssertionError

h2i(pkt, x)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused # noqa: E501

  • x (int) – unused; must be equal to default value

Returns

int; default value

Raises

AssertionError

i2h(pkt, x)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused # noqa: E501

  • x (int) – unused; must be equal to default value

Returns

int; default value

Raises

AssertionError

i2m(pkt, x)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused # noqa: E501

  • x (int) – unused; must be equal to default value

Returns

int; default value

Raises

AssertionError

m2i(pkt, x)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused # noqa: E501

  • x (int) – must be the machine representatino of the default value

Returns

int; default value

Raises

AssertionError

class scapy.contrib.http2.HPackStrLenField(name, default, length_from, type_from)

Bases: scapy.fields.Field

HPackStrLenField is a StrLenField variant specialized for HTTP/2 HPack

This variant uses an internal representation that implements HPackStringsInterface. # noqa: E501

addfield(pkt, s, val)
any2i(pkt, x)
Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance. # noqa: E501

  • x (str|HPackStringsInterface) – the value to convert

Returns

HPackStringsInterface: the Scapy internal value for this field

Raises

AssertionError, InvalidEncodingException

getfield(pkt, s)
Parameters
  • pkt (packet.Packet) – the packet instance containing this field instance. # noqa: E501

  • s (str) – the string to parse this field from.

Returns

(str, HPackStringsInterface): the remaining string after this field was carved out & the extracted # noqa: E501 value.

Raises

KeyError if “type_from” is not a field of pkt or its payloads.

Raises

InvalidEncodingException

h2i(pkt, x)
i2h(pkt, x)
i2len(pkt, x)
i2m(pkt, x)
i2repr(pkt, x)
m2i(pkt, x)
Parameters
  • pkt (packet.Packet) – the packet instance containing this field instance. # noqa: E501

  • x (str) – the string to parse.

Returns

HPackStringsInterface: the internal type of the value parsed from x. # noqa: E501

Raises

AssertionError

Raises

InvalidEncodingException

Raises

KeyError if _type_from is not one of pkt fields.

class scapy.contrib.http2.HPackStringsInterface

Bases: abc.ABC, collections.abc.Sized, typing.Generic

abstract origin()
class scapy.contrib.http2.HPackZString(s)

Bases: scapy.contrib.http2.HPackStringsInterface

classmethod huffman_compute_decode_tree()

huffman_compute_decode_tree initializes/builds the static_huffman_tree

Returns

None

Raises

InvalidEncodingException if there is an encoding problem

classmethod huffman_conv2bitstring(s)

huffman_conv2bitstring converts a string into its bitstring representation. It returns a tuple: the bitstring and its bitlength. This function DOES NOT compress/decompress the string!

Parameters

s (str) – the bytestring to convert.

Returns

(int, int): the bitstring of s, and its bitlength.

Raises

AssertionError

classmethod huffman_conv2str(bit_str, bit_len)

huffman_conv2str converts a bitstring of bit_len bitlength into a binary string. It DOES NOT compress/decompress the bitstring!

Parameters
  • bit_str (int) – the bitstring to convert.

  • bit_len (int) – the bitlength of bit_str.

Returns

str: the converted bitstring as a bytestring.

Raises

AssertionError

classmethod huffman_decode(i, ibl)

huffman_decode decodes the bitstring provided as parameters.

Parameters
  • i (int) – the bitstring to decode

  • ibl (int) – the bitlength of i

Returns

str: the string decoded from the bitstring

Raises

AssertionError, InvalidEncodingException

classmethod huffman_encode(s)

huffman_encode returns the bitstring and the bitlength of the bitstring representing the string provided as a parameter

Parameters

s (str) – the string to encode

Returns

(int, int): the bitstring of s and its bitlength

Raises

AssertionError

origin()
static_huffman_code = [(8184, 13), (8388568, 23), (268435426, 28), (268435427, 28), (268435428, 28), (268435429, 28), (268435430, 28), (268435431, 28), (268435432, 28), (16777194, 24), (1073741820, 30), (268435433, 28), (268435434, 28), (1073741821, 30), (268435435, 28), (268435436, 28), (268435437, 28), (268435438, 28), (268435439, 28), (268435440, 28), (268435441, 28), (268435442, 28), (1073741822, 30), (268435443, 28), (268435444, 28), (268435445, 28), (268435446, 28), (268435447, 28), (268435448, 28), (268435449, 28), (268435450, 28), (268435451, 28), (20, 6), (1016, 10), (1017, 10), (4090, 12), (8185, 13), (21, 6), (248, 8), (2042, 11), (1018, 10), (1019, 10), (249, 8), (2043, 11), (250, 8), (22, 6), (23, 6), (24, 6), (0, 5), (1, 5), (2, 5), (25, 6), (26, 6), (27, 6), (28, 6), (29, 6), (30, 6), (31, 6), (92, 7), (251, 8), (32764, 15), (32, 6), (4091, 12), (1020, 10), (8186, 13), (33, 6), (93, 7), (94, 7), (95, 7), (96, 7), (97, 7), (98, 7), (99, 7), (100, 7), (101, 7), (102, 7), (103, 7), (104, 7), (105, 7), (106, 7), (107, 7), (108, 7), (109, 7), (110, 7), (111, 7), (112, 7), (113, 7), (114, 7), (252, 8), (115, 7), (253, 8), (8187, 13), (524272, 19), (8188, 13), (16380, 14), (34, 6), (32765, 15), (3, 5), (35, 6), (4, 5), (36, 6), (5, 5), (37, 6), (38, 6), (39, 6), (6, 5), (116, 7), (117, 7), (40, 6), (41, 6), (42, 6), (7, 5), (43, 6), (118, 7), (44, 6), (8, 5), (9, 5), (45, 6), (119, 7), (120, 7), (121, 7), (122, 7), (123, 7), (32766, 15), (2044, 11), (16381, 14), (8189, 13), (268435452, 28), (1048550, 20), (4194258, 22), (1048551, 20), (1048552, 20), (4194259, 22), (4194260, 22), (4194261, 22), (8388569, 23), (4194262, 22), (8388570, 23), (8388571, 23), (8388572, 23), (8388573, 23), (8388574, 23), (16777195, 24), (8388575, 23), (16777196, 24), (16777197, 24), (4194263, 22), (8388576, 23), (16777198, 24), (8388577, 23), (8388578, 23), (8388579, 23), (8388580, 23), (2097116, 21), (4194264, 22), (8388581, 23), (4194265, 22), (8388582, 23), (8388583, 23), (16777199, 24), (4194266, 22), (2097117, 21), (1048553, 20), (4194267, 22), (4194268, 22), (8388584, 23), (8388585, 23), (2097118, 21), (8388586, 23), (4194269, 22), (4194270, 22), (16777200, 24), (2097119, 21), (4194271, 22), (8388587, 23), (8388588, 23), (2097120, 21), (2097121, 21), (4194272, 22), (2097122, 21), (8388589, 23), (4194273, 22), (8388590, 23), (8388591, 23), (1048554, 20), (4194274, 22), (4194275, 22), (4194276, 22), (8388592, 23), (4194277, 22), (4194278, 22), (8388593, 23), (67108832, 26), (67108833, 26), (1048555, 20), (524273, 19), (4194279, 22), (8388594, 23), (4194280, 22), (33554412, 25), (67108834, 26), (67108835, 26), (67108836, 26), (134217694, 27), (134217695, 27), (67108837, 26), (16777201, 24), (33554413, 25), (524274, 19), (2097123, 21), (67108838, 26), (134217696, 27), (134217697, 27), (67108839, 26), (134217698, 27), (16777202, 24), (2097124, 21), (2097125, 21), (67108840, 26), (67108841, 26), (268435453, 28), (134217699, 27), (134217700, 27), (134217701, 27), (1048556, 20), (16777203, 24), (1048557, 20), (2097126, 21), (4194281, 22), (2097127, 21), (2097128, 21), (8388595, 23), (4194282, 22), (4194283, 22), (33554414, 25), (33554415, 25), (16777204, 24), (16777205, 24), (67108842, 26), (8388596, 23), (67108843, 26), (134217702, 27), (67108844, 26), (67108845, 26), (134217703, 27), (134217704, 27), (134217705, 27), (134217706, 27), (134217707, 27), (268435454, 28), (134217708, 27), (134217709, 27), (134217710, 27), (134217711, 27), (134217712, 27), (67108846, 26), (1073741823, 30)]
static_huffman_tree = None
class scapy.contrib.http2.HuffmanNode(left, right)

Bases: object

HuffmanNode is an entry of the binary tree used for encoding/decoding HPack compressed HTTP/2 headers

left
right
exception scapy.contrib.http2.InvalidEncodingException

Bases: Exception

InvalidEncodingException is raised when a supposedly huffman-encoded string is decoded and a decoding error arises

class scapy.contrib.http2.UVarIntField(name, default, size)

Bases: scapy.contrib.http2.AbstractUVarIntField

any2i(pkt, x)

any2i is overloaded to restrict the acceptable x values (not None)

Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused. # noqa: E501

  • x (str|int) – the value to convert.

Returns

int: the converted value.

Raises

AssertionError

h2i(pkt, x)

h2i is overloaded to restrict the acceptable x values (not None)

Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused. # noqa: E501

  • x (int) – the value to convert.

Returns

int: the converted value.

Raises

AssertionError

i2h(pkt, x)

i2h is overloaded to restrict the acceptable x values (not None)

Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused. # noqa: E501

  • x (int) – the value to convert.

Returns

int: the converted value.

Raises

AssertionError

i2repr(pkt, x)

i2repr is overloaded to restrict the acceptable x values (not None)

Parameters
  • pkt (packet.Packet|None) – the packet instance containing this field instance; probably unused. # noqa: E501

  • x (int) – the value to convert.

Returns

str: the converted value.