pidsmaker 5.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.
- pidsmaker/__init__.py +1 -0
- pidsmaker/cli.py +81 -0
- pidsmaker/config/__init__.py +2 -0
- pidsmaker/config/config.py +2100 -0
- pidsmaker/config/pipeline.py +1824 -0
- pidsmaker/config/schemas.py +1032 -0
- pidsmaker/datasets.py +323 -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 +255 -0
- pidsmaker/detection/evaluation_methods/evaluation_utils.py +1788 -0
- pidsmaker/detection/evaluation_methods/host_two_stage_evaluation.py +115 -0
- pidsmaker/detection/evaluation_methods/node_evaluation.py +459 -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 +456 -0
- pidsmaker/detection/evaluation_methods/tw_evaluation.py +93 -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 +287 -0
- pidsmaker/detection/training_methods/ocrapt_early_stop.py +165 -0
- pidsmaker/detection/training_methods/threatrace_training.py +168 -0
- pidsmaker/detection/training_methods/training_loop.py +383 -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 +30 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_TRW.py +65 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_alacarte.py +14 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_doc2vec.py +53 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_fasttext.py +37 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_flash.py +69 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_graph2vec.py +84 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_ocrapt_features.py +95 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_pretrained.py +1728 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_word2vec.py +55 -0
- pidsmaker/featurization/featurization_methods/__init__.py +0 -0
- pidsmaker/featurization/featurization_methods/build_trw.py +66 -0
- pidsmaker/featurization/featurization_methods/featurization_alacarte.py +747 -0
- pidsmaker/featurization/featurization_methods/featurization_doc2vec.py +98 -0
- pidsmaker/featurization/featurization_methods/featurization_fasttext.py +74 -0
- pidsmaker/featurization/featurization_methods/featurization_flash.py +201 -0
- pidsmaker/featurization/featurization_methods/featurization_graph2vec.py +242 -0
- pidsmaker/featurization/featurization_methods/featurization_trw.py +114 -0
- pidsmaker/featurization/featurization_methods/featurization_word2vec.py +89 -0
- pidsmaker/featurization/featurization_utils.py +275 -0
- pidsmaker/featurization/utils/build_random_walks.py +66 -0
- pidsmaker/featurization/utils/trw.py +203 -0
- pidsmaker/hetero.py +81 -0
- pidsmaker/losses.py +170 -0
- pidsmaker/main.py +478 -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 +825 -0
- pidsmaker/preprocessing/build_graph_methods/build_magic_graphs.py +216 -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 +1427 -0
- pidsmaker/pretrained/embedding_generator.py +252 -0
- pidsmaker/pretrained/finetune.py +1434 -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 +275 -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/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 +126 -0
- pidsmaker/resources/config/orthrus_fixed.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/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/tasks/__init__.py +10 -0
- pidsmaker/tasks/batching.py +47 -0
- pidsmaker/tasks/construction.py +31 -0
- pidsmaker/tasks/evaluation.py +241 -0
- pidsmaker/tasks/feat_inference.py +413 -0
- pidsmaker/tasks/featurization.py +43 -0
- pidsmaker/tasks/training.py +17 -0
- pidsmaker/tasks/transformation.py +306 -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/console.py +282 -0
- pidsmaker/utils/data_utils.py +1742 -0
- pidsmaker/utils/database.py +150 -0
- pidsmaker/utils/dataset_utils.py +413 -0
- pidsmaker/utils/dataset_writer.py +570 -0
- pidsmaker/utils/graph_store.py +634 -0
- pidsmaker/utils/labelling.py +445 -0
- pidsmaker/utils/loss_files.py +193 -0
- pidsmaker/utils/process_tags.py +44 -0
- pidsmaker/utils/utils.py +712 -0
- pidsmaker/vizgen/__init__.py +1 -0
- pidsmaker/vizgen/backfill_manifests.py +100 -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-5.0.0.dist-info/METADATA +597 -0
- pidsmaker-5.0.0.dist-info/RECORD +339 -0
- pidsmaker-5.0.0.dist-info/WHEEL +5 -0
- pidsmaker-5.0.0.dist-info/entry_points.txt +2 -0
- pidsmaker-5.0.0.dist-info/licenses/LICENSE +201 -0
- pidsmaker-5.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"""Edge-level evaluation: each test edge is scored by its loss.
|
|
2
|
+
|
|
3
|
+
Test sets of network datasets have tens of millions of edges, so the predictions are kept as
|
|
4
|
+
numpy arrays, and the edges are given to the metrics as a lazy sequence of (src, dst, time,
|
|
5
|
+
edge_type) tuples (`EdgeTuples`): tuples are only built for the edges the metrics need
|
|
6
|
+
(malicious edges, top-ranked edges, ties).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
from collections.abc import Sequence
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
import pandas as pd
|
|
14
|
+
import torch
|
|
15
|
+
|
|
16
|
+
from pidsmaker.detection.evaluation_methods.evaluation_utils import (
|
|
17
|
+
classifier_evaluation,
|
|
18
|
+
compute_discrimination_score,
|
|
19
|
+
compute_discrimination_tp,
|
|
20
|
+
get_detected_tps,
|
|
21
|
+
get_metrics_if_all_attacks_detected,
|
|
22
|
+
get_threshold,
|
|
23
|
+
plot_detected_attacks_vs_precision,
|
|
24
|
+
plot_discrimination_metric,
|
|
25
|
+
plot_scores_neat,
|
|
26
|
+
plot_scores_with_paths_edge_level,
|
|
27
|
+
transform_attack2nodes_to_node2attacks,
|
|
28
|
+
)
|
|
29
|
+
from pidsmaker.utils.dataset_utils import get_rel2id_considering_triplets
|
|
30
|
+
from pidsmaker.utils.labelling import (
|
|
31
|
+
get_attack_to_mal_edges,
|
|
32
|
+
get_ground_truth_edges,
|
|
33
|
+
ground_truth_attacks,
|
|
34
|
+
has_event_labels,
|
|
35
|
+
)
|
|
36
|
+
from pidsmaker.utils.loss_files import compact_int_columns, read_losses
|
|
37
|
+
from pidsmaker.utils.utils import listdir_sorted, log, log_tqdm
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class EdgeTuples(Sequence):
|
|
41
|
+
"""The (src, dst, time, edge_type) tuples of the test edges, the edge identifiers of the
|
|
42
|
+
ground truth (node IDs as strings, edge type as its name), built on access."""
|
|
43
|
+
|
|
44
|
+
def __init__(self, src, dst, time, edge_type, type_names):
|
|
45
|
+
self.src, self.dst, self.time, self.edge_type = src, dst, time, edge_type
|
|
46
|
+
self.type_names = type_names
|
|
47
|
+
|
|
48
|
+
def __len__(self):
|
|
49
|
+
return len(self.src)
|
|
50
|
+
|
|
51
|
+
def __getitem__(self, i):
|
|
52
|
+
if isinstance(i, slice):
|
|
53
|
+
return self.take(np.arange(len(self))[i])
|
|
54
|
+
return self.take([i])[0]
|
|
55
|
+
|
|
56
|
+
def take(self, idx):
|
|
57
|
+
"""Tuples of the edges at the positions `idx`."""
|
|
58
|
+
idx = np.asarray(idx, dtype=np.int64)
|
|
59
|
+
names = self.type_names
|
|
60
|
+
return [
|
|
61
|
+
(str(s), str(d), t, names[e])
|
|
62
|
+
for s, d, t, e in zip(
|
|
63
|
+
self.src[idx].tolist(),
|
|
64
|
+
self.dst[idx].tolist(),
|
|
65
|
+
self.time[idx].tolist(),
|
|
66
|
+
self.edge_type[idx].tolist(),
|
|
67
|
+
)
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
def candidates(self, edge_tuples):
|
|
71
|
+
"""Positions of the edges whose source is the source of one of `edge_tuples`: a superset
|
|
72
|
+
of the edges equal to one of them (sources are compared as integers, without building
|
|
73
|
+
the tuples of all the edges)."""
|
|
74
|
+
srcs = set()
|
|
75
|
+
for edge in edge_tuples:
|
|
76
|
+
try:
|
|
77
|
+
srcs.add(int(edge[0]))
|
|
78
|
+
except (TypeError, ValueError):
|
|
79
|
+
pass # not the string of an integer: cannot be the source of an edge
|
|
80
|
+
return np.flatnonzero(np.isin(self.src, np.array(sorted(srcs), dtype=self.src.dtype)))
|
|
81
|
+
|
|
82
|
+
def attack_hits(self, edge2attack):
|
|
83
|
+
"""Same as `evaluation_utils.attack_hits`, checking only the candidate edges."""
|
|
84
|
+
idx = self.candidates(edge2attack.keys())
|
|
85
|
+
positions, attacks = [], []
|
|
86
|
+
for i, edge in zip(idx.tolist(), self.take(idx)):
|
|
87
|
+
found = edge2attack.get(edge)
|
|
88
|
+
if found is not None:
|
|
89
|
+
positions.append(i)
|
|
90
|
+
attacks.append(found)
|
|
91
|
+
return np.array(positions, dtype=np.int64), attacks
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def get_edge_predictions(val_tw_path, test_tw_path, cfg, **kwargs):
|
|
95
|
+
"""(scores, y_true, y_hat, edges, threshold, loss columns) of the test edges: arrays, and
|
|
96
|
+
the edges as `EdgeTuples`."""
|
|
97
|
+
threshold_method = cfg.evaluation.edge_evaluation.threshold_method
|
|
98
|
+
alpha = getattr(cfg.evaluation.edge_evaluation, "alpha", 1.0) or 1.0
|
|
99
|
+
|
|
100
|
+
if threshold_method == "magic":
|
|
101
|
+
thr = get_threshold(test_tw_path, threshold_method, alpha)
|
|
102
|
+
else:
|
|
103
|
+
thr = get_threshold(val_tw_path, threshold_method, alpha)
|
|
104
|
+
|
|
105
|
+
filelist = listdir_sorted(test_tw_path)
|
|
106
|
+
dfs = [
|
|
107
|
+
read_losses(os.path.join(test_tw_path, file))
|
|
108
|
+
for file in log_tqdm(filelist, desc="Compute edge labels")
|
|
109
|
+
]
|
|
110
|
+
columns = ("srcnode", "dstnode", "loss", "time", "edge_type")
|
|
111
|
+
df = pd.concat(dfs, ignore_index=True) if dfs else pd.DataFrame({c: [] for c in columns})
|
|
112
|
+
|
|
113
|
+
edge_type = df["edge_type"].to_numpy()
|
|
114
|
+
type_map = get_rel2id_considering_triplets(cfg)
|
|
115
|
+
edges = EdgeTuples(
|
|
116
|
+
df["srcnode"].to_numpy(),
|
|
117
|
+
df["dstnode"].to_numpy(),
|
|
118
|
+
df["time"].to_numpy(),
|
|
119
|
+
edge_type,
|
|
120
|
+
{t: type_map[t] for t in np.unique(edge_type).tolist()},
|
|
121
|
+
)
|
|
122
|
+
scores = df["loss"].to_numpy(dtype=np.float64)
|
|
123
|
+
y_hat = (scores > thr).astype(np.int8)
|
|
124
|
+
|
|
125
|
+
if "y" in df.columns:
|
|
126
|
+
# Event-level labels carried by the edges (datasets with labelled events)
|
|
127
|
+
y_true = (df["y"].to_numpy() > 0).astype(np.int8)
|
|
128
|
+
else:
|
|
129
|
+
y_true = np.zeros(len(df), dtype=np.int8)
|
|
130
|
+
ground_truth_edges = get_ground_truth_edges(cfg)
|
|
131
|
+
# CSV-based labels use 3-tuples (no timestamp), DB-based use 4-tuples
|
|
132
|
+
idx = edges.candidates(ground_truth_edges)
|
|
133
|
+
for i, edge in zip(idx.tolist(), edges.take(idx)):
|
|
134
|
+
if edge in ground_truth_edges or (edge[0], edge[1], edge[3]) in ground_truth_edges:
|
|
135
|
+
y_true[i] = 1
|
|
136
|
+
return scores, y_true, y_hat, edges, thr, df
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def main(val_tw_path, test_tw_path, model_epoch_dir, cfg, tw_to_malicious_nodes, **kwargs):
|
|
140
|
+
scores, y_truth, y_preds, edges, thr, losses = get_edge_predictions(
|
|
141
|
+
val_tw_path, test_tw_path, cfg, **kwargs
|
|
142
|
+
)
|
|
143
|
+
if has_event_labels(cfg):
|
|
144
|
+
# Edges carry their labels (`y`): malicious edges are assigned to the attack whose time
|
|
145
|
+
# window contains them. This also holds when edges are merged (e.g. `merge_edges`), whose
|
|
146
|
+
# times and types may differ from those of the labelled events of the database.
|
|
147
|
+
attacks = ground_truth_attacks(cfg)
|
|
148
|
+
attack_to_mal_edges = {i: set() for i in range(len(attacks))}
|
|
149
|
+
for edge in edges.take(np.flatnonzero(y_truth)):
|
|
150
|
+
t = int(edge[2])
|
|
151
|
+
i = next((i for i, (_, s, e) in enumerate(attacks) if s <= t <= e), 0)
|
|
152
|
+
attack_to_mal_edges[i].add(edge)
|
|
153
|
+
log(f"Found {int(y_truth.sum())} malicious edges in the test set")
|
|
154
|
+
else:
|
|
155
|
+
attack_to_mal_edges = get_attack_to_mal_edges(cfg)
|
|
156
|
+
log(
|
|
157
|
+
f"Found {int(y_truth.sum())} / {sum(len(edges) for edges in attack_to_mal_edges.values())} malicious edges"
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
edge2attack = transform_attack2nodes_to_node2attacks(attack_to_mal_edges)
|
|
161
|
+
|
|
162
|
+
out_dir = cfg.evaluation._precision_recall_dir
|
|
163
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
164
|
+
|
|
165
|
+
# Save edge-level scores (consistent with node_evaluation)
|
|
166
|
+
edge_records = pd.DataFrame(
|
|
167
|
+
{
|
|
168
|
+
"srcnode": edges.src,
|
|
169
|
+
"dstnode": edges.dst,
|
|
170
|
+
"loss": scores,
|
|
171
|
+
"time": edges.time,
|
|
172
|
+
"edge_type": edges.edge_type,
|
|
173
|
+
"src_is_malicious": y_truth.astype(np.int64),
|
|
174
|
+
"dst_is_malicious": y_truth.astype(np.int64),
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
edge_scores_file = os.path.join(out_dir, f"edge_scores_{model_epoch_dir}.pkl")
|
|
178
|
+
torch.save(compact_int_columns(edge_records), edge_scores_file)
|
|
179
|
+
del edge_records, losses
|
|
180
|
+
|
|
181
|
+
adp_img_file = os.path.join(out_dir, f"adp_curve_{model_epoch_dir}.png")
|
|
182
|
+
scores_img_file = os.path.join(out_dir, f"scores_{model_epoch_dir}.png")
|
|
183
|
+
neat_scores_img_file = os.path.join(out_dir, f"neat_scores_{model_epoch_dir}.svg")
|
|
184
|
+
discrim_img_file = os.path.join(out_dir, f"discrim_curve_{model_epoch_dir}.png")
|
|
185
|
+
|
|
186
|
+
save_figures = cfg.evaluation.save_figures is not False # unset: saved
|
|
187
|
+
adp_score = plot_detected_attacks_vs_precision(
|
|
188
|
+
scores, edges, edge2attack, y_truth, adp_img_file if save_figures else None
|
|
189
|
+
)
|
|
190
|
+
discrim_scores = compute_discrimination_score(scores, edges, edge2attack, y_truth)
|
|
191
|
+
discrim_tp = compute_discrimination_tp(scores, edges, edge2attack, y_truth)
|
|
192
|
+
if save_figures:
|
|
193
|
+
# The plots iterate over all the edges
|
|
194
|
+
scores_list, y_list, edges_list = scores.tolist(), y_truth.tolist(), list(edges)
|
|
195
|
+
plot_discrimination_metric(scores_list, y_list, discrim_img_file)
|
|
196
|
+
plot_scores_with_paths_edge_level(
|
|
197
|
+
scores_list,
|
|
198
|
+
y_list,
|
|
199
|
+
edges_list,
|
|
200
|
+
tw_to_malicious_nodes,
|
|
201
|
+
edge2attack,
|
|
202
|
+
scores_img_file,
|
|
203
|
+
cfg,
|
|
204
|
+
thr,
|
|
205
|
+
)
|
|
206
|
+
plot_scores_neat(scores_list, y_list, edges_list, edge2attack, neat_scores_img_file, thr)
|
|
207
|
+
del scores_list, y_list, edges_list
|
|
208
|
+
stats = classifier_evaluation(y_truth, y_preds, scores)
|
|
209
|
+
|
|
210
|
+
fps, tps, precision, recall = get_metrics_if_all_attacks_detected(
|
|
211
|
+
scores, edges, attack_to_mal_edges
|
|
212
|
+
)
|
|
213
|
+
stats["fps_if_all_attacks_detected"] = fps
|
|
214
|
+
stats["tps_if_all_attacks_detected"] = tps
|
|
215
|
+
stats["precision_if_all_attacks_detected"] = precision
|
|
216
|
+
stats["recall_if_all_attacks_detected"] = recall
|
|
217
|
+
|
|
218
|
+
stats["adp_score"] = round(adp_score, 3)
|
|
219
|
+
stats["threshold"] = thr
|
|
220
|
+
|
|
221
|
+
for k, v in discrim_scores.items():
|
|
222
|
+
stats[k] = round(v, 4)
|
|
223
|
+
|
|
224
|
+
attack2tps = get_detected_tps(scores, edges, edge2attack, y_truth, cfg)
|
|
225
|
+
for attack, detected_tps in attack2tps.items():
|
|
226
|
+
stats[f"tps_{attack}"] = str(detected_tps)
|
|
227
|
+
|
|
228
|
+
stats = {**stats, **discrim_tp}
|
|
229
|
+
|
|
230
|
+
# Edges as a structured array (src, dst, time, edge_type ID), indexable like tuples; the
|
|
231
|
+
# names of the edge type IDs are in `edge_type_names`
|
|
232
|
+
edge_array = np.empty(
|
|
233
|
+
len(edges),
|
|
234
|
+
dtype=[("src", np.int64), ("dst", np.int64), ("time", np.int64), ("edge_type", np.int64)],
|
|
235
|
+
)
|
|
236
|
+
edge_array["src"], edge_array["dst"] = edges.src, edges.dst
|
|
237
|
+
edge_array["time"], edge_array["edge_type"] = edges.time, edges.edge_type
|
|
238
|
+
scores_file = os.path.join(out_dir, f"scores_{model_epoch_dir}.pkl")
|
|
239
|
+
torch.save(
|
|
240
|
+
{
|
|
241
|
+
"pred_scores": scores,
|
|
242
|
+
"y_preds": y_preds,
|
|
243
|
+
"y_truth": y_truth,
|
|
244
|
+
"edges": edge_array,
|
|
245
|
+
"edge_type_names": edges.type_names,
|
|
246
|
+
"edge2attack": edge2attack,
|
|
247
|
+
},
|
|
248
|
+
scores_file,
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
stats["scores_file"] = scores_file
|
|
252
|
+
if save_figures:
|
|
253
|
+
stats["neat_scores_img_file"] = neat_scores_img_file
|
|
254
|
+
|
|
255
|
+
return stats
|