pcapng_utils.tshark package
Subpackages
- pcapng_utils.tshark.protocols package
- Submodules
- pcapng_utils.tshark.protocols.http1 module
Http1TrafficHttpConversationHttpRequestHttpRequestResponseHttpRequestResponse.FALLBACK_CONTENT_TYPEHttpRequestResponse.common_har_propsHttpRequestResponse.content_lengthHttpRequestResponse.content_typeHttpRequestResponse.header_lengthHttpRequestResponse.headersHttpRequestResponse.http_layerHttpRequestResponse.layersHttpRequestResponse.payloadHttpRequestResponse.raw_headers
HttpResponse
- pcapng_utils.tshark.protocols.http2 module
Http2HelperHttp2RequestHttp2RequestResponseHttp2RequestResponse.get_duration_ms()Http2RequestResponse.FALLBACK_CONTENT_TYPEHttp2RequestResponse.body_lengthHttp2RequestResponse.content_typeHttp2RequestResponse.dst_hostHttp2RequestResponse.dst_ipHttp2RequestResponse.dst_portHttp2RequestResponse.frames_nbsHttp2RequestResponse.header_lengthHttp2RequestResponse.headers_mapHttp2RequestResponse.http_methodHttp2RequestResponse.http_statusHttp2RequestResponse.http_versionHttp2RequestResponse.src_hostHttp2RequestResponse.src_ipHttp2RequestResponse.src_portHttp2RequestResponse.timestamp
Http2ResponseHttp2StreamHttp2SubstreamHttp2Traffic
- Module contents
Submodules
pcapng_utils.tshark.traffic module
- class pcapng_utils.tshark.traffic.NetworkTrafficDump(tshark_output)[source]
Bases:
objectThe NetworkTrafficDump class is designed to handle and process network traffic data.
- traffic
A list of dictionaries containing traffic data.
- Type:
list[dict]
- parsed_traffic
Mapping of parsed traffic per protocol class (e.g. Http1Traffic, Http2Traffic)
- Type:
dict[class,instance]
pcapng_utils.tshark.types module
pcapng_utils.tshark.utils module
- pcapng_utils.tshark.utils.get_tshark_bytes_from_raw(r)[source]
Format of ‘*_raw’ fields produced with ‘-x’ flag: [hexa: str, *sizes: int]
Sizes are 4 integers in tshark old versions and 5 integers in newer (>= v4.6)
- Return type:
pcapng_utils.tshark.wrapper module
- class pcapng_utils.tshark.wrapper.Tshark(tshark_cmd='/usr/bin/tshark', *, hash_algo='sha1', name_resolution='nds', hosts_file=PosixPath('/etc/hosts'), display_filter='http || http2 || websocket', protocol_match_filter='http http2 websocket', tcp_reassemble_out_of_order=True, timeout=60.0)[source]
Bases:
objectA class to interact with tshark for loading and parsing network traffic data from a PCAPNG file.
tshark is a command-line tool for capturing and analyzing network traffic. It is part of the Wireshark suite and provides similar functionality to the Wireshark GUI in a terminal environment.
Packet capture and analysis: tshark can capture live network traffic and analyze packets from capture files (e.g., PCAP, PCAPNG).
Protocol decoding: It supports decoding a wide range of network protocols, providing detailed information about each packet.
Filtering: tshark allows filtering packets using display filters to focus on specific traffic.
Statistics: It can generate various statistics about the captured traffic, such as protocol hierarchy,
endpoint statistics, and conversation lists. - Exporting data: tshark can export packet data to different formats, including JSON, CSV, and plain text. - Decryption: tshark supports decryption of encrypted traffic using SSL/TLS keys provided in an SSLKEYLOG file.
tshark can convert PCAPNG files to JSON format using the -T json option. This allows for easy parsing and analysis of network traffic data in a structured format.
Useful commands:
Capture live traffic: tshark -i <interface>
Read from a PCAP file: tshark -r <file.[pcap|pcapng]>
Display packet details: tshark -V
Filter packets: tshark -Y <filter>
Export to JSON: tshark -r <file.[pcap|pcapng]> -T json
Decrypt SSL/TLS traffic: tshark -r <file.[pcap|pcapng]> -o “ssl.keys_list: <key_file>”
Inject the TLS secrets: editcap –inject-secrets tls,<keylog_file> <file.pcap> <output.pcapng>
- load_traffic(pcapng_file)[source]
Loads network traffic data from the provided pcapng file using tshark.
This method runs the tshark command to read the pcapng file and parse the output as JSON. The parsed traffic data is then returned, together with some metadata.
- Raises:
subprocess.CalledProcessError – If the tshark command fails.
- Return type:
Note that no HTTP3 traffic is expected since it is rejected by Pirogue.
- display_filter: Annotated[str, _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='-Y', prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 'http || http2 || websocket'
Display filter (documented in tshark manual under -Y flag)
- hash_algo: Annotated[str, _ArgConfig(name=None, metavar=ALGO, help=None, help_behavior_hint=None, aliases=None, prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 'sha1'
Hash algorithm to generate digest of input .pcapng
- hosts_file: Path | None = PosixPath('/etc/hosts')
Hosts file for tshark name resolution - only used when name resolution contains’n’
- name_resolution: Annotated[Literal[False] | str, _ArgConfig(name=None, metavar=FLAGS | False, help=None, help_behavior_hint=None, aliases=None, prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 'nds'
Name resolution flags, as documented in tshark manual under -N flag; by default we avoid using any external DNS resolver
- protocol_match_filter: Annotated[str, _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='-J', prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 'http http2 websocket'
Protocol match filter (documented in tshark manual under -J flag), in addition to base protocols
- tcp_reassemble_out_of_order: bool = True
Whether to allow or not to reassemble out-of-order TCP segments
- timeout: Annotated[float, _ArgConfig(name=None, metavar=SECONDS, help=None, help_behavior_hint=None, aliases=None, prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 60.0
Timeout in seconds for tshark command completion
- class pcapng_utils.tshark.wrapper.TsharkOutput(list_packets, metadata)[source]
Bases:
objectOutput of tshark network traffic dump, together with some metadata of about it.
Module contents
- class pcapng_utils.tshark.NetworkTrafficDump(tshark_output)[source]
Bases:
objectThe NetworkTrafficDump class is designed to handle and process network traffic data.
- traffic
A list of dictionaries containing traffic data.
- Type:
list[dict]
- parsed_traffic
Mapping of parsed traffic per protocol class (e.g. Http1Traffic, Http2Traffic)
- Type:
dict[class,instance]
- class pcapng_utils.tshark.Tshark(tshark_cmd='/usr/bin/tshark', *, hash_algo='sha1', name_resolution='nds', hosts_file=PosixPath('/etc/hosts'), display_filter='http || http2 || websocket', protocol_match_filter='http http2 websocket', tcp_reassemble_out_of_order=True, timeout=60.0)[source]
Bases:
objectA class to interact with tshark for loading and parsing network traffic data from a PCAPNG file.
tshark is a command-line tool for capturing and analyzing network traffic. It is part of the Wireshark suite and provides similar functionality to the Wireshark GUI in a terminal environment.
Packet capture and analysis: tshark can capture live network traffic and analyze packets from capture files (e.g., PCAP, PCAPNG).
Protocol decoding: It supports decoding a wide range of network protocols, providing detailed information about each packet.
Filtering: tshark allows filtering packets using display filters to focus on specific traffic.
Statistics: It can generate various statistics about the captured traffic, such as protocol hierarchy,
endpoint statistics, and conversation lists. - Exporting data: tshark can export packet data to different formats, including JSON, CSV, and plain text. - Decryption: tshark supports decryption of encrypted traffic using SSL/TLS keys provided in an SSLKEYLOG file.
tshark can convert PCAPNG files to JSON format using the -T json option. This allows for easy parsing and analysis of network traffic data in a structured format.
Useful commands:
Capture live traffic: tshark -i <interface>
Read from a PCAP file: tshark -r <file.[pcap|pcapng]>
Display packet details: tshark -V
Filter packets: tshark -Y <filter>
Export to JSON: tshark -r <file.[pcap|pcapng]> -T json
Decrypt SSL/TLS traffic: tshark -r <file.[pcap|pcapng]> -o “ssl.keys_list: <key_file>”
Inject the TLS secrets: editcap –inject-secrets tls,<keylog_file> <file.pcap> <output.pcapng>
- load_traffic(pcapng_file)[source]
Loads network traffic data from the provided pcapng file using tshark.
This method runs the tshark command to read the pcapng file and parse the output as JSON. The parsed traffic data is then returned, together with some metadata.
- Raises:
subprocess.CalledProcessError – If the tshark command fails.
- Return type:
Note that no HTTP3 traffic is expected since it is rejected by Pirogue.
- display_filter: Annotated[str, _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='-Y', prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 'http || http2 || websocket'
Display filter (documented in tshark manual under -Y flag)
- hash_algo: Annotated[str, _ArgConfig(name=None, metavar=ALGO, help=None, help_behavior_hint=None, aliases=None, prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 'sha1'
Hash algorithm to generate digest of input .pcapng
- hosts_file: Path | None = PosixPath('/etc/hosts')
Hosts file for tshark name resolution - only used when name resolution contains’n’
- name_resolution: Annotated[Literal[False] | str, _ArgConfig(name=None, metavar=FLAGS | False, help=None, help_behavior_hint=None, aliases=None, prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 'nds'
Name resolution flags, as documented in tshark manual under -N flag; by default we avoid using any external DNS resolver
- protocol_match_filter: Annotated[str, _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='-J', prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 'http http2 websocket'
Protocol match filter (documented in tshark manual under -J flag), in addition to base protocols
- tcp_reassemble_out_of_order: bool = True
Whether to allow or not to reassemble out-of-order TCP segments
- timeout: Annotated[float, _ArgConfig(name=None, metavar=SECONDS, help=None, help_behavior_hint=None, aliases=None, prefix_name=None, constructor_factory=None, default=tyro.MISSING_NONPROP)] = 60.0
Timeout in seconds for tshark command completion