text stringlengths 81 112k |
|---|
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 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 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 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 ... |
Used to select the L2 address
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) |
Extract the IPv6 payload
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 ... |
Compute the 'sources_number' field when needed
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 _IC... |
Compute the 'records_number' field when needed
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 _ICMP... |
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,... |
Add the endianness to the format
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 == '<'
... |
retrieve the field with endianness
def getfield(self, pkt, buf):
"""retrieve the field with endianness"""
self.set_endianess(pkt)
return self.fld.getfield(pkt, buf) |
add the field with endianness to the buffer
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) |
dispatch_hook to choose among different registered payloads
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_... |
_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... |
_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... |
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 "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.
... |
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... |
_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... |
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
def h2i(self, p... |
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.
def i2repr(self, pkt, x):
# type: ... |
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... |
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
def _huffman_encode_char(cls, c):
# type: (Union[str, EOS]) -> Tuple[... |
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
def huffman_encode(cls, s):
# type: (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, InvalidEncodingException
def huffman_decode(cls, i, ibl):
# type: (int... |
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_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_compute_decode_tree initializes/builds the static_huffman_tree
@return None
@raise InvalidEncodingException if there is an encoding problem
def huffman_compute_decode_tree(cls):
# type: () -> None
""" huffman_compute_decode_tree initializes/builds the static_huffman_tree
... |
self_build is overridden because type and len are determined at
build time, based on the "data" field internal type
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 in... |
dispatch_hook returns the subclass of HPackHeaders that must be used
to dissect the string.
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 d... |
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_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
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
... |
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 ... |
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
def resize(self, ns):
# type: (int)... |
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
def recap(self, nc):
# type: ... |
_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... |
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... |
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... |
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... |
_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... |
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... |
Craft an AVP based on its id and optional parameter fields
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... |
Update or fill the fields parameters depending on command code. Both cmd and drAppId can be provided # noqa: E501
in string or int format.
def getCmdParams(cmd, request, **fields):
"""Update or fill the fields parameters depending on command code. Both cmd and drAppId can be provided # noqa: E501
i... |
Craft Diameter request commands
def DiamReq(cmd, **fields):
"""Craft Diameter request commands"""
upfields, name = getCmdParams(cmd, True, **fields)
p = DiamG(**upfields)
p.name = name
return p |
Craft Diameter answer commands
def DiamAns(cmd, **fields):
"""Craft Diameter answer commands"""
upfields, name = getCmdParams(cmd, False, **fields)
p = DiamG(**upfields)
p.name = name
return p |
Convert internal value to machine value
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 |
Internal function used by _find_fld_pkt & _find_fld_pkt_val
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 us... |
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.
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 necessar... |
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 a FlagValue instance when needed. Internal method, to be
used in *2i() and i2*() methods.
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)(
... |
Checks .uuid_fmt, and raises an exception if it is not valid.
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.uui... |
We need to parse the padding and type as soon as possible,
else we won't be able to parse the message list...
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:
... |
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... |
Decrypt, verify and decompress the message.
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... |
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).
def post_dissect(self, s):
"""
Commit the pending read state if it has been triggered. We up... |
Return the TLSCiphertext.encrypted_record for AEAD ciphers.
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.c... |
Apply the previous methods according to the writing cipher type.
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... |
Encrypt data @data with key @key, skipping @skip first bytes of the
keystream
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())
... |
Source https://stackoverflow.com/questions/12018920/
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 <= ... |
Implement TKIP WEPSeed generation
TSC: packet IV
TA: target addr bytes
TK: temporal 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) ... |
Defined in 802.11i p.49
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... |
Defined in 802.11i p.48
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 + ... |
Extract TSCs, TA and encoded-data from a packet @pkt
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 tk... |
Build a TKIP header for IV @iv and mac @mac, and encrypt @data
based on temporal key @tk
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,
... |
Extract data from a WPA packet @pkt with temporal key @tk
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) |
Check MIC, ICV & return the data from a decrypted TKIP packet
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:]
MI... |
Compute and return the data with its MIC and 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
M... |
Least Common Multiple between 2 integers.
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) |
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... |
@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... |
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... |
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
def encrypt(self, sa,... |
Check that the key length is valid.
@param key: a byte string
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, mus... |
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
def sign(self, pkt, key):
"""
Sign an IPsec (ESP or AH) packet with this alg... |
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):
"""
... |
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... |
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
def decrypt(self, pkt... |
Increment the explicit nonce while avoiding any overflow.
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) |
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... |
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... |
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):
"""
Encrypt the ... |
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... |
:return: class representing the next tag, Raw on error, None on missing payload # noqa: E501
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
... |
get the class that holds the encapsulated payload of the TZSP packet
:return: class representing the payload, Raw() on error
def get_encapsulated_payload_class(self):
"""
get the class that holds the encapsulated payload of the TZSP packet
:return: class representing the payload, Raw() ... |
the type of the payload encapsulation is given be the outer TZSP layers attribute encapsulation_protocol # noqa: E501
def guess_payload_class(self, payload):
"""
the type of the payload encapsulation is given be the outer TZSP layers attribute encapsulation_protocol # noqa: E501
"""
... |
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.
def h2i(self, pkt, x):
"""The field accepts string values like v12.1, v1.1 or integer values.
Strin... |
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.
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, thro... |
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 ... |
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):
"""
... |
Internal usage only. Part of the _defrag_logic
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 ... |
Internal function used to defragment a list of packets.
It contains the logic behind the defrag() and defragment() functions
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
"""
... |
Tries to graph the timeskew between the timestamps and real time for a given ip
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) ... |
Instant TCP traceroute
traceroute(target, [maxttl=30,] [dport=80,] [sport=80,] [verbose=conf.verb]) -> None # noqa: E501
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, [max... |
portscan a target and output a LaTeX table
report_ports(target, ports) -> string
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"... |
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
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... |
Returns ttl or hlim, depending on the IP version
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 |
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
def trace3D(self, ... |
Same than trace3D, used when ran from Jupyther notebooks
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):
vpyth... |
Display traceroute results on a world map.
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
im... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.