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
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, but not HTTP/3.
Requirements
This converter requires a PCAPNG file as input. If you have a PCAP file, you can convert it to PCAPNG using editcap:
editcap <traffic.pcap> <traffic.pcapng>
Make sure the following tools are installed on your system:
- Python 3.11+
tshark(part of the Wireshark suite; requires version >= 4.0)
Known issues
- For
tshark < 4.2, HTTP/2 streams that are compressed and chunked are not decompressed during reassembly step bytshark. To properly handle such data, we advise you to usetshark >= 4.2.
Installation
pip install pcapng-utils
Usage
Shell
Run pcapng_to_har [-h] in your shell (with your Python virtual environment activated)
Python
from pcapng_utils.pcapng_to_har import pcapng_to_har
help(pcapng_to_har)
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> <traffic.pcap> <traffic.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 <traffic.pcapng> -o <traffic.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 <traffic.pcapng> -o <traffic.har> -sf <socket_trace.json>
In case there was a systematic time shift between socket operations timestamps vs. network traffic timestamps,
you may provide the --time-shift SECONDS flag to account for it.
Indeed socket operations timestamps come from phone date, whereas network traffic timestamps come from Pirogue date,
which may be desynchronized.
Positive shift means network traffic timestamps (Pirogue) were earlier than socket operations timestamps (phone).
Note: this enrichment is automatically performed provided that socket_trace.json is present in the folder containing your input PCAPNG
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 <traffic.pcapng> -o <traffic.har> -cf <aes_info.json>
Note: this enrichment is automatically performed provided that aes_info.json is present in the folder containing your input PCAPNG
Development
- Install Python 3.11 or higher.
- Install
tsharkfrom the Wireshark suite. - Clone this repository:
git clone https://github.com/PiRogueToolSuite/pcapng-utils
cd pcapng-utils
- Install the package in editable mode:
pip install -e .
Licensing
This work is licensed under multiple licences:
- All the code in this repository is licensed under the GPLv3 license.
- Copyright: 2024 U+039b hello@pts-project.org
- Copyright: 2024 Defensive Lab Agency contact@defensive-lab.agency
- The files containing a SPDX header are licensed under the MIT license.
- Copyright: 2024 Pôle d'Expertise de la Régulation Numérique - PEReN contact@peren.gouv.fr
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pcapng_utils-1.0.10.tar.gz.
File metadata
- Download URL: pcapng_utils-1.0.10.tar.gz
- Upload date:
- Size: 40.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ee93d9fccaa7fc656455e3576d77249cd605834822713d7518c6fb106ccaae8
|
|
| MD5 |
7f03b4b066440f34389448d38e47f7c3
|
|
| BLAKE2b-256 |
9597fcd1fb98edaa12450f2608314eb845cfe2dc9c3debaf976d760f14a82434
|
Provenance
The following attestation bundles were made for pcapng_utils-1.0.10.tar.gz:
Publisher:
publish-on-pypi.yml on PiRogueToolSuite/pcapng-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pcapng_utils-1.0.10.tar.gz -
Subject digest:
8ee93d9fccaa7fc656455e3576d77249cd605834822713d7518c6fb106ccaae8 - Sigstore transparency entry: 305831489
- Sigstore integration time:
-
Permalink:
PiRogueToolSuite/pcapng-utils@c3956a1c5ad30ecc9f08e5e7ae01307b518ce55b -
Branch / Tag:
refs/tags/v1.0.10 - Owner: https://github.com/PiRogueToolSuite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-on-pypi.yml@c3956a1c5ad30ecc9f08e5e7ae01307b518ce55b -
Trigger Event:
release
-
Statement type:
File details
Details for the file pcapng_utils-1.0.10-py3-none-any.whl.
File metadata
- Download URL: pcapng_utils-1.0.10-py3-none-any.whl
- Upload date:
- Size: 45.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f2f350589ce9e599dfb0b6a382fc9bfeb64bce8406b8997dc74ab5df40f3c9e
|
|
| MD5 |
ae80a6cd787bd1164b5d7c403905102e
|
|
| BLAKE2b-256 |
6f5a2f47a34c9654b6ee4347b413b234da7259909f4765794e3543d23cbbf00f
|
Provenance
The following attestation bundles were made for pcapng_utils-1.0.10-py3-none-any.whl:
Publisher:
publish-on-pypi.yml on PiRogueToolSuite/pcapng-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pcapng_utils-1.0.10-py3-none-any.whl -
Subject digest:
6f2f350589ce9e599dfb0b6a382fc9bfeb64bce8406b8997dc74ab5df40f3c9e - Sigstore transparency entry: 305831504
- Sigstore integration time:
-
Permalink:
PiRogueToolSuite/pcapng-utils@c3956a1c5ad30ecc9f08e5e7ae01307b518ce55b -
Branch / Tag:
refs/tags/v1.0.10 - Owner: https://github.com/PiRogueToolSuite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-on-pypi.yml@c3956a1c5ad30ecc9f08e5e7ae01307b518ce55b -
Trigger Event:
release
-
Statement type: