func_code_string
stringlengths
52
1.94M
func_documentation_string
stringlengths
1
47.2k
def _read_mode_route(self, size, kind): if size < 3 or (size - 3) % 4 != 0: raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format') _rptr = self._read_unpack(1) if _rptr < 4: raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format') ...
Read options with route data. Positional arguments: * size - int, length of option * kind - int, 7/131/137 (RR/LSR/SSR) Returns: * dict -- extracted option with route data Structure of these options: * [RFC 791] Loose Source Route ...
def _read_mode_qs(self, size, kind): if size != 8: raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format') _type = self._read_opt_type(kind) _fcrr = self._read_binary(1) _func = int(_fcrr[:4], base=2) _rate = int(_fcrr[4:], base=2) _ttlv =...
Read Quick Start option. Positional arguments: * size - int, length of option * kind - int, 25 (QS) Returns: * dict -- extracted Quick Start (QS) option Structure of Quick-Start (QS) option [RFC 4782]: * A Quick-Start Request. 0...
def _read_mode_ts(self, size, kind): if size > 40 or size < 4: raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format') _tptr = self._read_unpack(1) _oflg = self._read_binary(1) _oflw = int(_oflg[:4], base=2) _flag = int(_oflg[4:], base=2) ...
Read Time Stamp option. Positional arguments: * size - int, length of option * kind - int, 68 (TS) Returns: * dict -- extracted Time Stamp (TS) option Structure of Timestamp (TS) option [RFC 791]: +--------+--------+--------+--------+ ...
def _read_mode_tr(self, size, kind): if size != 12: raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format') _idnm = self._read_unpack(2) _ohcn = self._read_unpack(2) _rhcn = self._read_unpack(2) _ipad = self._read_ipv4_addr() data = dict( ...
Read Traceroute option. Positional arguments: size - int, length of option kind - int, 82 (TR) Returns: * dict -- extracted Traceroute (TR) option Structure of Traceroute (TR) option [RFC 1393][RFC 6814]: 0 8 16 ...
def _read_mode_sec(self, size, kind): if size < 3: raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format') _clvl = self._read_unpack(1) data = dict( kind=kind, type=self._read_opt_type(kind), length=size, level=_CLA...
Read options with security info. Positional arguments: size - int, length of option kind - int, 130 (SEC )/ 133 (ESEC) Returns: * dict -- extracted option with security info (E/SEC) Structure of these options: * [RFC 1108] Security (SEC) ...
def _read_mode_rsralt(self, size, kind): if size != 4: raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format') _code = self._read_unpack(2) data = dict( kind=kind, type=self._read_opt_type(kind), length=size, alert=...
Read Router Alert option. Positional arguments: size - int, length of option kind - int, 148 (RTRALT) Returns: * dict -- extracted Router Alert (RTRALT) option Structure of Router Alert (RTRALT) option [RFC 2113]: +--------+--------+--------+---...
def read_header(self): _magn = self._read_fileng(4) if _magn == b'\xd4\xc3\xb2\xa1': lilendian = True self._nsec = False self._byte = 'little' elif _magn == b'\xa1\xb2\xc3\xd4': lilendian = False self._nsec = False ...
Read global header of PCAP file. Structure of global header (C): typedef struct pcap_hdr_s { guint32 magic_number; /* magic number */ guint16 version_major; /* major version number */ guint16 version_minor; /* minor version number */ ...
def _read_protos(self, size): _byte = self._read_unpack(4, lilendian=True) _prot = LINKTYPE.get(_byte) return _prot
Read next layer protocol type. Positional arguments: * size -- int, buffer size Returns: * str -- link layer protocol name
def read_frame(self): # _scur = self._file.tell() _temp = self._read_unpack(4, lilendian=True, quiet=True) if _temp is None: raise EOFError _tsss = _temp _tsus = self._read_unpack(4, lilendian=True) _ilen = self._read_unpack(4, lilendian=True) ...
Read each block after global header. Structure of record/package header (C): typedef struct pcaprec_hdr_s { guint32 ts_sec; /* timestamp seconds */ guint32 ts_usec; /* timestamp microseconds */ guint32 incl_len; /* number of octets of packet ...
def _decode_next_layer(self, dict_, length=None): seek_cur = self._file.tell() try: next_ = self._import_next_layer(self._prot, length) except Exception: dict_['error'] = traceback.format_exc(limit=1).strip().split(os.linesep)[-1] self._file.seek(seek...
Decode next layer protocol. Positional arguments: dict_ -- dict, info buffer proto -- str, next layer protocol name length -- int, valid (not padding) length Returns: * dict -- current protocol with packet extracted
def _import_next_layer(self, proto, length, error=False): if proto == 1: from pcapkit.protocols.link import Ethernet as Protocol elif proto == 228: from pcapkit.protocols.internet import IPv4 as Protocol elif proto == 229: from pcapkit.protocols.inter...
Import next layer extractor. Positional arguments: * proto -- str, next layer protocol name * length -- int, valid (not padding) length Keyword arguments: * error -- bool, if function call on error Returns: * bool -- flag if extraction of next l...
def get(key, default=-1): if isinstance(key, int): return RegistrationFailure(key) if key not in RegistrationFailure._member_map_: extend_enum(RegistrationFailure, key, default) return RegistrationFailure[key]
Backport support for original codes.
def get(key, default=-1): if isinstance(key, int): return TOS_PRE(key) if key not in TOS_PRE._member_map_: extend_enum(TOS_PRE, key, default) return TOS_PRE[key]
Backport support for original codes.
def read_raw(self, length, *, error=None): if length is None: length = len(self) raw = dict( packet=self._read_fileng(length), error=error or None, ) return raw
Read raw packet data.
def get(key, default=-1): if isinstance(key, int): return NotifyMessage(key) if key not in NotifyMessage._member_map_: extend_enum(NotifyMessage, key, default) return NotifyMessage[key]
Backport support for original codes.
def _missing_(cls, value): if not (isinstance(value, int) and 0 <= value <= 65535): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) if 2 <= value <= 6: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) if 8 <= value...
Lookup function used when value is not found.
def ipv6_hdr_len(ipv6): hdr_len = ipv6.__hdr_len__ for code in (0, 60, 43): ext_hdr = ipv6.extension_hdrs.get(code) if ext_hdr is not None: hdr_len += ext_hdr.length return hdr_len
Calculate length of headers before IPv6-Frag
def packet2chain(packet): chain = [type(packet).__name__] payload = packet.data while not isinstance(payload, bytes): chain.append(type(payload).__name__) payload = payload.data return ':'.join(chain)
Fetch DPKT packet protocol chain.
def packet2dict(packet, timestamp, *, data_link): def wrapper(packet): dict_ = dict() for field in packet.__hdr_fields__: dict_[field] = getattr(packet, field, None) payload = packet.data if not isinstance(payload, bytes): dict_[type(payload).__name__] = ...
Convert DPKT packet into dict.
def ipv4_reassembly(packet, *, count=NotImplemented): ipv4 = getattr(packet, 'ip', None) if ipv4 is not None: if ipv4.df: # dismiss not fragmented packet return False, None data = dict( bufid=( ipaddress.ip_address(ipv4.src), # sou...
Make data for IPv4 reassembly.
def ipv6_reassembly(packet, *, count=NotImplemented): ipv6 = getattr(packet, 'ip6', None) if ipv6 is not None: ipv6_frag = ipv6.extension_hdrs.get(44) if ipv6_frag is None: # dismiss not fragmented packet return False, None hdr_len = ipv6_hdr_len(ipv6) data...
Make data for IPv6 reassembly.
def tcp_reassembly(packet, *, count=NotImplemented): if getattr(packet, 'ip', None): ip = packet['ip'] elif getattr(packet, 'ip6', None): ip = packet['ip6'] else: return False, None tcp = getattr(ip, 'tcp', None) if tcp is not None: flags = bin(tcp.flags)[2:].zfi...
Make data for TCP reassembly.
def tcp_traceflow(packet, timestamp, *, data_link, count=NotImplemented): if getattr(packet, 'ip', None): ip = packet['ip'] elif getattr(packet, 'ip6', None): ip = packet['ip6'] else: return False, None tcp = getattr(ip, 'tcp', None) if tcp is not None: flags = b...
Trace packet flow for TCP.
def read_http(self, length): if length is None: length = len(self) if length < 9: raise ProtocolError(f'HTTP/2: invalid format', quiet=True) _tlen = self._read_unpack(3) _type = self._read_unpack(1) _flag = self._read_binary(1) _rsid = sel...
Read Hypertext Transfer Protocol (HTTP/2). Structure of HTTP/2 packet [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) ...
def _read_http_none(self, size, kind, flag): if any((int(bit, base=2) for bit in flag)): raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) data = dict( flags=None, payload=self._read_fileng(size - 9) or None, ) return da...
Read HTTP packet with unsigned type.
def _read_http_data(self, size, kind, flag): _plen = 0 _flag = dict( END_STREAM=False, # bit 0 PADDED=False, # bit 3 ) for index, bit in enumerate(flag): if index == 0 and bit: _flag['END_STREAM'] = True eli...
Read HTTP/2 DATA frames. Structure of HTTP/2 DATA frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) | ...
def _read_http_headers(self, size, kind, flag): _plen = 0 _elen = 0 _flag = dict( END_STREAM=False, # bit 0 END_HEADERS=False, # bit 2 PADDED=False, # bit 3 PRIORITY=False, # bit 5 ) for index, ...
Read HTTP/2 HEADERS frames. Structure of HTTP/2 HEADERS frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) | ...
def _read_http_priority(self, size, kind, flag): if size != 9: raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) if any((int(bit, base=2) for bit in flag)): raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) _edep = se...
Read HTTP/2 PRIORITY frames. Structure of HTTP/2 PRIORITY frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) | ...
def _read_http_rst_stream(self, size, kind, flag): if size != 8: raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) if any((int(bit, base=2) for bit in flag)): raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) _code = ...
Read HTTP/2 RST_STREAM frames. Structure of HTTP/2 RST_STREAM frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) |...
def _read_http_settings(self, size, kind, flag): if size % 5 != 0: raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) _flag = dict( ACK=False, # bit 0 ) for index, bit in enumerate(flag): if index == 0 and bit: ...
Read HTTP/2 SETTINGS frames. Structure of HTTP/2 SETTINGS frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) | ...
def _read_http_push_promise(self, size, kind, flag): if size < 4: raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) _plen = 0 _flag = dict( END_HEADERS=False, # bit 2 PADDED=False, # bit 3 ) for in...
Read HTTP/2 PUSH_PROMISE frames. Structure of HTTP/2 PUSH_PROMISE frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8)...
def _read_http_ping(self, size, kind, flag): if size != 8: raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) _flag = dict( ACK=False, # bit 0 ) for index, bit in enumerate(flag): if index == 0 and bit: ...
Read HTTP/2 PING frames. Structure of HTTP/2 PING frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) | ...
def _read_http_goaway(self, size, kind, flag): _dlen = size - 8 if _dlen < 0: raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) if any((int(bit, base=2) for bit in flag)): raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=T...
Read HTTP/2 GOAWAY frames. Structure of HTTP/2 GOAWAY frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) | ...
def _read_http_window_update(self, size, kind, flag): if size != 4: raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) if any((int(bit, base=2) for bit in flag)): raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True) _size...
Read HTTP/2 WINDOW_UPDATE frames. Structure of HTTP/2 WINDOW_UPDATE frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (...
def _read_http_continuation(self, size, kind, flag): _flag = dict( END_HEADERS=False, # bit 2 ) for index, bit in enumerate(flag): if index == 2 and bit: _flag['END_HEADERS'] = True elif bit: raise ProtocolError(f'...
Read HTTP/2 WINDOW_UPDATE frames. Structure of HTTP/2 WINDOW_UPDATE frame [RFC 7540]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (...
def get(key, default=-1): if isinstance(key, int): return OptionNumber(key) if key not in OptionNumber._member_map_: extend_enum(OptionNumber, key, default) return OptionNumber[key]
Backport support for original codes.
def _import_next_layer(self, proto, length): if self._exproto == 'null' and self._exlayer == 'None': from pcapkit.protocols.raw import Raw as NextLayer else: from pcapkit.foundation.analysis import analyse as NextLayer # from pcapkit.foundation.analysis import an...
Import next layer extractor. Positional arguments: * proto -- str, next layer protocol name * length -- int, valid (not padding) length Returns: * bool -- flag if extraction of next layer succeeded * Info -- info of next layer * ProtoChain --...
def get(key, default=-1): if isinstance(key, int): return ProtectionAuthority(key) if key not in ProtectionAuthority._member_map_: extend_enum(ProtectionAuthority, key, default) return ProtectionAuthority[key]
Backport support for original codes.
def get(key, default=-1): if isinstance(key, int): return RouterAlert(key) if key not in RouterAlert._member_map_: extend_enum(RouterAlert, key, default) return RouterAlert[key]
Backport support for original codes.
def get(key, default=-1): if isinstance(key, int): return QS_Function(key) if key not in QS_Function._member_map_: extend_enum(QS_Function, key, default) return QS_Function[key]
Backport support for original codes.
def run(self): flag = True if self._exeng == 'dpkt': flag, engine = self.import_test('dpkt', name='DPKT') if flag: return self._run_dpkt(engine) elif self._exeng == 'scapy': flag, engine = self.import_test('scapy.all', name='Scapy') ...
Start extraction.
def record_header(self): self._gbhdr = Header(self._ifile) self._vinfo = self._gbhdr.version self._dlink = self._gbhdr.protocol self._nnsec = self._gbhdr.nanosecond if self._trace is not NotImplemented: self._trace._endian = self._gbhdr.byteorder ...
Read global header. - Extract global header. - Make Info object out of header properties. - Append Info. - Write plist file.
def _cleanup(self): self._expkg = None self._extmp = None self._flag_e = True self._ifile.close()
Cleanup after extraction & analysis.
def _aftermathmp(self): if not self._flag_e and self._flag_m: # join processes [proc.join() for proc in self._mpprc] if self._exeng == 'server': self._mpsvc.join() # restore attributes if self._exeng == 'server': ...
Aftermath for multiprocessing.
def _update_eof(self): self._aftermathmp() self._ifile.close() self._flag_e = True
Update EOF flag.
def _read_frame(self): if self._exeng == 'scapy': return self._scapy_read_frame() elif self._exeng == 'dpkt': return self._dpkt_read_frame() elif self._exeng == 'pyshark': return self._pyshark_read_frame() else: return self._defaul...
Headquarters for frame reader.
def _default_read_frame(self, *, frame=None, mpkit=None): from pcapkit.toolkit.default import (ipv4_reassembly, ipv6_reassembly, tcp_reassembly, tcp_traceflow) # read frame header if not self._flag_m: frame = Frame(self._ifile, nu...
Read frames with default engine. - Extract frames and each layer of packets. - Make Info object out of frame properties. - Append Info. - Write plist & append Info.
def _run_scapy(self, scapy_all): # if not self._flag_a: # self._flag_a = True # warnings.warn(f"'Extractor(engine=scapy)' object is not iterable; " # "so 'auto=False' will be ignored", AttributeWarning, stacklevel=stacklevel()) if self._exlyr ...
Call scapy.all.sniff to extract PCAP files.
def _scapy_read_frame(self): from pcapkit.toolkit.scapy import (ipv4_reassembly, ipv6_reassembly, packet2chain, packet2dict, tcp_reassembly, tcp_traceflow) # fetch Scapy packet packet = next(self._extm...
Read frames with Scapy.
def _run_dpkt(self, dpkt): # if not self._flag_a: # self._flag_a = True # warnings.warn(f"'Extractor(engine=dpkt)' object is not iterable; " # "so 'auto=False' will be ignored", AttributeWarning, stacklevel=stacklevel()) if self._exlyr != 'Non...
Call dpkt.pcap.Reader to extract PCAP files.
def _dpkt_read_frame(self): from pcapkit.toolkit.dpkt import (ipv4_reassembly, ipv6_reassembly, packet2chain, packet2dict, tcp_reassembly, tcp_traceflow) # fetch DPKT packet timestamp, packet = next(self...
Read frames.
def _run_pyshark(self, pyshark): # if not self._flag_a: # self._flag_a = True # warnings.warn(f"'Extractor(engine=pyshark)' object is not iterable; " # "so 'auto=False' will be ignored", AttributeWarning, stacklevel=stacklevel()) if self._exly...
Call pyshark.FileCapture to extract PCAP files.
def _pyshark_read_frame(self): from pcapkit.toolkit.pyshark import packet2dict, tcp_traceflow # fetch PyShark packet packet = next(self._extmp) # def _pyshark_packet2chain(packet): # # return ':'.join(map(lambda layer: layer.layer_name.upper(), packet.la...
Read frames.
def _run_pipeline(self, multiprocessing): if not self._flag_m: raise UnsupportedCall(f"Extractor(engine={self._exeng})' has no attribute '_run_pipline'") if not self._flag_q: self._flag_q = True warnings.warn("'Extractor(engine=pipeline)' does not support out...
Use pipeline multiprocessing to extract PCAP files.
def _pipeline_read_frame(self, *, mpfdp, mpkit): # check EOF if self._flag_e: raise EOFError def _analyse_frame(*, frame, mpkit): # wait until ready while mpkit.current != self._frnum: time.sleep(random.randint(0, datetime...
Extract frame.
def _run_server(self, multiprocessing): if not self._flag_m: raise UnsupportedCall(f"Extractor(engine={self._exeng})' has no attribute '_run_server'") if not self._flag_q: self._flag_q = True warnings.warn("'Extractor(engine=pipeline)' does not support output...
Use server multiprocessing to extract PCAP files.
def _server_extract_frame(self, *, mpfdp, mpkit, mpbuf): # check EOF if self._flag_e: raise EOFError # extract frame try: frame = Frame(self._ifile, num=self._frnum, proto=self._dlink, layer=self._exlyr, protocol=self._exptl, nan...
Extract frame.
def _server_analyse_frame(self, *, mpkit, mpfrm, mprsm, mpbuf): while True: # fetch frame # print(self._frnum, 'trying') frame = mpbuf.pop(self._frnum, None) if frame is EOFError: break if frame is None: continu...
Analyse frame.
def get(key, default=-1): if isinstance(key, int): return Checksum(key) if key not in Checksum._member_map_: extend_enum(Checksum, key, default) return Checksum[key]
Backport support for original codes.
def get(key, default=-1): if isinstance(key, int): return Operation(key) if key not in Operation._member_map_: extend_enum(Operation, key, default) return Operation[key]
Backport support for original codes.
def read_http(self, length): _plen = self._read_binary(3) _type = self._read_unpack(1) _flag = self._read_binary(1) _stid = self._read_binary(4)
Read Hypertext Transfer Protocol version 2. Structure of HTTP/2 packet [RFC 7230]: +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) ...
def analyse(file, length=None, *, _termination=False): seekset = file.tell() if not _termination: # FTP analysis flag, ftp = _analyse_ftp(file, length, seekset=seekset) if flag: return ftp # HTTP/1.* analysis flag, http = _analyse_httpv1(file, length, see...
Analyse application layer packets.
def get(key, default=-1): if isinstance(key, int): return Routing(key) if key not in Routing._member_map_: extend_enum(Routing, key, default) return Routing[key]
Backport support for original codes.
def _read_protos(self, size): _byte = self._read_unpack(size) _prot = ETHERTYPE.get(_byte) return _prot
Read next layer protocol type. Positional arguments: * size -- int, buffer size Returns: * str -- next layer's protocol name
def _import_next_layer(self, proto, length): if length == 0: from pcapkit.protocols.null import NoPayload as Protocol elif self._sigterm: from pcapkit.protocols.raw import Raw as Protocol elif proto == 0x0806: from pcapkit.protocols.link.arp import AR...
Import next layer extractor. Positional arguments: * proto -- str, next layer protocol name * length -- int, valid (not padding) length Returns: * bool -- flag if extraction of next layer succeeded * Info -- info of next layer * ProtoChain --...
def get(key, default=-1): if isinstance(key, int): return HIT_Suite(key) if key not in HIT_Suite._member_map_: extend_enum(HIT_Suite, key, default) return HIT_Suite[key]
Backport support for original codes.
def get(key, default=-1): if isinstance(key, int): return Authentication(key) if key not in Authentication._member_map_: extend_enum(Authentication, key, default) return Authentication[key]
Backport support for original codes.
def make_fout(fout='./tmp', fmt='pcap'): if fmt == 'pcap': # output PCAP file from pcapkit.dumpkit import PCAP as output elif fmt == 'plist': # output PLIST file from dictdumper import PLIST as output elif fmt == 'json': # output JSON file ...
Make root path for output. Positional arguments: * fout -- str, root path for output * fmt -- str, output format Returns: * output -- dumper of specified format
def dump(self, packet): # fetch flow label output = self.trace(packet, _check=False, _output=True) # dump files output(packet['frame'], name=f"Frame {packet['index']}", byteorder=self._endian, nanosecond=self._nnsecd)
Dump frame to output files. Positional arguments: * packet -- dict, a flow packet |-- (str) protocol -- data link type from global header |-- (int) index -- frame number |-- (Info) frame -- extracted frame info |-- (bool) syn -- TCP sy...
def trace(self, packet, *, _check=True, _output=False): self._newflg = True if _check: pkt_check(packet) info = Info(packet) # Buffer Identifier BUFID = tuple(sorted([str(info.src), str(info.srcport), # pylint: disable=E1101 s...
Trace packets. Positional arguments: * packet -- dict, a flow packet Keyword arguments: * _check -- bool, flag if run validations * _output -- bool, flag if has formatted dumper
def submit(self): self._newflg = False ret = list() for buf in self._buffer.values(): buf = copy.deepcopy(buf) if self._fdpext: buf['fpout'] = f"{self._fproot}/{buf['label']}.{self._fdpext}" else: del buf['fpout'] ...
Submit traced TCP flows.
def read_ah(self, length, version, extension): if length is None: length = len(self) _next = self._read_protos(1) _plen = self._read_unpack(1) _resv = self._read_fileng(2) _scpi = self._read_unpack(4) _dsnf = self._read_unpack(4) # ICV length ...
Read Authentication Header. Structure of AH header [RFC 4302]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next...
def read_ethernet(self, length): if length is None: length = len(self) _dstm = self._read_mac_addr() _srcm = self._read_mac_addr() _type = self._read_protos(2) ethernet = dict( dst=_dstm, src=_srcm, type=_type, ) ...
Read Ethernet Protocol. Structure of Ethernet Protocol header [RFC 7042]: Octets Bits Name Description 0 0 eth.dst Destination MAC Address 1 8 eth.src Source MAC Address ...
def _read_mac_addr(self): _byte = self._read_fileng(6) _addr = '-'.join(textwrap.wrap(_byte.hex(), 2)) return _addr
Read MAC address.
def get(key, default=-1): if isinstance(key, int): return Suite(key) if key not in Suite._member_map_: extend_enum(Suite, key, default) return Suite[key]
Backport support for original codes.
def get(key, default=-1): if isinstance(key, int): return ECDSA_Curve(key) if key not in ECDSA_Curve._member_map_: extend_enum(ECDSA_Curve, key, default) return ECDSA_Curve[key]
Backport support for original codes.
def packet2dict(packet): dict_ = dict() frame = packet.frame_info for field in frame.field_names: dict_[field] = getattr(frame, field) tempdict = dict_ for layer in packet.layers: tempdict[layer.layer_name.upper()] = dict() tempdict = tempdict[layer.layer_name.upper()] ...
Convert PyShark packet into dict.
def tcp_traceflow(packet): if 'TCP' in packet: ip = packet.ip if 'IP' in packet else packet.ipv6 tcp = packet.tcp data = dict( protocol=LINKTYPE.get(packet.layers[0].layer_name.upper()), # data link type from global header index=int(packet.number), ...
Trace packet flow for TCP.
def reassembly(self, info): BUFID = info.bufid # Buffer Identifier DSN = info.dsn # Data Sequence Number ACK = info.ack # Acknowledgement Number FIN = info.fin # Finish Flag (Termination) RST = info.rst # Reset Connection Flag (Termination) S...
Reassembly procedure. Positional arguments: * info -- Info, info dict of packets to be reassembled
def submit(self, buf, *, bufid): datagram = [] # reassembled datagram HDL = buf.pop('hdl') # hole descriptor list (remove from dict) # check through every buffer with ACK for (ack, buffer) in buf.items(): # if this buffer is not implemented #...
Submit reassembled payload. Positional arguments: * buf -- dict, buffer dict of reassembled packets Keyword arguments: * bufid -- tuple, buffer identifier Returns: * list -- reassembled packets
def packet2chain(packet): if scapy_all is None: raise ModuleNotFound("No module named 'scapy'", name='scapy') chain = [packet.name] payload = packet.payload while not isinstance(payload, scapy_all.packet.NoPayload): chain.append(payload.name) payload = payload.payload re...
Fetch Scapy packet protocol chain.
def packet2dict(packet, *, count=NotImplemented): if scapy_all is None: raise ModuleNotFound("No module named 'scapy'", name='scapy') def wrapper(packet): dict_ = packet.fields payload = packet.payload if not isinstance(payload, scapy_all.packet.NoPayload): dict_...
Convert Scapy packet into dict.
def ipv4_reassembly(packet, *, count=NotImplemented): if 'IP' in packet: ipv4 = packet['IP'] if ipv4.flags.DF: # dismiss not fragmented packet return False, None data = dict( bufid=( ipaddress.ip_address(ipv4.src), # source IP addres...
Make data for IPv4 reassembly.
def ipv6_reassembly(packet, *, count=NotImplemented): if scapy_all is None: raise ModuleNotFound("No module named 'scapy'", name='scapy') if 'IPv6' in packet: ipv6 = packet['IPv6'] if scapy_all.IPv6ExtHdrFragment not in ipv6: # pylint: disable=E1101 return False, None ...
Make data for IPv6 reassembly.
def tcp_reassembly(packet, *, count=NotImplemented): if 'TCP' in packet: ip = packet['IP'] if 'IP' in packet else packet['IPv6'] tcp = packet['TCP'] data = dict( bufid=( ipaddress.ip_address(ip.src), # source IP address ipaddress.ip_addr...
Store data for TCP reassembly.
def tcp_traceflow(packet, *, count=NotImplemented): if 'TCP' in packet: ip = packet['IP'] if 'IP' in packet else packet['IPv6'] tcp = packet['TCP'] data = dict( protocol=LINKTYPE.get(packet.name.upper()), # data link type from global header index=count, ...
Trace packet flow for TCP.
def read_hopopt(self, length, extension): if length is None: length = len(self) _next = self._read_protos(1) _hlen = self._read_unpack(1) # _opts = self._read_fileng(_hlen*8+6) hopopt = dict( next=_next, length=(_hlen + 1) * 8, ...
Read IPv6 Hop-by-Hop Options. Structure of HOPOPT header [RFC 8200]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header | Hdr Ext Len | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ...
def _read_hopopt_options(self, length): counter = 0 # length of read options optkind = list() # option type list options = dict() # dict of option data while counter < length: # break when eol triggered code = self._read_unpack(1) ...
Read HOPOPT options. Positional arguments: * length -- int, length of options Returns: * dict -- extracted HOPOPT options
def _read_opt_pad(self, code, *, desc): _type = self._read_opt_type(code) if code == 0: opt = dict( desc=desc, type=_type, length=1, ) elif code == 1: _size = self._read_unpack(1) _padn = sel...
Read HOPOPT padding options. Structure of HOPOPT padding options [RFC 8200]: * Pad1 Option: +-+-+-+-+-+-+-+-+ | 0 | +-+-+-+-+-+-+-+-+ Octets Bits Name Description 0 ...
def _read_opt_tun(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) if _size != 1: raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format') _limt = self._read_unpack(1) opt = dict( desc=desc, ...
Read HOPOPT Tunnel Encapsulation Limit option. Structure of HOPOPT Tunnel Encapsulation Limit option [RFC 2473]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header |Hdr Ext Len = 0| Opt Type = 4 |Opt Data Len=1 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
def _read_opt_ra(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) if _size != 2: raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format') _rval = self._read_unpack(2) if 4 <= _rval <= 35: _dscp = f'Ag...
Read HOPOPT Router Alert option. Structure of HOPOPT Router Alert option [RFC 2711]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0 0 0|0 0 1 0 1|0 0 0 0 0 0 1 0| Value (2 octets) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
def _read_opt_calipso(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) if _size < 8 and _size % 8 != 0: raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format') _cmpt = self._read_unpack(4) _clen = self._read_unp...
Read HOPOPT CALIPSO option. Structure of HOPOPT CALIPSO option [RFC 5570]: ------------------------------------------------------------ | Next Header | Hdr Ext Len | Option Type | Option Length| +-------------+---------------+-------------+--------------+ | ...
def _read_opt_smf_dpd(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) _tidd = self._read_binary(1) if _tidd[0] == '0': _mode = 'I-DPD' _tidt = _TID_TYPE.get(_tidd[1:4], 'Unassigned') _tidl = int(_tidd[4:], ...
Read HOPOPT SMF_DPD option. Structure of HOPOPT SMF_DPD option [RFC 5570]: * IPv6 SMF_DPD Option Header in I-DPD mode 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+...
def _read_opt_pdm(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) if _size != 10: raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format') _stlr = self._read_unpack(1) _stls = self._read_unpack(1) _psnt ...
Read HOPOPT PDM option. Structure of HOPOPT PDM option [RFC 8250]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ...
def _read_opt_qs(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) if _size != 6: raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format') _fcrr = self._read_binary(1) _func = int(_fcrr[:4], base=2) _rate ...
Read HOPOPT Quick Start option. Structure of HOPOPT Quick-Start option [RFC 4782]: * A Quick-Start Request. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+...
def _read_opt_rpl(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) if _size < 4: raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format') _flag = self._read_binary(1) _rpld = self._read_unpack(1) _rank = ...
Read HOPOPT RPL option. Structure of HOPOPT RPL option [RFC 6553]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ...
def _read_opt_ilnp(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) _nval = self._read_fileng(_size) opt = dict( desc=desc, type=_type, length=_size + 2, value=_nval, ) return opt
Read HOPOPT ILNP Nonce option. Structure of HOPOPT ILNP Nonce option [RFC 6744]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ...
def _read_opt_lio(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) _llen = self._read_unpack(1) _line = self._read_fileng(_llen) opt = dict( desc=desc, type=_type, length=_size + 2, lid_l...
Read HOPOPT Line-Identification option. Structure of HOPOPT Line-Identification option [RFC 6788]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-...
def _read_opt_jumbo(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) if _size != 4: raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format') _jlen = self._read_unpack(4) opt = dict( desc=desc, ...
Read HOPOPT Jumbo Payload option. Structure of HOPOPT Jumbo Payload option [RFC 2675]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Option Type | Opt Data Len | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
def _read_opt_home(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) if _size != 16: raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format') _addr = self._read_fileng(16) opt = dict( desc=desc, ...
Read HOPOPT Home Address option. Structure of HOPOPT Home Address option [RFC 6275]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...