flowmask 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.
Files changed (47) hide show
  1. flowmask-0.1.0/DECISIONS.md +300 -0
  2. flowmask-0.1.0/LICENSE +21 -0
  3. flowmask-0.1.0/MANIFEST.in +6 -0
  4. flowmask-0.1.0/PKG-INFO +357 -0
  5. flowmask-0.1.0/README.md +325 -0
  6. flowmask-0.1.0/docs/screenshots/arp.svg +21 -0
  7. flowmask-0.1.0/docs/screenshots/dhcp.svg +27 -0
  8. flowmask-0.1.0/docs/screenshots/icmp-error.svg +33 -0
  9. flowmask-0.1.0/docs/screenshots/ipv4-tcp.svg +31 -0
  10. flowmask-0.1.0/docs/screenshots/ipv6-udp.svg +29 -0
  11. flowmask-0.1.0/docs/screenshots/mdns.svg +43 -0
  12. flowmask-0.1.0/docs/screenshots/neighbour-discovery.svg +25 -0
  13. flowmask-0.1.0/docs/screenshots/netbios.svg +31 -0
  14. flowmask-0.1.0/docs/screenshots/report.svg +18 -0
  15. flowmask-0.1.0/docs/screenshots/text-log.svg +21 -0
  16. flowmask-0.1.0/pyproject.toml +59 -0
  17. flowmask-0.1.0/scripts/make_examples.py +525 -0
  18. flowmask-0.1.0/scripts/roundtrip_check.py +496 -0
  19. flowmask-0.1.0/setup.cfg +4 -0
  20. flowmask-0.1.0/src/flowmask/__init__.py +3 -0
  21. flowmask-0.1.0/src/flowmask/__main__.py +5 -0
  22. flowmask-0.1.0/src/flowmask/addresses.py +302 -0
  23. flowmask-0.1.0/src/flowmask/captures.py +382 -0
  24. flowmask-0.1.0/src/flowmask/cli.py +361 -0
  25. flowmask-0.1.0/src/flowmask/names.py +440 -0
  26. flowmask-0.1.0/src/flowmask/packets.py +560 -0
  27. flowmask-0.1.0/src/flowmask/text.py +365 -0
  28. flowmask-0.1.0/src/flowmask/verify.py +221 -0
  29. flowmask-0.1.0/src/flowmask.egg-info/PKG-INFO +357 -0
  30. flowmask-0.1.0/src/flowmask.egg-info/SOURCES.txt +45 -0
  31. flowmask-0.1.0/src/flowmask.egg-info/dependency_links.txt +1 -0
  32. flowmask-0.1.0/src/flowmask.egg-info/entry_points.txt +2 -0
  33. flowmask-0.1.0/src/flowmask.egg-info/requires.txt +4 -0
  34. flowmask-0.1.0/src/flowmask.egg-info/top_level.txt +1 -0
  35. flowmask-0.1.0/tests/checksums.py +152 -0
  36. flowmask-0.1.0/tests/conftest.py +49 -0
  37. flowmask-0.1.0/tests/pcapgen.py +398 -0
  38. flowmask-0.1.0/tests/test_addresses.py +147 -0
  39. flowmask-0.1.0/tests/test_cli.py +106 -0
  40. flowmask-0.1.0/tests/test_examples.py +40 -0
  41. flowmask-0.1.0/tests/test_files.py +161 -0
  42. flowmask-0.1.0/tests/test_leftovers.py +138 -0
  43. flowmask-0.1.0/tests/test_names.py +217 -0
  44. flowmask-0.1.0/tests/test_packets.py +259 -0
  45. flowmask-0.1.0/tests/test_roundtrip.py +125 -0
  46. flowmask-0.1.0/tests/test_text.py +137 -0
  47. flowmask-0.1.0/tests/test_wireshark.py +34 -0
