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.
- pidsmaker/__init__.py +22 -0
- pidsmaker/cli.py +32 -0
- pidsmaker/config/__init__.py +2 -0
- pidsmaker/config/config.py +2100 -0
- pidsmaker/config/pipeline.py +1768 -0
- pidsmaker/config/schemas.py +1032 -0
- pidsmaker/datasets.py +222 -0
- pidsmaker/debug_tests.py +30 -0
- pidsmaker/decoders/__init__.py +5 -0
- pidsmaker/decoders/custom_edge_mlp_decoder.py +17 -0
- pidsmaker/decoders/custom_mlp_decoder.py +10 -0
- pidsmaker/decoders/edge_linear_decoder.py +16 -0
- pidsmaker/decoders/inner_product_decoder.py +18 -0
- pidsmaker/decoders/nodlink_decoder.py +56 -0
- pidsmaker/detection/__init__.py +0 -0
- pidsmaker/detection/evaluation_methods/__init__.py +9 -0
- pidsmaker/detection/evaluation_methods/edge_evaluation.py +259 -0
- pidsmaker/detection/evaluation_methods/evaluation_utils.py +1730 -0
- pidsmaker/detection/evaluation_methods/host_two_stage_evaluation.py +115 -0
- pidsmaker/detection/evaluation_methods/node_evaluation.py +463 -0
- pidsmaker/detection/evaluation_methods/node_tw_evaluation.py +196 -0
- pidsmaker/detection/evaluation_methods/plot.py +192 -0
- pidsmaker/detection/evaluation_methods/queue_evaluation.py +451 -0
- pidsmaker/detection/evaluation_methods/tw_evaluation.py +95 -0
- pidsmaker/detection/flash_detection.py +162 -0
- pidsmaker/detection/magic_knn.py +190 -0
- pidsmaker/detection/node_scoring.py +52 -0
- pidsmaker/detection/threatrace_detection.py +65 -0
- pidsmaker/detection/training_methods/__init__.py +1 -0
- pidsmaker/detection/training_methods/inference_loop.py +293 -0
- pidsmaker/detection/training_methods/ocrapt_early_stop.py +165 -0
- pidsmaker/detection/training_methods/threatrace_training.py +169 -0
- pidsmaker/detection/training_methods/training_loop.py +377 -0
- pidsmaker/encoders/__init__.py +22 -0
- pidsmaker/encoders/argus_encoder.py +69 -0
- pidsmaker/encoders/custom_mlp.py +75 -0
- pidsmaker/encoders/custom_mlp_encoder.py +10 -0
- pidsmaker/encoders/egraphsage_encoder.py +56 -0
- pidsmaker/encoders/gat.py +67 -0
- pidsmaker/encoders/gcn.py +27 -0
- pidsmaker/encoders/gin.py +48 -0
- pidsmaker/encoders/glstm.py +298 -0
- pidsmaker/encoders/graph_attention.py +63 -0
- pidsmaker/encoders/gru.py +29 -0
- pidsmaker/encoders/hetero/__init__.py +4 -0
- pidsmaker/encoders/hetero/ancestor_encoder.py +98 -0
- pidsmaker/encoders/hetero/entity_encoder.py +33 -0
- pidsmaker/encoders/hetero/event_encoder.py +81 -0
- pidsmaker/encoders/hetero/hetero_graph_transformer.py +40 -0
- pidsmaker/encoders/lares_encoder.py +68 -0
- pidsmaker/encoders/linear_encoder.py +16 -0
- pidsmaker/encoders/magic_encoder.py +161 -0
- pidsmaker/encoders/rcaid_encoder.py +81 -0
- pidsmaker/encoders/rgcn.py +75 -0
- pidsmaker/encoders/sage.py +51 -0
- pidsmaker/encoders/shadewatcher_encoder.py +149 -0
- pidsmaker/encoders/sum_aggregation.py +20 -0
- pidsmaker/encoders/temporal_wrappers.py +80 -0
- pidsmaker/encoders/textrcnn.py +82 -0
- pidsmaker/encoders/tgn_encoder.py +193 -0
- pidsmaker/experiments/tuning.py +102 -0
- pidsmaker/experiments/uncertainty.py +261 -0
- pidsmaker/factory.py +1456 -0
- pidsmaker/featurization/__init__.py +0 -0
- pidsmaker/featurization/feat_inference_methods/__init__.py +7 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_HFH.py +31 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_TRW.py +67 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_alacarte.py +16 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_doc2vec.py +54 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_fasttext.py +38 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_flash.py +70 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_graph2vec.py +85 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_ocrapt_features.py +95 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_pretrained.py +1729 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_word2vec.py +56 -0
- pidsmaker/featurization/featurization_methods/__init__.py +0 -0
- pidsmaker/featurization/featurization_methods/build_trw.py +67 -0
- pidsmaker/featurization/featurization_methods/featurization_alacarte.py +748 -0
- pidsmaker/featurization/featurization_methods/featurization_doc2vec.py +99 -0
- pidsmaker/featurization/featurization_methods/featurization_fasttext.py +75 -0
- pidsmaker/featurization/featurization_methods/featurization_flash.py +203 -0
- pidsmaker/featurization/featurization_methods/featurization_graph2vec.py +243 -0
- pidsmaker/featurization/featurization_methods/featurization_trw.py +115 -0
- pidsmaker/featurization/featurization_methods/featurization_word2vec.py +87 -0
- pidsmaker/featurization/featurization_utils.py +275 -0
- pidsmaker/featurization/utils/build_random_walks.py +68 -0
- pidsmaker/featurization/utils/trw.py +203 -0
- pidsmaker/hetero.py +81 -0
- pidsmaker/losses.py +170 -0
- pidsmaker/main.py +377 -0
- pidsmaker/mimicry.py +284 -0
- pidsmaker/model.py +382 -0
- pidsmaker/objectives/__init__.py +16 -0
- pidsmaker/objectives/autoencode_edge_emb.py +43 -0
- pidsmaker/objectives/deep_graph_infomax.py +94 -0
- pidsmaker/objectives/detect_few_shot.py +21 -0
- pidsmaker/objectives/one_class.py +75 -0
- pidsmaker/objectives/predict_edge_contrastive.py +165 -0
- pidsmaker/objectives/predict_edge_supervised.py +77 -0
- pidsmaker/objectives/predict_edge_type.py +28 -0
- pidsmaker/objectives/predict_masked_struct.py +49 -0
- pidsmaker/objectives/predict_node_type.py +36 -0
- pidsmaker/objectives/predict_process_tag.py +169 -0
- pidsmaker/objectives/predict_snapshot_embedding.py +97 -0
- pidsmaker/objectives/reconstruct_edge_emb.py +16 -0
- pidsmaker/objectives/reconstruct_masked_feat.py +51 -0
- pidsmaker/objectives/reconstruct_node_emb.py +13 -0
- pidsmaker/objectives/reconstruct_node_feat.py +13 -0
- pidsmaker/objectives/validation_wrapper.py +55 -0
- pidsmaker/preprocessing/__init__.py +0 -0
- pidsmaker/preprocessing/build_graph_methods/__init__.py +1 -0
- pidsmaker/preprocessing/build_graph_methods/build_default_graphs.py +830 -0
- pidsmaker/preprocessing/build_graph_methods/build_magic_graphs.py +220 -0
- pidsmaker/preprocessing/cleaning.py +258 -0
- pidsmaker/preprocessing/transformation_methods/__init__.py +2 -0
- pidsmaker/preprocessing/transformation_methods/attack_generation/synthetic_attack_naive.py +194 -0
- pidsmaker/preprocessing/transformation_methods/transformation_dag.py +28 -0
- pidsmaker/preprocessing/transformation_methods/transformation_merge_edges.py +136 -0
- pidsmaker/preprocessing/transformation_methods/transformation_rcaid_pseudo_graph.py +510 -0
- pidsmaker/preprocessing/transformation_methods/transformation_undirected.py +24 -0
- pidsmaker/preprocessing/transformation_methods/transformation_utils.py +36 -0
- pidsmaker/pretrained/__init__.py +5 -0
- pidsmaker/pretrained/data/__init__.py +4 -0
- pidsmaker/pretrained/data/behavior_signatures.py +548 -0
- pidsmaker/pretrained/data/canonical_tokens.py +1035 -0
- pidsmaker/pretrained/data/edge_filter.py +381 -0
- pidsmaker/pretrained/data/entity_classes.py +476 -0
- pidsmaker/pretrained/data/sampler.py +926 -0
- pidsmaker/pretrained/data/tokenizer_bpe.py +1659 -0
- pidsmaker/pretrained/detect.py +1432 -0
- pidsmaker/pretrained/embedding_generator.py +252 -0
- pidsmaker/pretrained/finetune.py +1437 -0
- pidsmaker/pretrained/models/__init__.py +20 -0
- pidsmaker/pretrained/models/behavior.py +348 -0
- pidsmaker/pretrained/models/bert.py +286 -0
- pidsmaker/pretrained/models/deepwalk.py +128 -0
- pidsmaker/pretrained/models/dgi.py +120 -0
- pidsmaker/pretrained/models/gae.py +114 -0
- pidsmaker/pretrained/models/gnn_distill.py +475 -0
- pidsmaker/pretrained/models/graphmae.py +373 -0
- pidsmaker/pretrained/models/hf_pretrained.py +213 -0
- pidsmaker/pretrained/models/llama.py +110 -0
- pidsmaker/pretrained/models/modernbert.py +567 -0
- pidsmaker/pretrained/models/roberta.py +147 -0
- pidsmaker/pretrained/models/rope_utils.py +99 -0
- pidsmaker/pretrained/models/ropebert.py +322 -0
- pidsmaker/pretrained/models/spider.py +204 -0
- pidsmaker/pretrained/models/tgn.py +770 -0
- pidsmaker/pretrained/pretrain/__init__.py +3 -0
- pidsmaker/pretrained/pretrain/pretrain_behavior_cluster.py +513 -0
- pidsmaker/pretrained/pretrain/pretrain_common.py +585 -0
- pidsmaker/pretrained/pretrain/pretrain_deepwalk.py +31 -0
- pidsmaker/pretrained/pretrain/pretrain_dgi.py +143 -0
- pidsmaker/pretrained/pretrain/pretrain_gae.py +143 -0
- pidsmaker/pretrained/pretrain/pretrain_gnn_distill.py +438 -0
- pidsmaker/pretrained/pretrain/pretrain_graphmae.py +151 -0
- pidsmaker/pretrained/pretrain/pretrain_hf.py +169 -0
- pidsmaker/pretrained/pretrain/pretrain_main.py +276 -0
- pidsmaker/pretrained/pretrain/pretrain_mlm.py +491 -0
- pidsmaker/pretrained/pretrain/pretrain_spider.py +502 -0
- pidsmaker/pretrained/training_utils.py +157 -0
- pidsmaker/process_reapr_gt.py +101 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-CADETS/node_Nginx_Backdoor_06.csv +8 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-CADETS/node_Nginx_Backdoor_11.csv +4 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-CADETS/node_Nginx_Backdoor_12.csv +43 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-CADETS/node_Nginx_Backdoor_13.csv +24 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-CLEARSCOPE/node_clearscope_e3_firefox_0411.csv +41 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-CLEARSCOPE/node_clearscope_e3_firefox_0412.csv +0 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-FIVEDIRECTIONS/node_fivedirections_e3_browser_0412.csv +1 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-FIVEDIRECTIONS/node_fivedirections_e3_excel_0409.csv +63 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-FIVEDIRECTIONS/node_fivedirections_e3_firefox_0411.csv +56 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-THEIA/node_Browser_Extension_Drakon_Dropper.csv +61 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-THEIA/node_Firefox_Backdoor_Drakon_In_Memory.csv +58 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-TRACE/node_trace_e3_firefox_0410.csv +11 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-TRACE/node_trace_e3_phishing_executable_0413.csv +11 -0
- pidsmaker/resources/Ground_Truth/orthrus/E3-TRACE/node_trace_e3_pine_0413.csv +14 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-CADETS/node_Nginx_Drakon_APT.csv +19 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-CADETS/node_Nginx_Drakon_APT_17.csv +107 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_appstarter_0515.csv +26 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_firefox_0517.csv +1 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_lockwatch_0517.csv +17 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_tester_0517.csv +8 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_bits_0515.csv +54 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_copykatz_0509.csv +87 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_dns_0517.csv +11 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_drakon_0517.csv +6 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-THEIA/node_THEIA_1_Firefox_Drakon_APT_BinFmt_Elevate_Inject.csv +70 -0
- pidsmaker/resources/Ground_Truth/orthrus/E5-TRACE/node_Trace_Firefox_Drakon.csv +71 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m1.csv +1 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m2.csv +1 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m3.csv +1 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m4.csv +5 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m5.csv +23 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_m6.csv +18 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_s1.csv +1 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_s2.csv +1 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_s3.csv +16 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_edr/atlasv2_edr_s4.csv +22 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m1.csv +126 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m2.csv +105 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m3.csv +94 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m4.csv +139 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m5.csv +228 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_m6.csv +131 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_s1.csv +118 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_s2.csv +89 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_s3.csv +133 -0
- pidsmaker/resources/Ground_Truth/orthrus/atlasv2_h1/node_h1_s4.csv +135 -0
- pidsmaker/resources/Ground_Truth/orthrus/carbanakv2_edr/carbanakv2_edr.csv +2453 -0
- pidsmaker/resources/Ground_Truth/orthrus/h051/node_h051_0925.csv +114 -0
- pidsmaker/resources/Ground_Truth/orthrus/h201/node_h201_0923.csv +2905 -0
- pidsmaker/resources/Ground_Truth/orthrus/h501/node_h501_0924.csv +749 -0
- pidsmaker/resources/Ground_Truth/orthrus/readme.md +98 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-CADETS/node_Nginx_Backdoor_06.csv +3 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-CADETS/node_Nginx_Backdoor_12.csv +655 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-CADETS/node_Nginx_Backdoor_13.csv +770 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-FIVEDIRECTIONS/node_fivedirections_e3_excel_0409.csv +0 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-FIVEDIRECTIONS/node_fivedirections_e3_firefox_0411.csv +18 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-THEIA/node_Browser_Extension_Drakon_Dropper.csv +42 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-THEIA/node_Firefox_Backdoor_Drakon_In_Memory.csv +81 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-TRACE/node_trace_e3_firefox_0410.csv +37 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-TRACE/node_trace_e3_phishing_executable_0413.csv +9 -0
- pidsmaker/resources/Ground_Truth/reapr/E3-TRACE/node_trace_e3_pine_0413.csv +40 -0
- pidsmaker/resources/Ground_Truth/threatrace/E3-CADETS/ground_truth.txt +12858 -0
- pidsmaker/resources/Ground_Truth/threatrace/E3-FIVEDIRECTIONS/ground_truth.txt +18420 -0
- pidsmaker/resources/Ground_Truth/threatrace/E3-THEIA/ground_truth.txt +25363 -0
- pidsmaker/resources/Ground_Truth/threatrace/E3-TRACE/ground_truth.txt +68265 -0
- pidsmaker/resources/Ground_Truth/threatrace/README.md +123 -0
- pidsmaker/resources/config/anomal_e.yml +25 -0
- pidsmaker/resources/config/argus.yml +56 -0
- pidsmaker/resources/config/attack_edges/cadets_e3.yml +435 -0
- pidsmaker/resources/config/attack_edges/cadets_e5.yml +407 -0
- pidsmaker/resources/config/attack_edges/theia_e3.yml +382 -0
- pidsmaker/resources/config/attack_edges/theia_e5.yml +387 -0
- pidsmaker/resources/config/attack_edges/trace_e3.yml +415 -0
- pidsmaker/resources/config/attack_edges/trace_e5.yml +417 -0
- pidsmaker/resources/config/default.yml +315 -0
- pidsmaker/resources/config/egraphsage.yml +95 -0
- pidsmaker/resources/config/euler.yml +104 -0
- pidsmaker/resources/config/eval/eval_set_clustering.json +3170 -0
- pidsmaker/resources/config/experiments/tuning/components/tuning_featurization_methods.yml +29 -0
- pidsmaker/resources/config/experiments/tuning/systems/clearscope_e5/tuning_orthrus.yml +14 -0
- pidsmaker/resources/config/experiments/tuning/systems/default/tuning_default_baselines.yml +13 -0
- pidsmaker/resources/config/experiments/tuning/systems/default/tuning_orthrus_fixed.yml +16 -0
- pidsmaker/resources/config/experiments/uncertainty/none.yml +5 -0
- pidsmaker/resources/config/experiments/uncertainty/run_n_times.yml +12 -0
- pidsmaker/resources/config/experiments/uncertainty/run_n_times_hyperparameters.yml +12 -0
- pidsmaker/resources/config/experiments/uncertainty/uncertainty.yml +22 -0
- pidsmaker/resources/config/flash.yml +79 -0
- pidsmaker/resources/config/jbeil.yml +65 -0
- pidsmaker/resources/config/kairos.yml +121 -0
- pidsmaker/resources/config/lares.yml +115 -0
- pidsmaker/resources/config/magic.yml +86 -0
- pidsmaker/resources/config/nodlink.yml +79 -0
- pidsmaker/resources/config/ocrapt.yml +91 -0
- pidsmaker/resources/config/orthrus.yml +120 -0
- pidsmaker/resources/config/orthrus_fixed.yml +17 -0
- pidsmaker/resources/config/orthrus_non_snooped.yml +17 -0
- pidsmaker/resources/config/pretrained/README.md +101 -0
- pidsmaker/resources/config/pretrained/cybergfm/cybergfm.yml +49 -0
- pidsmaker/resources/config/pretrained/pretrained.yml +190 -0
- pidsmaker/resources/config/pretrained/pretrained_flash.yml +9 -0
- pidsmaker/resources/config/pretrained/pretrained_kairos.yml +12 -0
- pidsmaker/resources/config/pretrained/pretrained_magic.yml +1 -0
- pidsmaker/resources/config/pretrained/pretrained_nodlink.yml +1 -0
- pidsmaker/resources/config/pretrained/pretrained_orthrus.yml +1 -0
- pidsmaker/resources/config/pretrained/pretrained_supervised.yml +13 -0
- pidsmaker/resources/config/pretrained/pretrained_threatrace.yml +8 -0
- pidsmaker/resources/config/pretrained/pretrained_velox.yml +14 -0
- pidsmaker/resources/config/prographer.yml +136 -0
- pidsmaker/resources/config/rcaid.yml +88 -0
- pidsmaker/resources/config/shadewatcher.yml +146 -0
- pidsmaker/resources/config/tests.yml +10 -0
- pidsmaker/resources/config/threatrace.yml +73 -0
- pidsmaker/resources/config/tuned_baselines/optc_net/tuned_argus.yml +4 -0
- pidsmaker/resources/config/tuned_baselines/optc_net/tuned_lares.yml +13 -0
- pidsmaker/resources/config/velox.yml +10 -0
- pidsmaker/resources/config/viz_config.yml +10 -0
- pidsmaker/tasks/__init__.py +10 -0
- pidsmaker/tasks/batching.py +49 -0
- pidsmaker/tasks/construction.py +31 -0
- pidsmaker/tasks/evaluation.py +232 -0
- pidsmaker/tasks/feat_inference.py +413 -0
- pidsmaker/tasks/featurization.py +43 -0
- pidsmaker/tasks/training.py +19 -0
- pidsmaker/tasks/transformation.py +308 -0
- pidsmaker/tasks/triage.py +143 -0
- pidsmaker/tgn.py +635 -0
- pidsmaker/tokenization/__init__.py +112 -0
- pidsmaker/tokenization/base.py +58 -0
- pidsmaker/tokenization/bpe_tokenizer.py +83 -0
- pidsmaker/tokenization/hf_tokenizer.py +61 -0
- pidsmaker/tokenization/hierarchical_tokenizer.py +44 -0
- pidsmaker/tokenization/label_tokenizer.py +24 -0
- pidsmaker/tokenization/nltk_tokenizer.py +84 -0
- pidsmaker/tokenization/substitution.py +295 -0
- pidsmaker/triage/__init__.py +0 -0
- pidsmaker/triage/tracing_methods/__init__.py +1 -0
- pidsmaker/triage/tracing_methods/depimpact.py +213 -0
- pidsmaker/triage/tracing_methods/depimpact_utils.py +537 -0
- pidsmaker/triage/tracing_methods/ocrapt_subgraph.py +267 -0
- pidsmaker/utils/__init__.py +0 -0
- pidsmaker/utils/cache_utils.py +256 -0
- pidsmaker/utils/data_utils.py +1742 -0
- pidsmaker/utils/database.py +204 -0
- pidsmaker/utils/dataset_utils.py +413 -0
- pidsmaker/utils/dataset_writer.py +1057 -0
- pidsmaker/utils/graph_store.py +634 -0
- pidsmaker/utils/labelling.py +447 -0
- pidsmaker/utils/loss_files.py +193 -0
- pidsmaker/utils/process_tags.py +44 -0
- pidsmaker/utils/utils.py +730 -0
- pidsmaker/vizgen/__init__.py +1 -0
- pidsmaker/vizgen/dimensionality_reduction.py +249 -0
- pidsmaker/vizgen/embed_exporter.py +467 -0
- pidsmaker/vizgen/exporter.py +493 -0
- pidsmaker/vizgen/html_builder.py +936 -0
- pidsmaker/vizgen/web/__init__.py +1 -0
- pidsmaker/vizgen/web/export.py +62 -0
- pidsmaker/vizgen/web/static/css/app.css +250 -0
- pidsmaker/vizgen/web/static/index.html +182 -0
- pidsmaker/vizgen/web/static/js/app.js +627 -0
- pidsmaker/vizgen/web/static/js/campaign.js +123 -0
- pidsmaker/vizgen/web/static/js/data.js +119 -0
- pidsmaker/vizgen/web/static/js/dialogs.js +240 -0
- pidsmaker/vizgen/web/static/js/jobs.js +75 -0
- pidsmaker/vizgen/web/static/js/scene.js +651 -0
- pidsmaker/vizgen/web/static/js/ui.js +370 -0
- pidsmaker/vizgen/web/static/vendor/OrbitControls.js +1045 -0
- pidsmaker/vizgen/web/static/vendor/d3.v4.min.js +2 -0
- pidsmaker/vizgen/web/static/vendor/three.min.js +6 -0
- pidsmaker/vizgen/web/viz_server.py +2176 -0
- pidsmaker-4.0.0.dist-info/METADATA +596 -0
- pidsmaker-4.0.0.dist-info/RECORD +338 -0
- pidsmaker-4.0.0.dist-info/WHEEL +5 -0
- pidsmaker-4.0.0.dist-info/entry_points.txt +2 -0
- pidsmaker-4.0.0.dist-info/licenses/LICENSE +201 -0
- pidsmaker-4.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Undirected graph transformation.
|
|
2
|
+
|
|
3
|
+
Adds reverse edges to make provenance graphs undirected (bidirectional). This allows
|
|
4
|
+
encoders to propagate information in both directions along dependencies. Not
|
|
5
|
+
compatible with TGN (Temporal Graph Networks) due to time ordering requirements.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import networkx as nx
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main(G: nx.Graph) -> nx.Graph:
|
|
12
|
+
"""
|
|
13
|
+
Iterate through each edge in the graph and add the reverse edge if it doesn't exist.
|
|
14
|
+
By default, if an edge (u, v, t) doesn't have a reverse edge (v, u) in the graph,
|
|
15
|
+
an edge (v, u, t) is added. The timestamp t is thus the same for => and <= senses.
|
|
16
|
+
Shouldn't be used with TGN.
|
|
17
|
+
"""
|
|
18
|
+
edges_to_add = []
|
|
19
|
+
for u, v, data in G.edges(data=True):
|
|
20
|
+
if not G.has_edge(v, u):
|
|
21
|
+
edges_to_add.append((v, u, data))
|
|
22
|
+
|
|
23
|
+
G.add_edges_from(edges_to_add)
|
|
24
|
+
return G
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
|
|
3
|
+
import networkx as nx
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
# Context manager wrapping the draws of random timestamps, set in the processes transforming
|
|
7
|
+
# graphs in parallel to draw from the random state that a sequential run would have (see
|
|
8
|
+
# `tasks/transformation.py`). None: draws from the current global random state.
|
|
9
|
+
random_state_hook = None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def randint_timestamps(min_t, max_t, size):
|
|
13
|
+
"""`np.random.randint(min_t, max_t, size=size)` from the global random state."""
|
|
14
|
+
hook = random_state_hook or contextlib.nullcontext
|
|
15
|
+
with hook():
|
|
16
|
+
return np.random.randint(min_t, max_t, size=size)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def add_arbitrary_timestamps_to_graph(original_G: nx.Graph, new_G: nx.Graph) -> nx.Graph:
|
|
20
|
+
"""
|
|
21
|
+
Some transformations change the shape of the graph by adding or removing edges.
|
|
22
|
+
This makes the timestamps associated to edges unusable anymore as we can't associate
|
|
23
|
+
timestamps to newly added edges.
|
|
24
|
+
So we take the min/max timestamp range from the original graph and create random timestamps
|
|
25
|
+
in this range for the new graph.
|
|
26
|
+
Doing this, we can still use the framework, just the order of edges shouldn't be considered.
|
|
27
|
+
For example, TGN shouldn't be used if this function is used previously.
|
|
28
|
+
"""
|
|
29
|
+
timestamps = [edge[2]["time"] for edge in original_G.edges(data=True)]
|
|
30
|
+
min_t, max_t = min(timestamps), max(timestamps)
|
|
31
|
+
rand_t = randint_timestamps(min_t, max_t, len(new_G.edges()))
|
|
32
|
+
|
|
33
|
+
for t, (src, dst) in zip(rand_t, new_G.edges()):
|
|
34
|
+
new_G[src][dst]["time"] = t
|
|
35
|
+
|
|
36
|
+
return new_G
|
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Behavior signature extraction for provenance graph entities.
|
|
3
|
+
|
|
4
|
+
A behavior signature is the set of unique (direction, event_type,
|
|
5
|
+
neighbor_entity_type, neighbor_class) tuples observed in an entity's
|
|
6
|
+
1-hop neighborhood. Signatures are sets (no counts) so they capture
|
|
7
|
+
*what kinds of interactions* an entity has, not how frequently.
|
|
8
|
+
|
|
9
|
+
Example — nginx:
|
|
10
|
+
{OUT:EVENT_CONNECT:netflow:port_https,
|
|
11
|
+
OUT:EVENT_WRITE:file:log_web,
|
|
12
|
+
IN:EVENT_EXECUTE:subject:webserver,
|
|
13
|
+
IN:EVENT_RECVFROM:netflow:port_https}
|
|
14
|
+
|
|
15
|
+
The label vocabulary is built from all observed signatures across the
|
|
16
|
+
training corpus. Each entity's target is a sparse binary vector over
|
|
17
|
+
this vocabulary, used by model_behavior.py for multi-label BCE training.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import random
|
|
21
|
+
from collections import defaultdict
|
|
22
|
+
from typing import Dict, FrozenSet, List, Optional, Set, Tuple
|
|
23
|
+
|
|
24
|
+
import torch
|
|
25
|
+
|
|
26
|
+
from .entity_classes import classify_entity
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
30
|
+
# SIGNATURE LABEL
|
|
31
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
32
|
+
|
|
33
|
+
# A single behavior label: (direction, event_type, neighbor_node_type, neighbor_class)
|
|
34
|
+
# e.g. ("OUT", "EVENT_WRITE", "file", "log_web")
|
|
35
|
+
BehaviorLabel = Tuple[str, str, str, str]
|
|
36
|
+
|
|
37
|
+
# A behavior signature is a frozenset of such labels
|
|
38
|
+
BehaviorSignature = FrozenSet[BehaviorLabel]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _direction_from_edge(center_node: str, src: str, dst: str) -> str:
|
|
42
|
+
"""Determine if an edge is outgoing or incoming relative to center."""
|
|
43
|
+
if src == center_node:
|
|
44
|
+
return "OUT"
|
|
45
|
+
return "IN"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _neighbor_from_edge(center_node: str, src: str, dst: str) -> str:
|
|
49
|
+
"""Return the neighbor node (the one that isn't the center)."""
|
|
50
|
+
return dst if src == center_node else src
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
54
|
+
# SIGNATURE EXTRACTION FROM GRAPH
|
|
55
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
56
|
+
|
|
57
|
+
def extract_signature_from_neighborhood(
|
|
58
|
+
center_node: str,
|
|
59
|
+
edges: List[Tuple[str, str, str]],
|
|
60
|
+
indexid2msg: dict,
|
|
61
|
+
) -> BehaviorSignature:
|
|
62
|
+
"""Extract a behavior signature from a node's 1-hop neighborhood edges.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
center_node: the entity node ID.
|
|
66
|
+
edges: list of (src, dst, edge_type) tuples from the neighborhood.
|
|
67
|
+
indexid2msg: {node_id: (node_type, label_str)} mapping.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
A frozenset of BehaviorLabel tuples.
|
|
71
|
+
"""
|
|
72
|
+
labels: Set[BehaviorLabel] = set()
|
|
73
|
+
|
|
74
|
+
for src, dst, edge_type in edges:
|
|
75
|
+
direction = _direction_from_edge(center_node, src, dst)
|
|
76
|
+
neighbor = _neighbor_from_edge(center_node, src, dst)
|
|
77
|
+
|
|
78
|
+
if neighbor not in indexid2msg:
|
|
79
|
+
continue
|
|
80
|
+
|
|
81
|
+
neighbor_type, neighbor_label = indexid2msg[neighbor]
|
|
82
|
+
neighbor_class = classify_entity(neighbor_type, neighbor_label)
|
|
83
|
+
|
|
84
|
+
labels.add((direction, edge_type, neighbor_type, neighbor_class))
|
|
85
|
+
|
|
86
|
+
return frozenset(labels)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def extract_full_signature(
|
|
90
|
+
center_node: str,
|
|
91
|
+
sampler,
|
|
92
|
+
indexid2msg: dict,
|
|
93
|
+
filter_noisy: bool = False,
|
|
94
|
+
) -> BehaviorSignature:
|
|
95
|
+
"""Extract the FULL behavior signature from ALL edges of a node.
|
|
96
|
+
|
|
97
|
+
Unlike extract_signature_from_neighborhood (which uses a sampled
|
|
98
|
+
subset), this iterates over all forward and backward adjacency
|
|
99
|
+
entries to build the complete signature. Used for building the
|
|
100
|
+
training dataset (computed once, reused every epoch).
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
center_node: the entity node ID.
|
|
104
|
+
sampler: ProvenanceWalkSampler with forward_adj/backward_adj.
|
|
105
|
+
indexid2msg: {node_id: (node_type, label_str)} mapping.
|
|
106
|
+
filter_noisy: if True, skip noisy edges.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
A frozenset of BehaviorLabel tuples.
|
|
110
|
+
"""
|
|
111
|
+
if filter_noisy:
|
|
112
|
+
from .edge_filter import _is_noisy_file, _is_noisy_process
|
|
113
|
+
|
|
114
|
+
labels: Set[BehaviorLabel] = set()
|
|
115
|
+
|
|
116
|
+
# Forward edges: center → neighbor
|
|
117
|
+
if center_node in sampler.forward_adj:
|
|
118
|
+
for edge in sampler.forward_adj[center_node]:
|
|
119
|
+
neighbor = edge[0]
|
|
120
|
+
edge_type = edge[1]
|
|
121
|
+
|
|
122
|
+
if neighbor not in indexid2msg:
|
|
123
|
+
continue
|
|
124
|
+
|
|
125
|
+
neighbor_type, neighbor_label = indexid2msg[neighbor]
|
|
126
|
+
|
|
127
|
+
if filter_noisy:
|
|
128
|
+
if neighbor_type == "file" and _is_noisy_file(neighbor_label):
|
|
129
|
+
continue
|
|
130
|
+
if neighbor_type == "subject" and _is_noisy_process(neighbor_label):
|
|
131
|
+
continue
|
|
132
|
+
|
|
133
|
+
neighbor_class = classify_entity(neighbor_type, neighbor_label)
|
|
134
|
+
labels.add(("OUT", edge_type, neighbor_type, neighbor_class))
|
|
135
|
+
|
|
136
|
+
# Backward edges: neighbor → center
|
|
137
|
+
if center_node in sampler.backward_adj:
|
|
138
|
+
for edge in sampler.backward_adj[center_node]:
|
|
139
|
+
neighbor = edge[0]
|
|
140
|
+
edge_type = edge[1]
|
|
141
|
+
|
|
142
|
+
if neighbor not in indexid2msg:
|
|
143
|
+
continue
|
|
144
|
+
|
|
145
|
+
neighbor_type, neighbor_label = indexid2msg[neighbor]
|
|
146
|
+
|
|
147
|
+
if filter_noisy:
|
|
148
|
+
if neighbor_type == "file" and _is_noisy_file(neighbor_label):
|
|
149
|
+
continue
|
|
150
|
+
if neighbor_type == "subject" and _is_noisy_process(neighbor_label):
|
|
151
|
+
continue
|
|
152
|
+
|
|
153
|
+
neighbor_class = classify_entity(neighbor_type, neighbor_label)
|
|
154
|
+
labels.add(("IN", edge_type, neighbor_type, neighbor_class))
|
|
155
|
+
|
|
156
|
+
return frozenset(labels)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
160
|
+
# LABEL VOCABULARY
|
|
161
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
162
|
+
|
|
163
|
+
class BehaviorLabelVocab:
|
|
164
|
+
"""Maps behavior labels ↔ integer indices for the multi-label classifier.
|
|
165
|
+
|
|
166
|
+
The vocabulary is built once from all training signatures and frozen.
|
|
167
|
+
Each entity's target is a binary vector of size len(vocab).
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
def __init__(self):
|
|
171
|
+
self.label2idx: Dict[BehaviorLabel, int] = {}
|
|
172
|
+
self.idx2label: Dict[int, BehaviorLabel] = {}
|
|
173
|
+
|
|
174
|
+
def build_from_signatures(self, signatures: Dict[str, BehaviorSignature]):
|
|
175
|
+
"""Build vocabulary from a dict of {entity_key: signature}."""
|
|
176
|
+
all_labels: Set[BehaviorLabel] = set()
|
|
177
|
+
for sig in signatures.values():
|
|
178
|
+
all_labels.update(sig)
|
|
179
|
+
|
|
180
|
+
# Sort for deterministic ordering
|
|
181
|
+
sorted_labels = sorted(all_labels)
|
|
182
|
+
self.label2idx = {label: idx for idx, label in enumerate(sorted_labels)}
|
|
183
|
+
self.idx2label = {idx: label for label, idx in self.label2idx.items()}
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def size(self) -> int:
|
|
187
|
+
return len(self.label2idx)
|
|
188
|
+
|
|
189
|
+
def signature_to_vector(self, signature: BehaviorSignature) -> torch.Tensor:
|
|
190
|
+
"""Convert a signature to a binary vector."""
|
|
191
|
+
vec = torch.zeros(self.size, dtype=torch.float32)
|
|
192
|
+
for label in signature:
|
|
193
|
+
if label in self.label2idx:
|
|
194
|
+
vec[self.label2idx[label]] = 1.0
|
|
195
|
+
return vec
|
|
196
|
+
|
|
197
|
+
def signature_to_indices(self, signature: BehaviorSignature) -> List[int]:
|
|
198
|
+
"""Convert a signature to a list of active label indices."""
|
|
199
|
+
return [self.label2idx[label] for label in signature if label in self.label2idx]
|
|
200
|
+
|
|
201
|
+
def save(self, path: str):
|
|
202
|
+
"""Save vocabulary to a text file."""
|
|
203
|
+
with open(path, "w") as f:
|
|
204
|
+
f.write(f"# BehaviorLabelVocab: {self.size} labels\n")
|
|
205
|
+
for idx in range(self.size):
|
|
206
|
+
direction, event, ntype, nclass = self.idx2label[idx]
|
|
207
|
+
f.write(f"{idx}\t{direction}:{event}:{ntype}:{nclass}\n")
|
|
208
|
+
|
|
209
|
+
def load(self, path: str):
|
|
210
|
+
"""Load vocabulary from a text file."""
|
|
211
|
+
self.label2idx = {}
|
|
212
|
+
self.idx2label = {}
|
|
213
|
+
with open(path, "r") as f:
|
|
214
|
+
for line in f:
|
|
215
|
+
if line.startswith("#"):
|
|
216
|
+
continue
|
|
217
|
+
parts = line.strip().split("\t")
|
|
218
|
+
if len(parts) != 2:
|
|
219
|
+
continue
|
|
220
|
+
idx = int(parts[0])
|
|
221
|
+
label_parts = parts[1].split(":")
|
|
222
|
+
if len(label_parts) != 4:
|
|
223
|
+
continue
|
|
224
|
+
label = tuple(label_parts)
|
|
225
|
+
self.label2idx[label] = idx
|
|
226
|
+
self.idx2label[idx] = label
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
230
|
+
# BATCH-LEVEL UTILITIES
|
|
231
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
232
|
+
|
|
233
|
+
def jaccard_similarity(sig_a: BehaviorSignature, sig_b: BehaviorSignature) -> float:
|
|
234
|
+
"""Compute Jaccard similarity between two behavior signatures."""
|
|
235
|
+
if not sig_a and not sig_b:
|
|
236
|
+
return 1.0
|
|
237
|
+
intersection = len(sig_a & sig_b)
|
|
238
|
+
union = len(sig_a | sig_b)
|
|
239
|
+
if union == 0:
|
|
240
|
+
return 1.0
|
|
241
|
+
return intersection / union
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def batch_jaccard_matrix_from_vectors(target_vecs: torch.Tensor) -> torch.Tensor:
|
|
245
|
+
"""Compute pairwise Jaccard similarity from binary target vectors (vectorized).
|
|
246
|
+
|
|
247
|
+
Args:
|
|
248
|
+
target_vecs: [B, N] binary (0/1) tensor.
|
|
249
|
+
|
|
250
|
+
Returns:
|
|
251
|
+
[B, B] float tensor of Jaccard similarities.
|
|
252
|
+
"""
|
|
253
|
+
vecs = target_vecs.float()
|
|
254
|
+
# intersection[i,j] = sum of min(a_i, b_j) = dot product for binary vecs
|
|
255
|
+
intersection = vecs @ vecs.t()
|
|
256
|
+
# |A| + |B| for each pair
|
|
257
|
+
sizes = vecs.sum(dim=1) # [B]
|
|
258
|
+
union = sizes.unsqueeze(1) + sizes.unsqueeze(0) - intersection
|
|
259
|
+
jaccard = intersection / union.clamp(min=1e-8)
|
|
260
|
+
# Fix 0/0 case (both empty → Jaccard = 1)
|
|
261
|
+
both_empty = (sizes.unsqueeze(1) == 0) & (sizes.unsqueeze(0) == 0)
|
|
262
|
+
jaccard[both_empty] = 1.0
|
|
263
|
+
return jaccard
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
267
|
+
# TRAINING DATASET CONSTRUCTION
|
|
268
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
269
|
+
|
|
270
|
+
def build_behavior_dataset(
|
|
271
|
+
sampler_pairs: list,
|
|
272
|
+
combined_indexid2msg: dict,
|
|
273
|
+
filter_noisy: bool = False,
|
|
274
|
+
min_signature_size: int = 2,
|
|
275
|
+
) -> Tuple[
|
|
276
|
+
Dict[Tuple[str, str], BehaviorSignature],
|
|
277
|
+
Dict[Tuple[str, str], List[Tuple[str, int, List[int]]]],
|
|
278
|
+
BehaviorLabelVocab,
|
|
279
|
+
]:
|
|
280
|
+
"""Build the complete behavior signature dataset from all graph samplers.
|
|
281
|
+
|
|
282
|
+
Extracts the full 1-hop behavior signature for every entity across all
|
|
283
|
+
datasets. Entities with the same (node_type, label_str) are grouped
|
|
284
|
+
together (they share the same signature, since classification is
|
|
285
|
+
text-based).
|
|
286
|
+
|
|
287
|
+
Args:
|
|
288
|
+
sampler_pairs: list of (sampler, ds_indexid2msg) tuples.
|
|
289
|
+
combined_indexid2msg: merged {prefixed_node_id: (type, label)} mapping.
|
|
290
|
+
filter_noisy: whether to skip noisy edges.
|
|
291
|
+
min_signature_size: skip entities with fewer behavior labels.
|
|
292
|
+
|
|
293
|
+
Returns:
|
|
294
|
+
label_to_signature: {(node_type, label_str): frozenset_of_labels}
|
|
295
|
+
label_to_entities: {(node_type, label_str): [(node_id, sampler_idx, token_ids)]}
|
|
296
|
+
Note: token_ids is an empty list here; will be filled by the caller
|
|
297
|
+
after tokenizer is built.
|
|
298
|
+
vocab: BehaviorLabelVocab built from all signatures.
|
|
299
|
+
"""
|
|
300
|
+
# Step 1: For each unique entity label, collect its full signature
|
|
301
|
+
# across ALL graphs (union of signatures from different graph instances)
|
|
302
|
+
label_to_signature: Dict[Tuple[str, str], Set[BehaviorLabel]] = defaultdict(set)
|
|
303
|
+
label_to_entities: Dict[Tuple[str, str], List[Tuple[str, int]]] = defaultdict(list)
|
|
304
|
+
|
|
305
|
+
if filter_noisy:
|
|
306
|
+
from .edge_filter import _is_noisy_file, _is_noisy_process
|
|
307
|
+
|
|
308
|
+
for sidx, (sampler, ds_indexid2msg) in enumerate(sampler_pairs):
|
|
309
|
+
for node in sampler.nodes:
|
|
310
|
+
if node not in ds_indexid2msg:
|
|
311
|
+
continue
|
|
312
|
+
|
|
313
|
+
ntype, nlabel = ds_indexid2msg[node]
|
|
314
|
+
|
|
315
|
+
# Skip noisy center entities
|
|
316
|
+
if filter_noisy:
|
|
317
|
+
if ntype == "file" and _is_noisy_file(nlabel):
|
|
318
|
+
continue
|
|
319
|
+
if ntype == "subject" and _is_noisy_process(nlabel):
|
|
320
|
+
continue
|
|
321
|
+
|
|
322
|
+
label_key = (ntype, nlabel)
|
|
323
|
+
|
|
324
|
+
# Extract full signature (union of all edges)
|
|
325
|
+
sig = extract_full_signature(
|
|
326
|
+
node, sampler, ds_indexid2msg, filter_noisy=filter_noisy
|
|
327
|
+
)
|
|
328
|
+
label_to_signature[label_key].update(sig)
|
|
329
|
+
label_to_entities[label_key].append((node, sidx))
|
|
330
|
+
|
|
331
|
+
# Step 2: Filter by minimum signature size and freeze
|
|
332
|
+
final_signatures = {}
|
|
333
|
+
final_entities = {}
|
|
334
|
+
for label_key, sig_set in label_to_signature.items():
|
|
335
|
+
if len(sig_set) >= min_signature_size:
|
|
336
|
+
final_signatures[label_key] = frozenset(sig_set)
|
|
337
|
+
final_entities[label_key] = label_to_entities[label_key]
|
|
338
|
+
|
|
339
|
+
# Step 3: Build label vocabulary
|
|
340
|
+
vocab = BehaviorLabelVocab()
|
|
341
|
+
vocab.build_from_signatures(final_signatures)
|
|
342
|
+
|
|
343
|
+
return final_signatures, final_entities, vocab
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def dump_entity_classifications(
|
|
347
|
+
sampler_pairs: list,
|
|
348
|
+
filter_noisy: bool = False,
|
|
349
|
+
output_path: str = "entity_classifications.txt",
|
|
350
|
+
):
|
|
351
|
+
"""Dump entity class attributions to a file for analysis.
|
|
352
|
+
|
|
353
|
+
Writes a report with the same format as the standalone classify_entities.py:
|
|
354
|
+
summary table, per-class entity listings, and unclassified entities.
|
|
355
|
+
|
|
356
|
+
Args:
|
|
357
|
+
sampler_pairs: list of (sampler, ds_indexid2msg) tuples.
|
|
358
|
+
filter_noisy: whether to skip noisy entities.
|
|
359
|
+
output_path: where to write the report.
|
|
360
|
+
"""
|
|
361
|
+
from collections import Counter
|
|
362
|
+
|
|
363
|
+
if filter_noisy:
|
|
364
|
+
from .edge_filter import _is_noisy_file, _is_noisy_process
|
|
365
|
+
|
|
366
|
+
# Collect unique entities and classify them
|
|
367
|
+
classified = defaultdict(list) # class -> [(entity_type, label)]
|
|
368
|
+
unclassified = defaultdict(list) # entity_type -> [label]
|
|
369
|
+
entity_type_map = {"subject": "PROC", "file": "FILE", "netflow": "SOCK"}
|
|
370
|
+
|
|
371
|
+
seen = set()
|
|
372
|
+
for _sidx, (sampler, ds_indexid2msg) in enumerate(sampler_pairs):
|
|
373
|
+
for node in sampler.nodes:
|
|
374
|
+
if node not in ds_indexid2msg:
|
|
375
|
+
continue
|
|
376
|
+
|
|
377
|
+
ntype, nlabel = ds_indexid2msg[node]
|
|
378
|
+
|
|
379
|
+
if filter_noisy:
|
|
380
|
+
if ntype == "file" and _is_noisy_file(nlabel):
|
|
381
|
+
continue
|
|
382
|
+
if ntype == "subject" and _is_noisy_process(nlabel):
|
|
383
|
+
continue
|
|
384
|
+
|
|
385
|
+
label_key = (ntype, nlabel)
|
|
386
|
+
if label_key in seen:
|
|
387
|
+
continue
|
|
388
|
+
seen.add(label_key)
|
|
389
|
+
|
|
390
|
+
entity_class = classify_entity(ntype, nlabel)
|
|
391
|
+
display_type = entity_type_map.get(ntype, ntype.upper())
|
|
392
|
+
|
|
393
|
+
if entity_class == "unknown":
|
|
394
|
+
unclassified[display_type].append(nlabel)
|
|
395
|
+
else:
|
|
396
|
+
classified[entity_class].append((display_type, nlabel))
|
|
397
|
+
|
|
398
|
+
# Write report
|
|
399
|
+
total_classified = sum(len(v) for v in classified.values())
|
|
400
|
+
total_unclassified = sum(len(v) for v in unclassified.values())
|
|
401
|
+
total = total_classified + total_unclassified
|
|
402
|
+
|
|
403
|
+
with open(output_path, "w") as f:
|
|
404
|
+
f.write("=" * 80 + "\n")
|
|
405
|
+
f.write("ENTITY CLASSIFICATION REPORT\n")
|
|
406
|
+
f.write("=" * 80 + "\n\n")
|
|
407
|
+
f.write(f"Total unique entities: {total}\n")
|
|
408
|
+
if total > 0:
|
|
409
|
+
f.write(f" Classified: {total_classified} ({100*total_classified/total:.1f}%)\n")
|
|
410
|
+
f.write(f" Unclassified: {total_unclassified} ({100*total_unclassified/total:.1f}%)\n\n")
|
|
411
|
+
else:
|
|
412
|
+
f.write(" No entities found.\n\n")
|
|
413
|
+
|
|
414
|
+
# Per-type breakdown
|
|
415
|
+
type_counts = Counter()
|
|
416
|
+
for items in classified.values():
|
|
417
|
+
for etype, _ in items:
|
|
418
|
+
type_counts[etype] += 1
|
|
419
|
+
type_uncl = {etype: len(items) for etype, items in unclassified.items()}
|
|
420
|
+
for etype in ["PROC", "FILE", "SOCK"]:
|
|
421
|
+
c = type_counts.get(etype, 0)
|
|
422
|
+
u = type_uncl.get(etype, 0)
|
|
423
|
+
t = c + u
|
|
424
|
+
if t > 0:
|
|
425
|
+
f.write(f" {etype}: {c}/{t} classified ({100*c/t:.1f}%)\n")
|
|
426
|
+
f.write("\n")
|
|
427
|
+
|
|
428
|
+
# Summary table sorted by count
|
|
429
|
+
f.write("-" * 60 + "\n")
|
|
430
|
+
f.write(f"{'CLASS':<35} {'COUNT':>8}\n")
|
|
431
|
+
f.write("-" * 60 + "\n")
|
|
432
|
+
for cls in sorted(classified.keys(), key=lambda c: (-len(classified[c]), c)):
|
|
433
|
+
f.write(f"{cls:<35} {len(classified[cls]):>8}\n")
|
|
434
|
+
f.write("-" * 60 + "\n\n")
|
|
435
|
+
|
|
436
|
+
# Detailed per-class listings
|
|
437
|
+
f.write("=" * 80 + "\n")
|
|
438
|
+
f.write("DETAILED CLASSIFICATIONS\n")
|
|
439
|
+
f.write("=" * 80 + "\n\n")
|
|
440
|
+
|
|
441
|
+
for cls in sorted(classified.keys()):
|
|
442
|
+
items = classified[cls]
|
|
443
|
+
f.write(f"\n--- {cls} ({len(items)} entities) ---\n")
|
|
444
|
+
for etype, name in sorted(items, key=lambda x: (x[0], x[1])):
|
|
445
|
+
f.write(f" [{etype}] {name}\n")
|
|
446
|
+
|
|
447
|
+
# Unclassified
|
|
448
|
+
f.write("\n\n" + "=" * 80 + "\n")
|
|
449
|
+
f.write("UNCLASSIFIED ENTITIES\n")
|
|
450
|
+
f.write("=" * 80 + "\n\n")
|
|
451
|
+
|
|
452
|
+
for etype in ["PROC", "FILE", "SOCK"]:
|
|
453
|
+
items = unclassified.get(etype, [])
|
|
454
|
+
f.write(f"\n--- Unclassified {etype} ({len(items)} entities) ---\n")
|
|
455
|
+
for name in sorted(items):
|
|
456
|
+
f.write(f" [{etype}] {name}\n")
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def dump_behavior_signatures(
|
|
460
|
+
label_to_signature: Dict[Tuple[str, str], BehaviorSignature],
|
|
461
|
+
output_path: str = "behavior_signatures.txt",
|
|
462
|
+
):
|
|
463
|
+
"""Dump every entity's behavior signature in human-readable format.
|
|
464
|
+
|
|
465
|
+
For each entity, lists its class and all signature labels grouped
|
|
466
|
+
by direction (OUT / IN), showing the event type, neighbor entity
|
|
467
|
+
type, and neighbor class for each interaction.
|
|
468
|
+
|
|
469
|
+
Args:
|
|
470
|
+
label_to_signature: {(node_type, label_str): frozenset_of_labels}
|
|
471
|
+
output_path: where to write the report.
|
|
472
|
+
"""
|
|
473
|
+
from collections import Counter
|
|
474
|
+
|
|
475
|
+
entity_type_map = {"subject": "PROC", "file": "FILE", "netflow": "SOCK"}
|
|
476
|
+
|
|
477
|
+
# Compute stats
|
|
478
|
+
sig_sizes = [len(sig) for sig in label_to_signature.values()]
|
|
479
|
+
all_labels_flat: Set[BehaviorLabel] = set()
|
|
480
|
+
for sig in label_to_signature.values():
|
|
481
|
+
all_labels_flat.update(sig)
|
|
482
|
+
|
|
483
|
+
# Count how often each label appears across entities
|
|
484
|
+
label_freq = Counter()
|
|
485
|
+
for sig in label_to_signature.values():
|
|
486
|
+
for lbl in sig:
|
|
487
|
+
label_freq[lbl] += 1
|
|
488
|
+
|
|
489
|
+
with open(output_path, "w") as f:
|
|
490
|
+
f.write("=" * 90 + "\n")
|
|
491
|
+
f.write("BEHAVIOR SIGNATURE REPORT\n")
|
|
492
|
+
f.write("=" * 90 + "\n\n")
|
|
493
|
+
f.write(f"Entities with signatures: {len(label_to_signature):,}\n")
|
|
494
|
+
f.write(f"Unique behavior labels: {len(all_labels_flat):,}\n")
|
|
495
|
+
if sig_sizes:
|
|
496
|
+
f.write(f"Signature size: min={min(sig_sizes)}, "
|
|
497
|
+
f"median={sorted(sig_sizes)[len(sig_sizes)//2]}, "
|
|
498
|
+
f"max={max(sig_sizes)}, "
|
|
499
|
+
f"mean={sum(sig_sizes)/len(sig_sizes):.1f}\n")
|
|
500
|
+
f.write("\n")
|
|
501
|
+
|
|
502
|
+
# Global label frequency table
|
|
503
|
+
f.write("-" * 90 + "\n")
|
|
504
|
+
f.write(f"{'BEHAVIOR LABEL':<65} {'ENTITIES':>8}\n")
|
|
505
|
+
f.write("-" * 90 + "\n")
|
|
506
|
+
for lbl, count in label_freq.most_common():
|
|
507
|
+
direction, event, ntype, nclass = lbl
|
|
508
|
+
f.write(f" {direction}:{event}:{ntype}:{nclass:<45} {count:>8}\n")
|
|
509
|
+
f.write("-" * 90 + "\n\n")
|
|
510
|
+
|
|
511
|
+
# Per-entity signatures
|
|
512
|
+
f.write("=" * 90 + "\n")
|
|
513
|
+
f.write("PER-ENTITY SIGNATURES\n")
|
|
514
|
+
f.write("=" * 90 + "\n")
|
|
515
|
+
|
|
516
|
+
# Sort by entity type then label
|
|
517
|
+
sorted_entities = sorted(
|
|
518
|
+
label_to_signature.items(),
|
|
519
|
+
key=lambda x: (x[0][0], x[0][1]),
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
for (ntype, nlabel), sig in sorted_entities:
|
|
523
|
+
display_type = entity_type_map.get(ntype, ntype.upper())
|
|
524
|
+
entity_class = classify_entity(ntype, nlabel)
|
|
525
|
+
|
|
526
|
+
f.write(f"\n--- [{display_type}] {nlabel} ---\n")
|
|
527
|
+
f.write(f" class: {entity_class}\n")
|
|
528
|
+
f.write(f" signature size: {len(sig)}\n")
|
|
529
|
+
|
|
530
|
+
# Group by direction
|
|
531
|
+
out_labels = sorted(
|
|
532
|
+
(e, nt, nc) for d, e, nt, nc in sig if d == "OUT"
|
|
533
|
+
)
|
|
534
|
+
in_labels = sorted(
|
|
535
|
+
(e, nt, nc) for d, e, nt, nc in sig if d == "IN"
|
|
536
|
+
)
|
|
537
|
+
|
|
538
|
+
if out_labels:
|
|
539
|
+
f.write(f" OUT ({len(out_labels)}):\n")
|
|
540
|
+
for event, neighbor_type, neighbor_class in out_labels:
|
|
541
|
+
nt_display = entity_type_map.get(neighbor_type, neighbor_type)
|
|
542
|
+
f.write(f" → {event:<25} [{nt_display}] {neighbor_class}\n")
|
|
543
|
+
|
|
544
|
+
if in_labels:
|
|
545
|
+
f.write(f" IN ({len(in_labels)}):\n")
|
|
546
|
+
for event, neighbor_type, neighbor_class in in_labels:
|
|
547
|
+
nt_display = entity_type_map.get(neighbor_type, neighbor_type)
|
|
548
|
+
f.write(f" ← {event:<25} [{nt_display}] {neighbor_class}\n")
|