Skip to main content

A set of Python scripts to manipulate PCAPNG files

Project description

PCAPNG to HAR Converter

Python-based tool for converting PCAPNG files to HAR files.

License: GPLv3 and MIT

PyPI - Version GitHub Release

Website | Support

Overview

This project is a Python-based tool for converting PCAPNG files to HAR files. It supports both HTTP/1.1 and HTTP/2 protocols.

Requirements

This converter requires a PCAPNG file as input. If you have a PCAP file, you can convert it to PCAPNG using editcap:

editcap <input_file.pcap> <output_file.pcapng>

Make sure the following tools are installed on your system:

  • Python 3.11+
  • tshark (part of the Wireshark suite; requires version >= 4.0)

Installation

pip install pcapng-utils

Usage

Shell

Run pcapng_to_har [-h] in your shell (with your Python virtual environment activated)

Python

from pcapng_to_har import pcapng_to_har, Tshark
def pcapng_to_har(
    input_file: Path | str,
    output_file: Path | str | None = None,
    *,
    tshark: Tshark | None = None,
    socket_operations_file: Path | str | None = None,
    cryptography_operations_file: Path | str | None = None,
    overwrite: bool = False,
    **json_dump_kws: Any,
) -> None

Features

TLS Decryption

If the captured traffic contains TLS traffic and a SSLKEYLOGFILE has been generated during the capture, use the following command to inject the TLS client randoms read from the <keylog_file> into the PCAPNG file:

editcap --inject-secrets tls,<keylog_file> <file.pcap> <output.pcapng>

Once the secrets have been injected into the PCAPNG file, you can use pcapng_to_har to convert the PCAPNG file to a HAR file. The output HAR will contain the decrypted TLS traffic.

pcapng_to_har -i <input.pcapng> -o <input.har> 

Stacktrace Identification (PiRogue only)

If the traffic has been captured on a PiRogue with the command pirogue-intercept[single|gated], the stacktrace of all operations (read, write) on sockets have been logged in a file socket_trace.json. The converter will use this file to add the stacktrace information to each request and response. The attributes request._stacktrace and response._stacktrace will, respectively, contain the stacktrace of the socket operations that have been performed for the request and the response.

pcapng_to_har -i <input.pcapng> -o <input.har> -sf <socket_trace.json>

Payload Decryption (PiRogue only)

If the traffic has been captured on a PiRogue with the command pirogue-intercept[single|gated], the encryption and decryption operations have been logged in a file aes_info.json. The converter will use this file to identifies the payloads that have been encrypted before been transmitted. The encrypted payload will be replaced by its cleartext in request.postData.text and response.content.text.

Additional information about the encryption and decryption operations will be added to the HAR in the attributes request._decryption and response._decryption.

pcapng_to_har -i <input.pcapng> -o <input.har> -cf <aes_info.json>

Development

  1. Install Python 3.11 or higher.
  2. Install tshark from the Wireshark suite.
  3. Clone this repository:
git clone https://github.com/PiRogueToolSuite/pcapng-utils
cd pcapng-utils
  1. Install the required Python packages:
pip install -r requirements.txt

Licensing

This work is licensed under multiple licences:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pcapng_utils-1.0.5.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

pcapng_utils-1.0.5-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file pcapng_utils-1.0.5.tar.gz.

File metadata

  • Download URL: pcapng_utils-1.0.5.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pcapng_utils-1.0.5.tar.gz
Algorithm Hash digest
SHA256 71ba34e5d25b993cda5fcee7bf9534d4c51dcf7733108e5b7b920a449ee7b3b9
MD5 f85c238af202a5334acc463d7cd1c07d
BLAKE2b-256 cd06fa805756b4e0badc41e10150b279a8d1454bf8d36588ce4d3d6792706f14

See more details on using hashes here.

File details

Details for the file pcapng_utils-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: pcapng_utils-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pcapng_utils-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dccc0f42fd7eca47676da9e842a85dcc6704e493fc5d5fb38246d1497b16db1a
MD5 d77464d71d4ee6be5d702898a7b4b00b
BLAKE2b-256 8b4a565d9aa8422922889736f797fb0bd6e522d6122ce5041a08956a161ed85c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page