intraspannet 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.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,21 @@
1
+ # NOTICE
2
+
3
+ GDNet includes an independent implementation of a byte-level GDN encoder. The architecture follows the MambaNetBurst project:
4
+
5
+ - MambaNetBurst: https://github.com/gayanku/MambaNetBurst
6
+ - The upstream README declares the MIT license. The upstream checkout used during development did not contain a separate LICENSE file. No upstream source files are redistributed in this repository; the encoder here is a trimmed GDN-only implementation.
7
+
8
+ The GDN layer is provided by flash-linear-attention:
9
+
10
+ - flash-linear-attention: https://github.com/fla-org/flash-linear-attention
11
+ - Gated Delta Networks: Improving Mamba2 with the Delta Rule, arXiv:2412.06464.
12
+
13
+ Other dependencies:
14
+
15
+ - PyTorch, BSD-3-Clause.
16
+ - dpkt, BSD-3-Clause.
17
+ - NumPy, BSD-3-Clause.
18
+
19
+ Public benchmark names and numbers are cited for comparison. The datasets are not redistributed. See `docs/BENCHMARK_AUDIT.md` for the split audit and references.
20
+
21
+ The model was trained on lab traffic collected by the project authors and on public benchmark training splits. No customer traffic is included.
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: intraspannet
3
+ Version: 0.1.0
4
+ Summary: Byte-level traffic classification for security product discovery
5
+ Author: IntraSpanNet contributors
6
+ License: Apache-2.0
7
+ Keywords: network-security,traffic-classification,open-set-recognition,mamba,gdn
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Topic :: Security
11
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ License-File: NOTICE
16
+ Requires-Dist: numpy>=1.26
17
+ Requires-Dist: torch>=2.4
18
+ Requires-Dist: dpkt>=1.9
19
+ Requires-Dist: flash-linear-attention>=0.3
20
+ Provides-Extra: space
21
+ Requires-Dist: gradio>=5.0; extra == "space"
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=8.0; extra == "dev"
24
+ Requires-Dist: ruff>=0.6; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ # IntraSpanNet
28
+
29
+ Byte-level traffic classification for security product discovery.
30
+
31
+ IntraSpanNet identifies security products and services from the first five packets of a network flow. It reports the product, its type and tier, and rejects flows that do not match any known product. The released model is a four-arm ensemble with 2.86M parameters per arm.
32
+
33
+ - Model: [intraspannet on Hugging Face](https://huggingface.co/luping123/IntraSpanNet)
34
+ - Paper: [English PDF](paper/IntraSpanNet.pdf) and [Chinese PDF](paper/IntraSpanNet-zh.pdf)
35
+ - Project page: https://lupingQAQ.github.io/IntraSpanNet/
36
+ - Demo: not deployed. The Space code is in `space/` and requires a CUDA GPU.
37
+ - Report: [docs/RESULTS.md](docs/RESULTS.md)
38
+ - Benchmark audit: [docs/BENCHMARK_AUDIT.md](docs/BENCHMARK_AUDIT.md)
39
+
40
+ **DOI:** [10.5281/zenodo.23643146](https://zenodo.org/records/23643146)
41
+
42
+ ## What it does
43
+
44
+ Input: one unidirectional flow, represented as the first 5 packets, 320 bytes per packet (80 bytes of IPv4 and L4 headers, 240 bytes of payload), for a total of 1600 bytes. IPv4 source and destination addresses are zeroed.
45
+
46
+ Output per flow:
47
+
48
+ | Field | Meaning |
49
+ |---|---|
50
+ | `tier` | Security appliance, security software, or productivity software |
51
+ | `type` | WAF, behavior management, bastion host, NDR, zero trust/VPN, EDR/HIDS, antivirus, browser, file transfer, remote administration |
52
+ | `product` | One of 18 product labels, or `unknown` |
53
+ | `distance` | Cosine distance to the nearest class prototype |
54
+ | `confidence` | Mean softmax probability over the four classifier arms |
55
+ | `topk` | Top-3 product probabilities |
56
+
57
+ Unknown products are rejected when the mean prototype distance exceeds `0.1041`. The threshold was calibrated on the dev half of the validation split and was not tuned on the test half.
58
+
59
+ ## Results
60
+
61
+ The final system uses four classifier arms, A-S0, A-LDA, B-LDA and B-S0, and the gate uses A-LDA and B-LDA. Arm naming: the letter is the pre-training run (A or B), the suffix is the training variant (`s0` standard multi-task objective, `lda` logit adjustment by class prior, `hn` hard-negative weighting). Checkpoint files carry the same labels in lower case, for example `stage3_a_s0.pth` is arm A-S0.
62
+
63
+ | Metric | Test (503 flows) | All validation (1006 flows) |
64
+ |---|---:|---:|
65
+ | Product accuracy | 0.8787 | 0.8817 |
66
+ | Tier accuracy | 0.9245 | 0.9334 |
67
+ | Macro-F1 (supported classes) | 0.7621 | 0.8240 |
68
+ | Gate AUROC | 0.9784 | 0.9820 (dev) |
69
+
70
+ Additional results:
71
+
72
+ - Malicious family macro-F1: 0.9702 on the deduplicated USTC-TFC2016 test set (n=1242).
73
+ - Unknown rejection: 100% on 18 unknown-product bins. The operating point is stable from q=0.64 to q=0.75.
74
+ - Acceptance demo: 9/10 products with the timing-rescue rule, 8/10 without it. Unknown rejection is 100%.
75
+ - End-to-end service: 6/6 known flows. Few-shot enrollment: 8/8 after registering three sub-prototypes.
76
+ - Throughput: 253 flows/s for the four-arm ensemble at batch 32 or higher; 1017 flows/s for a single arm. Latency at batch 1 is 43.1 ms and 10.7 ms respectively.
77
+ - Memory: 3.4 GB peak at batch 128 on an RTX 4090; the ensemble weights total about 46 MB.
78
+
79
+ The test split is a flow-level half of the validation set, not a session-level holdout. Every product class has one held-out session. This limits the strength of the absolute numbers. See [docs/RESULTS.md](docs/RESULTS.md) for the full protocol and confidence intervals.
80
+
81
+ ## Quick start
82
+
83
+ Requirements:
84
+
85
+ - Linux or Windows with an NVIDIA GPU and a working CUDA driver.
86
+ - Python 3.10 or newer.
87
+ - PyTorch built for your CUDA version.
88
+ - `flash-linear-attention` and its dependencies.
89
+
90
+ CPU inference is not supported in v0.1.0. The GDN backbone uses Triton kernels and requires CUDA.
91
+
92
+ ```bash
93
+ git clone https://github.com/lupingQAQ/IntraSpanNet.git
94
+ cd IntraSpanNet
95
+ python -m venv .venv
96
+ source .venv/bin/activate
97
+ pip install -e .
98
+ ```
99
+
100
+ Download the weights from Hugging Face:
101
+
102
+ ```bash
103
+ huggingface-cli download luping123/IntraSpanNet --local-dir weights/intraspannet
104
+ ```
105
+
106
+ Classify a capture:
107
+
108
+ ```bash
109
+ python -m intraspannet.cli classify \
110
+ --pcap sample.pcap \
111
+ --weights-dir weights/intraspannet \
112
+ --json results.json
113
+ ```
114
+
115
+ The command prints a table and a summary. `--json` writes one record per flow.
116
+
117
+ Example record:
118
+
119
+ ```json
120
+ {
121
+ "product": "wazuh_agent",
122
+ "display": "Wazuh agent",
123
+ "tier": "安全软件",
124
+ "type": "EDR / HIDS",
125
+ "unknown": false,
126
+ "distance": 0.0104,
127
+ "confidence": 0.9991,
128
+ "class_id": 6,
129
+ "topk": [
130
+ {"product": "wazuh_agent", "display": "Wazuh agent", "probability": 0.9991},
131
+ {"product": "osquery", "display": "osquery", "probability": 0.0006},
132
+ {"product": "velociraptor", "display": "Velociraptor", "probability": 0.0002}
133
+ ]
134
+ }
135
+ ```
136
+
137
+ Serve the probe format over HTTP:
138
+
139
+ ```bash
140
+ python -m intraspannet.cli serve --weights-dir weights/intraspannet --port 9012
141
+ ```
142
+
143
+ The service accepts `POST /` with one or more 1620-byte `FLW1` records. It returns a JSON array of results.
144
+
145
+ ## Input format
146
+
147
+ The released model uses the same format as the training pipeline:
148
+
149
+ - Ethernet, IPv4, TCP or UDP.
150
+ - One direction per flow, keyed by source address, source port, destination address, destination port, and protocol.
151
+ - First 5 packets, in capture order.
152
+ - Each packet contributes 80 bytes of IP and L4 headers followed by 240 bytes of payload.
153
+ - Short packets and short flows are zero-padded.
154
+ - IPv4 source and destination addresses are zeroed at bytes 12:20 of each flow.
155
+
156
+ `pcap`, `pcapng`, and `cap` files are accepted. The preprocessor uses dpkt.
157
+
158
+ ## Model
159
+
160
+ ![Architecture](docs/assets/architecture.svg)
161
+
162
+ ```
163
+ bytes (1600)
164
+ -> ByteEmbed (256)
165
+ -> [bytes, CLS] + positional embedding
166
+ -> 4 x GDN blocks (d_model=256, d_state=16)
167
+ -> CLS feature (256)
168
+ -> product head (18), type head (10), tier head (3), malicious head (11)
169
+ ```
170
+
171
+ The open-set decision uses three sub-prototypes per class. For a flow feature `f` and prototype matrix `P`, the distance is `1 - max(cos(f, P))`. The gate averages the distance over the two gate arms.
172
+
173
+ The four classifier arms share the same architecture and differ in pretraining recipe, loss weighting, and hard-negative sampling. The ensemble averages their softmax outputs and prototype distances.
174
+
175
+ ## Training
176
+
177
+ | Stage | Data | Objective |
178
+ |---|---|---|
179
+ | 1. Contrastive pretraining | 33,184 training-only flows | NT-Xent / SimCLR |
180
+ | 2. Multi-task SFT | Product, benchmark, and malicious training flows | Product, type, tier, malicious, domain-adversarial losses |
181
+ | 3. RL fine-tuning | Training split with reward shaping | Correct product, correct type, honest rejection |
182
+
183
+ Training data comes from lab captures of 18 products and services, plus public benchmark training splits. The SSL pool excludes validation and holdout flows. The validation split is divided into dev and test halves at the flow level. Selection, threshold calibration, and ensemble choice use dev only.
184
+
185
+ The model was trained on 4 x RTX 4090 GPUs. The released checkpoints are the final arms.
186
+
187
+ ## Evaluation protocol
188
+
189
+ - Product and tier accuracy: flow-level accuracy on the test half (503 flows) and on the full validation set (1006 flows).
190
+ - Macro-F1: macro-F1 over classes with at least one test sample. Small classes make this metric unstable; the all-validation value is the more stable reference.
191
+ - Open-set AUROC: known-product flows versus unknown and novel flows.
192
+ - Unknown rejection: fraction of unknown-product bins rejected at the fixed threshold.
193
+ - Malicious detection: macro-F1 on the deduplicated USTC-TFC2016 test split.
194
+
195
+ The report also includes a leakage audit. Five of the six public benchmark splits contain about 80% byte-identical train/test overlap; Tor is the exception at 0%. All benchmark comparisons in the report use the same split, so relative comparisons remain same-protocol comparisons, but absolute benchmark accuracy is not evidence of generalization. The audit scripts and clean-subset lists are in the report archive.
196
+
197
+ ## Limitations
198
+
199
+ - `stunnel` is the only product with zero recall in the acceptance demo (0/30). It needs enrollment or additional data.
200
+ - The test split is flow-level, not session-level. Each class has one held-out session, so session-level generalization is not measured.
201
+ - The timing-rescue rule used in the 9/10 acceptance result is not included in v0.1.0. The released ensemble alone reproduces the 8/10 raw result.
202
+ - Mobile and IoT benchmarks are out of scope. The target scope is PCs, servers, and internal network devices.
203
+ - The model was trained on lab traffic. Performance on production networks with different software versions, proxies, or NAT configurations is unknown.
204
+ - CPU inference is not supported.
205
+ - The distilled student is included for experiments. It is 5.6 percentage points below the ensemble and is not the recommended deployment.
206
+
207
+ ## Data and privacy
208
+
209
+ The repository does not include captures. The released weights were trained on lab traffic and public benchmark training splits. No customer traffic is included. Do not upload sensitive captures to public demos.
210
+
211
+ ## License
212
+
213
+ Code and weights: Apache-2.0. Documentation: CC-BY-4.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
214
+
215
+ ## Citation
216
+
217
+ ```bibtex
218
+ @software{intraspannet2026,
219
+ title = {IntraSpanNet: an intranet traffic detection model for security product identification},
220
+ year = {2026},
221
+ url = {https://github.com/lupingQAQ/IntraSpanNet},
222
+ note = {Model: https://huggingface.co/luping123/IntraSpanNet}
223
+ }
224
+ ```
225
+
226
+ ## Acknowledgements
227
+
228
+ The byte-level backbone follows the architecture of MambaNetBurst. The GDN layer is provided by flash-linear-attention. See [NOTICE](NOTICE) for details.
@@ -0,0 +1,202 @@
1
+ # IntraSpanNet
2
+
3
+ Byte-level traffic classification for security product discovery.
4
+
5
+ IntraSpanNet identifies security products and services from the first five packets of a network flow. It reports the product, its type and tier, and rejects flows that do not match any known product. The released model is a four-arm ensemble with 2.86M parameters per arm.
6
+
7
+ - Model: [intraspannet on Hugging Face](https://huggingface.co/luping123/IntraSpanNet)
8
+ - Paper: [English PDF](paper/IntraSpanNet.pdf) and [Chinese PDF](paper/IntraSpanNet-zh.pdf)
9
+ - Project page: https://lupingQAQ.github.io/IntraSpanNet/
10
+ - Demo: not deployed. The Space code is in `space/` and requires a CUDA GPU.
11
+ - Report: [docs/RESULTS.md](docs/RESULTS.md)
12
+ - Benchmark audit: [docs/BENCHMARK_AUDIT.md](docs/BENCHMARK_AUDIT.md)
13
+
14
+ **DOI:** [10.5281/zenodo.23643146](https://zenodo.org/records/23643146)
15
+
16
+ ## What it does
17
+
18
+ Input: one unidirectional flow, represented as the first 5 packets, 320 bytes per packet (80 bytes of IPv4 and L4 headers, 240 bytes of payload), for a total of 1600 bytes. IPv4 source and destination addresses are zeroed.
19
+
20
+ Output per flow:
21
+
22
+ | Field | Meaning |
23
+ |---|---|
24
+ | `tier` | Security appliance, security software, or productivity software |
25
+ | `type` | WAF, behavior management, bastion host, NDR, zero trust/VPN, EDR/HIDS, antivirus, browser, file transfer, remote administration |
26
+ | `product` | One of 18 product labels, or `unknown` |
27
+ | `distance` | Cosine distance to the nearest class prototype |
28
+ | `confidence` | Mean softmax probability over the four classifier arms |
29
+ | `topk` | Top-3 product probabilities |
30
+
31
+ Unknown products are rejected when the mean prototype distance exceeds `0.1041`. The threshold was calibrated on the dev half of the validation split and was not tuned on the test half.
32
+
33
+ ## Results
34
+
35
+ The final system uses four classifier arms, A-S0, A-LDA, B-LDA and B-S0, and the gate uses A-LDA and B-LDA. Arm naming: the letter is the pre-training run (A or B), the suffix is the training variant (`s0` standard multi-task objective, `lda` logit adjustment by class prior, `hn` hard-negative weighting). Checkpoint files carry the same labels in lower case, for example `stage3_a_s0.pth` is arm A-S0.
36
+
37
+ | Metric | Test (503 flows) | All validation (1006 flows) |
38
+ |---|---:|---:|
39
+ | Product accuracy | 0.8787 | 0.8817 |
40
+ | Tier accuracy | 0.9245 | 0.9334 |
41
+ | Macro-F1 (supported classes) | 0.7621 | 0.8240 |
42
+ | Gate AUROC | 0.9784 | 0.9820 (dev) |
43
+
44
+ Additional results:
45
+
46
+ - Malicious family macro-F1: 0.9702 on the deduplicated USTC-TFC2016 test set (n=1242).
47
+ - Unknown rejection: 100% on 18 unknown-product bins. The operating point is stable from q=0.64 to q=0.75.
48
+ - Acceptance demo: 9/10 products with the timing-rescue rule, 8/10 without it. Unknown rejection is 100%.
49
+ - End-to-end service: 6/6 known flows. Few-shot enrollment: 8/8 after registering three sub-prototypes.
50
+ - Throughput: 253 flows/s for the four-arm ensemble at batch 32 or higher; 1017 flows/s for a single arm. Latency at batch 1 is 43.1 ms and 10.7 ms respectively.
51
+ - Memory: 3.4 GB peak at batch 128 on an RTX 4090; the ensemble weights total about 46 MB.
52
+
53
+ The test split is a flow-level half of the validation set, not a session-level holdout. Every product class has one held-out session. This limits the strength of the absolute numbers. See [docs/RESULTS.md](docs/RESULTS.md) for the full protocol and confidence intervals.
54
+
55
+ ## Quick start
56
+
57
+ Requirements:
58
+
59
+ - Linux or Windows with an NVIDIA GPU and a working CUDA driver.
60
+ - Python 3.10 or newer.
61
+ - PyTorch built for your CUDA version.
62
+ - `flash-linear-attention` and its dependencies.
63
+
64
+ CPU inference is not supported in v0.1.0. The GDN backbone uses Triton kernels and requires CUDA.
65
+
66
+ ```bash
67
+ git clone https://github.com/lupingQAQ/IntraSpanNet.git
68
+ cd IntraSpanNet
69
+ python -m venv .venv
70
+ source .venv/bin/activate
71
+ pip install -e .
72
+ ```
73
+
74
+ Download the weights from Hugging Face:
75
+
76
+ ```bash
77
+ huggingface-cli download luping123/IntraSpanNet --local-dir weights/intraspannet
78
+ ```
79
+
80
+ Classify a capture:
81
+
82
+ ```bash
83
+ python -m intraspannet.cli classify \
84
+ --pcap sample.pcap \
85
+ --weights-dir weights/intraspannet \
86
+ --json results.json
87
+ ```
88
+
89
+ The command prints a table and a summary. `--json` writes one record per flow.
90
+
91
+ Example record:
92
+
93
+ ```json
94
+ {
95
+ "product": "wazuh_agent",
96
+ "display": "Wazuh agent",
97
+ "tier": "安全软件",
98
+ "type": "EDR / HIDS",
99
+ "unknown": false,
100
+ "distance": 0.0104,
101
+ "confidence": 0.9991,
102
+ "class_id": 6,
103
+ "topk": [
104
+ {"product": "wazuh_agent", "display": "Wazuh agent", "probability": 0.9991},
105
+ {"product": "osquery", "display": "osquery", "probability": 0.0006},
106
+ {"product": "velociraptor", "display": "Velociraptor", "probability": 0.0002}
107
+ ]
108
+ }
109
+ ```
110
+
111
+ Serve the probe format over HTTP:
112
+
113
+ ```bash
114
+ python -m intraspannet.cli serve --weights-dir weights/intraspannet --port 9012
115
+ ```
116
+
117
+ The service accepts `POST /` with one or more 1620-byte `FLW1` records. It returns a JSON array of results.
118
+
119
+ ## Input format
120
+
121
+ The released model uses the same format as the training pipeline:
122
+
123
+ - Ethernet, IPv4, TCP or UDP.
124
+ - One direction per flow, keyed by source address, source port, destination address, destination port, and protocol.
125
+ - First 5 packets, in capture order.
126
+ - Each packet contributes 80 bytes of IP and L4 headers followed by 240 bytes of payload.
127
+ - Short packets and short flows are zero-padded.
128
+ - IPv4 source and destination addresses are zeroed at bytes 12:20 of each flow.
129
+
130
+ `pcap`, `pcapng`, and `cap` files are accepted. The preprocessor uses dpkt.
131
+
132
+ ## Model
133
+
134
+ ![Architecture](docs/assets/architecture.svg)
135
+
136
+ ```
137
+ bytes (1600)
138
+ -> ByteEmbed (256)
139
+ -> [bytes, CLS] + positional embedding
140
+ -> 4 x GDN blocks (d_model=256, d_state=16)
141
+ -> CLS feature (256)
142
+ -> product head (18), type head (10), tier head (3), malicious head (11)
143
+ ```
144
+
145
+ The open-set decision uses three sub-prototypes per class. For a flow feature `f` and prototype matrix `P`, the distance is `1 - max(cos(f, P))`. The gate averages the distance over the two gate arms.
146
+
147
+ The four classifier arms share the same architecture and differ in pretraining recipe, loss weighting, and hard-negative sampling. The ensemble averages their softmax outputs and prototype distances.
148
+
149
+ ## Training
150
+
151
+ | Stage | Data | Objective |
152
+ |---|---|---|
153
+ | 1. Contrastive pretraining | 33,184 training-only flows | NT-Xent / SimCLR |
154
+ | 2. Multi-task SFT | Product, benchmark, and malicious training flows | Product, type, tier, malicious, domain-adversarial losses |
155
+ | 3. RL fine-tuning | Training split with reward shaping | Correct product, correct type, honest rejection |
156
+
157
+ Training data comes from lab captures of 18 products and services, plus public benchmark training splits. The SSL pool excludes validation and holdout flows. The validation split is divided into dev and test halves at the flow level. Selection, threshold calibration, and ensemble choice use dev only.
158
+
159
+ The model was trained on 4 x RTX 4090 GPUs. The released checkpoints are the final arms.
160
+
161
+ ## Evaluation protocol
162
+
163
+ - Product and tier accuracy: flow-level accuracy on the test half (503 flows) and on the full validation set (1006 flows).
164
+ - Macro-F1: macro-F1 over classes with at least one test sample. Small classes make this metric unstable; the all-validation value is the more stable reference.
165
+ - Open-set AUROC: known-product flows versus unknown and novel flows.
166
+ - Unknown rejection: fraction of unknown-product bins rejected at the fixed threshold.
167
+ - Malicious detection: macro-F1 on the deduplicated USTC-TFC2016 test split.
168
+
169
+ The report also includes a leakage audit. Five of the six public benchmark splits contain about 80% byte-identical train/test overlap; Tor is the exception at 0%. All benchmark comparisons in the report use the same split, so relative comparisons remain same-protocol comparisons, but absolute benchmark accuracy is not evidence of generalization. The audit scripts and clean-subset lists are in the report archive.
170
+
171
+ ## Limitations
172
+
173
+ - `stunnel` is the only product with zero recall in the acceptance demo (0/30). It needs enrollment or additional data.
174
+ - The test split is flow-level, not session-level. Each class has one held-out session, so session-level generalization is not measured.
175
+ - The timing-rescue rule used in the 9/10 acceptance result is not included in v0.1.0. The released ensemble alone reproduces the 8/10 raw result.
176
+ - Mobile and IoT benchmarks are out of scope. The target scope is PCs, servers, and internal network devices.
177
+ - The model was trained on lab traffic. Performance on production networks with different software versions, proxies, or NAT configurations is unknown.
178
+ - CPU inference is not supported.
179
+ - The distilled student is included for experiments. It is 5.6 percentage points below the ensemble and is not the recommended deployment.
180
+
181
+ ## Data and privacy
182
+
183
+ The repository does not include captures. The released weights were trained on lab traffic and public benchmark training splits. No customer traffic is included. Do not upload sensitive captures to public demos.
184
+
185
+ ## License
186
+
187
+ Code and weights: Apache-2.0. Documentation: CC-BY-4.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
188
+
189
+ ## Citation
190
+
191
+ ```bibtex
192
+ @software{intraspannet2026,
193
+ title = {IntraSpanNet: an intranet traffic detection model for security product identification},
194
+ year = {2026},
195
+ url = {https://github.com/lupingQAQ/IntraSpanNet},
196
+ note = {Model: https://huggingface.co/luping123/IntraSpanNet}
197
+ }
198
+ ```
199
+
200
+ ## Acknowledgements
201
+
202
+ The byte-level backbone follows the architecture of MambaNetBurst. The GDN layer is provided by flash-linear-attention. See [NOTICE](NOTICE) for details.
@@ -0,0 +1,7 @@
1
+ """IntraSpanNet: byte-level traffic classification for security product discovery."""
2
+
3
+ from .inference import Ensemble
4
+ from .labels import PRODUCTS, describe
5
+
6
+ __version__ = "0.1.0"
7
+ __all__ = ["Ensemble", "PRODUCTS", "describe", "__version__"]