@@ -0,0 +1,300 @@
1
+ # Decisions
2
+
3
+ A short record of design decisions, the reason for each, and a public source for
4
+ any fact a decision relies on. Entries are based on public documentation, on
5
+ measurements described in the entry, or on general engineering practice.
6
+
7
+ ## 2026-12-03: Name
8
+
9
+ `flowmask` was free on PyPI (no project page, no simple index entry) and on
10
+ GitHub under FSayedio when checked on 2026-12-03. One unrelated repository
11
+ with a longer name (`FlowMaskAI`) exists under another account.
12
+
13
+ ## 2026-12-03: What it replaces, and what it keeps
14
+
15
+ flowmask replaces client IP addresses and nothing else. Hardware addresses,
16
+ device and host names, domain names, server addresses and packet contents are
17
+ kept as they were. The documentation describes the output in exactly those
18
+ terms: what is replaced and what is kept, and makes no wider claim.
19
+ (Device names were added later the same day: see "Device names are replaced
20
+ too" below.)
21
+
22
+ - Why: the masked files must still line up with each other and still be
23
+ useful for analysis (which application, which server, how much). Claiming
24
+ more than address replacement would mislead: names, hardware addresses and
25
+ contents can still identify a device or a person.
26
+
27
+ ## 2026-12-03: opticflow's -log writes classic pcap
28
+
29
+ `opticflow -log NAME` runs `dumpcap -q -i IFACE -f "host ADDRESS" -F pcap -w -`
30
+ and copies the stream into `NAME.pcap`, so the capture is classic pcap with
31
+ the engine interface's link type (Ethernet on flowspool's `lima0`). `NAME.txt`
32
+ holds exactly what was printed, without colour: a start line naming the
33
+ device, a line naming the capture filter, and box-drawn tables whose columns
34
+ are padded to the widest value.
35
+
36
+ - Source: `src/opticflow/capture.py` and `app.py` in
37
+ https://github.com/FSayedio/opticflow at commit 9b9434f.
38
+ - Consequence: flowmask reads pcapng too, but the main case is classic pcap,
39
+ and text masking has to keep box-drawn tables aligned.
40
+
41
+ ## 2026-12-03: Standard library only; no tcprewrite, no Scapy at run time
42
+
43
+ flowmask parses and rewrites packets itself with the Python standard library.
44
+
45
+ - tcprewrite (tcpreplay 4.x) maps CIDR blocks to CIDR blocks (`--pnat`,
46
+ `--srcipmap`), cannot export its mapping for the text log, skips checksum
47
+ recalculation when a packet's captured length differs from its length on the
48
+ wire ("Unable to checksum packet: L4 length exceeds captured data"), offers
49
+ `--fixlen pad|trunc|del` for cut-short packets (which changes lengths or
50
+ drops packets), writes through `pcap_dump_open` (so pcapng comes out as
51
+ classic pcap), and does not rewrite the IP header quoted inside ICMP errors.
52
+ Sources: `src/tcpedit/tcpedit_opts.def`, `src/tcpedit/checksum.c`,
53
+ `src/tcpedit/edit_packet.c` and `src/tcprewrite.c` in
54
+ https://github.com/appneta/tcpreplay (master, read 2026-12-03).
55
+ - Scapy rebuilds packets and, in the usual approach, recomputes checksums
56
+ over the captured bytes, which puts new errors into cut-short packets; it is
57
+ also a large dependency for a tool that runs in the flowspool VM.
58
+ - Decided with the user on 2026-12-03: the rewriter stays stdlib-only; tests
59
+ build packets with a stdlib generator and check checksums with an
60
+ independent full recomputation, and CI also checks with tshark on Linux.
61
+
62
+ ## 2026-12-03: Client ranges and the dummy pool
63
+
64
+ Clients are, by default, addresses in the private and local ranges: IPv4
65
+ `10/8`, `172.16/12`, `192.168/16`, `100.64/10` (shared address space, RFC
66
+ 6598), `169.254/16`, `127/8`; IPv6 `fc00::/7`, `fe80::/10`, `::1`. An
67
+ IPv4-mapped IPv6 address is judged by its IPv4 part. Multicast, unspecified
68
+ and the limited broadcast address are never clients. `--client-net` replaces
69
+ the default.
70
+
71
+ Dummies come from RFC 5737 (`192.0.2.0/24`, `198.51.100.0/24`,
72
+ `203.0.113.0/24`, hosts .1 to .254 only, 762 addresses) and RFC 3849
73
+ (`2001:db8::/32`, from `::1` up), in order of first appearance across all
74
+ inputs in command-line order. A dummy is never an address that appears in the
75
+ input, and never one inside the client ranges. Too many clients stops the run
76
+ with a message, unless `--dummy-net` names a larger range.
77
+
78
+ - Why 100.64/10 is in the default: devices behind carrier-grade NAT have such
79
+ addresses. Agreed with the user on 2026-12-03.
80
+ - Why .0 and .255 are skipped: tools treat them as network and broadcast
81
+ addresses.
82
+
83
+ ## 2026-12-03: One mapping per run, built before anything is written
84
+
85
+ Every input is scanned first, then the mapping is built, then every output is
86
+ written with it. If writing fails, outputs already created in that run are
87
+ removed. Outputs are created with `O_EXCL` and mode 0600, so an existing file
88
+ is never overwritten. The mapping is printed only with `--show-map`; map files
89
+ (`--map-out`, `--map-in`) are JSON with a `warning` field, mode 0600, and a
90
+ warning on stderr whenever one is written or read.
91
+
92
+ ## 2026-12-03: Text alignment
93
+
94
+ A replacement that changes length takes the difference from the padding beside
95
+ the address when the address sits in a column. A column is recognised when
96
+ another line of the same block of lines has a word starting (left-aligned) or
97
+ ending (right-aligned) at the same place behind the same kind of divider, or
98
+ has a rule character there (a separator line). When the padding is too short,
99
+ the column is widened at its first padding position in every line that shares
100
+ it, with spaces, or with the rule character in separator lines. Free text in a
101
+ framed line (`╭─ … ─╮`) takes the difference from the run of rule characters
102
+ after it, so the frame keeps its width. Other free text is replaced as it is.
103
+
104
+ - Why: opticflow's tables pad to the widest value, so a longer dummy would
105
+ otherwise push every later column out of line.
106
+
107
+ ## 2026-12-03: tcpdump's address.port form
108
+
109
+ `10.42.0.5.443` is read as an address and a port. A version-like string such
110
+ as `1.10.42.0.5.2` is not replaced, and verification then reports it, so it is
111
+ never silently left.
112
+
113
+ ## 2026-12-03: Checksums by incremental update (RFC 1624)
114
+
115
+ For each checksum covering a changed address (IPv4 header; TCP, UDP, UDP-Lite
116
+ and ICMPv6 through their pseudo-headers; ICMP when a quoted header changed;
117
+ the quoted inner IPv4 header and inner transport checksums), flowmask adds
118
+ `~m + m'` for every changed 16-bit word to `~HC` (RFC 1624, equation 3).
119
+ Inner checksums are fixed first, so the outer ICMP checksum also accounts for
120
+ their change.
121
+
122
+ - Why: it needs only the checksum field and the changed words, so it works on
123
+ packets cut short by the snapshot length and on IP fragments (the first
124
+ fragment carries the checksum of the whole datagram), and a checksum that
125
+ was wrong (for example from checksum offloading on the capturing host)
126
+ stays wrong by the same amount: the masked capture has no checksum error
127
+ the original did not have.
128
+ - A UDP checksum of zero over IPv4 means "none" and stays zero; a computed
129
+ zero is written as 0xFFFF (RFC 768).
130
+ - With an IPv6 routing header that has segments left, the pseudo-header holds
131
+ the final destination from the routing header, so a change to the
132
+ destination field does not touch the transport checksum.
133
+ - An Ethernet frame check sequence, when the file says frames carry one
134
+ (pcapng `if_fcslen`, or the pcap header's FCS bits, draft-ietf-opsawg-pcap
135
+ section 4), is recomputed only when it was correct and the frame complete.
136
+ - Source: RFC 1624, https://www.rfc-editor.org/rfc/rfc1624.
137
+
138
+ ## 2026-12-03: What cannot be fixed in a cut-short packet
139
+
140
+ - An address cut off by the snapshot length: its captured bytes are replaced
141
+ with the matching bytes of the dummy of the first client whose address starts
142
+ with them.
143
+ - A checksum whose covered address was not captured at all, or a checksum cut
144
+ between its two bytes, is left as captured: its correct new value depends on
145
+ bytes that were never captured. (Such a checksum is a function of the real
146
+ address; snapshot lengths that small are unusual.)
147
+ - An ICMP error cut inside its quoted packet: the outer checksum cannot account
148
+ for a quoted checksum that was not captured. Wireshark cannot verify an ICMP
149
+ checksum of a message that was cut short either, so it reports nothing new.
150
+ - Tests check that masking a packet cut at any byte gives exactly the first
151
+ bytes of the whole packet masked, except in these cases.
152
+
153
+ ## 2026-12-03: What is rewritten inside packets, and what is only reported
154
+
155
+ Rewritten: IPv4 and IPv6 source and destination, ARP sender and target, the
156
+ IP header quoted in ICMP and ICMPv6 errors, the ICMP redirect gateway, the
157
+ IPv6 neighbour discovery target (and redirect destination), IP-in-IP and
158
+ 6in4 inner headers, and in pcapng the interface address options and name
159
+ resolution records (names kept).
160
+
161
+ - Why neighbour discovery: it is IPv6's counterpart of ARP. Agreed with the
162
+ user on 2026-12-03.
163
+ - Everything else (DHCP, DNS, mDNS, SSDP, SIP, STUN, FTP, HTTP, IPv4 options,
164
+ routing headers, GRE, VXLAN, GTP) is packet contents: left as it was and
165
+ reported by verification. Device names inside those contents are the one
166
+ exception (see "Device names are replaced too").
167
+
168
+ ## 2026-12-03: Verification is always on
169
+
170
+ After writing, every output is searched for every original client address: as
171
+ text (any spelling, reverse lookup names, the comma form), and in captures as
172
+ raw bytes (the address, an IPv4 address in little-endian byte order, a
173
+ reverse name in DNS wire format, STUN's XOR-mapped IPv4 form), in packets
174
+ (link-layer headers included) and in pcapng options and metadata blocks. pcap record
175
+ headers (times and lengths) are not searched. Each leftover is reported with
176
+ its place, by the client's dummy address, and the exit status is 1 unless
177
+ `--allow-leftovers` is given.
178
+
179
+ - A raw 4-byte match can occur by chance in large binary payloads; the report
180
+ says where each match sits so it can be judged.
181
+ - Hardware addresses are kept, but some hold an IPv4 address: Docker's
182
+ `02:42:` followed by the container's address (nDPI's
183
+ `log4j-webapp-exploit.pcap`, Linux cooked header bytes 8 to 11), or
184
+ hand-made test addresses (`dlms.pcap`). The report names the Ethernet or
185
+ Linux cooked address field.
186
+
187
+ ## 2026-12-03: Round-trip check
188
+
189
+ `scripts/roundtrip_check.py` runs `ndpiReader -q -i FILE -C CSV` on both
190
+ captures, matches flows by protocol, the unordered pair of endpoints after
191
+ translating the original's addresses through the mapping, and start time when
192
+ several flows share a key. It compares application, server name, packets,
193
+ bytes, start time and duration, and which side is the client; then
194
+ `flowreel summary` and `flowreel list` (direction fix); then, with tshark,
195
+ frames with a bad checksum (`*.checksum.status == 0`, with IP, TCP and UDP
196
+ checksum checking switched on) or a malformed packet.
197
+
198
+ - flowreel's direction fix uses Python's `ipaddress.is_private`, which is true
199
+ for the three RFC 5737 ranges and for `2001:db8::/32`. A private client
200
+ therefore stays "private" after masking. It is not true for `100.64.0.0/10`
201
+ or for a public address given with `--client-net`, so such clients can be
202
+ turned round differently when the ports do not decide. The check reports
203
+ any flow where that happens, with the original address's category only.
204
+
205
+ ## 2026-12-03: What nDPI notices about documentation addresses
206
+
207
+ Measured with `scripts/roundtrip_check.py` on nDPI 6.0's public sample
208
+ captures (`tests/cfgs/default/pcap` at tag 6.0) and read in nDPI 6.0's source:
209
+
210
+ - nDPI's `ndpi_is_public_ipv4` (`src/lib/ndpi_main.c`) counts only `10/8`,
211
+ `172.16/12`, `192.168/16`, `127/8` and `224/4` as non-public, so the RFC 5737
212
+ documentation ranges are "public" to nDPI (while Python's `is_private`, which
213
+ flowreel uses, calls them private). In nDPI 6.0 this matters for:
214
+ - Sonos over UDP (`src/lib/protocols/sonos.c`), detected only towards a
215
+ non-public destination: a private Sonos flow becomes Unknown after
216
+ masking, and ndpiReader leaves it out of its flow CSV (`sonos.pcapng`).
217
+ - the "Unusual TCP fingerprint" risk, which nDPI skips for private sources
218
+ but not for documentation ones (risks are not in the compared columns).
219
+ - IP-list matching, done only for public addresses; documentation addresses
220
+ are on no list, so this changes nothing.
221
+ - NetBIOS datagrams to UDP port 138 (`src/lib/protocols/netbios.c`): nDPI
222
+ labels the flow NetBIOS, and SMBv1 with the host name, only when the source
223
+ address inside the NetBIOS datagram header (payload bytes 4 to 7) equals the
224
+ IP source address. flowmask rewrites the IP header and leaves that payload
225
+ field, so such flows lose the `SMBv1` label and host name, and verification
226
+ reports the field as a leftover.
227
+ - EGD (`src/lib/protocols/egd.c`, line 42): nDPI recognises EGD only when
228
+ the ProducerID at payload bytes 4 to 7 equals the IP source address. The
229
+ EGD flow in `egd.pcapng` is no longer recognised after masking.
230
+ - Lustre (`src/lib/protocols/lustre.c`, lines 51 to 69): nDPI recognises
231
+ LNet only when the destination address in the LNet header (payload bytes 8
232
+ or 24, little-endian) equals the IP destination. Both Lustre flows in
233
+ `lustre.pcapng` are no longer recognised; verification finds the copies as
234
+ little-endian IPv4 bytes.
235
+ - Rewriting these payload copies would keep the labels, but would change
236
+ packet contents, which flowmask keeps as they were. Not done; decided with
237
+ the user on 2026-12-03.
238
+
239
+ ## 2026-12-03: Device names are replaced too
240
+
241
+ The names client devices give themselves are replaced with dummy names, by
242
+ default; `--keep-names` turns this off and `--device-name` adds names.
243
+ Decided with the user on 2026-12-03, after measuring that three of four of
244
+ their test captures carry the device's own name in mDNS announcements, and
245
+ one in DHCP host name options, while opticflow's log names the device only by
246
+ its address (`device {self.device}`, `src/opticflow/app.py`).
247
+
248
+ - Where names are learned: mDNS and LLMNR records that give a client's
249
+ address (the host label of `NAME.local`, or a single-label LLMNR name), PTR
250
+ records for a client's reverse name, and in messages a client sends, service
251
+ instance names and SRV targets (RFC 6763 section 4.1); DHCP options 12 and
252
+ 81 in client requests (RFC 2132, RFC 4702); DHCPv6 option 39 (RFC 4704);
253
+ NetBIOS name registrations and positive responses from a client, and the
254
+ source name of NetBIOS datagrams a client sends, unique names with suffix
255
+ 0x00 or 0x20 only (RFC 1002 sections 4.2.2 and 4.4). Domain names
256
+ and server names are not device names and stay.
257
+ - Learned names shorter than 4 bytes, all digits, or factory defaults that
258
+ identify no one (`localhost`, `iphone`, `ipad`, `android`, `raspberrypi`,
259
+ `workgroup`, `unknown`) are left. Why 4: a short name would match by chance
260
+ in binary payloads; a 4-letter name, matched in any case, is expected
261
+ about once in 270 MB of random bytes. Given names need 2 characters.
262
+ - Same length: a name's dummy is `device<N>` padded with `x` (shorter forms
263
+ `dev<N>`, `d<N>` for short names), N in order of first appearance, upper
264
+ case where the original was. Lengths, DNS compression offsets, pcapng
265
+ block sizes and text columns stay as they were, and checksums are adjusted
266
+ with the same incremental method as for addresses.
267
+ - Forms: plain bytes or text in any letter case, UTF-16LE (Windows, SMB),
268
+ NetBIOS first-level encoding (RFC 1001 section 14.1) of the first 15
269
+ characters, and for a name longer than 15 characters its first 15 as plain
270
+ text (NetBIOS cuts names there, and SMB browser announcements and nDPI's
271
+ output show that form). A 15-character name learned that is the start of a
272
+ known longer name is the same device. Where two names share a form, the
273
+ earlier-numbered one keeps it in every form. Verification searches for
274
+ exactly these forms.
275
+ - Text logs get a dummy of the same length in characters (so columns stay
276
+ straight); packets get one of the same length in bytes. They differ only
277
+ for names with characters outside ASCII. The round-trip check translates
278
+ nDPI's server-name field by bytes, as in the capture.
279
+ - No word-boundary rule. A first version replaced a name only between
280
+ characters that are not letters or digits. In a DHCP request the host name
281
+ (option 12) was followed by option 81, whose code byte 0x51 is the letter
282
+ `Q`, so the name was left, and verification, using the same rule, missed it.
283
+ Names are therefore replaced and searched for wherever their bytes appear,
284
+ even inside a longer word.
285
+ - A name in a later IP fragment is left: the transport checksum that covers
286
+ it is in the first fragment, another packet. Verification reports it. A
287
+ name is never written over an address or checksum field.
288
+ - Map files are version 2, with a `names` list (version 1 files are still
289
+ read). A name's number, and so its dummy, comes from its place in the list.
290
+ - Measured on the user's four captures: 2 names learned in each of three,
291
+ 13 to 18 replacements per capture, and the round-trip check unchanged
292
+ (all flows matched, no differences). Learning names again from the masked
293
+ outputs finds no name that is not a dummy.
294
+ - Measured on nDPI 6.0's 629 sample captures: 55 names in 23 files, no
295
+ device name left in any output, and the same 11 files as before failing
296
+ the round-trip check, for the reasons in "What nDPI notices about
297
+ documentation addresses". The first run found two faults, fixed since:
298
+ names with characters outside ASCII were translated by characters in the
299
+ round-trip check (`iphone.pcap`), and the 15-character NetBIOS form of a
300
+ longer name was not replaced as plain text (`1kxun.pcap`).
flowmask-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Farhan Sayed
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.
@@ -0,0 +1,6 @@
1
+ # Extra files for the source distribution (sdist), so it can be tested.
2
+ include DECISIONS.md
3
+ graft tests
4
+ graft scripts
5
+ graft docs
6
+ global-exclude __pycache__ *.py[cod] *.pcap *.pcapng *.cap