pidsmaker 4.0.0__py3-none-any.whl

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.

Potentially problematic release.


This version of pidsmaker might be problematic. Click here for more details.

Files changed (338) hide show
  1. pidsmaker/__init__.py +22 -0
  2. pidsmaker/cli.py +32 -0
  3. pidsmaker/config/__init__.py +2 -0
  4. pidsmaker/config/config.py +2100 -0
  5. pidsmaker/config/pipeline.py +1768 -0
  6. pidsmaker/config/schemas.py +1032 -0
  7. pidsmaker/datasets.py +222 -0
  8. pidsmaker/debug_tests.py +30 -0
  9. pidsmaker/decoders/__init__.py +5 -0
  10. pidsmaker/decoders/custom_edge_mlp_decoder.py +17 -0
  11. pidsmaker/decoders/custom_mlp_decoder.py +10 -0
  12. pidsmaker/decoders/edge_linear_decoder.py +16 -0
  13. pidsmaker/decoders/inner_product_decoder.py +18 -0
  14. pidsmaker/decoders/nodlink_decoder.py +56 -0
  15. pidsmaker/detection/__init__.py +0 -0
  16. pidsmaker/detection/evaluation_methods/__init__.py +9 -0
  17. pidsmaker/detection/evaluation_methods/edge_evaluation.py +259 -0
  18. pidsmaker/detection/evaluation_methods/evaluation_utils.py +1730 -0
  19. pidsmaker/detection/evaluation_methods/host_two_stage_evaluation.py +115 -0
  20. pidsmaker/detection/evaluation_methods/node_evaluation.py +463 -0
  21. pidsmaker/detection/evaluation_methods/node_tw_evaluation.py +196 -0
  22. pidsmaker/detection/evaluation_methods/plot.py +192 -0
  23. pidsmaker/detection/evaluation_methods/queue_evaluation.py +451 -0
  24. pidsmaker/detection/evaluation_methods/tw_evaluation.py +95 -0
  25. pidsmaker/detection/flash_detection.py +162 -0
  26. pidsmaker/detection/magic_knn.py +190 -0
  27. pidsmaker/detection/node_scoring.py +52 -0
  28. pidsmaker/detection/threatrace_detection.py +65 -0
  29. pidsmaker/detection/training_methods/__init__.py +1 -0
  30. pidsmaker/detection/training_methods/inference_loop.py +293 -0
  31. pidsmaker/detection/training_methods/ocrapt_early_stop.py +165 -0
  32. pidsmaker/detection/training_methods/threatrace_training.py +169 -0
  33. pidsmaker/detection/training_methods/training_loop.py +377 -0
  34. pidsmaker/encoders/__init__.py +22 -0
  35. pidsmaker/encoders/argus_encoder.py +69 -0
  36. pidsmaker/encoders/custom_mlp.py +75 -0
  37. pidsmaker/encoders/custom_mlp_encoder.py +10 -0
  38. pidsmaker/encoders/egraphsage_encoder.py +56 -0
  39. pidsmaker/encoders/gat.py +67 -0
  40. pidsmaker/encoders/gcn.py +27 -0
  41. pidsmaker/encoders/gin.py +48 -0
  42. pidsmaker/encoders/glstm.py +298 -0
  43. pidsmaker/encoders/graph_attention.py +63 -0
  44. pidsmaker/encoders/gru.py +29 -0
  45. pidsmaker/encoders/hetero/__init__.py +4 -0
  46. pidsmaker/encoders/hetero/ancestor_encoder.py +98 -0
  47. pidsmaker/encoders/hetero/entity_encoder.py +33 -0
  48. pidsmaker/encoders/hetero/event_encoder.py +81 -0
  49. pidsmaker/encoders/hetero/hetero_graph_transformer.py +40 -0
  50. pidsmaker/encoders/lares_encoder.py +68 -0
  51. pidsmaker/encoders/linear_encoder.py +16 -0
  52. pidsmaker/encoders/magic_encoder.py +161 -0
  53. pidsmaker/encoders/rcaid_encoder.py +81 -0
  54. pidsmaker/encoders/rgcn.py +75 -0
  55. pidsmaker/encoders/sage.py +51 -0
  56. pidsmaker/encoders/shadewatcher_encoder.py +149 -0
  57. pidsmaker/encoders/sum_aggregation.py +20 -0
  58. pidsmaker/encoders/temporal_wrappers.py +80 -0
  59. pidsmaker/encoders/textrcnn.py +82 -0
  60. pidsmaker/encoders/tgn_encoder.py +193 -0
  61. pidsmaker/experiments/tuning.py +102 -0
  62. pidsmaker/experiments/uncertainty.py +261 -0
  63. pidsmaker/factory.py +1456 -0
  64. pidsmaker/featurization/__init__.py +0 -0
  65. pidsmaker/featurization/feat_inference_methods/__init__.py +7 -0
  66. pidsmaker/featurization/feat_inference_methods/feat_inference_HFH.py +31 -0
  67. pidsmaker/featurization/feat_inference_methods/feat_inference_TRW.py +67 -0
  68. pidsmaker/featurization/feat_inference_methods/feat_inference_alacarte.py +16 -0
  69. pidsmaker/featurization/feat_inference_methods/feat_inference_doc2vec.py +54 -0
  70. pidsmaker/featurization/feat_inference_methods/feat_inference_fasttext.py +38 -0
  71. pidsmaker/featurization/feat_inference_methods/feat_inference_flash.py +70 -0
  72. pidsmaker/featurization/feat_inference_methods/feat_inference_graph2vec.py +85 -0
  73. pidsmaker/featurization/feat_inference_methods/feat_inference_ocrapt_features.py +95 -0
  74. pidsmaker/featurization/feat_inference_methods/feat_inference_pretrained.py +1729 -0
  75. pidsmaker/featurization/feat_inference_methods/feat_inference_word2vec.py +56 -0
  76. pidsmaker/featurization/featurization_methods/__init__.py +0 -0
  77. pidsmaker/featurization/featurization_methods/build_trw.py +67 -0
  78. pidsmaker/featurization/featurization_methods/featurization_alacarte.py +748 -0
  79. pidsmaker/featurization/featurization_methods/featurization_doc2vec.py +99 -0
  80. pidsmaker/featurization/featurization_methods/featurization_fasttext.py +75 -0
  81. pidsmaker/featurization/featurization_methods/featurization_flash.py +203 -0
  82. pidsmaker/featurization/featurization_methods/featurization_graph2vec.py +243 -0
  83. pidsmaker/featurization/featurization_methods/featurization_trw.py +115 -0
  84. pidsmaker/featurization/featurization_methods/featurization_word2vec.py +87 -0
  85. pidsmaker/featurization/featurization_utils.py +275 -0
  86. pidsmaker/featurization/utils/build_random_walks.py +68 -0
  87. pidsmaker/featurization/utils/trw.py +203 -0
  88. pidsmaker/hetero.py +81 -0
  89. pidsmaker/losses.py +170 -0
  90. pidsmaker/main.py +377 -0
  91. pidsmaker/mimicry.py +284 -0
  92. pidsmaker/model.py +382 -0
  93. pidsmaker/objectives/__init__.py +16 -0
  94. pidsmaker/objectives/autoencode_edge_emb.py +43 -0
  95. pidsmaker/objectives/deep_graph_infomax.py +94 -0
  96. pidsmaker/objectives/detect_few_shot.py +21 -0
  97. pidsmaker/objectives/one_class.py +75 -0
  98. pidsmaker/objectives/predict_edge_contrastive.py +165 -0
  99. pidsmaker/objectives/predict_edge_supervised.py +77 -0
  100. pidsmaker/objectives/predict_edge_type.py +28 -0
  101. pidsmaker/objectives/predict_masked_struct.py +49 -0
  102. pidsmaker/objectives/predict_node_type.py +36 -0
  103. pidsmaker/objectives/predict_process_tag.py +169 -0
  104. pidsmaker/objectives/predict_snapshot_embedding.py +97 -0
  105. pidsmaker/objectives/reconstruct_edge_emb.py +16 -0
  106. pidsmaker/objectives/reconstruct_masked_feat.py +51 -0
  107. pidsmaker/objectives/reconstruct_node_emb.py +13 -0
  108. pidsmaker/objectives/reconstruct_node_feat.py +13 -0
  109. pidsmaker/objectives/validation_wrapper.py +55 -0
  110. pidsmaker/preprocessing/__init__.py +0 -0
  111. pidsmaker/preprocessing/build_graph_methods/__init__.py +1 -0
  112. pidsmaker/preprocessing/build_graph_methods/build_default_graphs.py +830 -0
  113. pidsmaker/preprocessing/build_graph_methods/build_magic_graphs.py +220 -0
  114. pidsmaker/preprocessing/cleaning.py +258 -0
  115. pidsmaker/preprocessing/transformation_methods/__init__.py +2 -0
  116. pidsmaker/preprocessing/transformation_methods/attack_generation/synthetic_attack_naive.py +194 -0
  117. pidsmaker/preprocessing/transformation_methods/transformation_dag.py +28 -0
  118. pidsmaker/preprocessing/transformation_methods/transformation_merge_edges.py +136 -0
  119. pidsmaker/preprocessing/transformation_methods/transformation_rcaid_pseudo_graph.py +510 -0
  120. pidsmaker/preprocessing/transformation_methods/transformation_undirected.py +24 -0
  121. pidsmaker/preprocessing/transformation_methods/transformation_utils.py +36 -0
  122. pidsmaker/pretrained/__init__.py +5 -0
  123. pidsmaker/pretrained/data/__init__.py +4 -0
  124. pidsmaker/pretrained/data/behavior_signatures.py +548 -0
  125. pidsmaker/pretrained/data/canonical_tokens.py +1035 -0
  126. pidsmaker/pretrained/data/edge_filter.py +381 -0
  127. pidsmaker/pretrained/data/entity_classes.py +476 -0
  128. pidsmaker/pretrained/data/sampler.py +926 -0
  129. pidsmaker/pretrained/data/tokenizer_bpe.py +1659 -0
  130. pidsmaker/pretrained/detect.py +1432 -0
  131. pidsmaker/pretrained/embedding_generator.py +252 -0
  132. pidsmaker/pretrained/finetune.py +1437 -0
  133. pidsmaker/pretrained/models/__init__.py +20 -0
  134. pidsmaker/pretrained/models/behavior.py +348 -0
  135. pidsmaker/pretrained/models/bert.py +286 -0
  136. pidsmaker/pretrained/models/deepwalk.py +128 -0
  137. pidsmaker/pretrained/models/dgi.py +120 -0
  138. pidsmaker/pretrained/models/gae.py +114 -0
  139. pidsmaker/pretrained/models/gnn_distill.py +475 -0
  140. pidsmaker/pretrained/models/graphmae.py +373 -0
  141. pidsmaker/pretrained/models/hf_pretrained.py +213 -0
  142. pidsmaker/pretrained/models/llama.py +110 -0
  143. pidsmaker/pretrained/models/modernbert.py +567 -0
  144. pidsmaker/pretrained/models/roberta.py +147 -0
  145. pidsmaker/pretrained/models/rope_utils.py +99 -0
  146. pidsmaker/pretrained/models/ropebert.py +322 -0
  147. pidsmaker/pretrained/models/spider.py +204 -0
  148. pidsmaker/pretrained/models/tgn.py +770 -0
  149. pidsmaker/pretrained/pretrain/__init__.py +3 -0
  150. pidsmaker/pretrained/pretrain/pretrain_behavior_cluster.py +513 -0
  151. pidsmaker/pretrained/pretrain/pretrain_common.py +585 -0
  152. pidsmaker/pretrained/pretrain/pretrain_deepwalk.py +31 -0
  153. pidsmaker/pretrained/pretrain/pretrain_dgi.py +143 -0
  154. pidsmaker/pretrained/pretrain/pretrain_gae.py +143 -0
  155. pidsmaker/pretrained/pretrain/pretrain_gnn_distill.py +438 -0
  156. pidsmaker/pretrained/pretrain/pretrain_graphmae.py +151 -0
  157. pidsmaker/pretrained/pretrain/pretrain_hf.py +169 -0
  158. pidsmaker/pretrained/pretrain/pretrain_main.py +276 -0
  159. pidsmaker/pretrained/pretrain/pretrain_mlm.py +491 -0
  160. pidsmaker/pretrained/pretrain/pretrain_spider.py +502 -0
  161. pidsmaker/pretrained/training_utils.py +157 -0
  162. pidsmaker/process_reapr_gt.py +101 -0
  163. pidsmaker/resources/Ground_Truth/orthrus/E3-CADETS/node_Nginx_Backdoor_06.csv +8 -0
  164. pidsmaker/resources/Ground_Truth/orthrus/E3-CADETS/node_Nginx_Backdoor_11.csv +4 -0
  165. pidsmaker/resources/Ground_Truth/orthrus/E3-CADETS/node_Nginx_Backdoor_12.csv +43 -0
  166. pidsmaker/resources/Ground_Truth/orthrus/E3-CADETS/node_Nginx_Backdoor_13.csv +24 -0
  167. pidsmaker/resources/Ground_Truth/orthrus/E3-CLEARSCOPE/node_clearscope_e3_firefox_0411.csv +41 -0
  168. pidsmaker/resources/Ground_Truth/orthrus/E3-CLEARSCOPE/node_clearscope_e3_firefox_0412.csv +0 -0
  169. pidsmaker/resources/Ground_Truth/orthrus/E3-FIVEDIRECTIONS/node_fivedirections_e3_browser_0412.csv +1 -0
  170. pidsmaker/resources/Ground_Truth/orthrus/E3-FIVEDIRECTIONS/node_fivedirections_e3_excel_0409.csv +63 -0
  171. pidsmaker/resources/Ground_Truth/orthrus/E3-FIVEDIRECTIONS/node_fivedirections_e3_firefox_0411.csv +56 -0
  172. pidsmaker/resources/Ground_Truth/orthrus/E3-THEIA/node_Browser_Extension_Drakon_Dropper.csv +61 -0
  173. pidsmaker/resources/Ground_Truth/orthrus/E3-THEIA/node_Firefox_Backdoor_Drakon_In_Memory.csv +58 -0
  174. pidsmaker/resources/Ground_Truth/orthrus/E3-TRACE/node_trace_e3_firefox_0410.csv +11 -0
  175. pidsmaker/resources/Ground_Truth/orthrus/E3-TRACE/node_trace_e3_phishing_executable_0413.csv +11 -0
  176. pidsmaker/resources/Ground_Truth/orthrus/E3-TRACE/node_trace_e3_pine_0413.csv +14 -0
  177. pidsmaker/resources/Ground_Truth/orthrus/E5-CADETS/node_Nginx_Drakon_APT.csv +19 -0
  178. pidsmaker/resources/Ground_Truth/orthrus/E5-CADETS/node_Nginx_Drakon_APT_17.csv +107 -0
  179. pidsmaker/resources/Ground_Truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_appstarter_0515.csv +26 -0
  180. pidsmaker/resources/Ground_Truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_firefox_0517.csv +1 -0
  181. pidsmaker/resources/Ground_Truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_lockwatch_0517.csv +17 -0
  182. pidsmaker/resources/Ground_Truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_tester_0517.csv +8 -0
  183. pidsmaker/resources/Ground_Truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_bits_0515.csv +54 -0
  184. pidsmaker/resources/Ground_Truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_copykatz_0509.csv +87 -0
  185. pidsmaker/resources/Ground_Truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_dns_0517.csv +11 -0
  186. pidsmaker/resources/Ground_Truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_drakon_0517.csv +6 -0
  187. pidsmaker/resources/Ground_Truth/orthrus/E5-THEIA/node_THEIA_1_Firefox_Drakon_APT_BinFmt_Elevate_Inject.csv +70 -0
  188. pidsmaker/resources/Ground_Truth/orthrus/E5-TRACE/node_Trace_Firefox_Drakon.csv +71 -0
  189. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m1.csv +1 -0
  190. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m2.csv +1 -0
  191. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m3.csv +1 -0
  192. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m4.csv +5 -0
  193. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m5.csv +23 -0
  194. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m6.csv +18 -0
  195. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_s1.csv +1 -0
  196. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_s2.csv +1 -0
  197. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_s3.csv +16 -0
  198. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_s4.csv +22 -0
  199. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m1.csv +126 -0
  200. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m2.csv +105 -0
  201. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m3.csv +94 -0
  202. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m4.csv +139 -0
  203. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m5.csv +228 -0
  204. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m6.csv +131 -0
  205. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_s1.csv +118 -0
  206. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_s2.csv +89 -0
  207. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_s3.csv +133 -0
  208. pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_s4.csv +135 -0
  209. pidsmaker/resources/Ground_Truth/orthrus/carbanakv2_edr/carbanakv2_edr.csv +2453 -0
  210. pidsmaker/resources/Ground_Truth/orthrus/h051/node_h051_0925.csv +114 -0
  211. pidsmaker/resources/Ground_Truth/orthrus/h201/node_h201_0923.csv +2905 -0
  212. pidsmaker/resources/Ground_Truth/orthrus/h501/node_h501_0924.csv +749 -0
  213. pidsmaker/resources/Ground_Truth/orthrus/readme.md +98 -0
  214. pidsmaker/resources/Ground_Truth/reapr/E3-CADETS/node_Nginx_Backdoor_06.csv +3 -0
  215. pidsmaker/resources/Ground_Truth/reapr/E3-CADETS/node_Nginx_Backdoor_12.csv +655 -0
  216. pidsmaker/resources/Ground_Truth/reapr/E3-CADETS/node_Nginx_Backdoor_13.csv +770 -0
  217. pidsmaker/resources/Ground_Truth/reapr/E3-FIVEDIRECTIONS/node_fivedirections_e3_excel_0409.csv +0 -0
  218. pidsmaker/resources/Ground_Truth/reapr/E3-FIVEDIRECTIONS/node_fivedirections_e3_firefox_0411.csv +18 -0
  219. pidsmaker/resources/Ground_Truth/reapr/E3-THEIA/node_Browser_Extension_Drakon_Dropper.csv +42 -0
  220. pidsmaker/resources/Ground_Truth/reapr/E3-THEIA/node_Firefox_Backdoor_Drakon_In_Memory.csv +81 -0
  221. pidsmaker/resources/Ground_Truth/reapr/E3-TRACE/node_trace_e3_firefox_0410.csv +37 -0
  222. pidsmaker/resources/Ground_Truth/reapr/E3-TRACE/node_trace_e3_phishing_executable_0413.csv +9 -0
  223. pidsmaker/resources/Ground_Truth/reapr/E3-TRACE/node_trace_e3_pine_0413.csv +40 -0
  224. pidsmaker/resources/Ground_Truth/threatrace/E3-CADETS/ground_truth.txt +12858 -0
  225. pidsmaker/resources/Ground_Truth/threatrace/E3-FIVEDIRECTIONS/ground_truth.txt +18420 -0
  226. pidsmaker/resources/Ground_Truth/threatrace/E3-THEIA/ground_truth.txt +25363 -0
  227. pidsmaker/resources/Ground_Truth/threatrace/E3-TRACE/ground_truth.txt +68265 -0
  228. pidsmaker/resources/Ground_Truth/threatrace/README.md +123 -0
  229. pidsmaker/resources/config/anomal_e.yml +25 -0
  230. pidsmaker/resources/config/argus.yml +56 -0
  231. pidsmaker/resources/config/attack_edges/cadets_e3.yml +435 -0
  232. pidsmaker/resources/config/attack_edges/cadets_e5.yml +407 -0
  233. pidsmaker/resources/config/attack_edges/theia_e3.yml +382 -0
  234. pidsmaker/resources/config/attack_edges/theia_e5.yml +387 -0
  235. pidsmaker/resources/config/attack_edges/trace_e3.yml +415 -0
  236. pidsmaker/resources/config/attack_edges/trace_e5.yml +417 -0
  237. pidsmaker/resources/config/default.yml +315 -0
  238. pidsmaker/resources/config/egraphsage.yml +95 -0
  239. pidsmaker/resources/config/euler.yml +104 -0
  240. pidsmaker/resources/config/eval/eval_set_clustering.json +3170 -0
  241. pidsmaker/resources/config/experiments/tuning/components/tuning_featurization_methods.yml +29 -0
  242. pidsmaker/resources/config/experiments/tuning/systems/clearscope_e5/tuning_orthrus.yml +14 -0
  243. pidsmaker/resources/config/experiments/tuning/systems/default/tuning_default_baselines.yml +13 -0
  244. pidsmaker/resources/config/experiments/tuning/systems/default/tuning_orthrus_fixed.yml +16 -0
  245. pidsmaker/resources/config/experiments/uncertainty/none.yml +5 -0
  246. pidsmaker/resources/config/experiments/uncertainty/run_n_times.yml +12 -0
  247. pidsmaker/resources/config/experiments/uncertainty/run_n_times_hyperparameters.yml +12 -0
  248. pidsmaker/resources/config/experiments/uncertainty/uncertainty.yml +22 -0
  249. pidsmaker/resources/config/flash.yml +79 -0
  250. pidsmaker/resources/config/jbeil.yml +65 -0
  251. pidsmaker/resources/config/kairos.yml +121 -0
  252. pidsmaker/resources/config/lares.yml +115 -0
  253. pidsmaker/resources/config/magic.yml +86 -0
  254. pidsmaker/resources/config/nodlink.yml +79 -0
  255. pidsmaker/resources/config/ocrapt.yml +91 -0
  256. pidsmaker/resources/config/orthrus.yml +120 -0
  257. pidsmaker/resources/config/orthrus_fixed.yml +17 -0
  258. pidsmaker/resources/config/orthrus_non_snooped.yml +17 -0
  259. pidsmaker/resources/config/pretrained/README.md +101 -0
  260. pidsmaker/resources/config/pretrained/cybergfm/cybergfm.yml +49 -0
  261. pidsmaker/resources/config/pretrained/pretrained.yml +190 -0
  262. pidsmaker/resources/config/pretrained/pretrained_flash.yml +9 -0
  263. pidsmaker/resources/config/pretrained/pretrained_kairos.yml +12 -0
  264. pidsmaker/resources/config/pretrained/pretrained_magic.yml +1 -0
  265. pidsmaker/resources/config/pretrained/pretrained_nodlink.yml +1 -0
  266. pidsmaker/resources/config/pretrained/pretrained_orthrus.yml +1 -0
  267. pidsmaker/resources/config/pretrained/pretrained_supervised.yml +13 -0
  268. pidsmaker/resources/config/pretrained/pretrained_threatrace.yml +8 -0
  269. pidsmaker/resources/config/pretrained/pretrained_velox.yml +14 -0
  270. pidsmaker/resources/config/prographer.yml +136 -0
  271. pidsmaker/resources/config/rcaid.yml +88 -0
  272. pidsmaker/resources/config/shadewatcher.yml +146 -0
  273. pidsmaker/resources/config/tests.yml +10 -0
  274. pidsmaker/resources/config/threatrace.yml +73 -0
  275. pidsmaker/resources/config/tuned_baselines/optc_net/tuned_argus.yml +4 -0
  276. pidsmaker/resources/config/tuned_baselines/optc_net/tuned_lares.yml +13 -0
  277. pidsmaker/resources/config/velox.yml +10 -0
  278. pidsmaker/resources/config/viz_config.yml +10 -0
  279. pidsmaker/tasks/__init__.py +10 -0
  280. pidsmaker/tasks/batching.py +49 -0
  281. pidsmaker/tasks/construction.py +31 -0
  282. pidsmaker/tasks/evaluation.py +232 -0
  283. pidsmaker/tasks/feat_inference.py +413 -0
  284. pidsmaker/tasks/featurization.py +43 -0
  285. pidsmaker/tasks/training.py +19 -0
  286. pidsmaker/tasks/transformation.py +308 -0
  287. pidsmaker/tasks/triage.py +143 -0
  288. pidsmaker/tgn.py +635 -0
  289. pidsmaker/tokenization/__init__.py +112 -0
  290. pidsmaker/tokenization/base.py +58 -0
  291. pidsmaker/tokenization/bpe_tokenizer.py +83 -0
  292. pidsmaker/tokenization/hf_tokenizer.py +61 -0
  293. pidsmaker/tokenization/hierarchical_tokenizer.py +44 -0
  294. pidsmaker/tokenization/label_tokenizer.py +24 -0
  295. pidsmaker/tokenization/nltk_tokenizer.py +84 -0
  296. pidsmaker/tokenization/substitution.py +295 -0
  297. pidsmaker/triage/__init__.py +0 -0
  298. pidsmaker/triage/tracing_methods/__init__.py +1 -0
  299. pidsmaker/triage/tracing_methods/depimpact.py +213 -0
  300. pidsmaker/triage/tracing_methods/depimpact_utils.py +537 -0
  301. pidsmaker/triage/tracing_methods/ocrapt_subgraph.py +267 -0
  302. pidsmaker/utils/__init__.py +0 -0
  303. pidsmaker/utils/cache_utils.py +256 -0
  304. pidsmaker/utils/data_utils.py +1742 -0
  305. pidsmaker/utils/database.py +204 -0
  306. pidsmaker/utils/dataset_utils.py +413 -0
  307. pidsmaker/utils/dataset_writer.py +1057 -0
  308. pidsmaker/utils/graph_store.py +634 -0
  309. pidsmaker/utils/labelling.py +447 -0
  310. pidsmaker/utils/loss_files.py +193 -0
  311. pidsmaker/utils/process_tags.py +44 -0
  312. pidsmaker/utils/utils.py +730 -0
  313. pidsmaker/vizgen/__init__.py +1 -0
  314. pidsmaker/vizgen/dimensionality_reduction.py +249 -0
  315. pidsmaker/vizgen/embed_exporter.py +467 -0
  316. pidsmaker/vizgen/exporter.py +493 -0
  317. pidsmaker/vizgen/html_builder.py +936 -0
  318. pidsmaker/vizgen/web/__init__.py +1 -0
  319. pidsmaker/vizgen/web/export.py +62 -0
  320. pidsmaker/vizgen/web/static/css/app.css +250 -0
  321. pidsmaker/vizgen/web/static/index.html +182 -0
  322. pidsmaker/vizgen/web/static/js/app.js +627 -0
  323. pidsmaker/vizgen/web/static/js/campaign.js +123 -0
  324. pidsmaker/vizgen/web/static/js/data.js +119 -0
  325. pidsmaker/vizgen/web/static/js/dialogs.js +240 -0
  326. pidsmaker/vizgen/web/static/js/jobs.js +75 -0
  327. pidsmaker/vizgen/web/static/js/scene.js +651 -0
  328. pidsmaker/vizgen/web/static/js/ui.js +370 -0
  329. pidsmaker/vizgen/web/static/vendor/OrbitControls.js +1045 -0
  330. pidsmaker/vizgen/web/static/vendor/d3.v4.min.js +2 -0
  331. pidsmaker/vizgen/web/static/vendor/three.min.js +6 -0
  332. pidsmaker/vizgen/web/viz_server.py +2176 -0
  333. pidsmaker-4.0.0.dist-info/METADATA +596 -0
  334. pidsmaker-4.0.0.dist-info/RECORD +338 -0
  335. pidsmaker-4.0.0.dist-info/WHEEL +5 -0
  336. pidsmaker-4.0.0.dist-info/entry_points.txt +2 -0
  337. pidsmaker-4.0.0.dist-info/licenses/LICENSE +201 -0
  338. pidsmaker-4.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,476 @@
