repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
secdev/scapy | scapy/layers/inet6.py | NDP_Attack_NA_Spoofing | def NDP_Attack_NA_Spoofing(iface=None, mac_src_filter=None, tgt_filter=None,
reply_mac=None, router=False):
"""
The main purpose of this function is to send fake Neighbor Advertisement
messages to a victim. As the emission of unsolicited Neighbor Advertisement
is pretty pointl... | python | def NDP_Attack_NA_Spoofing(iface=None, mac_src_filter=None, tgt_filter=None,
reply_mac=None, router=False):
"""
The main purpose of this function is to send fake Neighbor Advertisement
messages to a victim. As the emission of unsolicited Neighbor Advertisement
is pretty pointl... | [
"def",
"NDP_Attack_NA_Spoofing",
"(",
"iface",
"=",
"None",
",",
"mac_src_filter",
"=",
"None",
",",
"tgt_filter",
"=",
"None",
",",
"reply_mac",
"=",
"None",
",",
"router",
"=",
"False",
")",
":",
"def",
"is_request",
"(",
"req",
",",
"mac_src_filter",
",... | The main purpose of this function is to send fake Neighbor Advertisement
messages to a victim. As the emission of unsolicited Neighbor Advertisement
is pretty pointless (from an attacker standpoint) because it will not
lead to a modification of a victim's neighbor cache, the function send
advertisements... | [
"The",
"main",
"purpose",
"of",
"this",
"function",
"is",
"to",
"send",
"fake",
"Neighbor",
"Advertisement",
"messages",
"to",
"a",
"victim",
".",
"As",
"the",
"emission",
"of",
"unsolicited",
"Neighbor",
"Advertisement",
"is",
"pretty",
"pointless",
"(",
"fro... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet6.py#L3549-L3684 | train |
secdev/scapy | scapy/layers/inet6.py | NDP_Attack_NS_Spoofing | def NDP_Attack_NS_Spoofing(src_lladdr=None, src=None, target="2001:db8::1",
dst=None, src_mac=None, dst_mac=None, loop=True,
inter=1, iface=None):
"""
The main purpose of this function is to send fake Neighbor Solicitations
messages to a victim, in order... | python | def NDP_Attack_NS_Spoofing(src_lladdr=None, src=None, target="2001:db8::1",
dst=None, src_mac=None, dst_mac=None, loop=True,
inter=1, iface=None):
"""
The main purpose of this function is to send fake Neighbor Solicitations
messages to a victim, in order... | [
"def",
"NDP_Attack_NS_Spoofing",
"(",
"src_lladdr",
"=",
"None",
",",
"src",
"=",
"None",
",",
"target",
"=",
"\"2001:db8::1\"",
",",
"dst",
"=",
"None",
",",
"src_mac",
"=",
"None",
",",
"dst_mac",
"=",
"None",
",",
"loop",
"=",
"True",
",",
"inter",
... | The main purpose of this function is to send fake Neighbor Solicitations
messages to a victim, in order to either create a new entry in its neighbor
cache or update an existing one. In section 7.2.3 of RFC 4861, it is stated
that a node SHOULD create the entry or update an existing one (if it is not
cur... | [
"The",
"main",
"purpose",
"of",
"this",
"function",
"is",
"to",
"send",
"fake",
"Neighbor",
"Solicitations",
"messages",
"to",
"a",
"victim",
"in",
"order",
"to",
"either",
"create",
"a",
"new",
"entry",
"in",
"its",
"neighbor",
"cache",
"or",
"update",
"a... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet6.py#L3687-L3791 | train |
secdev/scapy | scapy/layers/inet6.py | NDP_Attack_Kill_Default_Router | def NDP_Attack_Kill_Default_Router(iface=None, mac_src_filter=None,
ip_src_filter=None, reply_mac=None,
tgt_mac=None):
"""
The purpose of the function is to monitor incoming RA messages
sent by default routers (RA with a non-zero Router L... | python | def NDP_Attack_Kill_Default_Router(iface=None, mac_src_filter=None,
ip_src_filter=None, reply_mac=None,
tgt_mac=None):
"""
The purpose of the function is to monitor incoming RA messages
sent by default routers (RA with a non-zero Router L... | [
"def",
"NDP_Attack_Kill_Default_Router",
"(",
"iface",
"=",
"None",
",",
"mac_src_filter",
"=",
"None",
",",
"ip_src_filter",
"=",
"None",
",",
"reply_mac",
"=",
"None",
",",
"tgt_mac",
"=",
"None",
")",
":",
"def",
"is_request",
"(",
"req",
",",
"mac_src_fi... | The purpose of the function is to monitor incoming RA messages
sent by default routers (RA with a non-zero Router Lifetime values)
and invalidate them by immediately replying with fake RA messages
advertising a zero Router Lifetime value.
The result on receivers is that the router is immediately invali... | [
"The",
"purpose",
"of",
"the",
"function",
"is",
"to",
"monitor",
"incoming",
"RA",
"messages",
"sent",
"by",
"default",
"routers",
"(",
"RA",
"with",
"a",
"non",
"-",
"zero",
"Router",
"Lifetime",
"values",
")",
"and",
"invalidate",
"them",
"by",
"immedia... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet6.py#L3794-L3913 | train |
secdev/scapy | scapy/layers/inet6.py | NDP_Attack_Fake_Router | def NDP_Attack_Fake_Router(ra, iface=None, mac_src_filter=None,
ip_src_filter=None):
"""
The purpose of this function is to send provided RA message at layer 2
(i.e. providing a packet starting with IPv6 will not work) in response
to received RS messages. In the end, the funct... | python | def NDP_Attack_Fake_Router(ra, iface=None, mac_src_filter=None,
ip_src_filter=None):
"""
The purpose of this function is to send provided RA message at layer 2
(i.e. providing a packet starting with IPv6 will not work) in response
to received RS messages. In the end, the funct... | [
"def",
"NDP_Attack_Fake_Router",
"(",
"ra",
",",
"iface",
"=",
"None",
",",
"mac_src_filter",
"=",
"None",
",",
"ip_src_filter",
"=",
"None",
")",
":",
"def",
"is_request",
"(",
"req",
",",
"mac_src_filter",
",",
"ip_src_filter",
")",
":",
"\"\"\"\n Che... | The purpose of this function is to send provided RA message at layer 2
(i.e. providing a packet starting with IPv6 will not work) in response
to received RS messages. In the end, the function is a simple wrapper
around sendp() that monitor the link for RS messages.
It is probably better explained with ... | [
"The",
"purpose",
"of",
"this",
"function",
"is",
"to",
"send",
"provided",
"RA",
"message",
"at",
"layer",
"2",
"(",
"i",
".",
"e",
".",
"providing",
"a",
"packet",
"starting",
"with",
"IPv6",
"will",
"not",
"work",
")",
"in",
"response",
"to",
"recei... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet6.py#L3916-L3994 | train |
secdev/scapy | scapy/layers/inet6.py | IPv6.route | def route(self):
"""Used to select the L2 address"""
dst = self.dst
if isinstance(dst, Gen):
dst = next(iter(dst))
return conf.route6.route(dst) | python | def route(self):
"""Used to select the L2 address"""
dst = self.dst
if isinstance(dst, Gen):
dst = next(iter(dst))
return conf.route6.route(dst) | [
"def",
"route",
"(",
"self",
")",
":",
"dst",
"=",
"self",
".",
"dst",
"if",
"isinstance",
"(",
"dst",
",",
"Gen",
")",
":",
"dst",
"=",
"next",
"(",
"iter",
"(",
"dst",
")",
")",
"return",
"conf",
".",
"route6",
".",
"route",
"(",
"dst",
")"
] | Used to select the L2 address | [
"Used",
"to",
"select",
"the",
"L2",
"address"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet6.py#L282-L287 | train |
secdev/scapy | scapy/layers/inet6.py | IPv6.extract_padding | def extract_padding(self, data):
"""Extract the IPv6 payload"""
if self.plen == 0 and self.nh == 0 and len(data) >= 8:
# Extract Hop-by-Hop extension length
hbh_len = orb(data[1])
hbh_len = 8 + hbh_len * 8
# Extract length from the Jumbogram option
... | python | def extract_padding(self, data):
"""Extract the IPv6 payload"""
if self.plen == 0 and self.nh == 0 and len(data) >= 8:
# Extract Hop-by-Hop extension length
hbh_len = orb(data[1])
hbh_len = 8 + hbh_len * 8
# Extract length from the Jumbogram option
... | [
"def",
"extract_padding",
"(",
"self",
",",
"data",
")",
":",
"if",
"self",
".",
"plen",
"==",
"0",
"and",
"self",
".",
"nh",
"==",
"0",
"and",
"len",
"(",
"data",
")",
">=",
"8",
":",
"# Extract Hop-by-Hop extension length",
"hbh_len",
"=",
"orb",
"("... | Extract the IPv6 payload | [
"Extract",
"the",
"IPv6",
"payload"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet6.py#L299-L329 | train |
secdev/scapy | scapy/layers/inet6.py | ICMPv6MLQuery2.post_build | def post_build(self, packet, payload):
"""Compute the 'sources_number' field when needed"""
if self.sources_number is None:
srcnum = struct.pack("!H", len(self.sources))
packet = packet[:26] + srcnum + packet[28:]
return _ICMPv6.post_build(self, packet, payload) | python | def post_build(self, packet, payload):
"""Compute the 'sources_number' field when needed"""
if self.sources_number is None:
srcnum = struct.pack("!H", len(self.sources))
packet = packet[:26] + srcnum + packet[28:]
return _ICMPv6.post_build(self, packet, payload) | [
"def",
"post_build",
"(",
"self",
",",
"packet",
",",
"payload",
")",
":",
"if",
"self",
".",
"sources_number",
"is",
"None",
":",
"srcnum",
"=",
"struct",
".",
"pack",
"(",
"\"!H\"",
",",
"len",
"(",
"self",
".",
"sources",
")",
")",
"packet",
"=",
... | Compute the 'sources_number' field when needed | [
"Compute",
"the",
"sources_number",
"field",
"when",
"needed"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet6.py#L1508-L1513 | train |
secdev/scapy | scapy/layers/inet6.py | ICMPv6MLReport2.post_build | def post_build(self, packet, payload):
"""Compute the 'records_number' field when needed"""
if self.records_number is None:
recnum = struct.pack("!H", len(self.records))
packet = packet[:6] + recnum + packet[8:]
return _ICMPv6.post_build(self, packet, payload) | python | def post_build(self, packet, payload):
"""Compute the 'records_number' field when needed"""
if self.records_number is None:
recnum = struct.pack("!H", len(self.records))
packet = packet[:6] + recnum + packet[8:]
return _ICMPv6.post_build(self, packet, payload) | [
"def",
"post_build",
"(",
"self",
",",
"packet",
",",
"payload",
")",
":",
"if",
"self",
".",
"records_number",
"is",
"None",
":",
"recnum",
"=",
"struct",
".",
"pack",
"(",
"\"!H\"",
",",
"len",
"(",
"self",
".",
"records",
")",
")",
"packet",
"=",
... | Compute the 'records_number' field when needed | [
"Compute",
"the",
"records_number",
"field",
"when",
"needed"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet6.py#L1550-L1555 | train |
secdev/scapy | scapy/tools/UTscapy.py | parse_config_file | def parse_config_file(config_path, verb=3):
"""Parse provided json to get configuration
Empty default json:
{
"testfiles": [],
"breakfailed": true,
"onlyfailed": false,
"verb": 3,
"dump": 0,
"crc": true,
"scapy": "scapy",
"preexec": {},
"global_preexec":... | python | def parse_config_file(config_path, verb=3):
"""Parse provided json to get configuration
Empty default json:
{
"testfiles": [],
"breakfailed": true,
"onlyfailed": false,
"verb": 3,
"dump": 0,
"crc": true,
"scapy": "scapy",
"preexec": {},
"global_preexec":... | [
"def",
"parse_config_file",
"(",
"config_path",
",",
"verb",
"=",
"3",
")",
":",
"import",
"json",
"import",
"unicodedata",
"with",
"open",
"(",
"config_path",
")",
"as",
"config_file",
":",
"data",
"=",
"json",
".",
"load",
"(",
"config_file",
",",
"encod... | Parse provided json to get configuration
Empty default json:
{
"testfiles": [],
"breakfailed": true,
"onlyfailed": false,
"verb": 3,
"dump": 0,
"crc": true,
"scapy": "scapy",
"preexec": {},
"global_preexec": "",
"outputfile": null,
"local": true,... | [
"Parse",
"provided",
"json",
"to",
"get",
"configuration",
"Empty",
"default",
"json",
":",
"{",
"testfiles",
":",
"[]",
"breakfailed",
":",
"true",
"onlyfailed",
":",
"false",
"verb",
":",
"3",
"dump",
":",
"0",
"crc",
":",
"true",
"scapy",
":",
"scapy"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/tools/UTscapy.py#L255-L302 | train |
secdev/scapy | scapy/contrib/dce_rpc.py | EndiannessField.set_endianess | def set_endianess(self, pkt):
"""Add the endianness to the format"""
end = self.endianess_from(pkt)
if isinstance(end, str) and end:
if isinstance(self.fld, UUIDField):
self.fld.uuid_fmt = (UUIDField.FORMAT_LE if end == '<'
else UU... | python | def set_endianess(self, pkt):
"""Add the endianness to the format"""
end = self.endianess_from(pkt)
if isinstance(end, str) and end:
if isinstance(self.fld, UUIDField):
self.fld.uuid_fmt = (UUIDField.FORMAT_LE if end == '<'
else UU... | [
"def",
"set_endianess",
"(",
"self",
",",
"pkt",
")",
":",
"end",
"=",
"self",
".",
"endianess_from",
"(",
"pkt",
")",
"if",
"isinstance",
"(",
"end",
",",
"str",
")",
"and",
"end",
":",
"if",
"isinstance",
"(",
"self",
".",
"fld",
",",
"UUIDField",
... | Add the endianness to the format | [
"Add",
"the",
"endianness",
"to",
"the",
"format"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/dce_rpc.py#L41-L51 | train |
secdev/scapy | scapy/contrib/dce_rpc.py | EndiannessField.getfield | def getfield(self, pkt, buf):
"""retrieve the field with endianness"""
self.set_endianess(pkt)
return self.fld.getfield(pkt, buf) | python | def getfield(self, pkt, buf):
"""retrieve the field with endianness"""
self.set_endianess(pkt)
return self.fld.getfield(pkt, buf) | [
"def",
"getfield",
"(",
"self",
",",
"pkt",
",",
"buf",
")",
":",
"self",
".",
"set_endianess",
"(",
"pkt",
")",
"return",
"self",
".",
"fld",
".",
"getfield",
"(",
"pkt",
",",
"buf",
")"
] | retrieve the field with endianness | [
"retrieve",
"the",
"field",
"with",
"endianness"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/dce_rpc.py#L53-L56 | train |
secdev/scapy | scapy/contrib/dce_rpc.py | EndiannessField.addfield | def addfield(self, pkt, buf, val):
"""add the field with endianness to the buffer"""
self.set_endianess(pkt)
return self.fld.addfield(pkt, buf, val) | python | def addfield(self, pkt, buf, val):
"""add the field with endianness to the buffer"""
self.set_endianess(pkt)
return self.fld.addfield(pkt, buf, val) | [
"def",
"addfield",
"(",
"self",
",",
"pkt",
",",
"buf",
",",
"val",
")",
":",
"self",
".",
"set_endianess",
"(",
"pkt",
")",
"return",
"self",
".",
"fld",
".",
"addfield",
"(",
"pkt",
",",
"buf",
",",
"val",
")"
] | add the field with endianness to the buffer | [
"add",
"the",
"field",
"with",
"endianness",
"to",
"the",
"buffer"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/dce_rpc.py#L58-L61 | train |
secdev/scapy | scapy/contrib/dce_rpc.py | DceRpcPayload.dispatch_hook | def dispatch_hook(cls, _pkt, _underlayer=None, *args, **kargs):
"""dispatch_hook to choose among different registered payloads"""
for klass in cls._payload_class:
if hasattr(klass, "can_handle") and \
klass.can_handle(_pkt, _underlayer):
return klass
... | python | def dispatch_hook(cls, _pkt, _underlayer=None, *args, **kargs):
"""dispatch_hook to choose among different registered payloads"""
for klass in cls._payload_class:
if hasattr(klass, "can_handle") and \
klass.can_handle(_pkt, _underlayer):
return klass
... | [
"def",
"dispatch_hook",
"(",
"cls",
",",
"_pkt",
",",
"_underlayer",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kargs",
")",
":",
"for",
"klass",
"in",
"cls",
".",
"_payload_class",
":",
"if",
"hasattr",
"(",
"klass",
",",
"\"can_handle\"",
")",
... | dispatch_hook to choose among different registered payloads | [
"dispatch_hook",
"to",
"choose",
"among",
"different",
"registered",
"payloads"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/dce_rpc.py#L145-L152 | train |
secdev/scapy | scapy/contrib/http2.py | AbstractUVarIntField._detect_multi_byte | def _detect_multi_byte(self, fb):
# type: (str) -> bool
""" _detect_multi_byte returns whether the AbstractUVarIntField is represented on # noqa: E501
multiple bytes or not.
A multibyte representation is indicated by all of the first size bits being set # noqa: E501
@para... | python | def _detect_multi_byte(self, fb):
# type: (str) -> bool
""" _detect_multi_byte returns whether the AbstractUVarIntField is represented on # noqa: E501
multiple bytes or not.
A multibyte representation is indicated by all of the first size bits being set # noqa: E501
@para... | [
"def",
"_detect_multi_byte",
"(",
"self",
",",
"fb",
")",
":",
"# type: (str) -> bool",
"assert",
"(",
"isinstance",
"(",
"fb",
",",
"int",
")",
"or",
"len",
"(",
"fb",
")",
"==",
"1",
")",
"return",
"(",
"orb",
"(",
"fb",
")",
"&",
"self",
".",
"_... | _detect_multi_byte returns whether the AbstractUVarIntField is represented on # noqa: E501
multiple bytes or not.
A multibyte representation is indicated by all of the first size bits being set # noqa: E501
@param str fb: first byte, as a character.
@return bool: True if multibyt... | [
"_detect_multi_byte",
"returns",
"whether",
"the",
"AbstractUVarIntField",
"is",
"represented",
"on",
"#",
"noqa",
":",
"E501",
"multiple",
"bytes",
"or",
"not",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L234-L246 | train |
secdev/scapy | scapy/contrib/http2.py | AbstractUVarIntField._parse_multi_byte | def _parse_multi_byte(self, s):
# type: (str) -> int
""" _parse_multi_byte parses x as a multibyte representation to get the
int value of this AbstractUVarIntField.
@param str s: the multibyte string to parse.
@return int: The parsed int value represented by this AbstractUVarI... | python | def _parse_multi_byte(self, s):
# type: (str) -> int
""" _parse_multi_byte parses x as a multibyte representation to get the
int value of this AbstractUVarIntField.
@param str s: the multibyte string to parse.
@return int: The parsed int value represented by this AbstractUVarI... | [
"def",
"_parse_multi_byte",
"(",
"self",
",",
"s",
")",
":",
"# type: (str) -> int",
"assert",
"(",
"len",
"(",
"s",
")",
">=",
"2",
")",
"tmp_len",
"=",
"len",
"(",
"s",
")",
"value",
"=",
"0",
"i",
"=",
"1",
"byte",
"=",
"orb",
"(",
"s",
"[",
... | _parse_multi_byte parses x as a multibyte representation to get the
int value of this AbstractUVarIntField.
@param str s: the multibyte string to parse.
@return int: The parsed int value represented by this AbstractUVarIntField. # noqa: E501
@raise: AssertionError
@raise: Sca... | [
"_parse_multi_byte",
"parses",
"x",
"as",
"a",
"multibyte",
"representation",
"to",
"get",
"the",
"int",
"value",
"of",
"this",
"AbstractUVarIntField",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L248-L282 | train |
secdev/scapy | scapy/contrib/http2.py | AbstractUVarIntField.m2i | def m2i(self, pkt, x):
# type: (Optional[packet.Packet], Union[str, Tuple[str, int]]) -> int
"""
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... | python | def m2i(self, pkt, x):
# type: (Optional[packet.Packet], Union[str, Tuple[str, int]]) -> int
"""
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... | [
"def",
"m2i",
"(",
"self",
",",
"pkt",
",",
"x",
")",
":",
"# type: (Optional[packet.Packet], Union[str, Tuple[str, int]]) -> int",
"assert",
"(",
"isinstance",
"(",
"x",
",",
"bytes",
")",
"or",
"(",
"isinstance",
"(",
"x",
",",
"tuple",
")",
"and",
"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".
@param packet.Packet|None pkt: un... | [
"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",
".",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L284-L310 | train |
secdev/scapy | scapy/contrib/http2.py | AbstractUVarIntField.any2i | def any2i(self, pkt, x):
# type: (Optional[packet.Packet], Union[None, str, int]) -> Optional[int] # noqa: E501
"""
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.
@param pack... | python | def any2i(self, pkt, x):
# type: (Optional[packet.Packet], Union[None, str, int]) -> Optional[int] # noqa: E501
"""
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.
@param pack... | [
"def",
"any2i",
"(",
"self",
",",
"pkt",
",",
"x",
")",
":",
"# type: (Optional[packet.Packet], Union[None, str, int]) -> Optional[int] # noqa: E501",
"if",
"isinstance",
"(",
"x",
",",
"type",
"(",
"None",
")",
")",
":",
"return",
"x",
"if",
"isinstance",
"(",
... | 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.
@param packet.Packet|None pkt: the packet containing this field; probably unused. # noqa: E501
@param str|int|None x: the value to convert.
... | [
"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",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L335-L357 | train |
secdev/scapy | scapy/contrib/http2.py | AbstractUVarIntField.addfield | def addfield(self, pkt, s, val):
# type: (Optional[packet.Packet], Union[str, Tuple[str, int, int]], int) -> str # noqa: E501
""" 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 leng... | python | def addfield(self, pkt, s, val):
# type: (Optional[packet.Packet], Union[str, Tuple[str, int, int]], int) -> str # noqa: E501
""" 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 leng... | [
"def",
"addfield",
"(",
"self",
",",
"pkt",
",",
"s",
",",
"val",
")",
":",
"# type: (Optional[packet.Packet], Union[str, Tuple[str, int, int]], int) -> str # noqa: E501",
"assert",
"(",
"val",
">=",
"0",
")",
"if",
"isinstance",
"(",
"s",
",",
"bytes",
")",
":",... | 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
@param packet.Packet|None pkt: the packet containing this field. Probably unuse... | [
"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"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L368-L397 | train |
secdev/scapy | scapy/contrib/http2.py | AbstractUVarIntField._detect_bytelen_from_str | def _detect_bytelen_from_str(s):
# type: (str) -> int
""" _detect_bytelen_from_str returns the length of the machine
representation of an AbstractUVarIntField starting at the beginning
of s and which is assumed to expand over multiple bytes
(value > _max_prefix_value).
... | python | def _detect_bytelen_from_str(s):
# type: (str) -> int
""" _detect_bytelen_from_str returns the length of the machine
representation of an AbstractUVarIntField starting at the beginning
of s and which is assumed to expand over multiple bytes
(value > _max_prefix_value).
... | [
"def",
"_detect_bytelen_from_str",
"(",
"s",
")",
":",
"# type: (str) -> int",
"assert",
"(",
"len",
"(",
"s",
")",
">=",
"2",
")",
"tmp_len",
"=",
"len",
"(",
"s",
")",
"i",
"=",
"1",
"while",
"orb",
"(",
"s",
"[",
"i",
"]",
")",
"&",
"0x80",
">... | _detect_bytelen_from_str returns the length of the machine
representation of an AbstractUVarIntField starting at the beginning
of s and which is assumed to expand over multiple bytes
(value > _max_prefix_value).
@param str s: the string to parse. It is assumed that it is a multiby... | [
"_detect_bytelen_from_str",
"returns",
"the",
"length",
"of",
"the",
"machine",
"representation",
"of",
"an",
"AbstractUVarIntField",
"starting",
"at",
"the",
"beginning",
"of",
"s",
"and",
"which",
"is",
"assumed",
"to",
"expand",
"over",
"multiple",
"bytes",
"("... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L400-L421 | train |
secdev/scapy | scapy/contrib/http2.py | UVarIntField.h2i | def h2i(self, pkt, x):
# type: (Optional[packet.Packet], int) -> int
""" h2i is overloaded to restrict the acceptable x values (not None)
@param packet.Packet|None pkt: the packet instance containing this field instance; probably unused. # noqa: E501
@param int x: the value to convert.... | python | def h2i(self, pkt, x):
# type: (Optional[packet.Packet], int) -> int
""" h2i is overloaded to restrict the acceptable x values (not None)
@param packet.Packet|None pkt: the packet instance containing this field instance; probably unused. # noqa: E501
@param int x: the value to convert.... | [
"def",
"h2i",
"(",
"self",
",",
"pkt",
",",
"x",
")",
":",
"# type: (Optional[packet.Packet], int) -> int",
"ret",
"=",
"super",
"(",
"UVarIntField",
",",
"self",
")",
".",
"h2i",
"(",
"pkt",
",",
"x",
")",
"assert",
"(",
"not",
"isinstance",
"(",
"ret",... | h2i is overloaded to restrict the acceptable x values (not None)
@param packet.Packet|None pkt: the packet instance containing this field instance; probably unused. # noqa: E501
@param int x: the value to convert.
@return int: the converted value.
@raise AssertionError | [
"h2i",
"is",
"overloaded",
"to",
"restrict",
"the",
"acceptable",
"x",
"values",
"(",
"not",
"None",
")"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L504-L515 | train |
secdev/scapy | scapy/contrib/http2.py | UVarIntField.i2repr | def i2repr(self, pkt, x):
# type: (Optional[packet.Packet], int) -> str
""" i2repr is overloaded to restrict the acceptable x values (not None)
@param packet.Packet|None pkt: the packet instance containing this field instance; probably unused. # noqa: E501
@param int x: the value to co... | python | def i2repr(self, pkt, x):
# type: (Optional[packet.Packet], int) -> str
""" i2repr is overloaded to restrict the acceptable x values (not None)
@param packet.Packet|None pkt: the packet instance containing this field instance; probably unused. # noqa: E501
@param int x: the value to co... | [
"def",
"i2repr",
"(",
"self",
",",
"pkt",
",",
"x",
")",
":",
"# type: (Optional[packet.Packet], int) -> str",
"return",
"super",
"(",
"UVarIntField",
",",
"self",
")",
".",
"i2repr",
"(",
"pkt",
",",
"x",
")"
] | i2repr is overloaded to restrict the acceptable x values (not None)
@param packet.Packet|None pkt: the packet instance containing this field instance; probably unused. # noqa: E501
@param int x: the value to convert.
@return str: the converted value. | [
"i2repr",
"is",
"overloaded",
"to",
"restrict",
"the",
"acceptable",
"x",
"values",
"(",
"not",
"None",
")"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L543-L551 | train |
secdev/scapy | scapy/contrib/http2.py | FieldUVarLenField._compute_value | def _compute_value(self, pkt):
# type: (packet.Packet) -> int
""" Computes the value of this field based on the provided packet and
the length_of field and the adjust callback
@param packet.Packet pkt: the packet from which is computed this field value. # noqa: E501
@return int... | python | def _compute_value(self, pkt):
# type: (packet.Packet) -> int
""" Computes the value of this field based on the provided packet and
the length_of field and the adjust callback
@param packet.Packet pkt: the packet from which is computed this field value. # noqa: E501
@return int... | [
"def",
"_compute_value",
"(",
"self",
",",
"pkt",
")",
":",
"# type: (packet.Packet) -> int",
"fld",
",",
"fval",
"=",
"pkt",
".",
"getfield_and_val",
"(",
"self",
".",
"_length_of",
")",
"val",
"=",
"fld",
".",
"i2len",
"(",
"pkt",
",",
"fval",
")",
"re... | Computes the value of this field based on the provided packet and
the length_of field and the adjust callback
@param packet.Packet pkt: the packet from which is computed this field value. # noqa: E501
@return int: the computed value for this field.
@raise KeyError: the packet nor its p... | [
"Computes",
"the",
"value",
"of",
"this",
"field",
"based",
"on",
"the",
"provided",
"packet",
"and",
"the",
"length_of",
"field",
"and",
"the",
"adjust",
"callback"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L616-L632 | train |
secdev/scapy | scapy/contrib/http2.py | HPackZString._huffman_encode_char | def _huffman_encode_char(cls, c):
# type: (Union[str, EOS]) -> Tuple[int, int]
""" huffman_encode_char assumes that the static_huffman_tree was
previously initialized
@param str|EOS c: a symbol to encode
@return (int, int): the bitstring of the symbol and its bitlength
@... | python | def _huffman_encode_char(cls, c):
# type: (Union[str, EOS]) -> Tuple[int, int]
""" huffman_encode_char assumes that the static_huffman_tree was
previously initialized
@param str|EOS c: a symbol to encode
@return (int, int): the bitstring of the symbol and its bitlength
@... | [
"def",
"_huffman_encode_char",
"(",
"cls",
",",
"c",
")",
":",
"# type: (Union[str, EOS]) -> Tuple[int, int]",
"if",
"isinstance",
"(",
"c",
",",
"EOS",
")",
":",
"return",
"cls",
".",
"static_huffman_code",
"[",
"-",
"1",
"]",
"else",
":",
"assert",
"(",
"i... | huffman_encode_char assumes that the static_huffman_tree was
previously initialized
@param str|EOS c: a symbol to encode
@return (int, int): the bitstring of the symbol and its bitlength
@raise AssertionError | [
"huffman_encode_char",
"assumes",
"that",
"the",
"static_huffman_tree",
"was",
"previously",
"initialized"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1009-L1022 | train |
secdev/scapy | scapy/contrib/http2.py | HPackZString.huffman_encode | def huffman_encode(cls, s):
# type: (str) -> Tuple[int, int]
""" huffman_encode returns the bitstring and the bitlength of the
bitstring representing the string provided as a parameter
@param str s: the string to encode
@return (int, int): the bitstring of s and its bitlength
... | python | def huffman_encode(cls, s):
# type: (str) -> Tuple[int, int]
""" huffman_encode returns the bitstring and the bitlength of the
bitstring representing the string provided as a parameter
@param str s: the string to encode
@return (int, int): the bitstring of s and its bitlength
... | [
"def",
"huffman_encode",
"(",
"cls",
",",
"s",
")",
":",
"# type: (str) -> Tuple[int, int]",
"i",
"=",
"0",
"ibl",
"=",
"0",
"for",
"c",
"in",
"s",
":",
"val",
",",
"bl",
"=",
"cls",
".",
"_huffman_encode_char",
"(",
"c",
")",
"i",
"=",
"(",
"i",
"... | huffman_encode returns the bitstring and the bitlength of the
bitstring representing the string provided as a parameter
@param str s: the string to encode
@return (int, int): the bitstring of s and its bitlength
@raise AssertionError | [
"huffman_encode",
"returns",
"the",
"bitstring",
"and",
"the",
"bitlength",
"of",
"the",
"bitstring",
"representing",
"the",
"string",
"provided",
"as",
"a",
"parameter"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1025-L1050 | train |
secdev/scapy | scapy/contrib/http2.py | HPackZString.huffman_decode | def huffman_decode(cls, i, ibl):
# type: (int, int) -> str
""" huffman_decode decodes the bitstring provided as parameters.
@param int i: the bitstring to decode
@param int ibl: the bitlength of i
@return str: the string decoded from the bitstring
@raise AssertionError, ... | python | def huffman_decode(cls, i, ibl):
# type: (int, int) -> str
""" huffman_decode decodes the bitstring provided as parameters.
@param int i: the bitstring to decode
@param int ibl: the bitlength of i
@return str: the string decoded from the bitstring
@raise AssertionError, ... | [
"def",
"huffman_decode",
"(",
"cls",
",",
"i",
",",
"ibl",
")",
":",
"# type: (int, int) -> str",
"assert",
"(",
"i",
">=",
"0",
")",
"assert",
"(",
"ibl",
">=",
"0",
")",
"if",
"isinstance",
"(",
"cls",
".",
"static_huffman_tree",
",",
"type",
"(",
"N... | huffman_decode decodes the bitstring provided as parameters.
@param int i: the bitstring to decode
@param int ibl: the bitlength of i
@return str: the string decoded from the bitstring
@raise AssertionError, InvalidEncodingException | [
"huffman_decode",
"decodes",
"the",
"bitstring",
"provided",
"as",
"parameters",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1053-L1108 | train |
secdev/scapy | scapy/contrib/http2.py | HPackZString.huffman_conv2str | def huffman_conv2str(cls, bit_str, bit_len):
# type: (int, int) -> str
""" huffman_conv2str converts a bitstring of bit_len bitlength into a
binary string. It DOES NOT compress/decompress the bitstring!
@param int bit_str: the bitstring to convert.
@param int bit_len: the bitlen... | python | def huffman_conv2str(cls, bit_str, bit_len):
# type: (int, int) -> str
""" huffman_conv2str converts a bitstring of bit_len bitlength into a
binary string. It DOES NOT compress/decompress the bitstring!
@param int bit_str: the bitstring to convert.
@param int bit_len: the bitlen... | [
"def",
"huffman_conv2str",
"(",
"cls",
",",
"bit_str",
",",
"bit_len",
")",
":",
"# type: (int, int) -> str",
"assert",
"(",
"bit_str",
">=",
"0",
")",
"assert",
"(",
"bit_len",
">=",
"0",
")",
"byte_len",
"=",
"bit_len",
"//",
"8",
"rem_bit",
"=",
"bit_le... | huffman_conv2str converts a bitstring of bit_len bitlength into a
binary string. It DOES NOT compress/decompress the bitstring!
@param int bit_str: the bitstring to convert.
@param int bit_len: the bitlength of bit_str.
@return str: the converted bitstring as a bytestring.
@rais... | [
"huffman_conv2str",
"converts",
"a",
"bitstring",
"of",
"bit_len",
"bitlength",
"into",
"a",
"binary",
"string",
".",
"It",
"DOES",
"NOT",
"compress",
"/",
"decompress",
"the",
"bitstring!"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1111-L1137 | train |
secdev/scapy | scapy/contrib/http2.py | HPackZString.huffman_conv2bitstring | def huffman_conv2bitstring(cls, s):
# type: (str) -> Tuple[int, int]
""" 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!
@param str s: the byte... | python | def huffman_conv2bitstring(cls, s):
# type: (str) -> Tuple[int, int]
""" 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!
@param str s: the byte... | [
"def",
"huffman_conv2bitstring",
"(",
"cls",
",",
"s",
")",
":",
"# type: (str) -> Tuple[int, int]",
"i",
"=",
"0",
"ibl",
"=",
"len",
"(",
"s",
")",
"*",
"8",
"for",
"c",
"in",
"s",
":",
"i",
"=",
"(",
"i",
"<<",
"8",
")",
"+",
"orb",
"(",
"c",
... | 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!
@param str s: the bytestring to convert.
@return (int, int): the bitstring of s, and its bitlength.
... | [
"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... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1140-L1158 | train |
secdev/scapy | scapy/contrib/http2.py | HPackZString.huffman_compute_decode_tree | def huffman_compute_decode_tree(cls):
# type: () -> None
""" huffman_compute_decode_tree initializes/builds the static_huffman_tree
@return None
@raise InvalidEncodingException if there is an encoding problem
"""
cls.static_huffman_tree = HuffmanNode(None, None)
... | python | def huffman_compute_decode_tree(cls):
# type: () -> None
""" huffman_compute_decode_tree initializes/builds the static_huffman_tree
@return None
@raise InvalidEncodingException if there is an encoding problem
"""
cls.static_huffman_tree = HuffmanNode(None, None)
... | [
"def",
"huffman_compute_decode_tree",
"(",
"cls",
")",
":",
"# type: () -> None",
"cls",
".",
"static_huffman_tree",
"=",
"HuffmanNode",
"(",
"None",
",",
"None",
")",
"i",
"=",
"0",
"for",
"entry",
"in",
"cls",
".",
"static_huffman_code",
":",
"parent",
"=",
... | huffman_compute_decode_tree initializes/builds the static_huffman_tree
@return None
@raise InvalidEncodingException if there is an encoding problem | [
"huffman_compute_decode_tree",
"initializes",
"/",
"builds",
"the",
"static_huffman_tree"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1161-L1181 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHdrString.self_build | def self_build(self, field_pos_list=None):
# type: (Any) -> str
"""self_build is overridden because type and len are determined at
build time, based on the "data" field internal type
"""
if self.getfieldval('type') is None:
self.type = 1 if isinstance(self.getfieldval... | python | def self_build(self, field_pos_list=None):
# type: (Any) -> str
"""self_build is overridden because type and len are determined at
build time, based on the "data" field internal type
"""
if self.getfieldval('type') is None:
self.type = 1 if isinstance(self.getfieldval... | [
"def",
"self_build",
"(",
"self",
",",
"field_pos_list",
"=",
"None",
")",
":",
"# type: (Any) -> str",
"if",
"self",
".",
"getfieldval",
"(",
"'type'",
")",
"is",
"None",
":",
"self",
".",
"type",
"=",
"1",
"if",
"isinstance",
"(",
"self",
".",
"getfiel... | self_build is overridden because type and len are determined at
build time, based on the "data" field internal type | [
"self_build",
"is",
"overridden",
"because",
"type",
"and",
"len",
"are",
"determined",
"at",
"build",
"time",
"based",
"on",
"the",
"data",
"field",
"internal",
"type"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1330-L1337 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHeaders.dispatch_hook | def dispatch_hook(cls, s=None, *_args, **_kwds):
# type: (Optional[str], *Any, **Any) -> base_classes.Packet_metaclass
"""dispatch_hook returns the subclass of HPackHeaders that must be used
to dissect the string.
"""
if s is None:
return config.conf.raw_layer
... | python | def dispatch_hook(cls, s=None, *_args, **_kwds):
# type: (Optional[str], *Any, **Any) -> base_classes.Packet_metaclass
"""dispatch_hook returns the subclass of HPackHeaders that must be used
to dissect the string.
"""
if s is None:
return config.conf.raw_layer
... | [
"def",
"dispatch_hook",
"(",
"cls",
",",
"s",
"=",
"None",
",",
"*",
"_args",
",",
"*",
"*",
"_kwds",
")",
":",
"# type: (Optional[str], *Any, **Any) -> base_classes.Packet_metaclass",
"if",
"s",
"is",
"None",
":",
"return",
"config",
".",
"conf",
".",
"raw_la... | dispatch_hook returns the subclass of HPackHeaders that must be used
to dissect the string. | [
"dispatch_hook",
"returns",
"the",
"subclass",
"of",
"HPackHeaders",
"that",
"must",
"be",
"used",
"to",
"dissect",
"the",
"string",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1346-L1360 | train |
secdev/scapy | scapy/contrib/http2.py | H2PaddedDataFrame.get_data_len | def get_data_len(self):
# type: () -> int
""" 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
... | python | def get_data_len(self):
# type: () -> int
""" 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
... | [
"def",
"get_data_len",
"(",
"self",
")",
":",
"# type: () -> int",
"padding_len",
"=",
"self",
".",
"getfieldval",
"(",
"'padlen'",
")",
"fld",
",",
"fval",
"=",
"self",
".",
"getfield_and_val",
"(",
"'padlen'",
")",
"padding_len_len",
"=",
"fld",
".",
"i2le... | 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 fra... | [
"get_data_len",
"computes",
"the",
"length",
"of",
"the",
"data",
"field"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1469-L1485 | train |
secdev/scapy | scapy/contrib/http2.py | H2PaddedPriorityHeadersFrame.get_hdrs_len | def get_hdrs_len(self):
# type: () -> int
""" 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... | python | def get_hdrs_len(self):
# type: () -> int
""" 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... | [
"def",
"get_hdrs_len",
"(",
"self",
")",
":",
"# type: () -> int",
"padding_len",
"=",
"self",
".",
"getfieldval",
"(",
"'padlen'",
")",
"fld",
",",
"fval",
"=",
"self",
".",
"getfield_and_val",
"(",
"'padlen'",
")",
"padding_len_len",
"=",
"fld",
".",
"i2le... | 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 hdr... | [
"get_hdrs_len",
"computes",
"the",
"length",
"of",
"the",
"hdrs",
"field"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1619-L1644 | train |
secdev/scapy | scapy/contrib/http2.py | H2PaddedPushPromiseFrame.get_hdrs_len | def get_hdrs_len(self):
# type: () -> int
""" 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 par... | python | def get_hdrs_len(self):
# type: () -> int
""" 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 par... | [
"def",
"get_hdrs_len",
"(",
"self",
")",
":",
"# type: () -> int",
"fld",
",",
"padding_len",
"=",
"self",
".",
"getfield_and_val",
"(",
"'padlen'",
")",
"padding_len_len",
"=",
"fld",
".",
"i2len",
"(",
"self",
",",
"padding_len",
")",
"bit_len",
"=",
"self... | 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
... | [
"get_hdrs_len",
"computes",
"the",
"length",
"of",
"the",
"hdrs",
"field"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1834-L1855 | train |
secdev/scapy | scapy/contrib/http2.py | H2Frame.guess_payload_class | def guess_payload_class(self, payload):
# type: (str) -> base_classes.Packet_metaclass
""" 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
per... | python | def guess_payload_class(self, payload):
# type: (str) -> base_classes.Packet_metaclass
""" 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
per... | [
"def",
"guess_payload_class",
"(",
"self",
",",
"payload",
")",
":",
"# type: (str) -> base_classes.Packet_metaclass",
"if",
"len",
"(",
"payload",
")",
"==",
"0",
":",
"return",
"packet",
".",
"NoPayload",
"t",
"=",
"self",
".",
"getfieldval",
"(",
"'type'",
... | 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 ... | [
"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",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1999-L2054 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHdrTable.resize | def resize(self, ns):
# type: (int) -> None
"""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
@ra... | python | def resize(self, ns):
# type: (int) -> None
"""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
@ra... | [
"def",
"resize",
"(",
"self",
",",
"ns",
")",
":",
"# type: (int) -> None",
"assert",
"0",
"<=",
"ns",
"<=",
"self",
".",
"_dynamic_table_cap_size",
",",
"'EINVAL: ns: out-of-range value; expected value is in the range [0;{}['",
".",
"format",
"(",
"self",
".",
"_dyna... | 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
@raise AssertionError | [
"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",... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2312-L2326 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHdrTable.recap | def recap(self, nc):
# type: (int) -> None
"""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
... | python | def recap(self, nc):
# type: (int) -> None
"""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
... | [
"def",
"recap",
"(",
"self",
",",
"nc",
")",
":",
"# type: (int) -> None",
"assert",
"(",
"nc",
">=",
"0",
")",
"t",
"=",
"self",
".",
"_dynamic_table_cap_size",
">",
"nc",
"self",
".",
"_dynamic_table_cap_size",
"=",
"nc",
"if",
"t",
":",
"# The RFC is no... | 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
@raise AssertionError | [
"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",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2328-L2342 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHdrTable._reduce_dynamic_table | def _reduce_dynamic_table(self, new_entry_size=0):
# type: (int) -> None
"""_reduce_dynamic_table evicts entries from the dynamic table until it
fits in less than the current size limit. The optional parameter,
new_entry_size, allows the resize to happen so that a new entry of this
... | python | def _reduce_dynamic_table(self, new_entry_size=0):
# type: (int) -> None
"""_reduce_dynamic_table evicts entries from the dynamic table until it
fits in less than the current size limit. The optional parameter,
new_entry_size, allows the resize to happen so that a new entry of this
... | [
"def",
"_reduce_dynamic_table",
"(",
"self",
",",
"new_entry_size",
"=",
"0",
")",
":",
"# type: (int) -> None",
"assert",
"(",
"new_entry_size",
">=",
"0",
")",
"cur_sz",
"=",
"len",
"(",
"self",
")",
"dyn_tbl_sz",
"=",
"len",
"(",
"self",
".",
"_dynamic_ta... | _reduce_dynamic_table evicts entries from the dynamic table until it
fits in less than the current size limit. The optional parameter,
new_entry_size, allows the resize to happen so that a new entry of this
size fits in.
@param int new_entry_size: if called before adding a new entry, the... | [
"_reduce_dynamic_table",
"evicts",
"entries",
"from",
"the",
"dynamic",
"table",
"until",
"it",
"fits",
"in",
"less",
"than",
"the",
"current",
"size",
"limit",
".",
"The",
"optional",
"parameter",
"new_entry_size",
"allows",
"the",
"resize",
"to",
"happen",
"so... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2344-L2361 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHdrTable.register | def register(self, hdrs):
# type: (Union[HPackLitHdrFldWithIncrIndexing, H2Frame, List[HPackHeaders]]) -> None # noqa: E501
"""register adds to this table the instances of
HPackLitHdrFldWithIncrIndexing provided as parameters.
A H2Frame with a H2HeadersFrame payload can be provided, as... | python | def register(self, hdrs):
# type: (Union[HPackLitHdrFldWithIncrIndexing, H2Frame, List[HPackHeaders]]) -> None # noqa: E501
"""register adds to this table the instances of
HPackLitHdrFldWithIncrIndexing provided as parameters.
A H2Frame with a H2HeadersFrame payload can be provided, as... | [
"def",
"register",
"(",
"self",
",",
"hdrs",
")",
":",
"# type: (Union[HPackLitHdrFldWithIncrIndexing, H2Frame, List[HPackHeaders]]) -> None # noqa: E501",
"if",
"isinstance",
"(",
"hdrs",
",",
"H2Frame",
")",
":",
"hdrs",
"=",
"[",
"hdr",
"for",
"hdr",
"in",
"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 HPackLitHdrFldWithInc... | [
"register",
"adds",
"to",
"this",
"table",
"the",
"instances",
"of",
"HPackLitHdrFldWithIncrIndexing",
"provided",
"as",
"parameters",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2363-L2407 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHdrTable.get_idx_by_name | def get_idx_by_name(self, name):
# type: (str) -> Optional[int]
""" 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,... | python | def get_idx_by_name(self, name):
# type: (str) -> Optional[int]
""" 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,... | [
"def",
"get_idx_by_name",
"(",
"self",
",",
"name",
")",
":",
"# type: (str) -> Optional[int]",
"name",
"=",
"name",
".",
"lower",
"(",
")",
"for",
"key",
",",
"val",
"in",
"six",
".",
"iteritems",
"(",
"type",
"(",
"self",
")",
".",
"_static_entries",
"... | 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 retur... | [
"get_idx_by_name",
"returns",
"the",
"index",
"of",
"a",
"matching",
"registered",
"header"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2409-L2426 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHdrTable.gen_txt_repr | def gen_txt_repr(self, hdrs, register=True):
# type: (Union[H2Frame, List[HPackHeaders]], Optional[bool]) -> str
""" 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.
@para... | python | def gen_txt_repr(self, hdrs, register=True):
# type: (Union[H2Frame, List[HPackHeaders]], Optional[bool]) -> str
""" 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.
@para... | [
"def",
"gen_txt_repr",
"(",
"self",
",",
"hdrs",
",",
"register",
"=",
"True",
")",
":",
"# type: (Union[H2Frame, List[HPackHeaders]], Optional[bool]) -> str",
"lst",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"hdrs",
",",
"H2Frame",
")",
":",
"hdrs",
"=",
"hdrs",
... | 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.
@param H2Frame|list of HPackHeaders hdrs: the list of headers to convert to textual representation # noqa: E501
@param bool: whet... | [
"gen_txt_repr",
"returns",
"a",
"textual",
"representation",
"of",
"the",
"provided",
"headers",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2453-L2501 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHdrTable._convert_a_header_to_a_h2_header | def _convert_a_header_to_a_h2_header(self, hdr_name, hdr_value, is_sensitive, should_index): # noqa: E501
# type: (str, str, Callable[[str, str], bool], Callable[[str], bool]) -> Tuple[HPackHeaders, int] # noqa: E501
""" _convert_a_header_to_a_h2_header builds a HPackHeaders from a header
name... | python | def _convert_a_header_to_a_h2_header(self, hdr_name, hdr_value, is_sensitive, should_index): # noqa: E501
# type: (str, str, Callable[[str, str], bool], Callable[[str], bool]) -> Tuple[HPackHeaders, int] # noqa: E501
""" _convert_a_header_to_a_h2_header builds a HPackHeaders from a header
name... | [
"def",
"_convert_a_header_to_a_h2_header",
"(",
"self",
",",
"hdr_name",
",",
"hdr_value",
",",
"is_sensitive",
",",
"should_index",
")",
":",
"# noqa: E501",
"# type: (str, str, Callable[[str, str], bool], Callable[[str], bool]) -> Tuple[HPackHeaders, int] # noqa: E501",
"# If both... | _convert_a_header_to_a_h2_header builds a HPackHeaders from a header
name and a value. It returns a HPackIndexedHdr whenever possible. If not, # noqa: E501
it returns a HPackLitHdrFldWithoutIndexing or a
HPackLitHdrFldWithIncrIndexing, based on the should_index callback.
HPackLitHdrFldW... | [
"_convert_a_header_to_a_h2_header",
"builds",
"a",
"HPackHeaders",
"from",
"a",
"header",
"name",
"and",
"a",
"value",
".",
"It",
"returns",
"a",
"HPackIndexedHdr",
"whenever",
"possible",
".",
"If",
"not",
"#",
"noqa",
":",
"E501",
"it",
"returns",
"a",
"HPac... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2512-L2605 | train |
secdev/scapy | scapy/contrib/http2.py | HPackHdrTable.parse_txt_hdrs | def parse_txt_hdrs(self,
s, # type: str
stream_id=1, # type: int
body=None, # type: Optional[str]
max_frm_sz=4096, # type: int
max_hdr_lst_sz=0, # type: int
is_sensitive=lambda ... | python | def parse_txt_hdrs(self,
s, # type: str
stream_id=1, # type: int
body=None, # type: Optional[str]
max_frm_sz=4096, # type: int
max_hdr_lst_sz=0, # type: int
is_sensitive=lambda ... | [
"def",
"parse_txt_hdrs",
"(",
"self",
",",
"s",
",",
"# type: str",
"stream_id",
"=",
"1",
",",
"# type: int",
"body",
"=",
"None",
",",
"# type: Optional[str]",
"max_frm_sz",
"=",
"4096",
",",
"# type: int",
"max_hdr_lst_sz",
"=",
"0",
",",
"# type: int",
"is... | 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 frame... | [
"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",
"ca... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2625-L2730 | train |
secdev/scapy | scapy/contrib/diameter.py | AVP | def AVP(avpId, **fields):
""" Craft an AVP based on its id and optional parameter fields"""
val = None
classType = AVP_Unknown
if isinstance(avpId, str):
try:
for vnd in AvpDefDict:
for code in AvpDefDict[vnd]:
val = AvpDefDict[vnd][code]
... | python | def AVP(avpId, **fields):
""" Craft an AVP based on its id and optional parameter fields"""
val = None
classType = AVP_Unknown
if isinstance(avpId, str):
try:
for vnd in AvpDefDict:
for code in AvpDefDict[vnd]:
val = AvpDefDict[vnd][code]
... | [
"def",
"AVP",
"(",
"avpId",
",",
"*",
"*",
"fields",
")",
":",
"val",
"=",
"None",
"classType",
"=",
"AVP_Unknown",
"if",
"isinstance",
"(",
"avpId",
",",
"str",
")",
":",
"try",
":",
"for",
"vnd",
"in",
"AvpDefDict",
":",
"for",
"code",
"in",
"Avp... | Craft an AVP based on its id and optional parameter fields | [
"Craft",
"an",
"AVP",
"based",
"on",
"its",
"id",
"and",
"optional",
"parameter",
"fields"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/diameter.py#L391-L440 | train |
secdev/scapy | scapy/contrib/diameter.py | getCmdParams | def getCmdParams(cmd, request, **fields):
"""Update or fill the fields parameters depending on command code. Both cmd and drAppId can be provided # noqa: E501
in string or int format."""
drCode = None
params = None
drAppId = None
# Fetch the parameters if cmd is found in dict
if isinstan... | python | def getCmdParams(cmd, request, **fields):
"""Update or fill the fields parameters depending on command code. Both cmd and drAppId can be provided # noqa: E501
in string or int format."""
drCode = None
params = None
drAppId = None
# Fetch the parameters if cmd is found in dict
if isinstan... | [
"def",
"getCmdParams",
"(",
"cmd",
",",
"request",
",",
"*",
"*",
"fields",
")",
":",
"drCode",
"=",
"None",
"params",
"=",
"None",
"drAppId",
"=",
"None",
"# Fetch the parameters if cmd is found in dict",
"if",
"isinstance",
"(",
"cmd",
",",
"int",
")",
":"... | Update or fill the fields parameters depending on command code. Both cmd and drAppId can be provided # noqa: E501
in string or int format. | [
"Update",
"or",
"fill",
"the",
"fields",
"parameters",
"depending",
"on",
"command",
"code",
".",
"Both",
"cmd",
"and",
"drAppId",
"can",
"be",
"provided",
"#",
"noqa",
":",
"E501",
"in",
"string",
"or",
"int",
"format",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/diameter.py#L4744-L4808 | train |
secdev/scapy | scapy/contrib/diameter.py | DiamReq | def DiamReq(cmd, **fields):
"""Craft Diameter request commands"""
upfields, name = getCmdParams(cmd, True, **fields)
p = DiamG(**upfields)
p.name = name
return p | python | def DiamReq(cmd, **fields):
"""Craft Diameter request commands"""
upfields, name = getCmdParams(cmd, True, **fields)
p = DiamG(**upfields)
p.name = name
return p | [
"def",
"DiamReq",
"(",
"cmd",
",",
"*",
"*",
"fields",
")",
":",
"upfields",
",",
"name",
"=",
"getCmdParams",
"(",
"cmd",
",",
"True",
",",
"*",
"*",
"fields",
")",
"p",
"=",
"DiamG",
"(",
"*",
"*",
"upfields",
")",
"p",
".",
"name",
"=",
"nam... | Craft Diameter request commands | [
"Craft",
"Diameter",
"request",
"commands"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/diameter.py#L4811-L4816 | train |
secdev/scapy | scapy/contrib/diameter.py | DiamAns | def DiamAns(cmd, **fields):
"""Craft Diameter answer commands"""
upfields, name = getCmdParams(cmd, False, **fields)
p = DiamG(**upfields)
p.name = name
return p | python | def DiamAns(cmd, **fields):
"""Craft Diameter answer commands"""
upfields, name = getCmdParams(cmd, False, **fields)
p = DiamG(**upfields)
p.name = name
return p | [
"def",
"DiamAns",
"(",
"cmd",
",",
"*",
"*",
"fields",
")",
":",
"upfields",
",",
"name",
"=",
"getCmdParams",
"(",
"cmd",
",",
"False",
",",
"*",
"*",
"fields",
")",
"p",
"=",
"DiamG",
"(",
"*",
"*",
"upfields",
")",
"p",
".",
"name",
"=",
"na... | Craft Diameter answer commands | [
"Craft",
"Diameter",
"answer",
"commands"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/diameter.py#L4819-L4824 | train |
secdev/scapy | scapy/fields.py | Field.i2m | def i2m(self, pkt, x):
"""Convert internal value to machine value"""
if x is None:
x = 0
elif isinstance(x, str):
return bytes_encode(x)
return x | python | def i2m(self, pkt, x):
"""Convert internal value to machine value"""
if x is None:
x = 0
elif isinstance(x, str):
return bytes_encode(x)
return x | [
"def",
"i2m",
"(",
"self",
",",
"pkt",
",",
"x",
")",
":",
"if",
"x",
"is",
"None",
":",
"x",
"=",
"0",
"elif",
"isinstance",
"(",
"x",
",",
"str",
")",
":",
"return",
"bytes_encode",
"(",
"x",
")",
"return",
"x"
] | Convert internal value to machine value | [
"Convert",
"internal",
"value",
"to",
"machine",
"value"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L117-L123 | train |
secdev/scapy | scapy/fields.py | MultipleTypeField._iterate_fields_cond | def _iterate_fields_cond(self, pkt, val, use_val):
"""Internal function used by _find_fld_pkt & _find_fld_pkt_val"""
# Iterate through the fields
for fld, cond in self.flds:
if isinstance(cond, tuple):
if use_val:
if cond[1](pkt, val):
... | python | def _iterate_fields_cond(self, pkt, val, use_val):
"""Internal function used by _find_fld_pkt & _find_fld_pkt_val"""
# Iterate through the fields
for fld, cond in self.flds:
if isinstance(cond, tuple):
if use_val:
if cond[1](pkt, val):
... | [
"def",
"_iterate_fields_cond",
"(",
"self",
",",
"pkt",
",",
"val",
",",
"use_val",
")",
":",
"# Iterate through the fields",
"for",
"fld",
",",
"cond",
"in",
"self",
".",
"flds",
":",
"if",
"isinstance",
"(",
"cond",
",",
"tuple",
")",
":",
"if",
"use_v... | Internal function used by _find_fld_pkt & _find_fld_pkt_val | [
"Internal",
"function",
"used",
"by",
"_find_fld_pkt",
"&",
"_find_fld_pkt_val"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L278-L291 | train |
secdev/scapy | scapy/fields.py | MultipleTypeField._find_fld_pkt_val | def _find_fld_pkt_val(self, pkt, val):
"""Given a Packet instance `pkt` and the value `val` to be set,
returns the Field subclass to be used, and the updated `val` if necessary.
"""
fld = self._iterate_fields_cond(pkt, val, True)
# Default ? (in this case, let's make sure it's up-do-dat... | python | def _find_fld_pkt_val(self, pkt, val):
"""Given a Packet instance `pkt` and the value `val` to be set,
returns the Field subclass to be used, and the updated `val` if necessary.
"""
fld = self._iterate_fields_cond(pkt, val, True)
# Default ? (in this case, let's make sure it's up-do-dat... | [
"def",
"_find_fld_pkt_val",
"(",
"self",
",",
"pkt",
",",
"val",
")",
":",
"fld",
"=",
"self",
".",
"_iterate_fields_cond",
"(",
"pkt",
",",
"val",
",",
"True",
")",
"# Default ? (in this case, let's make sure it's up-do-date)",
"dflts_pkt",
"=",
"pkt",
".",
"de... | Given a Packet instance `pkt` and the value `val` to be set,
returns the Field subclass to be used, and the updated `val` if necessary. | [
"Given",
"a",
"Packet",
"instance",
"pkt",
"and",
"the",
"value",
"val",
"to",
"be",
"set",
"returns",
"the",
"Field",
"subclass",
"to",
"be",
"used",
"and",
"the",
"updated",
"val",
"if",
"necessary",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L301-L312 | train |
secdev/scapy | scapy/fields.py | MultipleTypeField._find_fld | def _find_fld(self):
"""Returns the Field subclass to be used, depending on the Packet
instance, or the default subclass.
DEV: since the Packet instance is not provided, we have to use a hack
to guess it. It should only be used if you cannot provide the current
Packet instance (for example, because of the curr... | python | def _find_fld(self):
"""Returns the Field subclass to be used, depending on the Packet
instance, or the default subclass.
DEV: since the Packet instance is not provided, we have to use a hack
to guess it. It should only be used if you cannot provide the current
Packet instance (for example, because of the curr... | [
"def",
"_find_fld",
"(",
"self",
")",
":",
"# Hack to preserve current Scapy API",
"# See https://stackoverflow.com/a/7272464/3223422",
"frame",
"=",
"inspect",
".",
"currentframe",
"(",
")",
".",
"f_back",
".",
"f_back",
"while",
"frame",
"is",
"not",
"None",
":",
... | Returns the Field subclass to be used, depending on the Packet
instance, or the default subclass.
DEV: since the Packet instance is not provided, we have to use a hack
to guess it. It should only be used if you cannot provide the current
Packet instance (for example, because of the current Scapy API).
If you have the... | [
"Returns",
"the",
"Field",
"subclass",
"to",
"be",
"used",
"depending",
"on",
"the",
"Packet",
"instance",
"or",
"the",
"default",
"subclass",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L314-L338 | train |
secdev/scapy | scapy/fields.py | FlagsField._fixup_val | def _fixup_val(self, x):
"""Returns a FlagValue instance when needed. Internal method, to be
used in *2i() and i2*() methods.
"""
if isinstance(x, (list, tuple)):
return type(x)(
v if v is None or isinstance(v, FlagValue)
else FlagValue(v, self.names)... | python | def _fixup_val(self, x):
"""Returns a FlagValue instance when needed. Internal method, to be
used in *2i() and i2*() methods.
"""
if isinstance(x, (list, tuple)):
return type(x)(
v if v is None or isinstance(v, FlagValue)
else FlagValue(v, self.names)... | [
"def",
"_fixup_val",
"(",
"self",
",",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"type",
"(",
"x",
")",
"(",
"v",
"if",
"v",
"is",
"None",
"or",
"isinstance",
"(",
"v",
",",
"FlagValue... | Returns a FlagValue instance when needed. Internal method, to be
used in *2i() and i2*() methods. | [
"Returns",
"a",
"FlagValue",
"instance",
"when",
"needed",
".",
"Internal",
"method",
"to",
"be",
"used",
"in",
"*",
"2i",
"()",
"and",
"i2",
"*",
"()",
"methods",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L1965-L1976 | train |
secdev/scapy | scapy/fields.py | UUIDField._check_uuid_fmt | def _check_uuid_fmt(self):
"""Checks .uuid_fmt, and raises an exception if it is not valid."""
if self.uuid_fmt not in UUIDField.FORMATS:
raise FieldValueRangeException(
"Unsupported uuid_fmt ({})".format(self.uuid_fmt)) | python | def _check_uuid_fmt(self):
"""Checks .uuid_fmt, and raises an exception if it is not valid."""
if self.uuid_fmt not in UUIDField.FORMATS:
raise FieldValueRangeException(
"Unsupported uuid_fmt ({})".format(self.uuid_fmt)) | [
"def",
"_check_uuid_fmt",
"(",
"self",
")",
":",
"if",
"self",
".",
"uuid_fmt",
"not",
"in",
"UUIDField",
".",
"FORMATS",
":",
"raise",
"FieldValueRangeException",
"(",
"\"Unsupported uuid_fmt ({})\"",
".",
"format",
"(",
"self",
".",
"uuid_fmt",
")",
")"
] | Checks .uuid_fmt, and raises an exception if it is not valid. | [
"Checks",
".",
"uuid_fmt",
"and",
"raises",
"an",
"exception",
"if",
"it",
"is",
"not",
"valid",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L2392-L2396 | train |
secdev/scapy | scapy/layers/tls/record_tls13.py | TLSInnerPlaintext.pre_dissect | def pre_dissect(self, s):
"""
We need to parse the padding and type as soon as possible,
else we won't be able to parse the message list...
"""
if len(s) < 1:
raise Exception("Invalid InnerPlaintext (too short).")
tmp_len = len(s) - 1
if s[-1] != b"\x... | python | def pre_dissect(self, s):
"""
We need to parse the padding and type as soon as possible,
else we won't be able to parse the message list...
"""
if len(s) < 1:
raise Exception("Invalid InnerPlaintext (too short).")
tmp_len = len(s) - 1
if s[-1] != b"\x... | [
"def",
"pre_dissect",
"(",
"self",
",",
"s",
")",
":",
"if",
"len",
"(",
"s",
")",
"<",
"1",
":",
"raise",
"Exception",
"(",
"\"Invalid InnerPlaintext (too short).\"",
")",
"tmp_len",
"=",
"len",
"(",
"s",
")",
"-",
"1",
"if",
"s",
"[",
"-",
"1",
"... | We need to parse the padding and type as soon as possible,
else we won't be able to parse the message list... | [
"We",
"need",
"to",
"parse",
"the",
"padding",
"and",
"type",
"as",
"soon",
"as",
"possible",
"else",
"we",
"won",
"t",
"be",
"able",
"to",
"parse",
"the",
"message",
"list",
"..."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L39-L59 | train |
secdev/scapy | scapy/layers/tls/record_tls13.py | TLS13._tls_auth_decrypt | def _tls_auth_decrypt(self, s):
"""
Provided with the record header and AEAD-ciphered data, return the
sliced and clear tuple (TLSInnerPlaintext, tag). Note that
we still return the slicing of the original input in case of decryption
failure. Also, if the integrity check fails, a... | python | def _tls_auth_decrypt(self, s):
"""
Provided with the record header and AEAD-ciphered data, return the
sliced and clear tuple (TLSInnerPlaintext, tag). Note that
we still return the slicing of the original input in case of decryption
failure. Also, if the integrity check fails, a... | [
"def",
"_tls_auth_decrypt",
"(",
"self",
",",
"s",
")",
":",
"rcs",
"=",
"self",
".",
"tls_session",
".",
"rcs",
"read_seq_num",
"=",
"struct",
".",
"pack",
"(",
"\"!Q\"",
",",
"rcs",
".",
"seq_num",
")",
"rcs",
".",
"seq_num",
"+=",
"1",
"try",
":",... | Provided with the record header and AEAD-ciphered data, return the
sliced and clear tuple (TLSInnerPlaintext, tag). Note that
we still return the slicing of the original input in case of decryption
failure. Also, if the integrity check fails, a warning will be issued,
but we still return... | [
"Provided",
"with",
"the",
"record",
"header",
"and",
"AEAD",
"-",
"ciphered",
"data",
"return",
"the",
"sliced",
"and",
"clear",
"tuple",
"(",
"TLSInnerPlaintext",
"tag",
")",
".",
"Note",
"that",
"we",
"still",
"return",
"the",
"slicing",
"of",
"the",
"o... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L104-L122 | train |
secdev/scapy | scapy/layers/tls/record_tls13.py | TLS13.pre_dissect | def pre_dissect(self, s):
"""
Decrypt, verify and decompress the message.
"""
if len(s) < 5:
raise Exception("Invalid record: header is too short.")
if isinstance(self.tls_session.rcs.cipher, Cipher_NULL):
self.deciphered_len = None
return s
... | python | def pre_dissect(self, s):
"""
Decrypt, verify and decompress the message.
"""
if len(s) < 5:
raise Exception("Invalid record: header is too short.")
if isinstance(self.tls_session.rcs.cipher, Cipher_NULL):
self.deciphered_len = None
return s
... | [
"def",
"pre_dissect",
"(",
"self",
",",
"s",
")",
":",
"if",
"len",
"(",
"s",
")",
"<",
"5",
":",
"raise",
"Exception",
"(",
"\"Invalid record: header is too short.\"",
")",
"if",
"isinstance",
"(",
"self",
".",
"tls_session",
".",
"rcs",
".",
"cipher",
... | Decrypt, verify and decompress the message. | [
"Decrypt",
"verify",
"and",
"decompress",
"the",
"message",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L124-L139 | train |
secdev/scapy | scapy/layers/tls/record_tls13.py | TLS13.post_dissect | def post_dissect(self, s):
"""
Commit the pending read state if it has been triggered. We update
nothing if the prcs was not set, as this probably means that we're
working out-of-context (and we need to keep the default rcs).
"""
if self.tls_session.triggered_prcs_commit:... | python | def post_dissect(self, s):
"""
Commit the pending read state if it has been triggered. We update
nothing if the prcs was not set, as this probably means that we're
working out-of-context (and we need to keep the default rcs).
"""
if self.tls_session.triggered_prcs_commit:... | [
"def",
"post_dissect",
"(",
"self",
",",
"s",
")",
":",
"if",
"self",
".",
"tls_session",
".",
"triggered_prcs_commit",
":",
"if",
"self",
".",
"tls_session",
".",
"prcs",
"is",
"not",
"None",
":",
"self",
".",
"tls_session",
".",
"rcs",
"=",
"self",
"... | Commit the pending read state if it has been triggered. We update
nothing if the prcs was not set, as this probably means that we're
working out-of-context (and we need to keep the default rcs). | [
"Commit",
"the",
"pending",
"read",
"state",
"if",
"it",
"has",
"been",
"triggered",
".",
"We",
"update",
"nothing",
"if",
"the",
"prcs",
"was",
"not",
"set",
"as",
"this",
"probably",
"means",
"that",
"we",
"re",
"working",
"out",
"-",
"of",
"-",
"con... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L141-L152 | train |
secdev/scapy | scapy/layers/tls/record_tls13.py | TLS13._tls_auth_encrypt | def _tls_auth_encrypt(self, s):
"""
Return the TLSCiphertext.encrypted_record for AEAD ciphers.
"""
wcs = self.tls_session.wcs
write_seq_num = struct.pack("!Q", wcs.seq_num)
wcs.seq_num += 1
return wcs.cipher.auth_encrypt(s, b"", write_seq_num) | python | def _tls_auth_encrypt(self, s):
"""
Return the TLSCiphertext.encrypted_record for AEAD ciphers.
"""
wcs = self.tls_session.wcs
write_seq_num = struct.pack("!Q", wcs.seq_num)
wcs.seq_num += 1
return wcs.cipher.auth_encrypt(s, b"", write_seq_num) | [
"def",
"_tls_auth_encrypt",
"(",
"self",
",",
"s",
")",
":",
"wcs",
"=",
"self",
".",
"tls_session",
".",
"wcs",
"write_seq_num",
"=",
"struct",
".",
"pack",
"(",
"\"!Q\"",
",",
"wcs",
".",
"seq_num",
")",
"wcs",
".",
"seq_num",
"+=",
"1",
"return",
... | Return the TLSCiphertext.encrypted_record for AEAD ciphers. | [
"Return",
"the",
"TLSCiphertext",
".",
"encrypted_record",
"for",
"AEAD",
"ciphers",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L172-L179 | train |
secdev/scapy | scapy/layers/tls/record_tls13.py | TLS13.post_build | def post_build(self, pkt, pay):
"""
Apply the previous methods according to the writing cipher type.
"""
# Compute the length of TLSPlaintext fragment
hdr, frag = pkt[:5], pkt[5:]
if not isinstance(self.tls_session.rcs.cipher, Cipher_NULL):
frag = self._tls_au... | python | def post_build(self, pkt, pay):
"""
Apply the previous methods according to the writing cipher type.
"""
# Compute the length of TLSPlaintext fragment
hdr, frag = pkt[:5], pkt[5:]
if not isinstance(self.tls_session.rcs.cipher, Cipher_NULL):
frag = self._tls_au... | [
"def",
"post_build",
"(",
"self",
",",
"pkt",
",",
"pay",
")",
":",
"# Compute the length of TLSPlaintext fragment",
"hdr",
",",
"frag",
"=",
"pkt",
"[",
":",
"5",
"]",
",",
"pkt",
"[",
"5",
":",
"]",
"if",
"not",
"isinstance",
"(",
"self",
".",
"tls_s... | Apply the previous methods according to the writing cipher type. | [
"Apply",
"the",
"previous",
"methods",
"according",
"to",
"the",
"writing",
"cipher",
"type",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L181-L206 | train |
secdev/scapy | scapy/modules/krack/crypto.py | ARC4_encrypt | def ARC4_encrypt(key, data, skip=0):
"""Encrypt data @data with key @key, skipping @skip first bytes of the
keystream"""
algorithm = algorithms.ARC4(key)
cipher = Cipher(algorithm, mode=None, backend=default_backend())
encryptor = cipher.encryptor()
if skip:
encryptor.update(b"\x00" * s... | python | def ARC4_encrypt(key, data, skip=0):
"""Encrypt data @data with key @key, skipping @skip first bytes of the
keystream"""
algorithm = algorithms.ARC4(key)
cipher = Cipher(algorithm, mode=None, backend=default_backend())
encryptor = cipher.encryptor()
if skip:
encryptor.update(b"\x00" * s... | [
"def",
"ARC4_encrypt",
"(",
"key",
",",
"data",
",",
"skip",
"=",
"0",
")",
":",
"algorithm",
"=",
"algorithms",
".",
"ARC4",
"(",
"key",
")",
"cipher",
"=",
"Cipher",
"(",
"algorithm",
",",
"mode",
"=",
"None",
",",
"backend",
"=",
"default_backend",
... | Encrypt data @data with key @key, skipping @skip first bytes of the
keystream | [
"Encrypt",
"data"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L18-L27 | train |
secdev/scapy | scapy/modules/krack/crypto.py | customPRF512 | def customPRF512(key, amac, smac, anonce, snonce):
"""Source https://stackoverflow.com/questions/12018920/"""
A = b"Pairwise key expansion"
B = b"".join(sorted([amac, smac]) + sorted([anonce, snonce]))
blen = 64
i = 0
R = b''
while i <= ((blen * 8 + 159) / 160):
hmacsha1 = hmac.new(... | python | def customPRF512(key, amac, smac, anonce, snonce):
"""Source https://stackoverflow.com/questions/12018920/"""
A = b"Pairwise key expansion"
B = b"".join(sorted([amac, smac]) + sorted([anonce, snonce]))
blen = 64
i = 0
R = b''
while i <= ((blen * 8 + 159) / 160):
hmacsha1 = hmac.new(... | [
"def",
"customPRF512",
"(",
"key",
",",
"amac",
",",
"smac",
",",
"anonce",
",",
"snonce",
")",
":",
"A",
"=",
"b\"Pairwise key expansion\"",
"B",
"=",
"b\"\"",
".",
"join",
"(",
"sorted",
"(",
"[",
"amac",
",",
"smac",
"]",
")",
"+",
"sorted",
"(",
... | Source https://stackoverflow.com/questions/12018920/ | [
"Source",
"https",
":",
"//",
"stackoverflow",
".",
"com",
"/",
"questions",
"/",
"12018920",
"/"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L38-L50 | train |
secdev/scapy | scapy/modules/krack/crypto.py | gen_TKIP_RC4_key | def gen_TKIP_RC4_key(TSC, TA, TK):
"""Implement TKIP WEPSeed generation
TSC: packet IV
TA: target addr bytes
TK: temporal key
"""
assert len(TSC) == 6
assert len(TA) == 6
assert len(TK) == 16
assert all(isinstance(x, six.integer_types) for x in TSC + TA + TK)
# Phase 1
# 80... | python | def gen_TKIP_RC4_key(TSC, TA, TK):
"""Implement TKIP WEPSeed generation
TSC: packet IV
TA: target addr bytes
TK: temporal key
"""
assert len(TSC) == 6
assert len(TA) == 6
assert len(TK) == 16
assert all(isinstance(x, six.integer_types) for x in TSC + TA + TK)
# Phase 1
# 80... | [
"def",
"gen_TKIP_RC4_key",
"(",
"TSC",
",",
"TA",
",",
"TK",
")",
":",
"assert",
"len",
"(",
"TSC",
")",
"==",
"6",
"assert",
"len",
"(",
"TA",
")",
"==",
"6",
"assert",
"len",
"(",
"TK",
")",
"==",
"16",
"assert",
"all",
"(",
"isinstance",
"(",
... | Implement TKIP WEPSeed generation
TSC: packet IV
TA: target addr bytes
TK: temporal key | [
"Implement",
"TKIP",
"WEPSeed",
"generation",
"TSC",
":",
"packet",
"IV",
"TA",
":",
"target",
"addr",
"bytes",
"TK",
":",
"temporal",
"key"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L148-L214 | train |
secdev/scapy | scapy/modules/krack/crypto.py | _michael_b | def _michael_b(m_l, m_r):
"""Defined in 802.11i p.49"""
m_r = m_r ^ _rotate_left32(m_l, 17)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _XSWAP(m_l)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _rotate_left32(m_l, 3)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _rotate_right32(m_l, 2)
m_l = (m_l + m_r) %... | python | def _michael_b(m_l, m_r):
"""Defined in 802.11i p.49"""
m_r = m_r ^ _rotate_left32(m_l, 17)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _XSWAP(m_l)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _rotate_left32(m_l, 3)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _rotate_right32(m_l, 2)
m_l = (m_l + m_r) %... | [
"def",
"_michael_b",
"(",
"m_l",
",",
"m_r",
")",
":",
"m_r",
"=",
"m_r",
"^",
"_rotate_left32",
"(",
"m_l",
",",
"17",
")",
"m_l",
"=",
"(",
"m_l",
"+",
"m_r",
")",
"%",
"2",
"**",
"32",
"m_r",
"=",
"m_r",
"^",
"_XSWAP",
"(",
"m_l",
")",
"m_... | Defined in 802.11i p.49 | [
"Defined",
"in",
"802",
".",
"11i",
"p",
".",
"49"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L233-L243 | train |
secdev/scapy | scapy/modules/krack/crypto.py | michael | def michael(key, to_hash):
"""Defined in 802.11i p.48"""
# Block size: 4
nb_block, nb_extra_bytes = divmod(len(to_hash), 4)
# Add padding
data = to_hash + chb(0x5a) + b"\x00" * (7 - nb_extra_bytes)
# Hash
m_l, m_r = unpack('<II', key)
for i in range(nb_block + 2):
# Convert i-t... | python | def michael(key, to_hash):
"""Defined in 802.11i p.48"""
# Block size: 4
nb_block, nb_extra_bytes = divmod(len(to_hash), 4)
# Add padding
data = to_hash + chb(0x5a) + b"\x00" * (7 - nb_extra_bytes)
# Hash
m_l, m_r = unpack('<II', key)
for i in range(nb_block + 2):
# Convert i-t... | [
"def",
"michael",
"(",
"key",
",",
"to_hash",
")",
":",
"# Block size: 4",
"nb_block",
",",
"nb_extra_bytes",
"=",
"divmod",
"(",
"len",
"(",
"to_hash",
")",
",",
"4",
")",
"# Add padding",
"data",
"=",
"to_hash",
"+",
"chb",
"(",
"0x5a",
")",
"+",
"b\... | Defined in 802.11i p.48 | [
"Defined",
"in",
"802",
".",
"11i",
"p",
".",
"48"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L246-L261 | train |
secdev/scapy | scapy/modules/krack/crypto.py | parse_TKIP_hdr | def parse_TKIP_hdr(pkt):
"""Extract TSCs, TA and encoded-data from a packet @pkt"""
# Note: FCS bit is not handled
assert pkt.FCfield.protected
# 802.11i - 8.3.2.2
tkip_layer = pkt[Dot11TKIP]
payload = tkip_layer.data
# IV
if not tkip_layer.ext_iv:
# 802.11i p. 46
raise... | python | def parse_TKIP_hdr(pkt):
"""Extract TSCs, TA and encoded-data from a packet @pkt"""
# Note: FCS bit is not handled
assert pkt.FCfield.protected
# 802.11i - 8.3.2.2
tkip_layer = pkt[Dot11TKIP]
payload = tkip_layer.data
# IV
if not tkip_layer.ext_iv:
# 802.11i p. 46
raise... | [
"def",
"parse_TKIP_hdr",
"(",
"pkt",
")",
":",
"# Note: FCS bit is not handled",
"assert",
"pkt",
".",
"FCfield",
".",
"protected",
"# 802.11i - 8.3.2.2",
"tkip_layer",
"=",
"pkt",
"[",
"Dot11TKIP",
"]",
"payload",
"=",
"tkip_layer",
".",
"data",
"# IV",
"if",
"... | Extract TSCs, TA and encoded-data from a packet @pkt | [
"Extract",
"TSCs",
"TA",
"and",
"encoded",
"-",
"data",
"from",
"a",
"packet"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L266-L295 | train |
secdev/scapy | scapy/modules/krack/crypto.py | build_TKIP_payload | def build_TKIP_payload(data, iv, mac, tk):
"""Build a TKIP header for IV @iv and mac @mac, and encrypt @data
based on temporal key @tk
"""
TSC5, TSC4, TSC3, TSC2, TSC1, TSC0 = (
(iv >> 40) & 0xFF,
(iv >> 32) & 0xFF,
(iv >> 24) & 0xFF,
(iv >> 16) & 0xFF,
(iv >> 8) ... | python | def build_TKIP_payload(data, iv, mac, tk):
"""Build a TKIP header for IV @iv and mac @mac, and encrypt @data
based on temporal key @tk
"""
TSC5, TSC4, TSC3, TSC2, TSC1, TSC0 = (
(iv >> 40) & 0xFF,
(iv >> 32) & 0xFF,
(iv >> 24) & 0xFF,
(iv >> 16) & 0xFF,
(iv >> 8) ... | [
"def",
"build_TKIP_payload",
"(",
"data",
",",
"iv",
",",
"mac",
",",
"tk",
")",
":",
"TSC5",
",",
"TSC4",
",",
"TSC3",
",",
"TSC2",
",",
"TSC1",
",",
"TSC0",
"=",
"(",
"(",
"iv",
">>",
"40",
")",
"&",
"0xFF",
",",
"(",
"iv",
">>",
"32",
")",... | Build a TKIP header for IV @iv and mac @mac, and encrypt @data
based on temporal key @tk | [
"Build",
"a",
"TKIP",
"header",
"for",
"IV"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L298-L319 | train |
secdev/scapy | scapy/modules/krack/crypto.py | parse_data_pkt | def parse_data_pkt(pkt, tk):
"""Extract data from a WPA packet @pkt with temporal key @tk"""
TSC, TA, data = parse_TKIP_hdr(pkt)
TK = [orb(x) for x in tk]
rc4_key = gen_TKIP_RC4_key(TSC, TA, TK)
return ARC4_decrypt(rc4_key, data) | python | def parse_data_pkt(pkt, tk):
"""Extract data from a WPA packet @pkt with temporal key @tk"""
TSC, TA, data = parse_TKIP_hdr(pkt)
TK = [orb(x) for x in tk]
rc4_key = gen_TKIP_RC4_key(TSC, TA, TK)
return ARC4_decrypt(rc4_key, data) | [
"def",
"parse_data_pkt",
"(",
"pkt",
",",
"tk",
")",
":",
"TSC",
",",
"TA",
",",
"data",
"=",
"parse_TKIP_hdr",
"(",
"pkt",
")",
"TK",
"=",
"[",
"orb",
"(",
"x",
")",
"for",
"x",
"in",
"tk",
"]",
"rc4_key",
"=",
"gen_TKIP_RC4_key",
"(",
"TSC",
",... | Extract data from a WPA packet @pkt with temporal key @tk | [
"Extract",
"data",
"from",
"a",
"WPA",
"packet"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L322-L328 | train |
secdev/scapy | scapy/modules/krack/crypto.py | check_MIC_ICV | def check_MIC_ICV(data, mic_key, source, dest):
"""Check MIC, ICV & return the data from a decrypted TKIP packet"""
assert len(data) > 12
# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV
# 802.11i p.47
ICV = data[-4:]
MIC = data[-12:-4]
data_clear = data[:-12]
expected_ICV ... | python | def check_MIC_ICV(data, mic_key, source, dest):
"""Check MIC, ICV & return the data from a decrypted TKIP packet"""
assert len(data) > 12
# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV
# 802.11i p.47
ICV = data[-4:]
MIC = data[-12:-4]
data_clear = data[:-12]
expected_ICV ... | [
"def",
"check_MIC_ICV",
"(",
"data",
",",
"mic_key",
",",
"source",
",",
"dest",
")",
":",
"assert",
"len",
"(",
"data",
")",
">",
"12",
"# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV",
"# 802.11i p.47",
"ICV",
"=",
"data",
"[",
"-",
"4",
":",
"]... | Check MIC, ICV & return the data from a decrypted TKIP packet | [
"Check",
"MIC",
"ICV",
"&",
"return",
"the",
"data",
"from",
"a",
"decrypted",
"TKIP",
"packet"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L341-L363 | train |
secdev/scapy | scapy/modules/krack/crypto.py | build_MIC_ICV | def build_MIC_ICV(data, mic_key, source, dest):
"""Compute and return the data with its MIC and ICV"""
# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV
# 802.11i p.47
sa = mac2str(source) # Source MAC
da = mac2str(dest) # Dest MAC
MIC = michael(mic_key, da + sa + b"\x00" + b"\x00" ... | python | def build_MIC_ICV(data, mic_key, source, dest):
"""Compute and return the data with its MIC and ICV"""
# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV
# 802.11i p.47
sa = mac2str(source) # Source MAC
da = mac2str(dest) # Dest MAC
MIC = michael(mic_key, da + sa + b"\x00" + b"\x00" ... | [
"def",
"build_MIC_ICV",
"(",
"data",
",",
"mic_key",
",",
"source",
",",
"dest",
")",
":",
"# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV",
"# 802.11i p.47",
"sa",
"=",
"mac2str",
"(",
"source",
")",
"# Source MAC",
"da",
"=",
"mac2str",
"(",
"dest",
... | Compute and return the data with its MIC and ICV | [
"Compute",
"and",
"return",
"the",
"data",
"with",
"its",
"MIC",
"and",
"ICV"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L366-L376 | train |
secdev/scapy | scapy/layers/ipsec.py | _lcm | def _lcm(a, b):
"""
Least Common Multiple between 2 integers.
"""
if a == 0 or b == 0:
return 0
else:
return abs(a * b) // gcd(a, b) | python | def _lcm(a, b):
"""
Least Common Multiple between 2 integers.
"""
if a == 0 or b == 0:
return 0
else:
return abs(a * b) // gcd(a, b) | [
"def",
"_lcm",
"(",
"a",
",",
"b",
")",
":",
"if",
"a",
"==",
"0",
"or",
"b",
"==",
"0",
":",
"return",
"0",
"else",
":",
"return",
"abs",
"(",
"a",
"*",
"b",
")",
"//",
"gcd",
"(",
"a",
",",
"b",
")"
] | Least Common Multiple between 2 integers. | [
"Least",
"Common",
"Multiple",
"between",
"2",
"integers",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L186-L193 | train |
secdev/scapy | scapy/layers/ipsec.py | split_for_transport | def split_for_transport(orig_pkt, transport_proto):
"""
Split an IP(v6) packet in the correct location to insert an ESP or AH
header.
@param orig_pkt: the packet to split. Must be an IP or IPv6 packet
@param transport_proto: the IPsec protocol number that will be inserted
... | python | def split_for_transport(orig_pkt, transport_proto):
"""
Split an IP(v6) packet in the correct location to insert an ESP or AH
header.
@param orig_pkt: the packet to split. Must be an IP or IPv6 packet
@param transport_proto: the IPsec protocol number that will be inserted
... | [
"def",
"split_for_transport",
"(",
"orig_pkt",
",",
"transport_proto",
")",
":",
"# force resolution of default fields to avoid padding errors",
"header",
"=",
"orig_pkt",
".",
"__class__",
"(",
"raw",
"(",
"orig_pkt",
")",
")",
"next_hdr",
"=",
"header",
".",
"payloa... | Split an IP(v6) packet in the correct location to insert an ESP or AH
header.
@param orig_pkt: the packet to split. Must be an IP or IPv6 packet
@param transport_proto: the IPsec protocol number that will be inserted
at the split position.
@return: a tuple (header, nh, paylo... | [
"Split",
"an",
"IP",
"(",
"v6",
")",
"packet",
"in",
"the",
"correct",
"location",
"to",
"insert",
"an",
"ESP",
"or",
"AH",
"header",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L642-L688 | train |
secdev/scapy | scapy/layers/ipsec.py | CryptAlgo.new_cipher | def new_cipher(self, key, mode_iv, digest=None):
"""
@param key: the secret key, a byte string
@param mode_iv: the initialization vector or nonce, a byte string.
Formatted by `format_mode_iv`.
@param digest: also known as tag or icv. A byte string containing ... | python | def new_cipher(self, key, mode_iv, digest=None):
"""
@param key: the secret key, a byte string
@param mode_iv: the initialization vector or nonce, a byte string.
Formatted by `format_mode_iv`.
@param digest: also known as tag or icv. A byte string containing ... | [
"def",
"new_cipher",
"(",
"self",
",",
"key",
",",
"mode_iv",
",",
"digest",
"=",
"None",
")",
":",
"if",
"self",
".",
"is_aead",
"and",
"digest",
"is",
"not",
"None",
":",
"# With AEAD, the mode needs the digest during decryption.",
"return",
"Cipher",
"(",
"... | @param key: the secret key, a byte string
@param mode_iv: the initialization vector or nonce, a byte string.
Formatted by `format_mode_iv`.
@param digest: also known as tag or icv. A byte string containing the
digest of the encrypted data. Only use th... | [
"@param",
"key",
":",
"the",
"secret",
"key",
"a",
"byte",
"string",
"@param",
"mode_iv",
":",
"the",
"initialization",
"vector",
"or",
"nonce",
"a",
"byte",
"string",
".",
"Formatted",
"by",
"format_mode_iv",
".",
"@param",
"digest",
":",
"also",
"known",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L281-L304 | train |
secdev/scapy | scapy/layers/ipsec.py | CryptAlgo.pad | def pad(self, esp):
"""
Add the correct amount of padding so that the data to encrypt is
exactly a multiple of the algorithm's block size.
Also, make sure that the total ESP packet length is a multiple of 4
bytes.
@param esp: an unencrypted _ESPPlain packet
... | python | def pad(self, esp):
"""
Add the correct amount of padding so that the data to encrypt is
exactly a multiple of the algorithm's block size.
Also, make sure that the total ESP packet length is a multiple of 4
bytes.
@param esp: an unencrypted _ESPPlain packet
... | [
"def",
"pad",
"(",
"self",
",",
"esp",
")",
":",
"# 2 extra bytes for padlen and nh",
"data_len",
"=",
"len",
"(",
"esp",
".",
"data",
")",
"+",
"2",
"# according to the RFC4303, section 2.4. Padding (for Encryption)",
"# the size of the ESP payload must be a multiple of 32 b... | Add the correct amount of padding so that the data to encrypt is
exactly a multiple of the algorithm's block size.
Also, make sure that the total ESP packet length is a multiple of 4
bytes.
@param esp: an unencrypted _ESPPlain packet
@return: an unencrypted _ESPPlain pac... | [
"Add",
"the",
"correct",
"amount",
"of",
"padding",
"so",
"that",
"the",
"data",
"to",
"encrypt",
"is",
"exactly",
"a",
"multiple",
"of",
"the",
"algorithm",
"s",
"block",
"size",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L306-L339 | train |
secdev/scapy | scapy/layers/ipsec.py | CryptAlgo.encrypt | def encrypt(self, sa, esp, key):
"""
Encrypt an ESP packet
@param sa: the SecurityAssociation associated with the ESP packet.
@param esp: an unencrypted _ESPPlain packet with valid padding
@param key: the secret key used for encryption
@return: a valid ESP packet... | python | def encrypt(self, sa, esp, key):
"""
Encrypt an ESP packet
@param sa: the SecurityAssociation associated with the ESP packet.
@param esp: an unencrypted _ESPPlain packet with valid padding
@param key: the secret key used for encryption
@return: a valid ESP packet... | [
"def",
"encrypt",
"(",
"self",
",",
"sa",
",",
"esp",
",",
"key",
")",
":",
"data",
"=",
"esp",
".",
"data_for_encryption",
"(",
")",
"if",
"self",
".",
"cipher",
":",
"mode_iv",
"=",
"self",
".",
"_format_mode_iv",
"(",
"algo",
"=",
"self",
",",
"... | Encrypt an ESP packet
@param sa: the SecurityAssociation associated with the ESP packet.
@param esp: an unencrypted _ESPPlain packet with valid padding
@param key: the secret key used for encryption
@return: a valid ESP packet encrypted with this algorithm | [
"Encrypt",
"an",
"ESP",
"packet"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L341-L366 | train |
secdev/scapy | scapy/layers/ipsec.py | AuthAlgo.check_key | def check_key(self, key):
"""
Check that the key length is valid.
@param key: a byte string
"""
if self.key_size and len(key) not in self.key_size:
raise TypeError('invalid key size %s, must be one of %s' %
(len(key), self.key_size)) | python | def check_key(self, key):
"""
Check that the key length is valid.
@param key: a byte string
"""
if self.key_size and len(key) not in self.key_size:
raise TypeError('invalid key size %s, must be one of %s' %
(len(key), self.key_size)) | [
"def",
"check_key",
"(",
"self",
",",
"key",
")",
":",
"if",
"self",
".",
"key_size",
"and",
"len",
"(",
"key",
")",
"not",
"in",
"self",
".",
"key_size",
":",
"raise",
"TypeError",
"(",
"'invalid key size %s, must be one of %s'",
"%",
"(",
"len",
"(",
"... | Check that the key length is valid.
@param key: a byte string | [
"Check",
"that",
"the",
"key",
"length",
"is",
"valid",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L516-L524 | train |
secdev/scapy | scapy/layers/ipsec.py | AuthAlgo.sign | def sign(self, pkt, key):
"""
Sign an IPsec (ESP or AH) packet with this algo.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@return: the signed packet
"""
if not self.mac:
... | python | def sign(self, pkt, key):
"""
Sign an IPsec (ESP or AH) packet with this algo.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@return: the signed packet
"""
if not self.mac:
... | [
"def",
"sign",
"(",
"self",
",",
"pkt",
",",
"key",
")",
":",
"if",
"not",
"self",
".",
"mac",
":",
"return",
"pkt",
"mac",
"=",
"self",
".",
"new_mac",
"(",
"key",
")",
"if",
"pkt",
".",
"haslayer",
"(",
"ESP",
")",
":",
"mac",
".",
"update",
... | Sign an IPsec (ESP or AH) packet with this algo.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@return: the signed packet | [
"Sign",
"an",
"IPsec",
"(",
"ESP",
"or",
"AH",
")",
"packet",
"with",
"this",
"algo",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L537-L560 | train |
secdev/scapy | scapy/layers/ipsec.py | AuthAlgo.verify | def verify(self, pkt, key):
"""
Check that the integrity check value (icv) of a packet is valid.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@raise IPSecIntegrityError: if the integrity check fails... | python | def verify(self, pkt, key):
"""
Check that the integrity check value (icv) of a packet is valid.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@raise IPSecIntegrityError: if the integrity check fails... | [
"def",
"verify",
"(",
"self",
",",
"pkt",
",",
"key",
")",
":",
"if",
"not",
"self",
".",
"mac",
"or",
"self",
".",
"icv_size",
"==",
"0",
":",
"return",
"mac",
"=",
"self",
".",
"new_mac",
"(",
"key",
")",
"pkt_icv",
"=",
"'not found'",
"computed_... | Check that the integrity check value (icv) of a packet is valid.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@raise IPSecIntegrityError: if the integrity check fails | [
"Check",
"that",
"the",
"integrity",
"check",
"value",
"(",
"icv",
")",
"of",
"a",
"packet",
"is",
"valid",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L562-L598 | train |
secdev/scapy | scapy/layers/ipsec.py | SecurityAssociation.encrypt | def encrypt(self, pkt, seq_num=None, iv=None):
"""
Encrypt (and encapsulate) an IP(v6) packet with ESP or AH according
to this SecurityAssociation.
@param pkt: the packet to encrypt
@param seq_num: if specified, use this sequence number instead of the
... | python | def encrypt(self, pkt, seq_num=None, iv=None):
"""
Encrypt (and encapsulate) an IP(v6) packet with ESP or AH according
to this SecurityAssociation.
@param pkt: the packet to encrypt
@param seq_num: if specified, use this sequence number instead of the
... | [
"def",
"encrypt",
"(",
"self",
",",
"pkt",
",",
"seq_num",
"=",
"None",
",",
"iv",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"pkt",
",",
"self",
".",
"SUPPORTED_PROTOS",
")",
":",
"raise",
"TypeError",
"(",
"'cannot encrypt %s, supported proto... | Encrypt (and encapsulate) an IP(v6) packet with ESP or AH according
to this SecurityAssociation.
@param pkt: the packet to encrypt
@param seq_num: if specified, use this sequence number instead of the
generated one
@param iv: if specified, use this initi... | [
"Encrypt",
"(",
"and",
"encapsulate",
")",
"an",
"IP",
"(",
"v6",
")",
"packet",
"with",
"ESP",
"or",
"AH",
"according",
"to",
"this",
"SecurityAssociation",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L959-L978 | train |
secdev/scapy | scapy/layers/ipsec.py | SecurityAssociation.decrypt | def decrypt(self, pkt, verify=True):
"""
Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH.
@param pkt: the packet to decrypt
@param verify: if False, do not perform the integrity check
@return: the decrypted/decapsulated packet
@raise IPSecIntegrityE... | python | def decrypt(self, pkt, verify=True):
"""
Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH.
@param pkt: the packet to decrypt
@param verify: if False, do not perform the integrity check
@return: the decrypted/decapsulated packet
@raise IPSecIntegrityE... | [
"def",
"decrypt",
"(",
"self",
",",
"pkt",
",",
"verify",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"pkt",
",",
"self",
".",
"SUPPORTED_PROTOS",
")",
":",
"raise",
"TypeError",
"(",
"'cannot decrypt %s, supported protos are %s'",
"%",
"(",
"pkt"... | Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH.
@param pkt: the packet to decrypt
@param verify: if False, do not perform the integrity check
@return: the decrypted/decapsulated packet
@raise IPSecIntegrityError: if the integrity check fails | [
"Decrypt",
"(",
"and",
"decapsulate",
")",
"an",
"IP",
"(",
"v6",
")",
"packet",
"containing",
"ESP",
"or",
"AH",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L1053-L1072 | train |
secdev/scapy | scapy/layers/tls/crypto/cipher_aead.py | _AEADCipher._update_nonce_explicit | def _update_nonce_explicit(self):
"""
Increment the explicit nonce while avoiding any overflow.
"""
ne = self.nonce_explicit + 1
self.nonce_explicit = ne % 2**(self.nonce_explicit_len * 8) | python | def _update_nonce_explicit(self):
"""
Increment the explicit nonce while avoiding any overflow.
"""
ne = self.nonce_explicit + 1
self.nonce_explicit = ne % 2**(self.nonce_explicit_len * 8) | [
"def",
"_update_nonce_explicit",
"(",
"self",
")",
":",
"ne",
"=",
"self",
".",
"nonce_explicit",
"+",
"1",
"self",
".",
"nonce_explicit",
"=",
"ne",
"%",
"2",
"**",
"(",
"self",
".",
"nonce_explicit_len",
"*",
"8",
")"
] | Increment the explicit nonce while avoiding any overflow. | [
"Increment",
"the",
"explicit",
"nonce",
"while",
"avoiding",
"any",
"overflow",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L130-L135 | train |
secdev/scapy | scapy/layers/tls/crypto/cipher_aead.py | _AEADCipher.auth_encrypt | def auth_encrypt(self, P, A, seq_num=None):
"""
Encrypt the data then prepend the explicit part of the nonce. The
authentication tag is directly appended with the most recent crypto
API. Additional data may be authenticated without encryption (as A).
The 'seq_num' should never b... | python | def auth_encrypt(self, P, A, seq_num=None):
"""
Encrypt the data then prepend the explicit part of the nonce. The
authentication tag is directly appended with the most recent crypto
API. Additional data may be authenticated without encryption (as A).
The 'seq_num' should never b... | [
"def",
"auth_encrypt",
"(",
"self",
",",
"P",
",",
"A",
",",
"seq_num",
"=",
"None",
")",
":",
"if",
"False",
"in",
"six",
".",
"itervalues",
"(",
"self",
".",
"ready",
")",
":",
"raise",
"CipherError",
"(",
"P",
",",
"A",
")",
"if",
"hasattr",
"... | Encrypt the data then prepend the explicit part of the nonce. The
authentication tag is directly appended with the most recent crypto
API. Additional data may be authenticated without encryption (as A).
The 'seq_num' should never be used here, it is only a safeguard needed
because one c... | [
"Encrypt",
"the",
"data",
"then",
"prepend",
"the",
"explicit",
"part",
"of",
"the",
"nonce",
".",
"The",
"authentication",
"tag",
"is",
"directly",
"appended",
"with",
"the",
"most",
"recent",
"crypto",
"API",
".",
"Additional",
"data",
"may",
"be",
"authen... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L137-L163 | train |
secdev/scapy | scapy/layers/tls/crypto/cipher_aead.py | _AEADCipher.auth_decrypt | def auth_decrypt(self, A, C, seq_num=None, add_length=True):
"""
Decrypt the data and authenticate the associated data (i.e. A).
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if deemed useful. If we lack the key, we
raise a Ciph... | python | def auth_decrypt(self, A, C, seq_num=None, add_length=True):
"""
Decrypt the data and authenticate the associated data (i.e. A).
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if deemed useful. If we lack the key, we
raise a Ciph... | [
"def",
"auth_decrypt",
"(",
"self",
",",
"A",
",",
"C",
",",
"seq_num",
"=",
"None",
",",
"add_length",
"=",
"True",
")",
":",
"nonce_explicit_str",
",",
"C",
",",
"mac",
"=",
"(",
"C",
"[",
":",
"self",
".",
"nonce_explicit_len",
"]",
",",
"C",
"[... | Decrypt the data and authenticate the associated data (i.e. A).
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if deemed useful. If we lack the key, we
raise a CipherError which contains the encrypted input.
Note that we add the TLSCiph... | [
"Decrypt",
"the",
"data",
"and",
"authenticate",
"the",
"associated",
"data",
"(",
"i",
".",
"e",
".",
"A",
")",
".",
"If",
"the",
"verification",
"fails",
"an",
"AEADTagError",
"is",
"raised",
".",
"It",
"is",
"the",
"user",
"s",
"responsibility",
"to",... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L165-L211 | train |
secdev/scapy | scapy/layers/tls/crypto/cipher_aead.py | _AEADCipher_TLS13.auth_encrypt | def auth_encrypt(self, P, A, seq_num):
"""
Encrypt the data, and append the computed authentication code.
TLS 1.3 does not use additional data, but we leave this option to the
user nonetheless.
Note that the cipher's authentication tag must be None when encrypting.
"""
... | python | def auth_encrypt(self, P, A, seq_num):
"""
Encrypt the data, and append the computed authentication code.
TLS 1.3 does not use additional data, but we leave this option to the
user nonetheless.
Note that the cipher's authentication tag must be None when encrypting.
"""
... | [
"def",
"auth_encrypt",
"(",
"self",
",",
"P",
",",
"A",
",",
"seq_num",
")",
":",
"if",
"False",
"in",
"six",
".",
"itervalues",
"(",
"self",
".",
"ready",
")",
":",
"raise",
"CipherError",
"(",
"P",
",",
"A",
")",
"if",
"hasattr",
"(",
"self",
"... | Encrypt the data, and append the computed authentication code.
TLS 1.3 does not use additional data, but we leave this option to the
user nonetheless.
Note that the cipher's authentication tag must be None when encrypting. | [
"Encrypt",
"the",
"data",
"and",
"append",
"the",
"computed",
"authentication",
"code",
".",
"TLS",
"1",
".",
"3",
"does",
"not",
"use",
"additional",
"data",
"but",
"we",
"leave",
"this",
"option",
"to",
"the",
"user",
"nonetheless",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L308-L333 | train |
secdev/scapy | scapy/layers/tls/crypto/cipher_aead.py | _AEADCipher_TLS13.auth_decrypt | def auth_decrypt(self, A, C, seq_num):
"""
Decrypt the data and verify the authentication code (in this order).
Note that TLS 1.3 is not supposed to use any additional data A.
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if dee... | python | def auth_decrypt(self, A, C, seq_num):
"""
Decrypt the data and verify the authentication code (in this order).
Note that TLS 1.3 is not supposed to use any additional data A.
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if dee... | [
"def",
"auth_decrypt",
"(",
"self",
",",
"A",
",",
"C",
",",
"seq_num",
")",
":",
"C",
",",
"mac",
"=",
"C",
"[",
":",
"-",
"self",
".",
"tag_len",
"]",
",",
"C",
"[",
"-",
"self",
".",
"tag_len",
":",
"]",
"if",
"False",
"in",
"six",
".",
... | Decrypt the data and verify the authentication code (in this order).
Note that TLS 1.3 is not supposed to use any additional data A.
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if deemed useful. If we lack the key, we
raise a CipherEr... | [
"Decrypt",
"the",
"data",
"and",
"verify",
"the",
"authentication",
"code",
"(",
"in",
"this",
"order",
")",
".",
"Note",
"that",
"TLS",
"1",
".",
"3",
"is",
"not",
"supposed",
"to",
"use",
"any",
"additional",
"data",
"A",
".",
"If",
"the",
"verificat... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L335-L370 | train |
secdev/scapy | scapy/contrib/tzsp.py | _tzsp_guess_next_tag | def _tzsp_guess_next_tag(payload):
"""
:return: class representing the next tag, Raw on error, None on missing payload # noqa: E501
"""
if not payload:
warning('missing payload')
return None
tag_type = orb(payload[0])
try:
tag_class_definition = _TZSP_TAG_CLASSES[tag_... | python | def _tzsp_guess_next_tag(payload):
"""
:return: class representing the next tag, Raw on error, None on missing payload # noqa: E501
"""
if not payload:
warning('missing payload')
return None
tag_type = orb(payload[0])
try:
tag_class_definition = _TZSP_TAG_CLASSES[tag_... | [
"def",
"_tzsp_guess_next_tag",
"(",
"payload",
")",
":",
"if",
"not",
"payload",
":",
"warning",
"(",
"'missing payload'",
")",
"return",
"None",
"tag_type",
"=",
"orb",
"(",
"payload",
"[",
"0",
"]",
")",
"try",
":",
"tag_class_definition",
"=",
"_TZSP_TAG_... | :return: class representing the next tag, Raw on error, None on missing payload # noqa: E501 | [
":",
"return",
":",
"class",
"representing",
"the",
"next",
"tag",
"Raw",
"on",
"error",
"None",
"on",
"missing",
"payload",
"#",
"noqa",
":",
"E501"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/tzsp.py#L153-L187 | train |
secdev/scapy | scapy/contrib/tzsp.py | TZSP.get_encapsulated_payload_class | def get_encapsulated_payload_class(self):
"""
get the class that holds the encapsulated payload of the TZSP packet
:return: class representing the payload, Raw() on error
"""
try:
return TZSP.ENCAPSULATED_PROTOCOL_CLASSES[self.encapsulated_protocol] # noqa: E501
... | python | def get_encapsulated_payload_class(self):
"""
get the class that holds the encapsulated payload of the TZSP packet
:return: class representing the payload, Raw() on error
"""
try:
return TZSP.ENCAPSULATED_PROTOCOL_CLASSES[self.encapsulated_protocol] # noqa: E501
... | [
"def",
"get_encapsulated_payload_class",
"(",
"self",
")",
":",
"try",
":",
"return",
"TZSP",
".",
"ENCAPSULATED_PROTOCOL_CLASSES",
"[",
"self",
".",
"encapsulated_protocol",
"]",
"# noqa: E501",
"except",
"KeyError",
":",
"warning",
"(",
"'unknown or invalid encapsulat... | get the class that holds the encapsulated payload of the TZSP packet
:return: class representing the payload, Raw() on error | [
"get",
"the",
"class",
"that",
"holds",
"the",
"encapsulated",
"payload",
"of",
"the",
"TZSP",
"packet",
":",
"return",
":",
"class",
"representing",
"the",
"payload",
"Raw",
"()",
"on",
"error"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/tzsp.py#L100-L111 | train |
secdev/scapy | scapy/contrib/tzsp.py | TZSPTagEnd.guess_payload_class | def guess_payload_class(self, payload):
"""
the type of the payload encapsulation is given be the outer TZSP layers attribute encapsulation_protocol # noqa: E501
"""
under_layer = self.underlayer
tzsp_header = None
while under_layer:
if isinstance(under_lay... | python | def guess_payload_class(self, payload):
"""
the type of the payload encapsulation is given be the outer TZSP layers attribute encapsulation_protocol # noqa: E501
"""
under_layer = self.underlayer
tzsp_header = None
while under_layer:
if isinstance(under_lay... | [
"def",
"guess_payload_class",
"(",
"self",
",",
"payload",
")",
":",
"under_layer",
"=",
"self",
".",
"underlayer",
"tzsp_header",
"=",
"None",
"while",
"under_layer",
":",
"if",
"isinstance",
"(",
"under_layer",
",",
"TZSP",
")",
":",
"tzsp_header",
"=",
"u... | the type of the payload encapsulation is given be the outer TZSP layers attribute encapsulation_protocol # noqa: E501 | [
"the",
"type",
"of",
"the",
"payload",
"encapsulation",
"is",
"given",
"be",
"the",
"outer",
"TZSP",
"layers",
"attribute",
"encapsulation_protocol",
"#",
"noqa",
":",
"E501"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/tzsp.py#L246-L264 | train |
secdev/scapy | scapy/contrib/eigrp.py | ShortVersionField.h2i | def h2i(self, pkt, x):
"""The field accepts string values like v12.1, v1.1 or integer values.
String values have to start with a "v" folled by a floating point number.
Valid numbers are between 0 and 255.
"""
if isinstance(x, str) and x.startswith("v") and len(x) <= 8:
... | python | def h2i(self, pkt, x):
"""The field accepts string values like v12.1, v1.1 or integer values.
String values have to start with a "v" folled by a floating point number.
Valid numbers are between 0 and 255.
"""
if isinstance(x, str) and x.startswith("v") and len(x) <= 8:
... | [
"def",
"h2i",
"(",
"self",
",",
"pkt",
",",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"str",
")",
"and",
"x",
".",
"startswith",
"(",
"\"v\"",
")",
"and",
"len",
"(",
"x",
")",
"<=",
"8",
":",
"major",
"=",
"int",
"(",
"x",
".",
"sp... | The field accepts string values like v12.1, v1.1 or integer values.
String values have to start with a "v" folled by a floating point number.
Valid numbers are between 0 and 255. | [
"The",
"field",
"accepts",
"string",
"values",
"like",
"v12",
".",
"1",
"v1",
".",
"1",
"or",
"integer",
"values",
".",
"String",
"values",
"have",
"to",
"start",
"with",
"a",
"v",
"folled",
"by",
"a",
"floating",
"point",
"number",
".",
"Valid",
"numb... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/eigrp.py#L284-L305 | train |
secdev/scapy | scapy/layers/tls/crypto/suites.py | get_algs_from_ciphersuite_name | def get_algs_from_ciphersuite_name(ciphersuite_name):
"""
Return the 3-tuple made of the Key Exchange Algorithm class, the Cipher
class and the HMAC class, through the parsing of the ciphersuite name.
"""
tls1_3 = False
if ciphersuite_name.startswith("TLS"):
s = ciphersuite_name[4:]
... | python | def get_algs_from_ciphersuite_name(ciphersuite_name):
"""
Return the 3-tuple made of the Key Exchange Algorithm class, the Cipher
class and the HMAC class, through the parsing of the ciphersuite name.
"""
tls1_3 = False
if ciphersuite_name.startswith("TLS"):
s = ciphersuite_name[4:]
... | [
"def",
"get_algs_from_ciphersuite_name",
"(",
"ciphersuite_name",
")",
":",
"tls1_3",
"=",
"False",
"if",
"ciphersuite_name",
".",
"startswith",
"(",
"\"TLS\"",
")",
":",
"s",
"=",
"ciphersuite_name",
"[",
"4",
":",
"]",
"if",
"s",
".",
"endswith",
"(",
"\"C... | Return the 3-tuple made of the Key Exchange Algorithm class, the Cipher
class and the HMAC class, through the parsing of the ciphersuite name. | [
"Return",
"the",
"3",
"-",
"tuple",
"made",
"of",
"the",
"Key",
"Exchange",
"Algorithm",
"class",
"the",
"Cipher",
"class",
"and",
"the",
"HMAC",
"class",
"through",
"the",
"parsing",
"of",
"the",
"ciphersuite",
"name",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/suites.py#L21-L67 | train |
secdev/scapy | scapy/layers/tls/crypto/suites.py | get_usable_ciphersuites | def get_usable_ciphersuites(l, kx):
"""
From a list of proposed ciphersuites, this function returns a list of
usable cipher suites, i.e. for which key exchange, cipher and hash
algorithms are known to be implemented and usable in current version of the
TLS extension. The order of the cipher suites i... | python | def get_usable_ciphersuites(l, kx):
"""
From a list of proposed ciphersuites, this function returns a list of
usable cipher suites, i.e. for which key exchange, cipher and hash
algorithms are known to be implemented and usable in current version of the
TLS extension. The order of the cipher suites i... | [
"def",
"get_usable_ciphersuites",
"(",
"l",
",",
"kx",
")",
":",
"res",
"=",
"[",
"]",
"for",
"c",
"in",
"l",
":",
"if",
"c",
"in",
"_tls_cipher_suites_cls",
":",
"ciph",
"=",
"_tls_cipher_suites_cls",
"[",
"c",
"]",
"if",
"ciph",
".",
"usable",
":",
... | From a list of proposed ciphersuites, this function returns a list of
usable cipher suites, i.e. for which key exchange, cipher and hash
algorithms are known to be implemented and usable in current version of the
TLS extension. The order of the cipher suites in the list returned by the
function matches ... | [
"From",
"a",
"list",
"of",
"proposed",
"ciphersuites",
"this",
"function",
"returns",
"a",
"list",
"of",
"usable",
"cipher",
"suites",
"i",
".",
"e",
".",
"for",
"which",
"key",
"exchange",
"cipher",
"and",
"hash",
"algorithms",
"are",
"known",
"to",
"be",... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/suites.py#L1300-L1317 | train |
secdev/scapy | scapy/layers/inet.py | in4_chksum | def in4_chksum(proto, u, p):
"""
As Specified in RFC 2460 - 8.1 Upper-Layer Checksums
Performs IPv4 Upper Layer checksum computation. Provided parameters are:
- 'proto' : value of upper layer protocol
- 'u' : IP upper layer instance
- 'p' : the payload of the upper layer provided as a string
... | python | def in4_chksum(proto, u, p):
"""
As Specified in RFC 2460 - 8.1 Upper-Layer Checksums
Performs IPv4 Upper Layer checksum computation. Provided parameters are:
- 'proto' : value of upper layer protocol
- 'u' : IP upper layer instance
- 'p' : the payload of the upper layer provided as a string
... | [
"def",
"in4_chksum",
"(",
"proto",
",",
"u",
",",
"p",
")",
":",
"if",
"not",
"isinstance",
"(",
"u",
",",
"IP",
")",
":",
"warning",
"(",
"\"No IP underlayer to compute checksum. Leaving null.\"",
")",
"return",
"0",
"if",
"u",
".",
"len",
"is",
"not",
... | As Specified in RFC 2460 - 8.1 Upper-Layer Checksums
Performs IPv4 Upper Layer checksum computation. Provided parameters are:
- 'proto' : value of upper layer protocol
- 'u' : IP upper layer instance
- 'p' : the payload of the upper layer provided as a string | [
"As",
"Specified",
"in",
"RFC",
"2460",
"-",
"8",
".",
"1",
"Upper",
"-",
"Layer",
"Checksums"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L578-L604 | train |
secdev/scapy | scapy/layers/inet.py | _defrag_list | def _defrag_list(lst, defrag, missfrag):
"""Internal usage only. Part of the _defrag_logic"""
p = lst[0]
lastp = lst[-1]
if p.frag > 0 or lastp.flags.MF: # first or last fragment missing
missfrag.append(lst)
return
p = p.copy()
if conf.padding_layer in p:
del(p[conf.padd... | python | def _defrag_list(lst, defrag, missfrag):
"""Internal usage only. Part of the _defrag_logic"""
p = lst[0]
lastp = lst[-1]
if p.frag > 0 or lastp.flags.MF: # first or last fragment missing
missfrag.append(lst)
return
p = p.copy()
if conf.padding_layer in p:
del(p[conf.padd... | [
"def",
"_defrag_list",
"(",
"lst",
",",
"defrag",
",",
"missfrag",
")",
":",
"p",
"=",
"lst",
"[",
"0",
"]",
"lastp",
"=",
"lst",
"[",
"-",
"1",
"]",
"if",
"p",
".",
"frag",
">",
"0",
"or",
"lastp",
".",
"flags",
".",
"MF",
":",
"# first or las... | Internal usage only. Part of the _defrag_logic | [
"Internal",
"usage",
"only",
".",
"Part",
"of",
"the",
"_defrag_logic"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1018-L1055 | train |
secdev/scapy | scapy/layers/inet.py | _defrag_logic | def _defrag_logic(plist, complete=False):
"""Internal function used to defragment a list of packets.
It contains the logic behind the defrag() and defragment() functions
"""
frags = defaultdict(lambda: [])
final = []
pos = 0
for p in plist:
p._defrag_pos = pos
pos += 1
... | python | def _defrag_logic(plist, complete=False):
"""Internal function used to defragment a list of packets.
It contains the logic behind the defrag() and defragment() functions
"""
frags = defaultdict(lambda: [])
final = []
pos = 0
for p in plist:
p._defrag_pos = pos
pos += 1
... | [
"def",
"_defrag_logic",
"(",
"plist",
",",
"complete",
"=",
"False",
")",
":",
"frags",
"=",
"defaultdict",
"(",
"lambda",
":",
"[",
"]",
")",
"final",
"=",
"[",
"]",
"pos",
"=",
"0",
"for",
"p",
"in",
"plist",
":",
"p",
".",
"_defrag_pos",
"=",
... | Internal function used to defragment a list of packets.
It contains the logic behind the defrag() and defragment() functions | [
"Internal",
"function",
"used",
"to",
"defragment",
"a",
"list",
"of",
"packets",
".",
"It",
"contains",
"the",
"logic",
"behind",
"the",
"defrag",
"()",
"and",
"defragment",
"()",
"functions"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1058-L1097 | train |
secdev/scapy | scapy/layers/inet.py | _packetlist_timeskew_graph | def _packetlist_timeskew_graph(self, ip, **kargs):
"""Tries to graph the timeskew between the timestamps and real time for a given ip""" # noqa: E501
# Filter TCP segments which source address is 'ip'
tmp = (self._elt2pkt(x) for x in self.res)
b = (x for x in tmp if IP in x and x[IP].src == ip and TCP... | python | def _packetlist_timeskew_graph(self, ip, **kargs):
"""Tries to graph the timeskew between the timestamps and real time for a given ip""" # noqa: E501
# Filter TCP segments which source address is 'ip'
tmp = (self._elt2pkt(x) for x in self.res)
b = (x for x in tmp if IP in x and x[IP].src == ip and TCP... | [
"def",
"_packetlist_timeskew_graph",
"(",
"self",
",",
"ip",
",",
"*",
"*",
"kargs",
")",
":",
"# noqa: E501",
"# Filter TCP segments which source address is 'ip'",
"tmp",
"=",
"(",
"self",
".",
"_elt2pkt",
"(",
"x",
")",
"for",
"x",
"in",
"self",
".",
"res",
... | Tries to graph the timeskew between the timestamps and real time for a given ip | [
"Tries",
"to",
"graph",
"the",
"timeskew",
"between",
"the",
"timestamps",
"and",
"real",
"time",
"for",
"a",
"given",
"ip"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1114-L1159 | train |
secdev/scapy | scapy/layers/inet.py | traceroute | def traceroute(target, dport=80, minttl=1, maxttl=30, sport=RandShort(), l4=None, filter=None, timeout=2, verbose=None, **kargs): # noqa: E501
"""Instant TCP traceroute
traceroute(target, [maxttl=30,] [dport=80,] [sport=80,] [verbose=conf.verb]) -> None # noqa: E501
"""
if verbose is None:
verbose = c... | python | def traceroute(target, dport=80, minttl=1, maxttl=30, sport=RandShort(), l4=None, filter=None, timeout=2, verbose=None, **kargs): # noqa: E501
"""Instant TCP traceroute
traceroute(target, [maxttl=30,] [dport=80,] [sport=80,] [verbose=conf.verb]) -> None # noqa: E501
"""
if verbose is None:
verbose = c... | [
"def",
"traceroute",
"(",
"target",
",",
"dport",
"=",
"80",
",",
"minttl",
"=",
"1",
",",
"maxttl",
"=",
"30",
",",
"sport",
"=",
"RandShort",
"(",
")",
",",
"l4",
"=",
"None",
",",
"filter",
"=",
"None",
",",
"timeout",
"=",
"2",
",",
"verbose"... | Instant TCP traceroute
traceroute(target, [maxttl=30,] [dport=80,] [sport=80,] [verbose=conf.verb]) -> None # noqa: E501 | [
"Instant",
"TCP",
"traceroute",
"traceroute",
"(",
"target",
"[",
"maxttl",
"=",
"30",
"]",
"[",
"dport",
"=",
"80",
"]",
"[",
"sport",
"=",
"80",
"]",
"[",
"verbose",
"=",
"conf",
".",
"verb",
"]",
")",
"-",
">",
"None",
"#",
"noqa",
":",
"E501"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1643-L1666 | train |
secdev/scapy | scapy/layers/inet.py | report_ports | def report_ports(target, ports):
"""portscan a target and output a LaTeX table
report_ports(target, ports) -> string"""
ans, unans = sr(IP(dst=target) / TCP(dport=ports), timeout=5)
rep = "\\begin{tabular}{|r|l|l|}\n\\hline\n"
for s, r in ans:
if not r.haslayer(ICMP):
if r.payload.fl... | python | def report_ports(target, ports):
"""portscan a target and output a LaTeX table
report_ports(target, ports) -> string"""
ans, unans = sr(IP(dst=target) / TCP(dport=ports), timeout=5)
rep = "\\begin{tabular}{|r|l|l|}\n\\hline\n"
for s, r in ans:
if not r.haslayer(ICMP):
if r.payload.fl... | [
"def",
"report_ports",
"(",
"target",
",",
"ports",
")",
":",
"ans",
",",
"unans",
"=",
"sr",
"(",
"IP",
"(",
"dst",
"=",
"target",
")",
"/",
"TCP",
"(",
"dport",
"=",
"ports",
")",
",",
"timeout",
"=",
"5",
")",
"rep",
"=",
"\"\\\\begin{tabular}{|... | portscan a target and output a LaTeX table
report_ports(target, ports) -> string | [
"portscan",
"a",
"target",
"and",
"output",
"a",
"LaTeX",
"table",
"report_ports",
"(",
"target",
"ports",
")",
"-",
">",
"string"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1811-L1830 | train |
secdev/scapy | scapy/layers/inet.py | IPID_count | def IPID_count(lst, funcID=lambda x: x[1].id, funcpres=lambda x: x[1].summary()): # noqa: E501
"""Identify IP id values classes in a list of packets
lst: a list of packets
funcID: a function that returns IP id values
funcpres: a function used to summarize packets"""
idlst = [funcID(e) for e in lst]
... | python | def IPID_count(lst, funcID=lambda x: x[1].id, funcpres=lambda x: x[1].summary()): # noqa: E501
"""Identify IP id values classes in a list of packets
lst: a list of packets
funcID: a function that returns IP id values
funcpres: a function used to summarize packets"""
idlst = [funcID(e) for e in lst]
... | [
"def",
"IPID_count",
"(",
"lst",
",",
"funcID",
"=",
"lambda",
"x",
":",
"x",
"[",
"1",
"]",
".",
"id",
",",
"funcpres",
"=",
"lambda",
"x",
":",
"x",
"[",
"1",
"]",
".",
"summary",
"(",
")",
")",
":",
"# noqa: E501",
"idlst",
"=",
"[",
"funcID... | Identify IP id values classes in a list of packets
lst: a list of packets
funcID: a function that returns IP id values
funcpres: a function used to summarize packets | [
"Identify",
"IP",
"id",
"values",
"classes",
"in",
"a",
"list",
"of",
"packets"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1834-L1848 | train |
secdev/scapy | scapy/layers/inet.py | IPTools._ttl | def _ttl(self):
"""Returns ttl or hlim, depending on the IP version"""
return self.hlim if isinstance(self, scapy.layers.inet6.IPv6) else self.ttl | python | def _ttl(self):
"""Returns ttl or hlim, depending on the IP version"""
return self.hlim if isinstance(self, scapy.layers.inet6.IPv6) else self.ttl | [
"def",
"_ttl",
"(",
"self",
")",
":",
"return",
"self",
".",
"hlim",
"if",
"isinstance",
"(",
"self",
",",
"scapy",
".",
"layers",
".",
"inet6",
".",
"IPv6",
")",
"else",
"self",
".",
"ttl"
] | Returns ttl or hlim, depending on the IP version | [
"Returns",
"ttl",
"or",
"hlim",
"depending",
"on",
"the",
"IP",
"version"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L62-L64 | train |
secdev/scapy | scapy/layers/inet.py | TracerouteResult.trace3D | def trace3D(self, join=True):
"""Give a 3D representation of the traceroute.
right button: rotate the scene
middle button: zoom
shift-left button: move the scene
left button on a ball: toggle IP displaying
double-click button on a ball: scan ports 21,22,23,25,80 and 443 a... | python | def trace3D(self, join=True):
"""Give a 3D representation of the traceroute.
right button: rotate the scene
middle button: zoom
shift-left button: move the scene
left button on a ball: toggle IP displaying
double-click button on a ball: scan ports 21,22,23,25,80 and 443 a... | [
"def",
"trace3D",
"(",
"self",
",",
"join",
"=",
"True",
")",
":",
"# noqa: E501",
"# When not ran from a notebook, vpython pooly closes itself",
"# using os._exit once finished. We pack it into a Process",
"import",
"multiprocessing",
"p",
"=",
"multiprocessing",
".",
"Process... | Give a 3D representation of the traceroute.
right button: rotate the scene
middle button: zoom
shift-left button: move the scene
left button on a ball: toggle IP displaying
double-click button on a ball: scan ports 21,22,23,25,80 and 443 and display the result | [
"Give",
"a",
"3D",
"representation",
"of",
"the",
"traceroute",
".",
"right",
"button",
":",
"rotate",
"the",
"scene",
"middle",
"button",
":",
"zoom",
"shift",
"-",
"left",
"button",
":",
"move",
"the",
"scene",
"left",
"button",
"on",
"a",
"ball",
":",... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1202-L1215 | train |
secdev/scapy | scapy/layers/inet.py | TracerouteResult.trace3D_notebook | def trace3D_notebook(self):
"""Same than trace3D, used when ran from Jupyther notebooks"""
trace = self.get_trace()
import vpython
class IPsphere(vpython.sphere):
def __init__(self, ip, **kargs):
vpython.sphere.__init__(self, **kargs)
self.ip ... | python | def trace3D_notebook(self):
"""Same than trace3D, used when ran from Jupyther notebooks"""
trace = self.get_trace()
import vpython
class IPsphere(vpython.sphere):
def __init__(self, ip, **kargs):
vpython.sphere.__init__(self, **kargs)
self.ip ... | [
"def",
"trace3D_notebook",
"(",
"self",
")",
":",
"trace",
"=",
"self",
".",
"get_trace",
"(",
")",
"import",
"vpython",
"class",
"IPsphere",
"(",
"vpython",
".",
"sphere",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"ip",
",",
"*",
"*",
"kargs",
... | Same than trace3D, used when ran from Jupyther notebooks | [
"Same",
"than",
"trace3D",
"used",
"when",
"ran",
"from",
"Jupyther",
"notebooks"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1217-L1362 | train |
secdev/scapy | scapy/layers/inet.py | TracerouteResult.world_trace | def world_trace(self):
"""Display traceroute results on a world map."""
# Check that the geoip2 module can be imported
# Doc: http://geoip2.readthedocs.io/en/latest/
try:
# GeoIP2 modules need to be imported as below
import geoip2.database
import geoi... | python | def world_trace(self):
"""Display traceroute results on a world map."""
# Check that the geoip2 module can be imported
# Doc: http://geoip2.readthedocs.io/en/latest/
try:
# GeoIP2 modules need to be imported as below
import geoip2.database
import geoi... | [
"def",
"world_trace",
"(",
"self",
")",
":",
"# Check that the geoip2 module can be imported",
"# Doc: http://geoip2.readthedocs.io/en/latest/",
"try",
":",
"# GeoIP2 modules need to be imported as below",
"import",
"geoip2",
".",
"database",
"import",
"geoip2",
".",
"errors",
... | Display traceroute results on a world map. | [
"Display",
"traceroute",
"results",
"on",
"a",
"world",
"map",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1364-L1480 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.