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
pidsmaker/main.py
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
"""PIDSMaker main entry point.
|
|
2
|
+
|
|
3
|
+
This module orchestrates the complete PIDS pipeline execution across three modes:
|
|
4
|
+
1. Standard mode: Single run through all pipeline tasks
|
|
5
|
+
2. Uncertainty mode: Multiple runs for uncertainty quantification (MC Dropout, deep ensemble, hyperparameter sensitivity)
|
|
6
|
+
3. Tuning mode: Hyperparameter sweeps using Weights & Biases
|
|
7
|
+
|
|
8
|
+
The pipeline executes 8 tasks sequentially: construction → transformation →
|
|
9
|
+
featurization → feat_inference → batching → training → evaluation → triage
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# First: sets the CPU threads before torch is imported (see pidsmaker/__init__.py)
|
|
13
|
+
import pidsmaker # noqa: F401
|
|
14
|
+
|
|
15
|
+
# isort: split
|
|
16
|
+
import argparse
|
|
17
|
+
import copy
|
|
18
|
+
import os
|
|
19
|
+
import shutil
|
|
20
|
+
import time
|
|
21
|
+
from collections import defaultdict
|
|
22
|
+
|
|
23
|
+
import torch
|
|
24
|
+
import wandb
|
|
25
|
+
|
|
26
|
+
from pidsmaker.config import (
|
|
27
|
+
get_runtime_required_args,
|
|
28
|
+
get_uncertainty_methods_to_run,
|
|
29
|
+
get_yml_cfg,
|
|
30
|
+
set_task_to_done,
|
|
31
|
+
update_task_paths_to_restart,
|
|
32
|
+
)
|
|
33
|
+
from pidsmaker.experiments.tuning import (
|
|
34
|
+
fuse_cfg_with_sweep_cfg,
|
|
35
|
+
get_tuning_sweep_cfg,
|
|
36
|
+
)
|
|
37
|
+
from pidsmaker.experiments.uncertainty import (
|
|
38
|
+
avg_std_metrics,
|
|
39
|
+
fuse_hyperparameter_metrics,
|
|
40
|
+
max_metrics,
|
|
41
|
+
min_metrics,
|
|
42
|
+
prepare_for_deep_ensemble,
|
|
43
|
+
push_best_files_to_wandb,
|
|
44
|
+
update_cfg_for_uncertainty_exp,
|
|
45
|
+
)
|
|
46
|
+
from pidsmaker.utils.loss_files import prune_non_best_epochs
|
|
47
|
+
from pidsmaker.tasks import (
|
|
48
|
+
batching,
|
|
49
|
+
construction,
|
|
50
|
+
evaluation,
|
|
51
|
+
feat_inference,
|
|
52
|
+
featurization,
|
|
53
|
+
training,
|
|
54
|
+
transformation,
|
|
55
|
+
triage,
|
|
56
|
+
)
|
|
57
|
+
from pidsmaker.utils.utils import log, remove_underscore_keys, set_seed, warn_if_low_memory
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def get_task_to_module(cfg):
|
|
61
|
+
"""Map task names to their corresponding modules and task paths.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
cfg: Configuration object containing task paths
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
dict: Mapping of task names to module and task_path information
|
|
68
|
+
"""
|
|
69
|
+
return {
|
|
70
|
+
"construction": {
|
|
71
|
+
"module": construction,
|
|
72
|
+
"task_path": cfg.construction._task_path,
|
|
73
|
+
},
|
|
74
|
+
"transformation": {
|
|
75
|
+
"module": transformation,
|
|
76
|
+
"task_path": cfg.transformation._task_path,
|
|
77
|
+
},
|
|
78
|
+
"featurization": {
|
|
79
|
+
"module": featurization,
|
|
80
|
+
"task_path": cfg.featurization._task_path,
|
|
81
|
+
},
|
|
82
|
+
"feat_inference": {
|
|
83
|
+
"module": feat_inference,
|
|
84
|
+
"task_path": cfg.feat_inference._task_path,
|
|
85
|
+
},
|
|
86
|
+
"batching": {
|
|
87
|
+
"module": batching,
|
|
88
|
+
"task_path": cfg.batching._task_path,
|
|
89
|
+
},
|
|
90
|
+
"training": {
|
|
91
|
+
"module": training,
|
|
92
|
+
"task_path": cfg.training._task_path,
|
|
93
|
+
},
|
|
94
|
+
"evaluation": {
|
|
95
|
+
"module": evaluation,
|
|
96
|
+
"task_path": cfg.evaluation._task_path,
|
|
97
|
+
},
|
|
98
|
+
"triage": {
|
|
99
|
+
"module": triage,
|
|
100
|
+
"task_path": cfg.triage._task_path,
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def clean_cfg_for_log(cfg):
|
|
106
|
+
"""Clean configuration for W&B logging by removing internal keys.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
cfg: Configuration object
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
dict: Cleaned configuration with underscore keys removed except specified ones
|
|
113
|
+
"""
|
|
114
|
+
return remove_underscore_keys(
|
|
115
|
+
dict(cfg), keys_to_keep=["_task_path", "_exp", "_tuning_file_path"]
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def main(cfg, project=None, exp=None, sweep_id=None, **kwargs):
|
|
120
|
+
"""Main execution function for PIDSMaker pipeline.
|
|
121
|
+
|
|
122
|
+
Orchestrates pipeline execution across three modes: standard, uncertainty, and tuning.
|
|
123
|
+
Handles task scheduling, restart logic, and metric collection.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
cfg: Configuration object with all pipeline settings
|
|
127
|
+
project: W&B project name for logging
|
|
128
|
+
exp: Experiment name for tracking
|
|
129
|
+
sweep_id: W&B sweep ID for tuning mode (optional)
|
|
130
|
+
**kwargs: Additional keyword arguments
|
|
131
|
+
"""
|
|
132
|
+
set_seed(cfg)
|
|
133
|
+
warn_if_low_memory()
|
|
134
|
+
|
|
135
|
+
def run_task(task: str, cfg, method=None, iteration=None):
|
|
136
|
+
"""Execute a single pipeline task with restart logic and timing.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
task: Task name (construction, transformation, featurization, etc.)
|
|
140
|
+
cfg: Configuration object
|
|
141
|
+
method: Uncertainty method name (for deep_ensemble restart logic)
|
|
142
|
+
iteration: Current iteration number (for uncertainty experiments)
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
dict: Contains 'time' (execution time) and 'return' (task result)
|
|
146
|
+
"""
|
|
147
|
+
start = time.time()
|
|
148
|
+
return_value = None
|
|
149
|
+
|
|
150
|
+
# Deep ensemble mode modifies cfg so that it restarts some tasks
|
|
151
|
+
if method == "deep_ensemble":
|
|
152
|
+
should_restart, cfg = prepare_for_deep_ensemble(cfg, iteration)
|
|
153
|
+
|
|
154
|
+
# This updates all task paths if needed
|
|
155
|
+
else:
|
|
156
|
+
should_restart = update_task_paths_to_restart(cfg)
|
|
157
|
+
|
|
158
|
+
task_to_module = get_task_to_module(cfg)
|
|
159
|
+
module = task_to_module[task]["module"]
|
|
160
|
+
task_path = task_to_module[task]["task_path"]
|
|
161
|
+
log(f"Task {task}: {task_path}")
|
|
162
|
+
|
|
163
|
+
# In uncertainty experiments, the metrics of each iteration are required, so the
|
|
164
|
+
# evaluation is computed again even if the trained model is already on disk
|
|
165
|
+
rerun_for_metrics = method is not None and task == "evaluation"
|
|
166
|
+
if should_restart[task] or rerun_for_metrics:
|
|
167
|
+
return_value = module.main(cfg)
|
|
168
|
+
set_task_to_done(task_path)
|
|
169
|
+
|
|
170
|
+
return {"time": time.time() - start, "return": return_value}
|
|
171
|
+
|
|
172
|
+
def run_pipeline(cfg, method=None, iteration=None):
|
|
173
|
+
"""Execute complete pipeline: all 8 tasks from construction to triage.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
cfg: Configuration object
|
|
177
|
+
method: Uncertainty method name (optional, for restart logic)
|
|
178
|
+
iteration: Current iteration number (optional, for deep ensemble)
|
|
179
|
+
|
|
180
|
+
Returns:
|
|
181
|
+
tuple: (metrics dict from evaluation, times dict with task execution times)
|
|
182
|
+
"""
|
|
183
|
+
tasks = get_task_to_module(cfg).keys()
|
|
184
|
+
task_results = {task: run_task(task, cfg, method, iteration) for task in tasks}
|
|
185
|
+
|
|
186
|
+
metrics = task_results["evaluation"]["return"] or {}
|
|
187
|
+
metrics = {
|
|
188
|
+
**metrics,
|
|
189
|
+
"val_score": task_results["training"]["return"],
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
times = {
|
|
193
|
+
f"time_{task}": round(results["time"], 2) for task, results in task_results.items()
|
|
194
|
+
}
|
|
195
|
+
log("Task times (s): " + ", ".join(f"{k[5:]}={v}" for k, v in times.items()))
|
|
196
|
+
|
|
197
|
+
if getattr(cfg, "_keep_best_epoch_only", False):
|
|
198
|
+
prune_non_best_epochs(cfg, metrics)
|
|
199
|
+
return metrics, times
|
|
200
|
+
|
|
201
|
+
def run_pipeline_with_experiments(cfg):
|
|
202
|
+
"""Run pipeline with experiment mode handling (standard, uncertainty, or tuning).
|
|
203
|
+
|
|
204
|
+
Execution modes:
|
|
205
|
+
- Standard: Single pipeline run with metrics logged to W&B
|
|
206
|
+
- Uncertainty: Multiple runs for MC Dropout, deep ensemble, or hyperparameter sensitivity
|
|
207
|
+
with averaged/min/max statistics computed and logged
|
|
208
|
+
|
|
209
|
+
Args:
|
|
210
|
+
cfg: Configuration object with experiment settings
|
|
211
|
+
"""
|
|
212
|
+
# Standard behavior: we run the whole pipeline
|
|
213
|
+
if cfg.experiment.used_method == "none":
|
|
214
|
+
log("Running pipeline in 'Standard' mode.")
|
|
215
|
+
metrics, times = run_pipeline(cfg)
|
|
216
|
+
wandb.log(metrics)
|
|
217
|
+
wandb.log(times)
|
|
218
|
+
|
|
219
|
+
elif cfg.experiment.used_method == "uncertainty":
|
|
220
|
+
log("Running pipeline in 'Uncertainty' mode.")
|
|
221
|
+
method_to_metrics = defaultdict(list)
|
|
222
|
+
original_cfg = copy.deepcopy(cfg)
|
|
223
|
+
|
|
224
|
+
uncertainty_methods = get_uncertainty_methods_to_run(cfg)
|
|
225
|
+
for method in uncertainty_methods:
|
|
226
|
+
iterations = getattr(cfg.experiment.uncertainty, method).iterations
|
|
227
|
+
log(f"[@method {method}] - Started", pre_return_line=True)
|
|
228
|
+
|
|
229
|
+
if method == "hyperparameter":
|
|
230
|
+
hyperparameters = cfg.experiment.uncertainty.hyperparameter.hyperparameters
|
|
231
|
+
hyperparameters = map(lambda x: x.strip(), hyperparameters.split(","))
|
|
232
|
+
assert iterations % 2 != 0, (
|
|
233
|
+
f"The number of iterations for hyperparameters should be odd, found {iterations}"
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
hyper_to_metrics = defaultdict(list)
|
|
237
|
+
for hyper in hyperparameters:
|
|
238
|
+
log(
|
|
239
|
+
f"[@hyperparameter {hyper}] - Started",
|
|
240
|
+
pre_return_line=True,
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
for i in range(iterations):
|
|
244
|
+
log(f"[@iteration {i}]", pre_return_line=True)
|
|
245
|
+
cfg = update_cfg_for_uncertainty_exp(
|
|
246
|
+
method,
|
|
247
|
+
i,
|
|
248
|
+
iterations,
|
|
249
|
+
copy.deepcopy(original_cfg),
|
|
250
|
+
hyperparameter=hyper,
|
|
251
|
+
)
|
|
252
|
+
metrics, times = run_pipeline(cfg, method=method, iteration=i)
|
|
253
|
+
hyper_to_metrics[hyper].append({**metrics, **times})
|
|
254
|
+
|
|
255
|
+
metrics = fuse_hyperparameter_metrics(hyper_to_metrics)
|
|
256
|
+
method_to_metrics[method] = metrics
|
|
257
|
+
|
|
258
|
+
else:
|
|
259
|
+
if method == "deep_ensemble":
|
|
260
|
+
new_tag = f"from_{cfg.experiment.uncertainty.deep_ensemble.restart_from}"
|
|
261
|
+
wandb.run.tags = list(wandb.run.tags) + [str(new_tag)]
|
|
262
|
+
|
|
263
|
+
for i in range(iterations):
|
|
264
|
+
log(f"[@iteration {i}]", pre_return_line=True)
|
|
265
|
+
cfg = update_cfg_for_uncertainty_exp(
|
|
266
|
+
method,
|
|
267
|
+
i,
|
|
268
|
+
iterations,
|
|
269
|
+
copy.deepcopy(original_cfg),
|
|
270
|
+
hyperparameter=None,
|
|
271
|
+
)
|
|
272
|
+
metrics, times = run_pipeline(cfg, method=method, iteration=i)
|
|
273
|
+
method_to_metrics[method].append({**metrics, **times})
|
|
274
|
+
|
|
275
|
+
# We force restart in some methods so we avoid forced restart for other methods
|
|
276
|
+
cfg._force_restart = ""
|
|
277
|
+
cfg._is_running_mc_dropout = False
|
|
278
|
+
|
|
279
|
+
# Save metrics to disk for future analysis and plots
|
|
280
|
+
out_dir = cfg.evaluation._uncertainty_exp_dir
|
|
281
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
282
|
+
method_to_metrics_path = os.path.join(out_dir, "method_to_metrics.pkl")
|
|
283
|
+
torch.save(method_to_metrics, method_to_metrics_path)
|
|
284
|
+
wandb.save(method_to_metrics_path, out_dir)
|
|
285
|
+
|
|
286
|
+
averaged_metrics = avg_std_metrics(method_to_metrics)
|
|
287
|
+
minimum_metrics = min_metrics(method_to_metrics)
|
|
288
|
+
maximum_metrics = max_metrics(method_to_metrics)
|
|
289
|
+
|
|
290
|
+
wandb.log(averaged_metrics)
|
|
291
|
+
wandb.log(minimum_metrics)
|
|
292
|
+
wandb.log(maximum_metrics)
|
|
293
|
+
|
|
294
|
+
push_best_files_to_wandb(method_to_metrics, cfg)
|
|
295
|
+
|
|
296
|
+
else:
|
|
297
|
+
raise ValueError(f"Invalid experiment {cfg.experiment.used_method}")
|
|
298
|
+
|
|
299
|
+
# Normal mode
|
|
300
|
+
if cfg._tuning_mode == "none":
|
|
301
|
+
run_pipeline_with_experiments(cfg)
|
|
302
|
+
|
|
303
|
+
# Sweep mode
|
|
304
|
+
else:
|
|
305
|
+
log("Running pipeline in 'Tuning' mode.")
|
|
306
|
+
sweep_config = get_tuning_sweep_cfg(cfg)
|
|
307
|
+
if not sweep_id:
|
|
308
|
+
sweep_config["name"] = exp
|
|
309
|
+
sweep_id = wandb.sweep(sweep_config, project=project)
|
|
310
|
+
|
|
311
|
+
def run_pipeline_from_sweep(cfg):
|
|
312
|
+
"""Execute pipeline for a single hyperparameter configuration from W&B sweep.
|
|
313
|
+
|
|
314
|
+
Args:
|
|
315
|
+
cfg: Base configuration object (will be updated with sweep parameters)
|
|
316
|
+
"""
|
|
317
|
+
with wandb.init(name=exp):
|
|
318
|
+
sweep_cfg = wandb.config
|
|
319
|
+
cfg = fuse_cfg_with_sweep_cfg(cfg, sweep_cfg)
|
|
320
|
+
|
|
321
|
+
wandb.log({"dataset": cfg.dataset.name, "exp": exp})
|
|
322
|
+
|
|
323
|
+
run_pipeline_with_experiments(cfg)
|
|
324
|
+
|
|
325
|
+
count = sweep_config["count"] if "count" in sweep_config else None
|
|
326
|
+
wandb.agent(sweep_id, lambda: run_pipeline_from_sweep(cfg), count=count)
|
|
327
|
+
|
|
328
|
+
log("==" * 30)
|
|
329
|
+
log("Run finished.")
|
|
330
|
+
log("==" * 30)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def cli(argv=None):
|
|
334
|
+
"""Runs the pipeline from the command line: `pidsmaker <model> <dataset> [args]` (see
|
|
335
|
+
pidsmaker/cli.py), or `python pidsmaker/main.py <model> <dataset> [args]`."""
|
|
336
|
+
args, unknown_args = get_runtime_required_args(return_unknown_args=True, args=argv)
|
|
337
|
+
|
|
338
|
+
exp_name = (
|
|
339
|
+
args.exp.replace("dataset", args.dataset)
|
|
340
|
+
if args.exp != ""
|
|
341
|
+
else f"{args.dataset}_{args.model}"
|
|
342
|
+
)
|
|
343
|
+
tags = args.tags.split(",") if args.tags != "" else [args.model]
|
|
344
|
+
|
|
345
|
+
wandb.init(
|
|
346
|
+
mode=("online" if (args.wandb and args.tuning_mode == "none") else "disabled"),
|
|
347
|
+
project=args.project,
|
|
348
|
+
name=exp_name,
|
|
349
|
+
tags=tags,
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
if len(unknown_args) > 0:
|
|
353
|
+
raise argparse.ArgumentTypeError(f"Unknown args {unknown_args}")
|
|
354
|
+
|
|
355
|
+
cfg = get_yml_cfg(args)
|
|
356
|
+
wandb.config.update(clean_cfg_for_log(cfg))
|
|
357
|
+
|
|
358
|
+
main(cfg, project=args.project, exp=exp_name, sweep_id=args.sweep_id)
|
|
359
|
+
|
|
360
|
+
# Persist the resolved config next to the run so the viz Run Browser can show it.
|
|
361
|
+
try:
|
|
362
|
+
run_dir = os.path.dirname(cfg.evaluation._task_path)
|
|
363
|
+
os.makedirs(run_dir, exist_ok=True)
|
|
364
|
+
with open(os.path.join(run_dir, "run_config.yml"), "w") as f:
|
|
365
|
+
f.write(cfg.dump())
|
|
366
|
+
except Exception as e:
|
|
367
|
+
log(f"Warning: could not save run_config.yml: {e}")
|
|
368
|
+
|
|
369
|
+
wandb.finish()
|
|
370
|
+
|
|
371
|
+
# If it's a one-time run, we delete the files as we can't leverage them in future
|
|
372
|
+
if cfg._restart_from_scratch:
|
|
373
|
+
shutil.rmtree(cfg.construction._task_path, ignore_errors=True)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
if __name__ == "__main__":
|
|
377
|
+
cli()
|
pidsmaker/mimicry.py
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import csv
|
|
2
|
+
import os
|
|
3
|
+
import random
|
|
4
|
+
from collections import defaultdict
|
|
5
|
+
|
|
6
|
+
import networkx as nx
|
|
7
|
+
|
|
8
|
+
from pidsmaker.config import *
|
|
9
|
+
from pidsmaker.utils.dataset_utils import get_rel2id
|
|
10
|
+
from pidsmaker.utils.utils import *
|
|
11
|
+
from pidsmaker.utils.utils import datetime_to_ns_time_US
|
|
12
|
+
|
|
13
|
+
possible_structure = [
|
|
14
|
+
["EVENT_OPEN", "EVENT_READ"],
|
|
15
|
+
["EVENT_OPEN", "EVENT_WRITE"],
|
|
16
|
+
["EVENT_OPEN", "EVENT_READ", "EVENT_WRITE"],
|
|
17
|
+
["EVENT_OPEN", "EVENT_WRITE", "EVENT_READ"],
|
|
18
|
+
["EVENT_OPEN", "EVENT_READ", "EVENT_WRITE", "EVENT_READ", "EVENT_WRITE"],
|
|
19
|
+
["EVENT_OPEN", "EVENT_WRITE", "EVENT_READ", "EVENT_WRITE", "EVENT_READ"],
|
|
20
|
+
["EVENT_OPEN", "EVENT_READ", "EVENT_WRITE", "EVENT_WRITE", "EVENT_READ"],
|
|
21
|
+
["EVENT_OPEN", "EVENT_WRITE", "EVENT_READ", "EVENT_WRITE", "EVENT_WRITE"],
|
|
22
|
+
[
|
|
23
|
+
"EVENT_OPEN",
|
|
24
|
+
"EVENT_READ",
|
|
25
|
+
"EVENT_WRITE",
|
|
26
|
+
"EVENT_READ",
|
|
27
|
+
"EVENT_WRITE",
|
|
28
|
+
"EVENT_WRITE",
|
|
29
|
+
"EVENT_WRITE",
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
"EVENT_OPEN",
|
|
33
|
+
"EVENT_WRITE",
|
|
34
|
+
"EVENT_READ",
|
|
35
|
+
"EVENT_READ",
|
|
36
|
+
"EVENT_READ",
|
|
37
|
+
"EVENT_WRITE",
|
|
38
|
+
"EVENT_READ",
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
"EVENT_OPEN",
|
|
42
|
+
"EVENT_READ",
|
|
43
|
+
"EVENT_READ",
|
|
44
|
+
"EVENT_READ",
|
|
45
|
+
"EVENT_WRITE",
|
|
46
|
+
"EVENT_WRITE",
|
|
47
|
+
"EVENT_READ",
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"EVENT_OPEN",
|
|
51
|
+
"EVENT_WRITE",
|
|
52
|
+
"EVENT_WRITE",
|
|
53
|
+
"EVENT_WRITE",
|
|
54
|
+
"EVENT_READ",
|
|
55
|
+
"EVENT_WRITE",
|
|
56
|
+
"EVENT_WRITE",
|
|
57
|
+
],
|
|
58
|
+
["EVENT_OPEN", "EVENT_READ", "EVENT_READ", "EVENT_READ", "EVENT_READ"],
|
|
59
|
+
[
|
|
60
|
+
"EVENT_OPEN",
|
|
61
|
+
"EVENT_WRITE",
|
|
62
|
+
"EVENT_WRITE",
|
|
63
|
+
"EVENT_WRITE",
|
|
64
|
+
"EVENT_WRITE",
|
|
65
|
+
],
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def get_uuid2nids2type(cur):
|
|
70
|
+
queries = {
|
|
71
|
+
"file": "SELECT index_id, node_uuid FROM file_node_table;",
|
|
72
|
+
"netflow": "SELECT index_id, node_uuid FROM netflow_node_table;",
|
|
73
|
+
"subject": "SELECT index_id, node_uuid FROM subject_node_table;",
|
|
74
|
+
}
|
|
75
|
+
uuid2nids = {}
|
|
76
|
+
nid2uuid = {}
|
|
77
|
+
nid2type = {}
|
|
78
|
+
for node_type, query in queries.items():
|
|
79
|
+
cur.execute(query)
|
|
80
|
+
rows = cur.fetchall()
|
|
81
|
+
for row in rows:
|
|
82
|
+
uuid2nids[row[1]] = row[0]
|
|
83
|
+
nid2uuid[row[0]] = row[1]
|
|
84
|
+
nid2type[row[0]] = node_type
|
|
85
|
+
return uuid2nids, nid2uuid, nid2type
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def obtain_all_files(cur):
|
|
89
|
+
sql = "SELECT index_id, node_uuid FROM file_node_table;"
|
|
90
|
+
cur.execute(sql)
|
|
91
|
+
rows = cur.fetchall()
|
|
92
|
+
|
|
93
|
+
file_set = set()
|
|
94
|
+
for row in rows:
|
|
95
|
+
file_set.add(row[0])
|
|
96
|
+
return file_set
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def divide_integer(a, b):
|
|
100
|
+
base_size = a // b
|
|
101
|
+
remainder = a % b
|
|
102
|
+
result = [base_size + 1 if i < remainder else base_size for i in range(b)]
|
|
103
|
+
return result
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def random_timestamp(start_ns, end_ns):
|
|
107
|
+
if start_ns > end_ns:
|
|
108
|
+
start_ns, end_ns = end_ns, start_ns
|
|
109
|
+
return random.randint(start_ns, end_ns)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def save_mimicry_nodes(cfg, cur, nodes, attack):
|
|
113
|
+
os.makedirs(cfg.construction._mimicry_dir, exist_ok=True)
|
|
114
|
+
save_dir = os.path.join(cfg.construction._mimicry_dir, attack.split("/")[-1])
|
|
115
|
+
|
|
116
|
+
data = []
|
|
117
|
+
sql1 = "SELECT node_uuid, index_id, path FROM file_node_table;"
|
|
118
|
+
sql2 = "SELECT node_uuid, index_id, path, cmd FROM subject_node_table;"
|
|
119
|
+
|
|
120
|
+
cur.execute(sql1)
|
|
121
|
+
rows = cur.fetchall()
|
|
122
|
+
for row in rows:
|
|
123
|
+
node_uuid = row[0]
|
|
124
|
+
index_id = int(row[1])
|
|
125
|
+
path = row[2] if row[2] is not None else "None"
|
|
126
|
+
if index_id in nodes:
|
|
127
|
+
data.append((node_uuid, {"file": path}, index_id))
|
|
128
|
+
|
|
129
|
+
cur.execute(sql2)
|
|
130
|
+
rows = cur.fetchall()
|
|
131
|
+
for row in rows:
|
|
132
|
+
node_uuid = row[0]
|
|
133
|
+
index_id = int(row[1])
|
|
134
|
+
path = row[2] if row[2] is not None else "None"
|
|
135
|
+
cmd = row[3] if row[3] is not None else "None"
|
|
136
|
+
if index_id in nodes:
|
|
137
|
+
data.append((node_uuid, {"subject": path + " " + cmd}, index_id))
|
|
138
|
+
|
|
139
|
+
with open(save_dir, "w") as f:
|
|
140
|
+
csv_writer = csv.writer(f)
|
|
141
|
+
for line in data:
|
|
142
|
+
csv_writer.writerow(line)
|
|
143
|
+
|
|
144
|
+
log(f"{len(data)} mimicry nodes saved into {save_dir}.")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def gen_mimicry_edges(cfg):
|
|
148
|
+
cur, connect = init_database_connection(cfg)
|
|
149
|
+
uuid2nids, nid2uuid, nid2type = get_uuid2nids2type(cur)
|
|
150
|
+
|
|
151
|
+
rel2id = get_rel2id(cfg)
|
|
152
|
+
|
|
153
|
+
mimicry_edge_num = cfg.construction.mimicry_edge_num
|
|
154
|
+
attack_num = len(cfg.dataset.ground_truth_relative_path)
|
|
155
|
+
num_each_att = divide_integer(mimicry_edge_num, attack_num)
|
|
156
|
+
|
|
157
|
+
attack_index = 0
|
|
158
|
+
attack_GPs = {}
|
|
159
|
+
attack_mimicry_events = {}
|
|
160
|
+
for attack_tuple in cfg.dataset.attack_to_time_window:
|
|
161
|
+
attack = attack_tuple[0]
|
|
162
|
+
start_time = datetime_to_ns_time_US(attack_tuple[1], timezone=cfg.dataset.timezone)
|
|
163
|
+
end_time = datetime_to_ns_time_US(attack_tuple[2], timezone=cfg.dataset.timezone)
|
|
164
|
+
|
|
165
|
+
# Obtain mimicry-connected nodes as new malicious nodes
|
|
166
|
+
mimicry_GPs = set()
|
|
167
|
+
|
|
168
|
+
# Find attack root and descendant process
|
|
169
|
+
ground_truth_nids = []
|
|
170
|
+
with open(os.path.join(cfg._ground_truth_dir, attack), "r") as f:
|
|
171
|
+
reader = csv.reader(f)
|
|
172
|
+
for row in reader:
|
|
173
|
+
node_uuid, node_labels, _ = row[0], row[1], row[2]
|
|
174
|
+
node_id = uuid2nids[node_uuid]
|
|
175
|
+
ground_truth_nids.append(int(node_id))
|
|
176
|
+
|
|
177
|
+
attack_GPs[attack] = set(ground_truth_nids)
|
|
178
|
+
|
|
179
|
+
# Create graph and obtain root nodes
|
|
180
|
+
rows = get_events_between_GPs(cur, start_time, end_time, ground_truth_nids)
|
|
181
|
+
|
|
182
|
+
edges = []
|
|
183
|
+
for row in rows:
|
|
184
|
+
src_id = row[1]
|
|
185
|
+
operation = row[2]
|
|
186
|
+
dst_id = row[4]
|
|
187
|
+
t = int(row[6])
|
|
188
|
+
if operation in rel2id:
|
|
189
|
+
edges.append((str(src_id), str(dst_id), int(t)))
|
|
190
|
+
|
|
191
|
+
dag_between_GPs, _ = generate_DAG(edges)
|
|
192
|
+
root_nodes = set(
|
|
193
|
+
[node for node, in_degree in dag_between_GPs.in_degree() if in_degree == 0]
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
# create graph and obtain all descendants
|
|
197
|
+
rows = get_events_between_time_range(cur, start_time, end_time)
|
|
198
|
+
edges = []
|
|
199
|
+
process2times = defaultdict(list)
|
|
200
|
+
for row in rows:
|
|
201
|
+
src_id = row[1]
|
|
202
|
+
operation = row[2]
|
|
203
|
+
dst_id = row[4]
|
|
204
|
+
t = int(row[6])
|
|
205
|
+
if operation in rel2id:
|
|
206
|
+
edges.append((str(src_id), str(dst_id), int(t)))
|
|
207
|
+
|
|
208
|
+
if nid2type[int(src_id)] == "subject":
|
|
209
|
+
process2times[src_id].append(t)
|
|
210
|
+
if nid2type[int(dst_id)] == "subject":
|
|
211
|
+
process2times[dst_id].append(t)
|
|
212
|
+
|
|
213
|
+
dag_of_attack, node_version = generate_DAG(edges)
|
|
214
|
+
|
|
215
|
+
all_descendants = set()
|
|
216
|
+
for root in root_nodes:
|
|
217
|
+
descendants = nx.descendants(dag_of_attack, root)
|
|
218
|
+
desc = set([v.split("-")[0] for v in descendants])
|
|
219
|
+
all_descendants |= desc
|
|
220
|
+
all_descendants |= set([v.split("-")[0] for v in root_nodes])
|
|
221
|
+
|
|
222
|
+
possible_process = set()
|
|
223
|
+
for nid in all_descendants:
|
|
224
|
+
if nid2type[int(nid)] == "subject":
|
|
225
|
+
possible_process.add(nid)
|
|
226
|
+
|
|
227
|
+
possible_file = obtain_all_files(cur)
|
|
228
|
+
|
|
229
|
+
possible_process = list(possible_process)
|
|
230
|
+
possible_file = list(possible_file)
|
|
231
|
+
|
|
232
|
+
# Generate mimicry events
|
|
233
|
+
mimicry_events = []
|
|
234
|
+
events_needed = num_each_att[attack_index]
|
|
235
|
+
while len(mimicry_events) < events_needed:
|
|
236
|
+
random_subject = random.choice(possible_process)
|
|
237
|
+
random_file = random.choice(possible_file)
|
|
238
|
+
random_time = random.choice(process2times[random_subject])
|
|
239
|
+
random_structure = random.choice(possible_structure)
|
|
240
|
+
|
|
241
|
+
mimicry_GPs.add(int(random_subject))
|
|
242
|
+
mimicry_GPs.add(int(random_file))
|
|
243
|
+
|
|
244
|
+
current_time = int(random_time)
|
|
245
|
+
|
|
246
|
+
for ope in random_structure:
|
|
247
|
+
time_bias = random.randint(0, int(3 * 1e9))
|
|
248
|
+
event_time = current_time + time_bias
|
|
249
|
+
current_time = event_time
|
|
250
|
+
event_uuid = stringtomd5(str(random_subject) + str(random_file) + str(current_time))
|
|
251
|
+
if ope == "EVENT_OPEN" or ope == "EVENT_WRITE":
|
|
252
|
+
event = (
|
|
253
|
+
nid2uuid[int(random_subject)],
|
|
254
|
+
str(random_subject),
|
|
255
|
+
ope,
|
|
256
|
+
nid2uuid[int(random_file)],
|
|
257
|
+
str(random_file),
|
|
258
|
+
event_uuid,
|
|
259
|
+
event_time,
|
|
260
|
+
0,
|
|
261
|
+
)
|
|
262
|
+
elif ope == "EVENT_READ":
|
|
263
|
+
event = (
|
|
264
|
+
nid2uuid[int(random_file)],
|
|
265
|
+
str(random_file),
|
|
266
|
+
ope,
|
|
267
|
+
nid2uuid[int(random_subject)],
|
|
268
|
+
str(random_subject),
|
|
269
|
+
event_uuid,
|
|
270
|
+
event_time,
|
|
271
|
+
0,
|
|
272
|
+
)
|
|
273
|
+
else:
|
|
274
|
+
log(f"Undefined event type {ope}")
|
|
275
|
+
|
|
276
|
+
mimicry_events.append(event)
|
|
277
|
+
|
|
278
|
+
save_mimicry_nodes(cfg, cur, mimicry_GPs, attack)
|
|
279
|
+
|
|
280
|
+
attack_mimicry_events[attack_index] = mimicry_events
|
|
281
|
+
log(f"For attack {attack_index}, {len(mimicry_events)} mimicry events are generated")
|
|
282
|
+
attack_index += 1
|
|
283
|
+
|
|
284
|
+
return attack_mimicry_events
|