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,1032 @@
1
+ """Dataset schemas: the entities, events and attributes of each family of datasets.
2
+
3
+ A schema describes what a dataset contains, independently of its domain (host provenance,
4
+ network authentication logs, network flows, ...):
5
+
6
+ - its node types: the database table of each type and the attributes read from it,
7
+ which are used to build node labels (`construction.node_label_features`);
8
+ - its edge type vocabulary (`rel2id`), i.e. the categorical attribute of events stored in
9
+ the `operation` column of the event table, along with the (source type, destination type)
10
+ pairs where each edge type can appear (`possible_events`).
11
+
12
+ Each dataset of `DATASET_DEFAULT_CONFIG` refers to a schema by name (its `schema` key), and
13
+ the pipeline reads the database, builds the graphs and sizes the models from the schema,
14
+ instead of assuming the node and edge types of a particular dataset.
15
+
16
+ This module must not import torch nor other parts of the framework: it is imported by the
17
+ configuration.
18
+ """
19
+
20
+ from dataclasses import dataclass, field, replace
21
+ from functools import lru_cache
22
+
23
+ # Attribute values considered as null when building node labels
24
+ NULL_VALUES = frozenset({"None", "NA", "0", "none", "null", ""})
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class NodeTypeSchema:
29
+ """A type of node, stored in its own database table.
30
+
31
+ Attributes:
32
+ name: name of the type, also used as key in `construction.node_label_features`.
33
+ id: 1-based id of the type, used in one-hot encodings of node types.
34
+ table: database table of the nodes of this type. All tables have the columns
35
+ `node_uuid`, `hash_id` and `index_id`, plus the attribute columns.
36
+ columns: (attribute, database column) pairs of the attributes of the nodes.
37
+ auto_label: attributes used by `node_label_features=auto`. The label is the first
38
+ non-null attribute of the list; if it is not the first one of the list, it is
39
+ prefixed by `null_token` (with `construction.null_label_tokens`). When empty,
40
+ all non-null attributes are concatenated in alphabetical order.
41
+ null_token: token of a node without attribute (with `construction.null_label_tokens`).
42
+ display: format of the path of a node shown in evaluation outputs, from its attributes.
43
+ display_extra: (key, attribute) pairs of raw attributes added to evaluation outputs.
44
+ label_format: how labels are tokenized: `path` (file system paths, split on '/'),
45
+ `address` (IPs and ports, split on '.' and ':') or `name` (identifiers).
46
+ """
47
+
48
+ name: str
49
+ id: int
50
+ table: str
51
+ columns: tuple
52
+ auto_label: tuple = ()
53
+ null_token: str = None
54
+ display: str = None
55
+ display_extra: tuple = ()
56
+ label_format: str = "name"
57
+
58
+ @property
59
+ def attributes(self):
60
+ return [attr for attr, _ in self.columns]
61
+
62
+ def label_choices(self):
63
+ """Values accepted by `construction.node_label_features.<type>`."""
64
+ return ["auto", "type"] + self.attributes
65
+
66
+ def auto_label_str(self, attrs, null_label_tokens):
67
+ """Label of a node with `node_label_features=auto`, from its (cleaned) attributes."""
68
+ if self.auto_label:
69
+ for i, attr in enumerate(self.auto_label):
70
+ value = attrs.get(attr, "")
71
+ if value not in NULL_VALUES:
72
+ if i > 0 and null_label_tokens and self.null_token:
73
+ return f"{self.null_token} {value}"
74
+ return value
75
+ return self.null_token if (null_label_tokens and self.null_token) else ""
76
+
77
+ label = " ".join(
78
+ attrs[key] for key in sorted(attrs) if key != "type" and attrs[key] not in NULL_VALUES
79
+ )
80
+ if not label and null_label_tokens and self.null_token:
81
+ return self.null_token
82
+ return label
83
+
84
+ def display_path(self, raw_attrs):
85
+ """Path shown for a node in evaluation outputs, from its raw database attributes."""
86
+ fmt = self.display or "{" + self.attributes[0] + "}"
87
+ return fmt.format(**{k: str(v) for k, v in raw_attrs.items()})
88
+
89
+
90
+ @dataclass(frozen=True)
91
+ class EdgeAttributeSchema:
92
+ """An attribute of events, stored in a column of the event table.
93
+
94
+ Attributes:
95
+ name: name of the attribute, used in configs and as edge attribute of the graphs.
96
+ column: column of the event table.
97
+ kind: `categorical` (string values from `vocab`) or `numeric` (float values).
98
+ vocab: values of a categorical attribute. Other values are mapped to `OTHER`.
99
+ """
100
+
101
+ name: str
102
+ column: str
103
+ kind: str
104
+ vocab: tuple = ()
105
+
106
+ OTHER = "OTHER"
107
+
108
+ def __post_init__(self):
109
+ if self.kind not in ("categorical", "numeric"):
110
+ raise ValueError(f"Invalid kind {self.kind} of edge attribute {self.name}")
111
+ if self.kind == "categorical" and not self.vocab:
112
+ raise ValueError(f"Categorical edge attribute {self.name} needs a vocabulary")
113
+
114
+ @property
115
+ def values(self):
116
+ """Values of a categorical attribute, including `OTHER`."""
117
+ return list(self.vocab) + ([] if self.OTHER in self.vocab else [self.OTHER])
118
+
119
+ @property
120
+ def rel2id(self):
121
+ """Bidirectional {value: id, id: value} vocabulary, with ids starting at 1."""
122
+ mapping = {}
123
+ for i, value in enumerate(self.values):
124
+ mapping[i + 1] = value
125
+ mapping[value] = i + 1
126
+ return mapping
127
+
128
+ def encode(self, value):
129
+ """Value stored in the graphs, from the database value."""
130
+ if self.kind == "numeric":
131
+ try:
132
+ return float(value)
133
+ except (TypeError, ValueError):
134
+ return float("nan")
135
+ value = str(value)
136
+ return value if value in self.vocab else self.OTHER
137
+
138
+
139
+ @dataclass(frozen=True)
140
+ class DatasetSchema:
141
+ """Description of the content of a family of datasets.
142
+
143
+ Attributes:
144
+ name: name of the schema, referenced by the `schema` key of datasets.
145
+ node_types: node types, in the order in which their tables are read.
146
+ rel2id: vocabulary of edge types of the graphs, as a bidirectional mapping
147
+ {type: id, id: type} with ids starting at 1.
148
+ possible_events: {(source type, destination type): [edge types]} of the
149
+ (source, edge, destination) triplets that exist in the dataset.
150
+ raw_rel2id: vocabulary of the `operation` column in the database, used to filter
151
+ events, when it differs from `rel2id` (i.e. when edge types are translated).
152
+ edge_type_translation: {(source type, raw edge type, destination type): edge type}
153
+ translation applied to events when building the graphs. Untranslated edge types
154
+ are kept as is.
155
+ supports_edge_type_triplets: whether `edge_type_triplet` edge features are available.
156
+ supports_hetero: whether heterogeneous encoders are available.
157
+ event_table: database table of events (edges).
158
+ edge_attributes: attributes of events besides their type, stored as edge attributes
159
+ in the graphs and usable as edge features (`batching.edge_features=edge_attrs`).
160
+ edge_type_attribute: name of the categorical edge attribute used as edge type, or
161
+ None for the `operation` column (see `construction.edge_type`).
162
+ label_column: column of the event table with the label of events (1: malicious),
163
+ used as ground truth instead of node-level ground truth files. None if absent.
164
+ operations: values of the `operation` column of the events kept when building graphs
165
+ (None: all the edge types of the schema). The schema's value is the default, which
166
+ `construction.operations` overrides (e.g. OpTC flows keep FLOW_START events by
167
+ default, as LARES and Argus).
168
+ noise_events_sql: SQL condition matching the events dropped with
169
+ `construction.drop_noise_events` (e.g. broadcast and multicast flows), or None.
170
+ drop_noise: whether the events of `noise_events_sql` are dropped.
171
+ """
172
+
173
+ name: str
174
+ node_types: tuple
175
+ rel2id: dict
176
+ possible_events: dict
177
+ raw_rel2id: dict = None
178
+ edge_type_translation: dict = None
179
+ supports_edge_type_triplets: bool = True
180
+ supports_hetero: bool = True
181
+ event_table: str = "event_table"
182
+ edge_attributes: tuple = ()
183
+ edge_type_attribute: str = None
184
+ label_column: str = None
185
+ operations: tuple = None
186
+ noise_events_sql: str = None
187
+ drop_noise: bool = False
188
+ _by_name: dict = field(default=None, repr=False, compare=False)
189
+
190
+ def __post_init__(self):
191
+ ids = sorted(nt.id for nt in self.node_types)
192
+ if ids != list(range(1, len(ids) + 1)):
193
+ raise ValueError(f"Node type ids of schema {self.name} must be 1..N, found {ids}")
194
+ object.__setattr__(self, "_by_name", {nt.name: nt for nt in self.node_types})
195
+
196
+ @property
197
+ def node_type_names(self):
198
+ """Names of the node types, in id order."""
199
+ return [nt.name for nt in sorted(self.node_types, key=lambda nt: nt.id)]
200
+
201
+ @property
202
+ def num_node_types(self):
203
+ return len(self.node_types)
204
+
205
+ @property
206
+ def num_edge_types(self):
207
+ return max(v for v in self.rel2id.values() if isinstance(v, int))
208
+
209
+ @property
210
+ def ntype2id(self):
211
+ """Bidirectional mapping {type: id, id: type} with ids starting at 1."""
212
+ mapping = {}
213
+ for nt in sorted(self.node_types, key=lambda nt: nt.id):
214
+ mapping[nt.id] = nt.name
215
+ mapping[nt.name] = nt.id
216
+ return mapping
217
+
218
+ @property
219
+ def raw_edge_types(self):
220
+ """Values of the `operation` column of the database."""
221
+ rel2id = self.raw_rel2id if self.raw_rel2id is not None else self.rel2id
222
+ return [k for k in rel2id if isinstance(k, str)]
223
+
224
+ @property
225
+ def event_filter_rel2id(self):
226
+ """Edge types of the database kept when building graphs."""
227
+ rel2id = self.raw_rel2id if self.raw_rel2id is not None else self.rel2id
228
+ if self.operations is None:
229
+ return rel2id
230
+ return {k: v for k, v in rel2id.items() if k in self.operations or v in self.operations}
231
+
232
+ def operations_sql(self):
233
+ """SQL condition (starting with ` AND`) selecting the events of `operations` (without
234
+ the noise events with `drop_noise`), or ""."""
235
+ sql = ""
236
+ if self.operations is not None:
237
+ values = ", ".join("'" + op.replace("'", "''") + "'" for op in self.operations)
238
+ sql = f" AND operation IN ({values})"
239
+ if self.drop_noise and self.noise_events_sql:
240
+ sql += f" AND NOT ({self.noise_events_sql})"
241
+ return sql
242
+
243
+ def with_noise_dropped(self, drop):
244
+ """The schema dropping its noise events (`construction.drop_noise_events`), if it has any."""
245
+ if not drop or not self.noise_events_sql:
246
+ return self
247
+ return replace(self, drop_noise=True)
248
+
249
+ def with_operations(self, operations):
250
+ """The schema keeping the events of the given operations (`construction.operations`):
251
+ `default` keeps the schema's default, `all` all events, otherwise a comma-separated
252
+ list of values of the `operation` column."""
253
+ if operations in (None, "default"):
254
+ return self
255
+ if operations == "all":
256
+ return replace(self, operations=None)
257
+ ops = tuple(op.strip() for op in operations.split(",") if op.strip())
258
+ unknown = [op for op in ops if op not in self.raw_edge_types]
259
+ if unknown or not ops:
260
+ raise ValueError(
261
+ f"Invalid construction.operations={operations} for schema {self.name}: "
262
+ f"expected `default`, `all` or a comma-separated list of {self.raw_edge_types}"
263
+ )
264
+ return replace(self, operations=ops)
265
+
266
+ def node_type(self, name):
267
+ return self._by_name[name]
268
+
269
+ def translate_edge_type(self, label, src_type, dst_type):
270
+ if not self.edge_type_translation:
271
+ return label
272
+ return self.edge_type_translation.get((src_type, label, dst_type), label)
273
+
274
+ def edge_attribute(self, name):
275
+ for attr in self.edge_attributes:
276
+ if attr.name == name:
277
+ return attr
278
+ raise ValueError(
279
+ f"Unknown edge attribute {name} in schema {self.name}. "
280
+ f"Available attributes: {[a.name for a in self.edge_attributes]}"
281
+ )
282
+
283
+ @property
284
+ def edge_type_choices(self):
285
+ """Values accepted by `construction.edge_type`."""
286
+ return ["operation"] + [a.name for a in self.edge_attributes if a.kind == "categorical"]
287
+
288
+ def with_edge_type(self, attribute):
289
+ """The schema whose edge types are the values of a categorical edge attribute.
290
+
291
+ Events are still filtered by their `operation`, but graphs and models use the values of
292
+ the attribute as edge types. With `operation`, the schema is returned unchanged.
293
+ """
294
+ if attribute in (None, "operation"):
295
+ return self
296
+ attr = self.edge_attribute(attribute)
297
+ if attr.kind != "categorical":
298
+ raise ValueError(f"Edge attribute {attribute} is not categorical: it can't be an edge type")
299
+ return replace(
300
+ self,
301
+ rel2id=attr.rel2id,
302
+ possible_events={pair: list(attr.values) for pair in self.possible_events},
303
+ raw_rel2id=self.event_filter_rel2id,
304
+ edge_type_translation=None,
305
+ edge_type_attribute=attribute,
306
+ )
307
+
308
+
309
+ # --------------------------------------------------------------------------------------
310
+ # Vocabularies
311
+ # --------------------------------------------------------------------------------------
312
+
313
+ # The directions of the following edge types need to be reversed
314
+ edge_reversed = [
315
+ "EVENT_EXECUTE",
316
+ "EVENT_LSEEK",
317
+ "EVENT_MMAP",
318
+ "EVENT_OPEN",
319
+ "EVENT_ACCEPT",
320
+ "EVENT_READ",
321
+ "EVENT_RECVFROM",
322
+ "EVENT_RECVMSG",
323
+ "EVENT_READ_SOCKET_PARAMS",
324
+ "EVENT_CHECK_FILE_ATTRIBUTES",
325
+ "READ",
326
+ ]
327
+
328
+ # The following edges are not considered to construct the
329
+ # temporal graph for experiments.
330
+ exclude_edge_type = set(
331
+ [
332
+ "EVENT_FCNTL", # EVENT_FCNTL does not have any predicate
333
+ "EVENT_OTHER", # EVENT_OTHER does not have any predicate
334
+ "EVENT_ADD_OBJECT_ATTRIBUTE", # This is used to add attributes to an object that was incomplete at the time of publish
335
+ "EVENT_FLOWS_TO", # No corresponding system call event
336
+ ]
337
+ )
338
+
339
+ rel2id_darpa_tc = {
340
+ 1: "EVENT_CONNECT",
341
+ "EVENT_CONNECT": 1,
342
+ 2: "EVENT_EXECUTE",
343
+ "EVENT_EXECUTE": 2,
344
+ 3: "EVENT_OPEN",
345
+ "EVENT_OPEN": 3,
346
+ 4: "EVENT_READ",
347
+ "EVENT_READ": 4,
348
+ 5: "EVENT_RECVFROM",
349
+ "EVENT_RECVFROM": 5,
350
+ 6: "EVENT_RECVMSG",
351
+ "EVENT_RECVMSG": 6,
352
+ 7: "EVENT_SENDMSG",
353
+ "EVENT_SENDMSG": 7,
354
+ 8: "EVENT_SENDTO",
355
+ "EVENT_SENDTO": 8,
356
+ 9: "EVENT_WRITE",
357
+ "EVENT_WRITE": 9,
358
+ 10: "EVENT_CLONE",
359
+ "EVENT_CLONE": 10,
360
+ }
361
+
362
+ possible_events = {
363
+ ("subject", "subject"): [
364
+ "EVENT_READ",
365
+ "EVENT_WRITE",
366
+ "EVENT_OPEN",
367
+ "EVENT_CONNECT",
368
+ "EVENT_RECVFROM",
369
+ "EVENT_SENDTO",
370
+ "EVENT_CLONE",
371
+ "EVENT_SENDMSG",
372
+ "EVENT_RECVMSG",
373
+ ],
374
+ ("subject", "file"): [
375
+ "EVENT_WRITE",
376
+ "EVENT_CONNECT",
377
+ "EVENT_SENDMSG",
378
+ "EVENT_SENDTO",
379
+ "EVENT_CLONE",
380
+ ],
381
+ ("subject", "netflow"): [
382
+ "EVENT_WRITE",
383
+ "EVENT_SENDTO",
384
+ "EVENT_CONNECT",
385
+ "EVENT_SENDMSG",
386
+ ],
387
+ ("file", "subject"): [
388
+ "EVENT_READ",
389
+ "EVENT_OPEN",
390
+ "EVENT_RECVFROM",
391
+ "EVENT_EXECUTE",
392
+ "EVENT_RECVMSG",
393
+ ],
394
+ ("netflow", "subject"): [
395
+ "EVENT_OPEN",
396
+ "EVENT_READ",
397
+ "EVENT_RECVFROM",
398
+ "EVENT_RECVMSG",
399
+ ],
400
+ }
401
+ rel2id_optc = {
402
+ 1: "OPEN",
403
+ "OPEN": 1,
404
+ 2: "READ",
405
+ "READ": 2,
406
+ 3: "CREATE",
407
+ "CREATE": 3,
408
+ 4: "MESSAGE",
409
+ "MESSAGE": 4,
410
+ 5: "MODIFY",
411
+ "MODIFY": 5,
412
+ 6: "START",
413
+ "START": 6,
414
+ 7: "RENAME",
415
+ "RENAME": 7,
416
+ 8: "DELETE",
417
+ "DELETE": 8,
418
+ 9: "TERMINATE",
419
+ "TERMINATE": 9,
420
+ 10: "WRITE",
421
+ "WRITE": 10,
422
+ }
423
+
424
+ # Vocabulary for OpTC graphs built with consistent_edge_types=True.
425
+ # Translated edges use the same IDs as rel2id_darpa_tc (enabling shared weights).
426
+ # Untranslated OpTC-only edges (CREATE/DELETE/RENAME for subject→file,
427
+ # TERMINATE for subject→subject) get new IDs starting at 11.
428
+ rel2id_optc_consistent = {
429
+ # Shared TC types — same IDs as rel2id_darpa_tc
430
+ 1: "EVENT_CONNECT", "EVENT_CONNECT": 1,
431
+ 3: "EVENT_OPEN", "EVENT_OPEN": 3,
432
+ 4: "EVENT_READ", "EVENT_READ": 4,
433
+ 5: "EVENT_RECVFROM", "EVENT_RECVFROM": 5,
434
+ 6: "EVENT_RECVMSG", "EVENT_RECVMSG": 6,
435
+ 7: "EVENT_SENDMSG", "EVENT_SENDMSG": 7,
436
+ 9: "EVENT_WRITE", "EVENT_WRITE": 9,
437
+ 10: "EVENT_CLONE", "EVENT_CLONE": 10,
438
+ # OpTC-specific types that are not translated
439
+ 11: "CREATE", "CREATE": 11,
440
+ 12: "DELETE", "DELETE": 12,
441
+ 13: "RENAME", "RENAME": 13,
442
+ 14: "TERMINATE", "TERMINATE": 14,
443
+ }
444
+ possible_events_optc = {
445
+ ("subject", "subject"): [
446
+ "CREATE",
447
+ "OPEN",
448
+ "TERMINATE",
449
+ ],
450
+ ("subject", "file"): [
451
+ "CREATE",
452
+ "DELETE",
453
+ "MODIFY",
454
+ "RENAME",
455
+ "WRITE",
456
+ ],
457
+ ("subject", "netflow"): [
458
+ "MESSAGE",
459
+ "START",
460
+ ],
461
+ ("file", "subject"): [
462
+ "READ",
463
+ ],
464
+ ("netflow", "subject"): [
465
+ "MESSAGE",
466
+ "OPEN",
467
+ "START",
468
+ ],
469
+ }
470
+
471
+ # Context-dependent mapping from OpTC edge types to DARPA TC edge types.
472
+ # Key: (src_type, optc_label, dst_type) -> tc_label
473
+ # This enables shared vocabulary between OpTC and TC for transfer learning.
474
+ OPTC_TO_TC_EDGE_MAP = {
475
+ # subject -> subject (process lifecycle)
476
+ ("subject", "CREATE", "subject"): "EVENT_CLONE",
477
+ ("subject", "START", "subject"): "EVENT_CLONE",
478
+ ("subject", "OPEN", "subject"): "EVENT_OPEN",
479
+ # subject -> file (file operations)
480
+ ("subject", "MODIFY", "file"): "EVENT_WRITE",
481
+ ("subject", "WRITE", "file"): "EVENT_WRITE",
482
+ # subject -> netflow (outbound network)
483
+ ("subject", "MESSAGE", "netflow"): "EVENT_SENDMSG",
484
+ ("subject", "START", "netflow"): "EVENT_CONNECT",
485
+ # file -> subject (reversed reads)
486
+ ("file", "READ", "subject"): "EVENT_READ",
487
+ # netflow -> subject (reversed inbound network)
488
+ ("netflow", "MESSAGE", "subject"): "EVENT_RECVMSG",
489
+ ("netflow", "OPEN", "subject"): "EVENT_OPEN",
490
+ ("netflow", "START", "subject"): "EVENT_RECVFROM",
491
+ }
492
+
493
+ # possible_events for OpTC when using consistent (TC) edge types
494
+ possible_events_optc_consistent = {
495
+ ("subject", "subject"): [
496
+ "EVENT_CLONE",
497
+ "EVENT_OPEN",
498
+ "TERMINATE",
499
+ ],
500
+ ("subject", "file"): [
501
+ "CREATE",
502
+ "DELETE",
503
+ "RENAME",
504
+ "EVENT_WRITE",
505
+ ],
506
+ ("subject", "netflow"): [
507
+ "EVENT_SENDMSG",
508
+ "EVENT_CONNECT",
509
+ ],
510
+ ("file", "subject"): [
511
+ "EVENT_READ",
512
+ ],
513
+ ("netflow", "subject"): [
514
+ "EVENT_RECVMSG",
515
+ "EVENT_OPEN",
516
+ "EVENT_RECVFROM",
517
+ ],
518
+ }
519
+
520
+ def translate_optc_to_tc(label, src_type, dst_type):
521
+ """Translate an OpTC edge label to its DARPA TC equivalent.
522
+
523
+ Uses (src_type, label, dst_type) context to disambiguate edge types
524
+ that map differently depending on direction (e.g. MESSAGE -> SENDMSG/RECVMSG).
525
+
526
+ Returns the TC label, or the original label if no mapping exists.
527
+ """
528
+ return OPTC_TO_TC_EDGE_MAP.get((src_type, label, dst_type), label)
529
+
530
+ rel2id_atlasv2 = {
531
+ 0: "ACTION_FILE_UNDELETE",
532
+ 1: "ACTION_FILE_OPEN_SET_ATTRIBUTES",
533
+ 2: "ACTION_FILE_CREATE",
534
+ 3: "ACTION_FILE_OPEN_DELETE",
535
+ 4: "ACTION_FILE_OPEN_SET_SECURITY",
536
+ 5: "ACTION_FILE_TRUNCATE",
537
+ 6: "ACTION_FILE_MOD_OPEN",
538
+ 7: "ACTION_FILE_DELETE",
539
+ 8: "ACTION_FILE_LAST_WRITE",
540
+ 9: "ACTION_FILE_OPEN_WRITE",
541
+ 10: "ACTION_FILE_RENAME",
542
+ 11: "ACTION_FILE_OPEN_READ",
543
+ 12: "ACTION_FILE_WRITE",
544
+ 13: "ACTION_OPEN_KEY_DELETE",
545
+ 14: "ACTION_WRITE_VALUE",
546
+ 15: "ACTION_DELETE_VALUE",
547
+ 16: "ACTION_OPEN_KEY_READ",
548
+ 17: "ACTION_DELETE_KEY",
549
+ 18: "ACTION_LOAD_KEY",
550
+ 19: "ACTION_CREATE_KEY",
551
+ 20: "ACTION_OPEN_KEY_WRITE",
552
+ 21: "ACTION_LOAD_MODULE",
553
+ 22: "ACTION_PROCESS_TERMINATE",
554
+ 23: "ACTION_PROCESS_DISCOVERED",
555
+ 24: "ACTION_CREATE_PROCESS",
556
+ 25: "ACTION_CREATE_PROCESS_EFFECTIVE",
557
+ 26: "ACTION_DUP_THREAD_HANDLE",
558
+ 27: "ACTION_DUP_PROCESS_HANDLE",
559
+ 28: "ACTION_OPEN_PROCESS_HANDLE",
560
+ 29: "ACTION_OPEN_THREAD_HANDLE",
561
+ 30: "ACTION_LOAD_SCRIPT",
562
+ 31: "ACTION_CONNECTION_ESTABLISHED",
563
+ 32: "ACTION_CONNECTION_LISTEN",
564
+ 33: "ACTION_CONNECTION_CREATE",
565
+ "ACTION_FILE_UNDELETE": 0,
566
+ "ACTION_FILE_OPEN_SET_ATTRIBUTES": 1,
567
+ "ACTION_FILE_CREATE": 2,
568
+ "ACTION_FILE_OPEN_DELETE": 3,
569
+ "ACTION_FILE_OPEN_SET_SECURITY": 4,
570
+ "ACTION_FILE_TRUNCATE": 5,
571
+ "ACTION_FILE_MOD_OPEN": 6,
572
+ "ACTION_FILE_DELETE": 7,
573
+ "ACTION_FILE_LAST_WRITE": 8,
574
+ "ACTION_FILE_OPEN_WRITE": 9,
575
+ "ACTION_FILE_RENAME": 10,
576
+ "ACTION_FILE_OPEN_READ": 11,
577
+ "ACTION_FILE_WRITE": 12,
578
+ "ACTION_OPEN_KEY_DELETE": 13,
579
+ "ACTION_WRITE_VALUE": 14,
580
+ "ACTION_DELETE_VALUE": 15,
581
+ "ACTION_OPEN_KEY_READ": 16,
582
+ "ACTION_DELETE_KEY": 17,
583
+ "ACTION_LOAD_KEY": 18,
584
+ "ACTION_CREATE_KEY": 19,
585
+ "ACTION_OPEN_KEY_WRITE": 20,
586
+ "ACTION_LOAD_MODULE": 21,
587
+ "ACTION_PROCESS_TERMINATE": 22,
588
+ "ACTION_PROCESS_DISCOVERED": 23,
589
+ "ACTION_CREATE_PROCESS": 24,
590
+ "ACTION_CREATE_PROCESS_EFFECTIVE": 25,
591
+ "ACTION_DUP_THREAD_HANDLE": 26,
592
+ "ACTION_DUP_PROCESS_HANDLE": 27,
593
+ "ACTION_OPEN_PROCESS_HANDLE": 28,
594
+ "ACTION_OPEN_THREAD_HANDLE": 29,
595
+ "ACTION_LOAD_SCRIPT": 30,
596
+ "ACTION_CONNECTION_ESTABLISHED": 31,
597
+ "ACTION_CONNECTION_LISTEN": 32,
598
+ "ACTION_CONNECTION_CREATE": 33,
599
+ }
600
+
601
+ rel2id_graph_processor_carbon_black_edr = {
602
+ 1: "FILE_OPENED",
603
+ 2: "FILE_CLOSED",
604
+ 3: "FILE_CREATED",
605
+ 4: "FILE_READ",
606
+ 5: "FILE_WRITTEN",
607
+ 6: "FILE_COPIED",
608
+ 7: "FILE_LINKED",
609
+ 8: "FILE_RENAMED",
610
+ 9: "FILE_TRUNCATED",
611
+ 10: "FILE_DELETED",
612
+ 11: "FILE_RESTORED",
613
+ 12: "NETFLOW_CREATED",
614
+ 13: "NETFLOW_CONNECTED",
615
+ 14: "NETFLOW_PACKET_RECEIVED",
616
+ 15: "NETFLOW_PACKET_SENT",
617
+ 16: "NETFLOW_DISCONNECTED",
618
+ 17: "PROCESS_EXECUTED",
619
+ 18: "PROCESS_KILLED",
620
+ 19: "MODULE_LOADED",
621
+ 20: "CROSS_PROCESS_INTERACTION",
622
+ 21: "REGISTRY_KEY_LOADED",
623
+ 22: "REGISTRY_KEY_UNLOADED",
624
+ 23: "REGISTRY_KEY_OPENED",
625
+ 24: "REGISTRY_KEY_CLOSED",
626
+ 25: "REGISTRY_KEY_CREATED",
627
+ 26: "REGISTRY_KEY_RENAMED",
628
+ 27: "REGISTRY_KEY_REPLACED",
629
+ 28: "REGISTRY_KEY_DELETED",
630
+ 29: "REGISTRY_KEY_RESTORED",
631
+ 30: "REGISTRY_VALUE_CREATED",
632
+ 31: "REGISTRY_VALUE_READ",
633
+ 32: "REGISTRY_VALUE_WRITTEN",
634
+ 33: "REGISTRY_VALUE_DELETED",
635
+ "FILE_OPENED": 1,
636
+ "FILE_CLOSED": 2,
637
+ "FILE_CREATED": 3,
638
+ "FILE_READ": 4,
639
+ "FILE_WRITTEN": 5,
640
+ "FILE_COPIED": 6,
641
+ "FILE_LINKED": 7,
642
+ "FILE_RENAMED": 8,
643
+ "FILE_TRUNCATED": 9,
644
+ "FILE_DELETED": 10,
645
+ "FILE_RESTORED": 11,
646
+ "NETFLOW_CREATED": 12,
647
+ "NETFLOW_CONNECTED": 13,
648
+ "NETFLOW_PACKET_RECEIVED": 14,
649
+ "NETFLOW_PACKET_SENT": 15,
650
+ "NETFLOW_DISCONNECTED": 16,
651
+ "PROCESS_EXECUTED": 17,
652
+ "PROCESS_KILLED": 18,
653
+ "MODULE_LOADED": 19,
654
+ "CROSS_PROCESS_INTERACTION": 20,
655
+ "REGISTRY_KEY_LOADED": 21,
656
+ "REGISTRY_KEY_UNLOADED": 22,
657
+ "REGISTRY_KEY_OPENED": 23,
658
+ "REGISTRY_KEY_CLOSED": 24,
659
+ "REGISTRY_KEY_CREATED": 25,
660
+ "REGISTRY_KEY_RENAMED": 26,
661
+ "REGISTRY_KEY_REPLACED": 27,
662
+ "REGISTRY_KEY_DELETED": 28,
663
+ "REGISTRY_KEY_RESTORED": 29,
664
+ "REGISTRY_VALUE_CREATED": 30,
665
+ "REGISTRY_VALUE_READ": 31,
666
+ "REGISTRY_VALUE_WRITTEN": 32,
667
+ "REGISTRY_VALUE_DELETED": 33,
668
+ }
669
+
670
+ possible_events_darpa_tc = {
671
+ ("subject", "subject"): [
672
+ "EVENT_READ",
673
+ "EVENT_WRITE",
674
+ "EVENT_OPEN",
675
+ "EVENT_CONNECT",
676
+ "EVENT_RECVFROM",
677
+ "EVENT_SENDTO",
678
+ "EVENT_CLONE",
679
+ "EVENT_SENDMSG",
680
+ "EVENT_RECVMSG",
681
+ ],
682
+ ("subject", "file"): [
683
+ "EVENT_WRITE",
684
+ "EVENT_CONNECT",
685
+ "EVENT_SENDMSG",
686
+ "EVENT_SENDTO",
687
+ "EVENT_CLONE",
688
+ ],
689
+ ("subject", "netflow"): [
690
+ "EVENT_WRITE",
691
+ "EVENT_SENDTO",
692
+ "EVENT_CONNECT",
693
+ "EVENT_SENDMSG",
694
+ ],
695
+ ("file", "subject"): [
696
+ "EVENT_READ",
697
+ "EVENT_OPEN",
698
+ "EVENT_RECVFROM",
699
+ "EVENT_EXECUTE",
700
+ "EVENT_RECVMSG",
701
+ ],
702
+ ("netflow", "subject"): [
703
+ "EVENT_OPEN",
704
+ "EVENT_READ",
705
+ "EVENT_RECVFROM",
706
+ "EVENT_RECVMSG",
707
+ ],
708
+ }
709
+
710
+ possible_events_graph_processor_carbon_black_edr = {
711
+ ("subject", "subject"): [
712
+ "PROCESS_EXECUTED",
713
+ "PROCESS_KILLED",
714
+ "CROSS_PROCESS_INTERACTION",
715
+ ],
716
+ ("subject", "file"): [
717
+ "FILE_OPENED",
718
+ "FILE_CLOSED",
719
+ "FILE_CREATED",
720
+ "FILE_WRITTEN",
721
+ "FILE_COPIED",
722
+ "FILE_LINKED",
723
+ "FILE_RENAMED",
724
+ "FILE_TRUNCATED",
725
+ "FILE_DELETED",
726
+ "FILE_RESTORED",
727
+ "REGISTRY_KEY_UNLOADED",
728
+ "REGISTRY_KEY_OPENED",
729
+ "REGISTRY_KEY_CLOSED",
730
+ "REGISTRY_KEY_CREATED",
731
+ "REGISTRY_KEY_RENAMED",
732
+ "REGISTRY_KEY_REPLACED",
733
+ "REGISTRY_KEY_DELETED",
734
+ "REGISTRY_KEY_RESTORED",
735
+ "REGISTRY_VALUE_CREATED",
736
+ "REGISTRY_VALUE_WRITTEN",
737
+ "REGISTRY_VALUE_DELETED",
738
+ ],
739
+ ("subject", "netflow"): [
740
+ "NETFLOW_CREATED",
741
+ "NETFLOW_CONNECTED",
742
+ "NETFLOW_PACKET_SENT",
743
+ "NETFLOW_DISCONNECTED",
744
+ ],
745
+ ("file", "subject"): [
746
+ "FILE_READ",
747
+ "MODULE_LOADED",
748
+ "REGISTRY_KEY_LOADED",
749
+ "REGISTRY_VALUE_READ",
750
+ ],
751
+ ("netflow", "subject"): [
752
+ "NETFLOW_PACKET_RECEIVED",
753
+ ],
754
+ }
755
+
756
+ ntype2id = {
757
+ 1: "subject",
758
+ "subject": 1,
759
+ 2: "file",
760
+ "file": 2,
761
+ 3: "netflow",
762
+ "netflow": 3,
763
+ }
764
+
765
+ OPTC_hostname_map = {
766
+ "optc_h051": "SysClient0051",
767
+ "optc_h201": "SysClient0201",
768
+ "optc_h501": "SysClient0501",
769
+ }
770
+
771
+
772
+ # --------------------------------------------------------------------------------------
773
+ # Schemas
774
+ # --------------------------------------------------------------------------------------
775
+
776
+ # Node types of host provenance datasets (DARPA TC, OpTC, Carbon Black EDR), which share the
777
+ # same database tables. Tables are read in this order (netflows first), which defines the
778
+ # order of nodes in the outputs of the construction.
779
+ PROVENANCE_NODE_TYPES = (
780
+ NodeTypeSchema(
781
+ name="netflow",
782
+ id=3,
783
+ table="netflow_node_table",
784
+ columns=(
785
+ ("local_ip", "src_addr"),
786
+ ("local_port", "src_port"),
787
+ ("remote_ip", "dst_addr"),
788
+ ("remote_port", "dst_port"),
789
+ ),
790
+ null_token="[NO_IP]",
791
+ display="{local_ip}:{local_port}->{remote_ip}:{remote_port}",
792
+ label_format="address",
793
+ ),
794
+ NodeTypeSchema(
795
+ name="subject",
796
+ id=1,
797
+ table="subject_node_table",
798
+ columns=(("path", "path"), ("cmd_line", "cmd")),
799
+ auto_label=("cmd_line", "path"),
800
+ null_token="[NO_CMD]",
801
+ display="{path}",
802
+ display_extra=(("cmd", "cmd_line"),),
803
+ label_format="path",
804
+ ),
805
+ NodeTypeSchema(
806
+ name="file",
807
+ id=2,
808
+ table="file_node_table",
809
+ columns=(("path", "path"),),
810
+ auto_label=("path",),
811
+ null_token="[NO_PATH]",
812
+ display="{path}",
813
+ label_format="path",
814
+ ),
815
+ )
816
+
817
+ SCHEMAS = {
818
+ schema.name: schema
819
+ for schema in [
820
+ DatasetSchema(
821
+ name="darpa_tc",
822
+ node_types=PROVENANCE_NODE_TYPES,
823
+ rel2id=rel2id_darpa_tc,
824
+ possible_events=possible_events_darpa_tc,
825
+ ),
826
+ DatasetSchema(
827
+ name="optc",
828
+ node_types=PROVENANCE_NODE_TYPES,
829
+ rel2id=rel2id_optc,
830
+ possible_events=possible_events_optc,
831
+ supports_edge_type_triplets=False,
832
+ supports_hetero=False,
833
+ ),
834
+ # OpTC with edge types translated to their DARPA TC equivalent
835
+ # (`construction.consistent_edge_types`), to share a vocabulary across datasets
836
+ DatasetSchema(
837
+ name="optc_tc_edge_types",
838
+ node_types=PROVENANCE_NODE_TYPES,
839
+ rel2id=rel2id_optc_consistent,
840
+ possible_events=possible_events_optc_consistent,
841
+ raw_rel2id=rel2id_optc,
842
+ edge_type_translation=OPTC_TO_TC_EDGE_MAP,
843
+ supports_edge_type_triplets=False,
844
+ supports_hetero=False,
845
+ ),
846
+ DatasetSchema(
847
+ name="carbon_black_edr",
848
+ node_types=PROVENANCE_NODE_TYPES,
849
+ rel2id=rel2id_graph_processor_carbon_black_edr,
850
+ possible_events=possible_events_graph_processor_carbon_black_edr,
851
+ ),
852
+ ]
853
+ }
854
+
855
+ # --------------------------------------------------------------------------------------
856
+ # Network datasets
857
+ # --------------------------------------------------------------------------------------
858
+
859
+ # Hosts of enterprise networks (computers, IP addresses), identified by their name.
860
+ HOST_NODE_TYPE = NodeTypeSchema(
861
+ name="host",
862
+ id=1,
863
+ table="host_node_table",
864
+ columns=(("name", "name"),),
865
+ auto_label=("name",),
866
+ null_token="[NO_NAME]",
867
+ display="{name}",
868
+ )
869
+
870
+ # LANL "Comprehensive, Multi-Source Cyber-Security Events" (Kent, 2015): authentication events
871
+ # between computers (auth.txt) and network flows between them (flows.txt), labelled by the red
872
+ # team events (redteam.txt). Authentications have the type (`operation`) of their orientation
873
+ # (LogOn, LogOff, ...), flows the type FLOW; attributes of the other kind of events are null.
874
+ # See `dataset_preprocessing/lanl/create_database_lanl.py`.
875
+ LANL_AUTH_ORIENTATIONS = ("LogOn", "LogOff", "TGS", "TGT", "AuthMap", "ScreenLock", "ScreenUnlock")
876
+ LANL_LOGON_TYPES = (
877
+ "Network",
878
+ "Service",
879
+ "Batch",
880
+ "Interactive",
881
+ "RemoteInteractive",
882
+ "CachedInteractive",
883
+ "NetworkCleartext",
884
+ "NewCredentials",
885
+ "Unlock",
886
+ "?",
887
+ )
888
+ LANL_AUTH_TYPES = ("NTLM", "Kerberos", "Negotiate", "MICROSOFT_AUTHENTICATION_PACKAGE_V1_0", "?")
889
+ # Kind of source user of authentications: user (U123@DOM1), computer account (C123$@DOM1),
890
+ # anonymous logon, or well-known system account (SYSTEM, LOCAL SERVICE, ...)
891
+ LANL_USER_KINDS = ("user", "computer", "anonymous", "system")
892
+
893
+ # Ports of flows: the most frequent well-known ports, and `N` for the de-identified ports of LANL
894
+ LANL_PORTS = (
895
+ "N", "445", "80", "389", "137", "88", "139", "443", "135", "138", "123", "161", "1433", "22",
896
+ "53", "3389",
897
+ ) # fmt: skip
898
+ LANL_PROTOCOLS = ("6", "17", "1", "41") # TCP, UDP, ICMP, IPv6 encapsulation
899
+ LANL_EVENT_TYPES = LANL_AUTH_ORIENTATIONS + ("FLOW", "OTHER")
900
+
901
+ rel2id_lanl = {}
902
+ for _i, _event_type in enumerate(LANL_EVENT_TYPES):
903
+ rel2id_lanl[_i + 1] = _event_type
904
+ rel2id_lanl[_event_type] = _i + 1
905
+
906
+ LANL_EDGE_ATTRIBUTES = (
907
+ # Authentications
908
+ EdgeAttributeSchema("logon_type", "logon_type", "categorical", LANL_LOGON_TYPES),
909
+ EdgeAttributeSchema("auth_type", "auth_type", "categorical", LANL_AUTH_TYPES),
910
+ EdgeAttributeSchema("success", "success", "categorical", ("Success", "Fail")),
911
+ EdgeAttributeSchema("src_user_kind", "src_user_kind", "categorical", LANL_USER_KINDS),
912
+ EdgeAttributeSchema("dst_user_kind", "dst_user_kind", "categorical", LANL_USER_KINDS),
913
+ # Flows
914
+ EdgeAttributeSchema("src_port", "src_port", "categorical", LANL_PORTS),
915
+ EdgeAttributeSchema("dst_port", "dst_port", "categorical", LANL_PORTS),
916
+ EdgeAttributeSchema("protocol", "protocol", "categorical", LANL_PROTOCOLS),
917
+ EdgeAttributeSchema("duration", "duration", "numeric"),
918
+ EdgeAttributeSchema("packets", "packets", "numeric"),
919
+ EdgeAttributeSchema("bytes", "bytes", "numeric"),
920
+ )
921
+
922
+ SCHEMAS["lanl_auth"] = DatasetSchema(
923
+ name="lanl_auth",
924
+ node_types=(HOST_NODE_TYPE,),
925
+ rel2id=rel2id_lanl,
926
+ possible_events={("host", "host"): list(LANL_EVENT_TYPES)},
927
+ edge_attributes=LANL_EDGE_ATTRIBUTES,
928
+ label_column="label",
929
+ )
930
+
931
+
932
+ # DARPA OpTC network flows of all hosts (FLOW START and FLOW MESSAGE events of eCAR), in the version
933
+ # preprocessed by LARES (Bilot et al., ACSAC 2026), whose hosts are integer ids. Ports are grouped as
934
+ # in LARES: common service ports are kept, other ports are grouped by range.
935
+ # See `dataset_preprocessing/optc/create_database_optc_net.py`.
936
+ rel2id_optc_flows = {}
937
+ for _i, _event_type in enumerate(("FLOW_START", "FLOW_MESSAGE", "OTHER")):
938
+ rel2id_optc_flows[_i + 1] = _event_type
939
+ rel2id_optc_flows[_event_type] = _i + 1
940
+
941
+ OPTC_PORTS = (
942
+ "0", "8", "53", "67", "68", "80", "88", "135", "136", "137", "138", "139", "389", "443", "445",
943
+ "1900", "3389", "5355", "5985", "1-1023", "1024-5354", "5356-50000", "50001-60000", "60001+",
944
+ ) # fmt: skip
945
+ OPTC_PROTOCOLS = ("6", "17", "1", "58") # TCP, UDP, ICMP, ICMPv6
946
+
947
+ OPTC_FLOWS_EDGE_ATTRIBUTES = (
948
+ EdgeAttributeSchema("src_port", "src_port", "categorical", OPTC_PORTS),
949
+ EdgeAttributeSchema("dst_port", "dst_port", "categorical", OPTC_PORTS),
950
+ EdgeAttributeSchema("protocol", "protocol", "categorical", OPTC_PROTOCOLS),
951
+ EdgeAttributeSchema("size", "size", "numeric"),
952
+ )
953
+
954
+ SCHEMAS["optc_flows"] = DatasetSchema(
955
+ name="optc_flows",
956
+ node_types=(HOST_NODE_TYPE,),
957
+ rel2id=rel2id_optc_flows,
958
+ possible_events={("host", "host"): ["FLOW_START", "FLOW_MESSAGE", "OTHER"]},
959
+ edge_attributes=OPTC_FLOWS_EDGE_ATTRIBUTES,
960
+ label_column="label",
961
+ # As in LARES and Argus, only FLOW START events are used by default
962
+ operations=("FLOW_START",),
963
+ # NetBIOS name/datagram (137, 138), LLMNR (5355) and SSDP (1900) broadcasts and multicasts
964
+ # and ICMPv6 neighbor discovery (types 135, 136), received by every host: 99.86% of the
965
+ # FLOW START events, they link each host to ~500 of the 625 hosts in every 30 min (LARES'
966
+ # `filter_noise_protocols` drops 137, 138 and 5355)
967
+ noise_events_sql=(
968
+ "COALESCE(dst_port, '') IN ('137', '138', '5355', '1900') "
969
+ "OR (COALESCE(protocol, '') = '58' AND COALESCE(dst_port, '') IN ('135', '136'))"
970
+ ),
971
+ )
972
+
973
+
974
+ # Schema used instead of a dataset's schema with `construction.consistent_edge_types`
975
+ CONSISTENT_EDGE_TYPES_SCHEMAS = {"optc": "optc_tc_edge_types"}
976
+
977
+
978
+ def get_schema_by_name(name):
979
+ if name not in SCHEMAS:
980
+ raise ValueError(f"Unknown dataset schema {name}. Available schemas: {list(SCHEMAS)}")
981
+ return SCHEMAS[name]
982
+
983
+
984
+ @lru_cache(maxsize=None)
985
+ def all_node_types():
986
+ """{node type name: NodeTypeSchema} across all schemas (a name has the same attributes everywhere)."""
987
+ node_types = {}
988
+ for schema in SCHEMAS.values():
989
+ for nt in schema.node_types:
990
+ node_types.setdefault(nt.name, nt)
991
+ return node_types
992
+
993
+
994
+ def get_schema(cfg):
995
+ """Schema of the dataset of `cfg` (see the `schema` key of `DATASET_DEFAULT_CONFIG`),
996
+ with the events selected by `construction.operations` and the edge types selected by
997
+ `construction.edge_type`."""
998
+ name = cfg.dataset.schema
999
+ construction = getattr(cfg, "construction", None)
1000
+ if construction is not None and getattr(construction, "consistent_edge_types", False):
1001
+ name = CONSISTENT_EDGE_TYPES_SCHEMAS.get(name, name)
1002
+ schema = get_schema_by_name(name)
1003
+ edge_type = getattr(construction, "edge_type", None) if construction is not None else None
1004
+ operations = getattr(construction, "operations", None) if construction is not None else None
1005
+ return (
1006
+ schema.with_operations(operations)
1007
+ .with_noise_dropped(drops_noise_events(construction))
1008
+ .with_edge_type(edge_type)
1009
+ )
1010
+
1011
+
1012
+ def benign_training(construction):
1013
+ """`construction.benign_training`, True when unset (configs not including default.yml)."""
1014
+ value = getattr(construction, "benign_training", None) if construction is not None else None
1015
+ return True if value is None else bool(value)
1016
+
1017
+
1018
+ def drops_noise_events(construction):
1019
+ """`construction.drop_noise_events`, True when unset (configs not including default.yml)."""
1020
+ value = getattr(construction, "drop_noise_events", None) if construction is not None else None
1021
+ return True if value is None else bool(value)
1022
+
1023
+
1024
+ def label_format(node_type):
1025
+ """Format of the labels of a node type (`path`, `address` or `name`), see `NodeTypeSchema`.
1026
+ None for texts that are not node labels (`node_type=None`)."""
1027
+ if node_type is None:
1028
+ return None
1029
+ node_types = all_node_types()
1030
+ if node_type not in node_types:
1031
+ raise ValueError(f"Invalid node type {node_type}")
1032
+ return node_types[node_type].label_format