fastpcap 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastpcap-0.1.0/.github/workflows/wheels.yml +56 -0
- fastpcap-0.1.0/.gitignore +57 -0
- fastpcap-0.1.0/CMakeLists.txt +26 -0
- fastpcap-0.1.0/LICENSE +21 -0
- fastpcap-0.1.0/PKG-INFO +306 -0
- fastpcap-0.1.0/README.md +288 -0
- fastpcap-0.1.0/fuzz/fuzz_reader.cpp +54 -0
- fastpcap-0.1.0/pyproject.toml +33 -0
- fastpcap-0.1.0/python/fastpcap/__init__.py +151 -0
- fastpcap-0.1.0/python/fastpcap/__main__.py +55 -0
- fastpcap-0.1.0/python/fastpcap/analysis.py +89 -0
- fastpcap-0.1.0/src/analyze.hpp +388 -0
- fastpcap-0.1.0/src/bindings.cpp +368 -0
- fastpcap-0.1.0/src/decode.hpp +629 -0
- fastpcap-0.1.0/src/reader.hpp +256 -0
- fastpcap-0.1.0/src/util.hpp +232 -0
- fastpcap-0.1.0/tests/make_seeds.py +12 -0
- fastpcap-0.1.0/tests/pcapgen.py +151 -0
- fastpcap-0.1.0/tests/test_fastpcap.py +126 -0
- fastpcap-0.1.0/tools/fp_dump.cpp +68 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: wheels
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ${{ matrix.os }}
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: pypa/cibuildwheel@v3.2.1
|
|
19
|
+
- uses: actions/upload-artifact@v4
|
|
20
|
+
with:
|
|
21
|
+
name: wheels-${{ matrix.os }}
|
|
22
|
+
path: wheelhouse/*.whl
|
|
23
|
+
|
|
24
|
+
sdist:
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
|
+
- run: pipx run build --sdist
|
|
29
|
+
- uses: actions/upload-artifact@v4
|
|
30
|
+
with:
|
|
31
|
+
name: sdist
|
|
32
|
+
path: dist/*.tar.gz
|
|
33
|
+
|
|
34
|
+
sanitize:
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
- name: Build fuzzer with ASan and UBSan, run on seed captures
|
|
39
|
+
run: |
|
|
40
|
+
python3 tests/make_seeds.py /tmp/seeds
|
|
41
|
+
g++ -std=c++17 -O1 -g -DFP_STANDALONE -fsanitize=address,undefined -fno-sanitize-recover=undefined fuzz/fuzz_reader.cpp -o fuzz_sa
|
|
42
|
+
for f in /tmp/seeds/*; do ./fuzz_sa "$f" 50000; done
|
|
43
|
+
|
|
44
|
+
publish:
|
|
45
|
+
needs: [build, sdist]
|
|
46
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
environment: pypi
|
|
49
|
+
permissions:
|
|
50
|
+
id-token: write
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/download-artifact@v4
|
|
53
|
+
with:
|
|
54
|
+
path: dist
|
|
55
|
+
merge-multiple: true
|
|
56
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# --- Python ---
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
.pytest_cache/
|
|
7
|
+
.mypy_cache/
|
|
8
|
+
.ruff_cache/
|
|
9
|
+
.venv/
|
|
10
|
+
venv/
|
|
11
|
+
env/
|
|
12
|
+
|
|
13
|
+
# --- Build output ---
|
|
14
|
+
build/
|
|
15
|
+
dist/
|
|
16
|
+
wheelhouse/
|
|
17
|
+
_skbuild/
|
|
18
|
+
.scikit-build/
|
|
19
|
+
cmake-build-*/
|
|
20
|
+
CMakeCache.txt
|
|
21
|
+
CMakeFiles/
|
|
22
|
+
*.so
|
|
23
|
+
*.pyd
|
|
24
|
+
*.dll
|
|
25
|
+
*.dylib
|
|
26
|
+
*.exe
|
|
27
|
+
*.obj
|
|
28
|
+
*.o
|
|
29
|
+
*.lib
|
|
30
|
+
*.exp
|
|
31
|
+
*.pdb
|
|
32
|
+
*.ilk
|
|
33
|
+
|
|
34
|
+
# --- Local tools and fuzzing artifacts ---
|
|
35
|
+
fp_dump
|
|
36
|
+
fuzz_sa
|
|
37
|
+
fuzz_reader
|
|
38
|
+
crash-*
|
|
39
|
+
leak-*
|
|
40
|
+
oom-*
|
|
41
|
+
timeout-*
|
|
42
|
+
|
|
43
|
+
# --- Capture files (can contain private traffic, keep them out of the repo) ---
|
|
44
|
+
*.pcap
|
|
45
|
+
*.pcapng
|
|
46
|
+
*.cap
|
|
47
|
+
# but keep tiny test fixtures if you add any on purpose:
|
|
48
|
+
!tests/data/*.pcap
|
|
49
|
+
!tests/data/*.pcapng
|
|
50
|
+
|
|
51
|
+
# --- Editors and OS ---
|
|
52
|
+
.vscode/
|
|
53
|
+
.idea/
|
|
54
|
+
*.swp
|
|
55
|
+
.DS_Store
|
|
56
|
+
Thumbs.db
|
|
57
|
+
desktop.ini
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.15...3.30)
|
|
2
|
+
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
|
|
3
|
+
|
|
4
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
5
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
|
+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
7
|
+
set(CMAKE_BUILD_TYPE Release)
|
|
8
|
+
endif()
|
|
9
|
+
|
|
10
|
+
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
|
|
11
|
+
find_package(pybind11 CONFIG REQUIRED)
|
|
12
|
+
|
|
13
|
+
pybind11_add_module(_core MODULE src/bindings.cpp)
|
|
14
|
+
target_compile_definitions(_core PRIVATE FASTPCAP_VERSION="${SKBUILD_PROJECT_VERSION}")
|
|
15
|
+
if(MSVC)
|
|
16
|
+
target_compile_options(_core PRIVATE /W3 /utf-8)
|
|
17
|
+
else()
|
|
18
|
+
target_compile_options(_core PRIVATE -Wall -Wextra)
|
|
19
|
+
endif()
|
|
20
|
+
install(TARGETS _core DESTINATION fastpcap)
|
|
21
|
+
|
|
22
|
+
# Optional standalone CLI (cmake -DFASTPCAP_TOOLS=ON); not part of the wheel.
|
|
23
|
+
option(FASTPCAP_TOOLS "build fp_dump" OFF)
|
|
24
|
+
if(FASTPCAP_TOOLS)
|
|
25
|
+
add_executable(fp_dump tools/fp_dump.cpp)
|
|
26
|
+
endif()
|
fastpcap-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 QNT Software
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
fastpcap-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: fastpcap
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fast, memory-safe pcap/pcapng analysis: C++ core, NumPy columns, flows and statistics
|
|
5
|
+
Keywords: pcap,pcapng,network,packet,security,dns,tls,ja3,netflow
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: C++
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
10
|
+
Classifier: Topic :: Security
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Requires-Dist: numpy>=1.22
|
|
13
|
+
Provides-Extra: pandas
|
|
14
|
+
Requires-Dist: pandas; extra == "pandas"
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest; extra == "test"
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
|
|
21
|
+
<img src="https://i.hizliresim.com/ltefwh5k.png" alt="fastpcap" width="100%"/>
|
|
22
|
+
|
|
23
|
+
<br/>
|
|
24
|
+
|
|
25
|
+
[](#-build-from-source)
|
|
26
|
+
[](#-quick-start)
|
|
27
|
+
[](#-column-reference)
|
|
28
|
+
[](LICENSE)
|
|
29
|
+
|
|
30
|
+
[](#-releasing)
|
|
31
|
+
[](#-robustness)
|
|
32
|
+
[](#-project-layout)
|
|
33
|
+
[](https://github.com/qntsoftware/fastpcap/stargazers)
|
|
34
|
+
[](https://github.com/qntsoftware/fastpcap/issues)
|
|
35
|
+
|
|
36
|
+
**[Quick start](#-quick-start)** · **[Features](#-features)** · **[Protocols](#-supported-protocols)** · **[Statistics](#-statistics)** · **[API](#-api)** · **[Robustness](#-robustness)** · **[Build](#-build-from-source)**
|
|
37
|
+
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## ⚡ Why fastpcap
|
|
43
|
+
|
|
44
|
+
Python packet libraries are convenient, but parsing millions of packets in pure Python is slow. fastpcap moves the heavy work into a **C++17 core** and returns **NumPy columns**, so you can filter, group and plot a whole capture with vectorized code.
|
|
45
|
+
|
|
46
|
+
<div align="center">
|
|
47
|
+
<img src="https://i.hizliresim.com/wou9rkl5.png" alt="fastpcap pipeline" width="100%"/>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
- 🚀 **One pass** gives you packets, bidirectional flows and capture statistics
|
|
51
|
+
- 🧵 **GIL released** while parsing, so other Python threads keep running
|
|
52
|
+
- 🛡️ **Hostile-input safe**: all reads are bounds-checked and the parser is fuzzed
|
|
53
|
+
- 📊 **Analysis built in**: entropy, jitter, RTT, retransmissions, beaconing and scan detection
|
|
54
|
+
- 🔌 **No C++ to write**: `import fastpcap` and work with arrays
|
|
55
|
+
|
|
56
|
+
## 📦 Installation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install fastpcap
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
> The package is not on PyPI until the first release is published. Until then, use [Build from source](#-build-from-source).
|
|
63
|
+
|
|
64
|
+
## 🚀 Quick start
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import fastpcap
|
|
68
|
+
|
|
69
|
+
cap = fastpcap.read("capture.pcap")
|
|
70
|
+
print(cap) # <fastpcap.Capture pcap-usec packets=... flows=... duration=...s>
|
|
71
|
+
|
|
72
|
+
# 📈 capture-level statistics
|
|
73
|
+
s = cap.summary
|
|
74
|
+
print(s["packets"], s["bytes"], s["duration"])
|
|
75
|
+
print(s["packet_size"]["mean"], s["packet_size"]["skew"])
|
|
76
|
+
print(s["l7_counts"]) # {'dns': 120, 'tls': 4031, ...}
|
|
77
|
+
print(s["top_src"][:3]) # top talkers by bytes
|
|
78
|
+
|
|
79
|
+
# 🧮 per-packet NumPy columns
|
|
80
|
+
p = cap.packets
|
|
81
|
+
https = (p["proto"] == 6) & (p["dport"] == 443)
|
|
82
|
+
print(p["ts_ns"][https][:5])
|
|
83
|
+
print(fastpcap.ips(p, "src")[:3])
|
|
84
|
+
|
|
85
|
+
# 🔀 bidirectional flows
|
|
86
|
+
f = cap.flows
|
|
87
|
+
print(f["bps"].max(), f["retransmissions"].sum())
|
|
88
|
+
|
|
89
|
+
# 🕵️ security helpers
|
|
90
|
+
print(fastpcap.beacon_candidates(f)) # suspiciously regular flows
|
|
91
|
+
print(fastpcap.port_scan_candidates(f)) # sources touching many targets
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
<details>
|
|
95
|
+
<summary><b>Memory-friendly modes for huge files</b></summary>
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
fastpcap.summary("huge.pcap") # statistics only
|
|
99
|
+
fastpcap.read_flows("huge.pcap") # flows only, no per-packet columns
|
|
100
|
+
fastpcap.read("huge.pcap", packets=False) # same idea, full Capture object
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
</details>
|
|
104
|
+
|
|
105
|
+
<details>
|
|
106
|
+
<summary><b>Command line and pandas</b></summary>
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
python -m fastpcap capture.pcap # human readable report
|
|
110
|
+
python -m fastpcap capture.pcap --json # machine readable
|
|
111
|
+
python -m fastpcap capture.pcap --checksums # also verify IPv4/TCP/UDP/ICMP checksums
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
pandas is optional:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
df = cap.to_pandas("packets") # or "flows"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
</details>
|
|
121
|
+
|
|
122
|
+
### Example output
|
|
123
|
+
|
|
124
|
+
Output of the standalone C++ tool (`fp_dump`) on a small synthetic capture generated by `tests/pcapgen.py`:
|
|
125
|
+
|
|
126
|
+
```text
|
|
127
|
+
$ ./fp_dump sample.pcap --flows --checksums
|
|
128
|
+
format=pcap-usec linktype=1 records=13 truncated=0 malformed=0
|
|
129
|
+
packets=13 bytes=1050 undecoded=0 ipv4=11 ipv6=1 arp=1 frag=0
|
|
130
|
+
duration=0.600000 size_mean=80.769 size_std=35.586 size_skew=0.8596 size_kurt=-0.1242
|
|
131
|
+
l7 dns=2
|
|
132
|
+
l7 http=3
|
|
133
|
+
l7 tls=1
|
|
134
|
+
l7 arp=1
|
|
135
|
+
flow 10.0.0.2:40000 <-> 93.184.216.34:80 p=6 pk=4/2 by=348/154 dur=0.030000 rtt=10000000 retr=1 l7=http info=example.com
|
|
136
|
+
flow 10.0.0.2:40001 <-> 93.184.216.34:443 p=6 pk=1/0 by=161/0 dur=0.000000 rtt=-1 retr=0 l7=tls info=example.org
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## ✨ Features
|
|
140
|
+
|
|
141
|
+
| | Feature | Details |
|
|
142
|
+
|---|---|---|
|
|
143
|
+
| 📂 | **Containers** | pcap (usec/nsec, little/big endian), pcapng (SHB, IDB, EPB, SPB, `if_tsresol`) |
|
|
144
|
+
| 🧱 | **Zero-copy reading** | `mmap` on Linux/macOS, whole-file read on Windows |
|
|
145
|
+
| 🔍 | **Deep decoding** | Ethernet to application layer, in a single pass |
|
|
146
|
+
| 🔀 | **Flow table** | bidirectional 5-tuple flows with optional idle timeout |
|
|
147
|
+
| 🧮 | **Streaming statistics** | Welford/Pébay moments, Shannon entropy, jitter, RTT |
|
|
148
|
+
| 🧪 | **Checksum verification** | RFC 1071 with IPv4 and IPv6 pseudo headers |
|
|
149
|
+
| 🕵️ | **Detection helpers** | beaconing, port scans, top talkers |
|
|
150
|
+
| 🔐 | **TLS fingerprinting** | SNI, version, JA3 MD5 |
|
|
151
|
+
|
|
152
|
+
## 🌐 Supported protocols
|
|
153
|
+
|
|
154
|
+
| Layer | Protocols |
|
|
155
|
+
|---|---|
|
|
156
|
+
| **Container** | pcap (usec/nsec, little/big endian), pcapng |
|
|
157
|
+
| **L2** | Ethernet, 802.1Q/QinQ, Linux SLL/SLL2, BSD loopback, raw IP, MPLS, PPPoE |
|
|
158
|
+
| **L3** | IPv4 (fragments, header checksum), IPv6 (extension headers, fragments), ARP |
|
|
159
|
+
| **L4** | TCP (flags, seq/ack, MSS, window scale), UDP, ICMP, ICMPv6, SCTP ports, IGMP |
|
|
160
|
+
| **L7** | DNS (compression, A/AAAA answers), HTTP/1.x, TLS (SNI, version, JA3), DHCP, SSH banner, NTP, QUIC long header |
|
|
161
|
+
|
|
162
|
+
> **Not supported yet:** TCP stream reassembly, IP defragmentation, tunnels (GRE, VXLAN, IPsec), HTTP/2, QUIC decryption, TLS handshakes split across segments.
|
|
163
|
+
> For full protocol dissection, use Wireshark/tshark. fastpcap is built for fast statistics and triage over large captures.
|
|
164
|
+
|
|
165
|
+
## 📐 Statistics
|
|
166
|
+
|
|
167
|
+
| Area | What you get |
|
|
168
|
+
|---|---|
|
|
169
|
+
| **Moments** | one-pass mean, standard deviation, skewness, excess kurtosis, coefficient of variation for packet sizes and inter-arrival times (per flow and per capture) |
|
|
170
|
+
| **Entropy** | Shannon entropy of payload bytes per flow, and of source, destination and port distributions per capture |
|
|
171
|
+
| **Timing** | inter-arrival jitter (RFC 3550 smoothing), periodicity score `1 / (1 + CV)`, packets and bits per second |
|
|
172
|
+
| **TCP** | handshake RTT, retransmissions (safe across 32-bit sequence wraparound), flag counts, MSS, window scale |
|
|
173
|
+
| **Integrity** | IPv4, TCP, UDP, ICMP and ICMPv6 checksum verification |
|
|
174
|
+
|
|
175
|
+
## 🧰 API
|
|
176
|
+
|
|
177
|
+
| Function | Purpose |
|
|
178
|
+
|---|---|
|
|
179
|
+
| `read(path, packets=True, flows=True, l7=True, verify_checksums=False, entropy=True, max_packets=0, flow_timeout=0.0)` | Parse a file, returns `Capture` |
|
|
180
|
+
| `read_bytes(data, ...)` | Same for in-memory captures |
|
|
181
|
+
| `read_flows(path, ...)` / `summary(path, ...)` | Flows only / statistics only |
|
|
182
|
+
| `iter_packets(path)` / `read_pcap(path)` | Convenience `Packet` tuples (slower, fine for small files) |
|
|
183
|
+
| `beacon_candidates(flows, min_packets=8, max_cv=0.25, min_interval=0.5)` | Regular-interval flows |
|
|
184
|
+
| `port_scan_candidates(flows, min_targets=20)` | Scan-like sources |
|
|
185
|
+
| `top_talkers(flows, n=10)` | Initiators ranked by bytes |
|
|
186
|
+
| `entropy(data)` / `checksum16(data)` | Byte entropy / RFC 1071 checksum |
|
|
187
|
+
|
|
188
|
+
`flow_timeout` (seconds) splits a 5-tuple into separate flows after that much idle time. `0` disables it.
|
|
189
|
+
|
|
190
|
+
## 📚 Column reference
|
|
191
|
+
|
|
192
|
+
<details>
|
|
193
|
+
<summary><b>Packet columns</b></summary>
|
|
194
|
+
|
|
195
|
+
`ts_ns, wirelen, caplen, ethertype, vlan, ip_ver, proto, ttl, tos, ip_id, src, dst, sport, dport, tcp_flags, seq, ack, window, tcp_mss, tcp_wscale, payload_len, frag, ip_csum, l4_csum, icmp_type, icmp_code, l7, app_code, info, extra`
|
|
196
|
+
|
|
197
|
+
`src` and `dst` are `(n, 16)` uint8 arrays. IPv4 is stored as `::ffff:a.b.c.d`. Use `fastpcap.ips()` for text.
|
|
198
|
+
|
|
199
|
+
| `l7` | `app_code` | `info` | `extra` |
|
|
200
|
+
|---|---|---|---|
|
|
201
|
+
| dns | query type | query name | flags, rcode, answer IPs |
|
|
202
|
+
| http | status (0 for requests) | Host header | first line |
|
|
203
|
+
| tls | version (`0x0304` = 1.3) | SNI | JA3 MD5 |
|
|
204
|
+
| dhcp | message type | hostname | request / reply |
|
|
205
|
+
| ssh | | banner | |
|
|
206
|
+
| ntp | mode | | version |
|
|
207
|
+
| quic | version | | |
|
|
208
|
+
| arp | opcode | sender MAC | target MAC |
|
|
209
|
+
|
|
210
|
+
Checksum columns: `1` ok, `0` bad, `2` not checked. Captures taken on a NIC with checksum offload often show bad TCP/UDP checksums on outgoing packets. That is normal.
|
|
211
|
+
|
|
212
|
+
</details>
|
|
213
|
+
|
|
214
|
+
<details>
|
|
215
|
+
<summary><b>Flow columns</b></summary>
|
|
216
|
+
|
|
217
|
+
`src, dst, sport, dport, proto, start_ns, end_ns, duration, fwd_packets, bwd_packets, fwd_bytes, bwd_bytes, fwd_payload, bwd_payload, size_mean, size_std, size_min, size_max, size_skew, size_kurtosis, iat_mean, iat_std, iat_cv, iat_min, iat_max, jitter, periodicity, pps, bps, payload_entropy, syn, synack, fin, rst, psh, urg, tcp_flags_or, retransmissions, rtt, ttl, window, mss, wscale, l7, app_code, info, extra`
|
|
218
|
+
|
|
219
|
+
`rtt` is `NaN` when no handshake was seen.
|
|
220
|
+
|
|
221
|
+
</details>
|
|
222
|
+
|
|
223
|
+
## 🛡️ Robustness
|
|
224
|
+
|
|
225
|
+
Network data is untrusted input, so the parser itself is an attack surface.
|
|
226
|
+
|
|
227
|
+
- Every byte is read through a **bounds-checked view** that returns `0` instead of touching memory out of range
|
|
228
|
+
- Malformed or truncated files stop cleanly and set `cap.meta["malformed"]` or `cap.meta["truncated"]`
|
|
229
|
+
- `fuzz/fuzz_reader.cpp` is a **libFuzzer** entry point and a standalone mutation fuzzer
|
|
230
|
+
- CI runs the fuzzer under **AddressSanitizer + UBSan** on every push
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
python3 tests/make_seeds.py /tmp/seeds
|
|
234
|
+
g++ -std=c++17 -O1 -g -DFP_STANDALONE -fsanitize=address,undefined \
|
|
235
|
+
-fno-sanitize-recover=undefined fuzz/fuzz_reader.cpp -o fuzz_sa
|
|
236
|
+
./fuzz_sa /tmp/seeds/usec_le.pcap 100000
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## 🔧 Build from source
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Debian / Ubuntu / Kali
|
|
243
|
+
sudo apt install build-essential cmake
|
|
244
|
+
|
|
245
|
+
git clone https://github.com/qntsoftware/fastpcap
|
|
246
|
+
cd fastpcap
|
|
247
|
+
pip install -e .
|
|
248
|
+
pytest tests -q
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**Standalone C++ tool** (no Python needed, the core is header-only):
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
g++ -std=c++17 -O3 -o fp_dump tools/fp_dump.cpp
|
|
255
|
+
./fp_dump capture.pcap --packets 20 --flows --checksums
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## 🗂️ Project layout
|
|
259
|
+
|
|
260
|
+
```text
|
|
261
|
+
fastpcap/
|
|
262
|
+
├── src/
|
|
263
|
+
│ ├── util.hpp bounds-checked Span, addresses, statistics, MD5
|
|
264
|
+
│ ├── reader.hpp mmap + pcap/pcapng reader
|
|
265
|
+
│ ├── decode.hpp L2 to L7 decoder
|
|
266
|
+
│ ├── analyze.hpp flow table, columns, capture summary
|
|
267
|
+
│ └── bindings.cpp pybind11 module
|
|
268
|
+
├── python/fastpcap/ Python API, analysis helpers, CLI
|
|
269
|
+
├── tests/ pytest suite and pure-Python packet builder
|
|
270
|
+
├── fuzz/ libFuzzer / standalone mutation fuzzer
|
|
271
|
+
└── tools/fp_dump.cpp standalone CLI
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## 🚢 Releasing
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
git tag v0.1.0 && git push --tags
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
`.github/workflows/wheels.yml` builds wheels for Linux, Windows and macOS with cibuildwheel and publishes to PyPI via Trusted Publishing, so no API token is stored in the repo.
|
|
281
|
+
|
|
282
|
+
## 🗺️ Roadmap
|
|
283
|
+
|
|
284
|
+
- [ ] TCP stream reassembly
|
|
285
|
+
- [ ] IP defragmentation
|
|
286
|
+
- [ ] Tunnel decapsulation (GRE, VXLAN)
|
|
287
|
+
- [ ] HTTP/2 and DNS-over-TLS awareness
|
|
288
|
+
- [ ] Streaming iterator API for captures larger than memory
|
|
289
|
+
|
|
290
|
+
## 🤝 Contributing
|
|
291
|
+
|
|
292
|
+
Issues and pull requests are welcome. Please run `pytest tests -q` and the fuzzer before opening a PR, and include a small capture (or the `pcapgen.py` code that builds it) for any decoder change.
|
|
293
|
+
|
|
294
|
+
## ⚖️ Responsible use
|
|
295
|
+
|
|
296
|
+
fastpcap analyzes captures. Only analyze traffic you own or are authorized to inspect, and follow the privacy laws that apply to you.
|
|
297
|
+
|
|
298
|
+
## 📄 License
|
|
299
|
+
|
|
300
|
+
[MIT](LICENSE)
|
|
301
|
+
|
|
302
|
+
<div align="center">
|
|
303
|
+
|
|
304
|
+
Made with C++ and curiosity. If fastpcap is useful to you, a ⭐ helps others find it.
|
|
305
|
+
|
|
306
|
+
</div>
|