1
+ """
2
+ Functional class labeling for provenance graph entities.
3
+
4
+ Maps every entity (process, file, socket) to a coarse functional class that
5
+ captures *what it is* independent of the specific binary/path/port. Two
6
+ nginx workers, Apache, and Caddy all get class "webserver". This is used
7
+ by behavior_signatures.py to build behavior signature labels of the form
8
+ (direction, event_type, neighbor_entity_type, neighbor_class).
9
+
10
+ Design:
11
+ - PROC classes: reuse canonical_tokens.PROC_CATEGORIES but strip the
12
+ bracket/prefix notation → plain lowercase strings.
13
+ - FILE classes: reuse canonical_tokens.FILE_DIR_CATEGORIES similarly,
14
+ plus extension-based fallback.
15
+ - SOCK classes: well-known port → named class, else range bucket.
16
+
17
+ All functions accept a raw label string (as stored in indexid2msg) and
18
+ return a plain string class name, or "unknown" if nothing matches.
19
+ """
20
+
21
+ import functools
22
+
23
+ import os
24
+ import re
25
+ from typing import Optional
26
+
27
+ from .canonical_tokens import (
28
+ PROC_CATEGORIES,
29
+ FILE_DIR_CATEGORIES,
30
+ _FILE_DIR_SORTED,
31
+ match_proc_category,
32
+ )
33
+ from .tokenizer_bpe import (
34
+ WELL_KNOWN_PORTS,
35
+ RE_IP,
36
+ RE_IPV6,
37
+ )
38
+
39
+
40
+ # ═══════════════════════════════════════════════════════════════════════════
41
+ # PROC CLASSES
42
+ # ═══════════════════════════════════════════════════════════════════════════
43
+ # Convert [CAT_WEBSERVER] → "webserver", [CAT_DB_CLIENT] → "db_client", etc.
44
+
45
+ # Merge classes that have the same behavioral profile.
46
+ # Applied after stripping the CAT_/FCAT_ prefix.
47
+ _CLASS_MERGE = {
48
+ # ── Port merges (reduce singleton socket classes) ─────────────────
49
+ "port_imap": "port_mail", # IMAP/SMTP/POP3 all serve mail
50
+ "port_imaps": "port_mail",
51
+ "port_smtp": "port_mail",
52
+ "port_pop3": "port_mail",
53
+ "port_ldaps": "port_ldap", # LDAP + LDAPS
54
+ "port_ftp_data": "port_ftp", # FTP control + data
55
+ "port_rdp": "port_ssh", # Remote access protocols
56
+ "port_telnet": "port_ssh",
57
+ "port_dhcp_c": "port_dhcp", # DHCP client + server
58
+ "port_mssql": "port_database", # Database protocols
59
+ "port_oracle": "port_database",
60
+ "port_syslog": "port_low", # Fold rare low-port services into port_low
61
+ "port_ntp": "port_low",
62
+ "unix_socket": "port_low",
63
+ "port_rpc": "port_low", # Windows RPC — confused with netbios, fold into port_low
64
+ "port_http_alt": "port_http", # 8080 → http
65
+ "port_https_alt": "port_https", # 8443 → https
66
+
67
+ # ── Fallback merges (from path/extension classifiers, not canonical_tokens) ──
68
+ "binary": "executable", # from _PROC_BIN_DIRS path fallback
69
+ "desktop": "executable", # from _PROC_BASENAME_CLASSES
70
+ "script": "executable", # from _FILE_EXT_CLASSES (.sh, .bat, .ps1)
71
+ "socket_file": "tmp", # from _FILE_EXT_CLASSES (.sock)
72
+ "package": "archive", # from _FILE_EXT_CLASSES (.deb, .rpm)
73
+ }
74
+
75
+
76
+ def _cat_token_to_class(token: str) -> str:
77
+ """Convert a canonical category token to a plain class name."""
78
+ # [CAT_WEBSERVER] → webserver, [FCAT_LOG_WEB] → log_web
79
+ s = token.strip("[]")
80
+ if s.startswith("CAT_"):
81
+ cls = s[4:].lower()
82
+ elif s.startswith("FCAT_"):
83
+ cls = s[5:].lower()
84
+ else:
85
+ cls = s.lower()
86
+ return _CLASS_MERGE.get(cls, cls)
87
+
88
+
89
+ # Pre-compute the set of unique PROC class names
90
+ _PROC_CLASS_SET = {_cat_token_to_class(v) for v in PROC_CATEGORIES.values()}
91
+
92
+ # Pre-compute the set of unique FILE class names
93
+ _FILE_CLASS_SET = {_cat_token_to_class(v) for v in FILE_DIR_CATEGORIES.values()}
94
+
95
+
96
+ # Known binary directories — if a process path starts with one of these
97
+ # and the basename isn't in PROC_CATEGORIES, classify as "binary".
98
+ _PROC_BIN_DIRS = (
99
+ "/usr/bin/", "/usr/sbin/", "/usr/local/bin/", "/usr/local/sbin/",
100
+ "/bin/", "/sbin/",
101
+ "/system/bin/", # Android
102
+ "/system/xbin/", # Android
103
+ "/vendor/bin/", # Android
104
+ )
105
+
106
+ # Bare command names that map to a SPECIFIC class (not just "binary").
107
+ # Commands not listed here will fall through to the generic "binary" catch-all.
108
+ # Only add entries here when the class is semantically meaningful and different
109
+ # from "binary" — don't enumerate every Unix command.
110
+ _PROC_BASENAME_CLASSES = {
111
+ # Browsers (not in PROC_CATEGORIES)
112
+ "firefox": "browser", "chromium-browse": "browser",
113
+ "chromium-browser": "browser", "chrome": "browser",
114
+ "chrome_crashpad": "browser", "geckodriver": "browser",
115
+ # Mail subsystems (postfix internals not in PROC_CATEGORIES)
116
+ "trivial-rewrite": "mail", "anvil": "mail",
117
+ # Terminal multiplexers (behaviorally like shells)
118
+ "screen": "shell", "tmux": "shell",
119
+ # Desktop apps
120
+ "telepathy-indicator": "desktop", "unity-2d-panel": "desktop",
121
+ }
122
+
123
+
124
+ def _extract_proc_basename(label_str: str) -> str:
125
+ """Extract the binary basename from a process label.
126
+
127
+ Handles paths (/usr/bin/foo → foo), .exe suffix (cmd.exe → cmd),
128
+ quoted paths with spaces ("C:/Program Files/foo.exe" → foo),
129
+ and the "subject" type prefix.
130
+ """
131
+ s = label_str
132
+ # Strip "subject" prefix
133
+ if s.startswith("subject "):
134
+ s = s[8:]
135
+
136
+ # Handle quoted paths (e.g. "//?/C:/Program Files (x86)/Firefox/firefox.exe" -args)
137
+ s = s.strip()
138
+ if s.startswith('"'):
139
+ end_quote = s.find('"', 1)
140
+ if end_quote > 0:
141
+ first = s[1:end_quote]
142
+ else:
143
+ first = s[1:]
144
+ else:
145
+ first = s.split()[0] if s else ""
146
+
147
+ first = first.replace("\\", "/")
148
+ # Strip Windows device path prefix //?/
149
+ if first.startswith("//?/"):
150
+ first = first[4:]
151
+ if "/" in first:
152
+ first = first.rsplit("/", 1)[-1]
153
+ if first.lower().endswith(".exe"):
154
+ first = first[:-4]
155
+ return first
156
+
157
+
158
+ def classify_proc(label_str: str) -> str:
159
+ """Classify a process entity by its command line / binary name.
160
+
161
+ Priority:
162
+ 1. canonical_tokens.PROC_CATEGORIES (functional roles like webserver, shell)
163
+ 2. _PROC_BASENAME_CLASSES (coreutils, sysadmin tools, browsers, etc.)
164
+ 3. Path-based fallback (known bin directories → "binary")
165
+ 4. Pattern-based fallback (Windows .exe, Android packages, apt-*/dpkg-*)
166
+
167
+ Returns a plain class name or "unknown" if no match.
168
+ """
169
+ cat_token = match_proc_category(label_str)
170
+ if cat_token is not None:
171
+ return _cat_token_to_class(cat_token)
172
+
173
+ # Basename lookup for common commands not in canonical_tokens
174
+ basename = _extract_proc_basename(label_str)
175
+ if basename in _PROC_BASENAME_CLASSES:
176
+ return _PROC_BASENAME_CLASSES[basename]
177
+
178
+ # Prefix-based matching
179
+ if basename.startswith(("apt-", "dpkg-")):
180
+ return "pkgmgr"
181
+
182
+ # Truncated daemon names: "sshd:" → ssh, "systemd-journal" → init
183
+ # Strip trailing ":" and check known prefixes against PROC_CATEGORIES
184
+ basename_clean = basename.rstrip(":")
185
+ if basename_clean in PROC_CATEGORIES:
186
+ return _cat_token_to_class(PROC_CATEGORIES[basename_clean])
187
+ # systemd-* variants (systemd-journald, systemd-networkd, systemd-resolved, etc.)
188
+ if basename.startswith("systemd-") or basename.startswith("systemd:"):
189
+ return "init"
190
+ # Android system:* processes
191
+ if basename.startswith("system:"):
192
+ return "android_sys"
193
+
194
+ # Versioned interpreters: python2.7, python3.6, perl5.30, ruby2.7, etc.
195
+ # PROC_CATEGORIES has "python", "python3", "perl", "ruby" but not versioned variants.
196
+ import re as _re
197
+ if _re.match(r'^(python|perl|ruby|php|lua|node)\d', basename):
198
+ base = _re.match(r'^(python|perl|ruby|php|lua|node)', basename).group(1)
199
+ if base in PROC_CATEGORIES:
200
+ return _cat_token_to_class(PROC_CATEGORIES[base])
201
+
202
+ # Path-based fallback: processes from known binary directories
203
+ parts = label_str.split()
204
+ if parts and parts[0] == "subject":
205
+ parts = parts[1:]
206
+ if parts:
207
+ first = parts[0].strip('"').replace("\\", "/")
208
+ for bin_dir in _PROC_BIN_DIRS:
209
+ if first.startswith(bin_dir):
210
+ return "binary"
211
+
212
+ # Windows .exe processes
213
+ if ".exe" in label_str.lower():
214
+ return "win_system"
215
+
216
+ # Android package-style processes (com.android.*, android.*)
217
+ if basename.startswith(("android.", "com.android.", "com.google.")):
218
+ return "android_sys"
219
+
220
+ # Firefox/chromium snap processes
221
+ if "firefox" in basename.lower() or "chromium" in basename.lower():
222
+ return "browser"
223
+
224
+ # Any bare alphabetic command name is a binary that was executed.
225
+ # Excludes flag-style args (-c, +%s), numbers, and garbage labels.
226
+ if basename and basename[0].isalpha() and all(c.isalnum() or c in "-_." for c in basename):
227
+ return "binary"
228
+
229
+ return "unknown"
230
+
231
+
232
+ # ═══════════════════════════════════════════════════════════════════════════
233
+ # FILE CLASSES
234
+ # ═══════════════════════════════════════════════════════════════════════════
235
+
236
+ # Extensions that identify file content type, used as fallback when no
237
+ # path-prefix rule matches. Path context wins for most files (a .tmp in
238
+ # browser data is browser_data, not tmp), but these catch files in
239
+ # unrecognized directories.
240
+ _FILE_EXT_CLASSES = {
241
+ # Source code
242
+ ".c": "source", ".h": "source", ".cpp": "source", ".hpp": "source",
243
+ ".cc": "source", ".py": "source", ".js": "source", ".ts": "source",
244
+ ".rs": "source", ".go": "source", ".java": "source", ".rb": "source",
245
+ ".pl": "source", ".m": "source", ".swift": "source",
246
+ ".sh": "script", ".bash": "script", ".bat": "script", ".ps1": "script",
247
+ ".cmd": "script", ".vbs": "script", ".wsf": "script",
248
+ # Web
249
+ ".html": "source", ".htm": "source", ".css": "source",
250
+ ".xhtml": "source", ".xul": "source", ".jsx": "source", ".tsx": "source",
251
+ ".php": "source", ".asp": "source", ".aspx": "source", ".jsp": "source",
252
+ # Compiled / bytecode
253
+ ".o": "object", ".obj": "object", ".a": "library", ".so": "library",
254
+ ".dylib": "library", ".dll": "library", ".class": "bytecode",
255
+ ".pyc": "bytecode", ".pyo": "bytecode",
256
+ # Binaries / executables
257
+ ".exe": "binary", ".msi": "binary", ".apk": "binary",
258
+ ".bin": "binary", ".elf": "binary",
259
+ # Config
260
+ ".conf": "config", ".cfg": "config", ".ini": "config",
261
+ ".yaml": "config", ".yml": "config", ".toml": "config",
262
+ ".properties": "config", ".reg": "config",
263
+ # Data
264
+ ".json": "data", ".xml": "data", ".csv": "data", ".tsv": "data",
265
+ ".sql": "data", ".dat": "data", ".plist": "data",
266
+ ".db": "database_file", ".sqlite": "database_file",
267
+ # Logs
268
+ ".log": "log", ".evtx": "log", ".etl": "log",
269
+ # Archives
270
+ ".tar": "archive", ".gz": "archive", ".zip": "archive",
271
+ ".bz2": "archive", ".xz": "archive", ".7z": "archive",
272
+ ".rar": "archive", ".cab": "archive",
273
+ ".deb": "package", ".rpm": "package",
274
+ # Security
275
+ ".pem": "certificate", ".key": "key_file", ".crt": "certificate",
276
+ ".cert": "certificate", ".pub": "pubkey",
277
+ # Media
278
+ ".png": "media", ".jpg": "media", ".jpeg": "media",
279
+ ".gif": "media", ".svg": "media", ".ico": "media", ".bmp": "media",
280
+ ".mp4": "media", ".mp3": "media", ".wav": "media", ".webm": "media",
281
+ ".ttf": "media", ".otf": "media", ".woff": "media", ".woff2": "media",
282
+ # Documents
283
+ ".pdf": "document", ".doc": "document", ".docx": "document",
284
+ ".xls": "document", ".xlsx": "document",
285
+ ".ppt": "document", ".pptx": "document", ".rtf": "document",
286
+ ".odt": "document", ".ods": "document", ".odp": "document",
287
+ ".txt": "document", ".md": "document", ".rst": "document",
288
+ # Windows-specific
289
+ ".mui": "library", ".sys": "library", ".drv": "library",
290
+ ".ocx": "library", ".cpl": "library",
291
+ ".lnk": "data", ".pf": "data", ".manifest": "config",
292
+ # Runtime
293
+ ".sock": "socket_file", ".pid": "runtime", ".lock": "runtime",
294
+ ".tmp": "tmp",
295
+ }
296
+
297
+
298
+ def classify_file(label_str: str) -> str:
299
+ """Classify a file entity by its path.
300
+
301
+ Extension first — a .docx is a document whether it's in /home/, /tmp/,
302
+ or /var/www/. Path only matters for extensionless files and dotfiles.
303
+
304
+ Returns a plain class name or "unknown".
305
+ """
306
+ parts = label_str.split()
307
+ if parts and parts[0] == "file":
308
+ parts = parts[1:]
309
+ if not parts:
310
+ return "unknown"
311
+
312
+ path = parts[0].replace("\\", "/")
313
+
314
+ # Extension always wins (defines what the file IS)
315
+ _, ext = os.path.splitext(path)
316
+ ext_lower = ext.lower()
317
+ if ext_lower in _FILE_EXT_CLASSES:
318
+ return _FILE_EXT_CLASSES[ext_lower]
319
+
320
+ # Path-prefix fallback for extensionless files and dotfiles.
321
+ # Find ALL matching patterns, pick the most specific:
322
+ # 1. Longest pattern wins (more specific path context)
323
+ # 2. At equal length, the one appearing DEEPER in the path wins
324
+ # e.g. for "/home/user/.git/refs", "/home/" matches at pos 0
325
+ # but "/.git/" matches at pos 37 — the deeper match is more specific.
326
+ best_match = None
327
+ best_len = -1
328
+ best_pos = -1
329
+ for pattern, category in _FILE_DIR_SORTED:
330
+ if pattern in path:
331
+ plen = len(pattern)
332
+ pos = path.rfind(pattern)
333
+ if plen > best_len or (plen == best_len and pos > best_pos):
334
+ best_match = category
335
+ best_len = plen
336
+ best_pos = pos
337
+ if best_match is not None:
338
+ return _cat_token_to_class(best_match)
339
+
340
+ return "unknown"
341
+
342
+
343
+ # ═══════════════════════════════════════════════════════════════════════════
344
+ # SOCK CLASSES
345
+ # ═══════════════════════════════════════════════════════════════════════════
346
+
347
+ # Map well-known port tokens to plain class names
348
+ # [PORT_SSH] → "port_ssh", [PORT_HTTP] → "port_http", etc.
349
+ _SOCK_PORT_CLASSES = {
350
+ port: token.strip("[]").lower()
351
+ for port, token in WELL_KNOWN_PORTS.items()
352
+ }
353
+
354
+ # Additional well-known ports not in tokenizer
355
+ _SOCK_PORT_CLASSES.update({
356
+ 123: "port_ntp",
357
+ 135: "port_rpc",
358
+ 137: "port_netbios", 138: "port_netbios", 139: "port_netbios",
359
+ 389: "port_ldap", 636: "port_ldaps",
360
+ 514: "port_syslog",
361
+ 1433: "port_mssql", 1521: "port_oracle",
362
+ 3389: "port_rdp",
363
+ 5985: "port_winrm", 5986: "port_winrm",
364
+ 6379: "port_redis",
365
+ 9200: "port_elasticsearch",
366
+ 27017: "port_mongodb",
367
+ })
368
+
369
+
370
+ def classify_sock(label_str: str) -> str:
371
+ """Classify a socket entity by its IP/port tuple.
372
+
373
+ Parses the label for port numbers and classifies by well-known port.
374
+ Falls back to range buckets: port_low (1-1023), port_reg (1024-49151),
375
+ port_eph (49152-65535).
376
+
377
+ Returns a plain class name or "unknown".
378
+ """
379
+ parts = label_str.split()
380
+ if parts and parts[0] == "netflow":
381
+ parts = parts[1:]
382
+
383
+ # Collect all port-like integers
384
+ ports = []
385
+ for token in parts:
386
+ # Handle IP:port format
387
+ if ":" in token and not token.startswith("0000:"):
388
+ for sub in token.split(":"):
389
+ try:
390
+ p = int(sub)
391
+ if 1 <= p <= 65535:
392
+ ports.append(p)
393
+ except ValueError:
394
+ pass
395
+ elif "->" in token:
396
+ for endpoint in token.split("->"):
397
+ for sub in endpoint.rsplit(":", 1):
398
+ try:
399
+ p = int(sub)
400
+ if 1 <= p <= 65535:
401
+ ports.append(p)
402
+ except ValueError:
403
+ pass
404
+ else:
405
+ try:
406
+ p = int(token)
407
+ if 1 <= p <= 65535:
408
+ ports.append(p)
409
+ except ValueError:
410
+ pass
411
+
412
+ # Classify by the well-known port (the service side).
413
+ # In a socket like "10.0.0.1 58425 192.168.1.1 80", port 80 is the
414
+ # service — port 58425 is ephemeral. If multiple well-known ports
415
+ # exist (shouldn't happen), pick the lowest (most specific service).
416
+ known = sorted([p for p in ports if p in _SOCK_PORT_CLASSES])
417
+ if known:
418
+ return _SOCK_PORT_CLASSES[known[0]]
419
+
420
+ # Range buckets based on the lowest port (most likely the service side)
421
+ if ports:
422
+ min_port = min(ports)
423
+ if min_port <= 1023:
424
+ return "port_low"
425
+ elif min_port <= 49151:
426
+ return "port_reg"
427
+ else:
428
+ return "port_eph"
429
+
430
+ # Unix domain socket or unrecognizable
431
+ if any("/" in t for t in parts):
432
+ return "unix_socket"
433
+
434
+ return "unknown"
435
+
436
+
437
+ # ═══════════════════════════════════════════════════════════════════════════
438
+ # UNIFIED INTERFACE
439
+ # ═══════════════════════════════════════════════════════════════════════════
440
+
441
+ @functools.lru_cache(maxsize=None)
442
+ def classify_entity(node_type: str, label_str: str) -> str:
443
+ """Classify any entity by its type and label.
444
+
445
+ Args:
446
+ node_type: "subject", "file", or "netflow"
447
+ label_str: the raw label string from indexid2msg
448
+
449
+ Returns:
450
+ A plain string class name (e.g. "webserver", "log_system", "port_ssh").
451
+ """
452
+ if node_type == "subject":
453
+ cls = classify_proc(label_str)
454
+ elif node_type == "file":
455
+ cls = classify_file(label_str)
456
+ elif node_type == "netflow":
457
+ cls = classify_sock(label_str)
458
+ else:
459
+ cls = "unknown"
460
+ return _CLASS_MERGE.get(cls, cls)
461
+
462
+
463
+ def get_all_entity_classes():
464
+ """Return the complete set of known entity class names.
465
+
466
+ Used to build the behavior signature label vocabulary.
467
+ """
468
+ classes = set()
469
+ classes.update(_PROC_CLASS_SET)
470
+ classes.update(_FILE_CLASS_SET)
471
+ classes.update({_cat_token_to_class(f"[{v.strip('[]')}]") for v in _SOCK_PORT_CLASSES.values()})
472
+ # Extension-based file classes
473
+ classes.update(set(_FILE_EXT_CLASSES.values()))
474
+ # Range buckets + special
475
+ classes.update({"port_low", "port_reg", "port_eph", "unix_socket", "unknown"})
476
+ return sorted(classes)