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,476 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functional class labeling for provenance graph entities.
|
|
3
|
+
|
|
4
|
+
Maps every entity (process, file, socket) to a coarse functional class that
|
|
5
|
+
captures *what it is* independent of the specific binary/path/port. Two
|
|
6
|
+
nginx workers, Apache, and Caddy all get class "webserver". This is used
|
|
7
|
+
by behavior_signatures.py to build behavior signature labels of the form
|
|
8
|
+
(direction, event_type, neighbor_entity_type, neighbor_class).
|
|
9
|
+
|
|
10
|
+
Design:
|
|
11
|
+
- PROC classes: reuse canonical_tokens.PROC_CATEGORIES but strip the
|
|
12
|
+
bracket/prefix notation → plain lowercase strings.
|
|
13
|
+
- FILE classes: reuse canonical_tokens.FILE_DIR_CATEGORIES similarly,
|
|
14
|
+
plus extension-based fallback.
|
|
15
|
+
- SOCK classes: well-known port → named class, else range bucket.
|
|
16
|
+
|
|
17
|
+
All functions accept a raw label string (as stored in indexid2msg) and
|
|
18
|
+
return a plain string class name, or "unknown" if nothing matches.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import functools
|
|
22
|
+
|
|
23
|
+
import os
|
|
24
|
+
import re
|
|
25
|
+
from typing import Optional
|
|
26
|
+
|
|
27
|
+
from .canonical_tokens import (
|
|
28
|
+
PROC_CATEGORIES,
|
|
29
|
+
FILE_DIR_CATEGORIES,
|
|
30
|
+
_FILE_DIR_SORTED,
|
|
31
|
+
match_proc_category,
|
|
32
|
+
)
|
|
33
|
+
from .tokenizer_bpe import (
|
|
34
|
+
WELL_KNOWN_PORTS,
|
|
35
|
+
RE_IP,
|
|
36
|
+
RE_IPV6,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
41
|
+
# PROC CLASSES
|
|
42
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
43
|
+
# Convert [CAT_WEBSERVER] → "webserver", [CAT_DB_CLIENT] → "db_client", etc.
|
|
44
|
+
|
|
45
|
+
# Merge classes that have the same behavioral profile.
|
|
46
|
+
# Applied after stripping the CAT_/FCAT_ prefix.
|
|
47
|
+
_CLASS_MERGE = {
|
|
48
|
+
# ── Port merges (reduce singleton socket classes) ─────────────────
|
|
49
|
+
"port_imap": "port_mail", # IMAP/SMTP/POP3 all serve mail
|
|
50
|
+
"port_imaps": "port_mail",
|
|
51
|
+
"port_smtp": "port_mail",
|
|
52
|
+
"port_pop3": "port_mail",
|
|
53
|
+
"port_ldaps": "port_ldap", # LDAP + LDAPS
|
|
54
|
+
"port_ftp_data": "port_ftp", # FTP control + data
|
|
55
|
+
"port_rdp": "port_ssh", # Remote access protocols
|
|
56
|
+
"port_telnet": "port_ssh",
|
|
57
|
+
"port_dhcp_c": "port_dhcp", # DHCP client + server
|
|
58
|
+
"port_mssql": "port_database", # Database protocols
|
|
59
|
+
"port_oracle": "port_database",
|
|
60
|
+
"port_syslog": "port_low", # Fold rare low-port services into port_low
|
|
61
|
+
"port_ntp": "port_low",
|
|
62
|
+
"unix_socket": "port_low",
|
|
63
|
+
"port_rpc": "port_low", # Windows RPC — confused with netbios, fold into port_low
|
|
64
|
+
"port_http_alt": "port_http", # 8080 → http
|
|
65
|
+
"port_https_alt": "port_https", # 8443 → https
|
|
66
|
+
|
|
67
|
+
# ── Fallback merges (from path/extension classifiers, not canonical_tokens) ──
|
|
68
|
+
"binary": "executable", # from _PROC_BIN_DIRS path fallback
|
|
69
|
+
"desktop": "executable", # from _PROC_BASENAME_CLASSES
|
|
70
|
+
"script": "executable", # from _FILE_EXT_CLASSES (.sh, .bat, .ps1)
|
|
71
|
+
"socket_file": "tmp", # from _FILE_EXT_CLASSES (.sock)
|
|
72
|
+
"package": "archive", # from _FILE_EXT_CLASSES (.deb, .rpm)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _cat_token_to_class(token: str) -> str:
|
|
77
|
+
"""Convert a canonical category token to a plain class name."""
|
|
78
|
+
# [CAT_WEBSERVER] → webserver, [FCAT_LOG_WEB] → log_web
|
|
79
|
+
s = token.strip("[]")
|
|
80
|
+
if s.startswith("CAT_"):
|
|
81
|
+
cls = s[4:].lower()
|
|
82
|
+
elif s.startswith("FCAT_"):
|
|
83
|
+
cls = s[5:].lower()
|
|
84
|
+
else:
|
|
85
|
+
cls = s.lower()
|
|
86
|
+
return _CLASS_MERGE.get(cls, cls)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# Pre-compute the set of unique PROC class names
|
|
90
|
+
_PROC_CLASS_SET = {_cat_token_to_class(v) for v in PROC_CATEGORIES.values()}
|
|
91
|
+
|
|
92
|
+
# Pre-compute the set of unique FILE class names
|
|
93
|
+
_FILE_CLASS_SET = {_cat_token_to_class(v) for v in FILE_DIR_CATEGORIES.values()}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# Known binary directories — if a process path starts with one of these
|
|
97
|
+
# and the basename isn't in PROC_CATEGORIES, classify as "binary".
|
|
98
|
+
_PROC_BIN_DIRS = (
|
|
99
|
+
"/usr/bin/", "/usr/sbin/", "/usr/local/bin/", "/usr/local/sbin/",
|
|
100
|
+
"/bin/", "/sbin/",
|
|
101
|
+
"/system/bin/", # Android
|
|
102
|
+
"/system/xbin/", # Android
|
|
103
|
+
"/vendor/bin/", # Android
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# Bare command names that map to a SPECIFIC class (not just "binary").
|
|
107
|
+
# Commands not listed here will fall through to the generic "binary" catch-all.
|
|
108
|
+
# Only add entries here when the class is semantically meaningful and different
|
|
109
|
+
# from "binary" — don't enumerate every Unix command.
|
|
110
|
+
_PROC_BASENAME_CLASSES = {
|
|
111
|
+
# Browsers (not in PROC_CATEGORIES)
|
|
112
|
+
"firefox": "browser", "chromium-browse": "browser",
|
|
113
|
+
"chromium-browser": "browser", "chrome": "browser",
|
|
114
|
+
"chrome_crashpad": "browser", "geckodriver": "browser",
|
|
115
|
+
# Mail subsystems (postfix internals not in PROC_CATEGORIES)
|
|
116
|
+
"trivial-rewrite": "mail", "anvil": "mail",
|
|
117
|
+
# Terminal multiplexers (behaviorally like shells)
|
|
118
|
+
"screen": "shell", "tmux": "shell",
|
|
119
|
+
# Desktop apps
|
|
120
|
+
"telepathy-indicator": "desktop", "unity-2d-panel": "desktop",
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _extract_proc_basename(label_str: str) -> str:
|
|
125
|
+
"""Extract the binary basename from a process label.
|
|
126
|
+
|
|
127
|
+
Handles paths (/usr/bin/foo → foo), .exe suffix (cmd.exe → cmd),
|
|
128
|
+
quoted paths with spaces ("C:/Program Files/foo.exe" → foo),
|
|
129
|
+
and the "subject" type prefix.
|
|
130
|
+
"""
|
|
131
|
+
s = label_str
|
|
132
|
+
# Strip "subject" prefix
|
|
133
|
+
if s.startswith("subject "):
|
|
134
|
+
s = s[8:]
|
|
135
|
+
|
|
136
|
+
# Handle quoted paths (e.g. "//?/C:/Program Files (x86)/Firefox/firefox.exe" -args)
|
|
137
|
+
s = s.strip()
|
|
138
|
+
if s.startswith('"'):
|
|
139
|
+
end_quote = s.find('"', 1)
|
|
140
|
+
if end_quote > 0:
|
|
141
|
+
first = s[1:end_quote]
|
|
142
|
+
else:
|
|
143
|
+
first = s[1:]
|
|
144
|
+
else:
|
|
145
|
+
first = s.split()[0] if s else ""
|
|
146
|
+
|
|
147
|
+
first = first.replace("\\", "/")
|
|
148
|
+
# Strip Windows device path prefix //?/
|
|
149
|
+
if first.startswith("//?/"):
|
|
150
|
+
first = first[4:]
|
|
151
|
+
if "/" in first:
|
|
152
|
+
first = first.rsplit("/", 1)[-1]
|
|
153
|
+
if first.lower().endswith(".exe"):
|
|
154
|
+
first = first[:-4]
|
|
155
|
+
return first
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def classify_proc(label_str: str) -> str:
|
|
159
|
+
"""Classify a process entity by its command line / binary name.
|
|
160
|
+
|
|
161
|
+
Priority:
|
|
162
|
+
1. canonical_tokens.PROC_CATEGORIES (functional roles like webserver, shell)
|
|
163
|
+
2. _PROC_BASENAME_CLASSES (coreutils, sysadmin tools, browsers, etc.)
|
|
164
|
+
3. Path-based fallback (known bin directories → "binary")
|
|
165
|
+
4. Pattern-based fallback (Windows .exe, Android packages, apt-*/dpkg-*)
|
|
166
|
+
|
|
167
|
+
Returns a plain class name or "unknown" if no match.
|
|
168
|
+
"""
|
|
169
|
+
cat_token = match_proc_category(label_str)
|
|
170
|
+
if cat_token is not None:
|
|
171
|
+
return _cat_token_to_class(cat_token)
|
|
172
|
+
|
|
173
|
+
# Basename lookup for common commands not in canonical_tokens
|
|
174
|
+
basename = _extract_proc_basename(label_str)
|
|
175
|
+
if basename in _PROC_BASENAME_CLASSES:
|
|
176
|
+
return _PROC_BASENAME_CLASSES[basename]
|
|
177
|
+
|
|
178
|
+
# Prefix-based matching
|
|
179
|
+
if basename.startswith(("apt-", "dpkg-")):
|
|
180
|
+
return "pkgmgr"
|
|
181
|
+
|
|
182
|
+
# Truncated daemon names: "sshd:" → ssh, "systemd-journal" → init
|
|
183
|
+
# Strip trailing ":" and check known prefixes against PROC_CATEGORIES
|
|
184
|
+
basename_clean = basename.rstrip(":")
|
|
185
|
+
if basename_clean in PROC_CATEGORIES:
|
|
186
|
+
return _cat_token_to_class(PROC_CATEGORIES[basename_clean])
|
|
187
|
+
# systemd-* variants (systemd-journald, systemd-networkd, systemd-resolved, etc.)
|
|
188
|
+
if basename.startswith("systemd-") or basename.startswith("systemd:"):
|
|
189
|
+
return "init"
|
|
190
|
+
# Android system:* processes
|
|
191
|
+
if basename.startswith("system:"):
|
|
192
|
+
return "android_sys"
|
|
193
|
+
|
|
194
|
+
# Versioned interpreters: python2.7, python3.6, perl5.30, ruby2.7, etc.
|
|
195
|
+
# PROC_CATEGORIES has "python", "python3", "perl", "ruby" but not versioned variants.
|
|
196
|
+
import re as _re
|
|
197
|
+
if _re.match(r'^(python|perl|ruby|php|lua|node)\d', basename):
|
|
198
|
+
base = _re.match(r'^(python|perl|ruby|php|lua|node)', basename).group(1)
|
|
199
|
+
if base in PROC_CATEGORIES:
|
|
200
|
+
return _cat_token_to_class(PROC_CATEGORIES[base])
|
|
201
|
+
|
|
202
|
+
# Path-based fallback: processes from known binary directories
|
|
203
|
+
parts = label_str.split()
|
|
204
|
+
if parts and parts[0] == "subject":
|
|
205
|
+
parts = parts[1:]
|
|
206
|
+
if parts:
|
|
207
|
+
first = parts[0].strip('"').replace("\\", "/")
|
|
208
|
+
for bin_dir in _PROC_BIN_DIRS:
|
|
209
|
+
if first.startswith(bin_dir):
|
|
210
|
+
return "binary"
|
|
211
|
+
|
|
212
|
+
# Windows .exe processes
|
|
213
|
+
if ".exe" in label_str.lower():
|
|
214
|
+
return "win_system"
|
|
215
|
+
|
|
216
|
+
# Android package-style processes (com.android.*, android.*)
|
|
217
|
+
if basename.startswith(("android.", "com.android.", "com.google.")):
|
|
218
|
+
return "android_sys"
|
|
219
|
+
|
|
220
|
+
# Firefox/chromium snap processes
|
|
221
|
+
if "firefox" in basename.lower() or "chromium" in basename.lower():
|
|
222
|
+
return "browser"
|
|
223
|
+
|
|
224
|
+
# Any bare alphabetic command name is a binary that was executed.
|
|
225
|
+
# Excludes flag-style args (-c, +%s), numbers, and garbage labels.
|
|
226
|
+
if basename and basename[0].isalpha() and all(c.isalnum() or c in "-_." for c in basename):
|
|
227
|
+
return "binary"
|
|
228
|
+
|
|
229
|
+
return "unknown"
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
233
|
+
# FILE CLASSES
|
|
234
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
235
|
+
|
|
236
|
+
# Extensions that identify file content type, used as fallback when no
|
|
237
|
+
# path-prefix rule matches. Path context wins for most files (a .tmp in
|
|
238
|
+
# browser data is browser_data, not tmp), but these catch files in
|
|
239
|
+
# unrecognized directories.
|
|
240
|
+
_FILE_EXT_CLASSES = {
|
|
241
|
+
# Source code
|
|
242
|
+
".c": "source", ".h": "source", ".cpp": "source", ".hpp": "source",
|
|
243
|
+
".cc": "source", ".py": "source", ".js": "source", ".ts": "source",
|
|
244
|
+
".rs": "source", ".go": "source", ".java": "source", ".rb": "source",
|
|
245
|
+
".pl": "source", ".m": "source", ".swift": "source",
|
|
246
|
+
".sh": "script", ".bash": "script", ".bat": "script", ".ps1": "script",
|
|
247
|
+
".cmd": "script", ".vbs": "script", ".wsf": "script",
|
|
248
|
+
# Web
|
|
249
|
+
".html": "source", ".htm": "source", ".css": "source",
|
|
250
|
+
".xhtml": "source", ".xul": "source", ".jsx": "source", ".tsx": "source",
|
|
251
|
+
".php": "source", ".asp": "source", ".aspx": "source", ".jsp": "source",
|
|
252
|
+
# Compiled / bytecode
|
|
253
|
+
".o": "object", ".obj": "object", ".a": "library", ".so": "library",
|
|
254
|
+
".dylib": "library", ".dll": "library", ".class": "bytecode",
|
|
255
|
+
".pyc": "bytecode", ".pyo": "bytecode",
|
|
256
|
+
# Binaries / executables
|
|
257
|
+
".exe": "binary", ".msi": "binary", ".apk": "binary",
|
|
258
|
+
".bin": "binary", ".elf": "binary",
|
|
259
|
+
# Config
|
|
260
|
+
".conf": "config", ".cfg": "config", ".ini": "config",
|
|
261
|
+
".yaml": "config", ".yml": "config", ".toml": "config",
|
|
262
|
+
".properties": "config", ".reg": "config",
|
|
263
|
+
# Data
|
|
264
|
+
".json": "data", ".xml": "data", ".csv": "data", ".tsv": "data",
|
|
265
|
+
".sql": "data", ".dat": "data", ".plist": "data",
|
|
266
|
+
".db": "database_file", ".sqlite": "database_file",
|
|
267
|
+
# Logs
|
|
268
|
+
".log": "log", ".evtx": "log", ".etl": "log",
|
|
269
|
+
# Archives
|
|
270
|
+
".tar": "archive", ".gz": "archive", ".zip": "archive",
|
|
271
|
+
".bz2": "archive", ".xz": "archive", ".7z": "archive",
|
|
272
|
+
".rar": "archive", ".cab": "archive",
|
|
273
|
+
".deb": "package", ".rpm": "package",
|
|
274
|
+
# Security
|
|
275
|
+
".pem": "certificate", ".key": "key_file", ".crt": "certificate",
|
|
276
|
+
".cert": "certificate", ".pub": "pubkey",
|
|
277
|
+
# Media
|
|
278
|
+
".png": "media", ".jpg": "media", ".jpeg": "media",
|
|
279
|
+
".gif": "media", ".svg": "media", ".ico": "media", ".bmp": "media",
|
|
280
|
+
".mp4": "media", ".mp3": "media", ".wav": "media", ".webm": "media",
|
|
281
|
+
".ttf": "media", ".otf": "media", ".woff": "media", ".woff2": "media",
|
|
282
|
+
# Documents
|
|
283
|
+
".pdf": "document", ".doc": "document", ".docx": "document",
|
|
284
|
+
".xls": "document", ".xlsx": "document",
|
|
285
|
+
".ppt": "document", ".pptx": "document", ".rtf": "document",
|
|
286
|
+
".odt": "document", ".ods": "document", ".odp": "document",
|
|
287
|
+
".txt": "document", ".md": "document", ".rst": "document",
|
|
288
|
+
# Windows-specific
|
|
289
|
+
".mui": "library", ".sys": "library", ".drv": "library",
|
|
290
|
+
".ocx": "library", ".cpl": "library",
|
|
291
|
+
".lnk": "data", ".pf": "data", ".manifest": "config",
|
|
292
|
+
# Runtime
|
|
293
|
+
".sock": "socket_file", ".pid": "runtime", ".lock": "runtime",
|
|
294
|
+
".tmp": "tmp",
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def classify_file(label_str: str) -> str:
|
|
299
|
+
"""Classify a file entity by its path.
|
|
300
|
+
|
|
301
|
+
Extension first — a .docx is a document whether it's in /home/, /tmp/,
|
|
302
|
+
or /var/www/. Path only matters for extensionless files and dotfiles.
|
|
303
|
+
|
|
304
|
+
Returns a plain class name or "unknown".
|
|
305
|
+
"""
|
|
306
|
+
parts = label_str.split()
|
|
307
|
+
if parts and parts[0] == "file":
|
|
308
|
+
parts = parts[1:]
|
|
309
|
+
if not parts:
|
|
310
|
+
return "unknown"
|
|
311
|
+
|
|
312
|
+
path = parts[0].replace("\\", "/")
|
|
313
|
+
|
|
314
|
+
# Extension always wins (defines what the file IS)
|
|
315
|
+
_, ext = os.path.splitext(path)
|
|
316
|
+
ext_lower = ext.lower()
|
|
317
|
+
if ext_lower in _FILE_EXT_CLASSES:
|
|
318
|
+
return _FILE_EXT_CLASSES[ext_lower]
|
|
319
|
+
|
|
320
|
+
# Path-prefix fallback for extensionless files and dotfiles.
|
|
321
|
+
# Find ALL matching patterns, pick the most specific:
|
|
322
|
+
# 1. Longest pattern wins (more specific path context)
|
|
323
|
+
# 2. At equal length, the one appearing DEEPER in the path wins
|
|
324
|
+
# e.g. for "/home/user/.git/refs", "/home/" matches at pos 0
|
|
325
|
+
# but "/.git/" matches at pos 37 — the deeper match is more specific.
|
|
326
|
+
best_match = None
|
|
327
|
+
best_len = -1
|
|
328
|
+
best_pos = -1
|
|
329
|
+
for pattern, category in _FILE_DIR_SORTED:
|
|
330
|
+
if pattern in path:
|
|
331
|
+
plen = len(pattern)
|
|
332
|
+
pos = path.rfind(pattern)
|
|
333
|
+
if plen > best_len or (plen == best_len and pos > best_pos):
|
|
334
|
+
best_match = category
|
|
335
|
+
best_len = plen
|
|
336
|
+
best_pos = pos
|
|
337
|
+
if best_match is not None:
|
|
338
|
+
return _cat_token_to_class(best_match)
|
|
339
|
+
|
|
340
|
+
return "unknown"
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
344
|
+
# SOCK CLASSES
|
|
345
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
346
|
+
|
|
347
|
+
# Map well-known port tokens to plain class names
|
|
348
|
+
# [PORT_SSH] → "port_ssh", [PORT_HTTP] → "port_http", etc.
|
|
349
|
+
_SOCK_PORT_CLASSES = {
|
|
350
|
+
port: token.strip("[]").lower()
|
|
351
|
+
for port, token in WELL_KNOWN_PORTS.items()
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
# Additional well-known ports not in tokenizer
|
|
355
|
+
_SOCK_PORT_CLASSES.update({
|
|
356
|
+
123: "port_ntp",
|
|
357
|
+
135: "port_rpc",
|
|
358
|
+
137: "port_netbios", 138: "port_netbios", 139: "port_netbios",
|
|
359
|
+
389: "port_ldap", 636: "port_ldaps",
|
|
360
|
+
514: "port_syslog",
|
|
361
|
+
1433: "port_mssql", 1521: "port_oracle",
|
|
362
|
+
3389: "port_rdp",
|
|
363
|
+
5985: "port_winrm", 5986: "port_winrm",
|
|
364
|
+
6379: "port_redis",
|
|
365
|
+
9200: "port_elasticsearch",
|
|
366
|
+
27017: "port_mongodb",
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def classify_sock(label_str: str) -> str:
|
|
371
|
+
"""Classify a socket entity by its IP/port tuple.
|
|
372
|
+
|
|
373
|
+
Parses the label for port numbers and classifies by well-known port.
|
|
374
|
+
Falls back to range buckets: port_low (1-1023), port_reg (1024-49151),
|
|
375
|
+
port_eph (49152-65535).
|
|
376
|
+
|
|
377
|
+
Returns a plain class name or "unknown".
|
|
378
|
+
"""
|
|
379
|
+
parts = label_str.split()
|
|
380
|
+
if parts and parts[0] == "netflow":
|
|
381
|
+
parts = parts[1:]
|
|
382
|
+
|
|
383
|
+
# Collect all port-like integers
|
|
384
|
+
ports = []
|
|
385
|
+
for token in parts:
|
|
386
|
+
# Handle IP:port format
|
|
387
|
+
if ":" in token and not token.startswith("0000:"):
|
|
388
|
+
for sub in token.split(":"):
|
|
389
|
+
try:
|
|
390
|
+
p = int(sub)
|
|
391
|
+
if 1 <= p <= 65535:
|
|
392
|
+
ports.append(p)
|
|
393
|
+
except ValueError:
|
|
394
|
+
pass
|
|
395
|
+
elif "->" in token:
|
|
396
|
+
for endpoint in token.split("->"):
|
|
397
|
+
for sub in endpoint.rsplit(":", 1):
|
|
398
|
+
try:
|
|
399
|
+
p = int(sub)
|
|
400
|
+
if 1 <= p <= 65535:
|
|
401
|
+
ports.append(p)
|
|
402
|
+
except ValueError:
|
|
403
|
+
pass
|
|
404
|
+
else:
|
|
405
|
+
try:
|
|
406
|
+
p = int(token)
|
|
407
|
+
if 1 <= p <= 65535:
|
|
408
|
+
ports.append(p)
|
|
409
|
+
except ValueError:
|
|
410
|
+
pass
|
|
411
|
+
|
|
412
|
+
# Classify by the well-known port (the service side).
|
|
413
|
+
# In a socket like "10.0.0.1 58425 192.168.1.1 80", port 80 is the
|
|
414
|
+
# service — port 58425 is ephemeral. If multiple well-known ports
|
|
415
|
+
# exist (shouldn't happen), pick the lowest (most specific service).
|
|
416
|
+
known = sorted([p for p in ports if p in _SOCK_PORT_CLASSES])
|
|
417
|
+
if known:
|
|
418
|
+
return _SOCK_PORT_CLASSES[known[0]]
|
|
419
|
+
|
|
420
|
+
# Range buckets based on the lowest port (most likely the service side)
|
|
421
|
+
if ports:
|
|
422
|
+
min_port = min(ports)
|
|
423
|
+
if min_port <= 1023:
|
|
424
|
+
return "port_low"
|
|
425
|
+
elif min_port <= 49151:
|
|
426
|
+
return "port_reg"
|
|
427
|
+
else:
|
|
428
|
+
return "port_eph"
|
|
429
|
+
|
|
430
|
+
# Unix domain socket or unrecognizable
|
|
431
|
+
if any("/" in t for t in parts):
|
|
432
|
+
return "unix_socket"
|
|
433
|
+
|
|
434
|
+
return "unknown"
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
438
|
+
# UNIFIED INTERFACE
|
|
439
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
440
|
+
|
|
441
|
+
@functools.lru_cache(maxsize=None)
|
|
442
|
+
def classify_entity(node_type: str, label_str: str) -> str:
|
|
443
|
+
"""Classify any entity by its type and label.
|
|
444
|
+
|
|
445
|
+
Args:
|
|
446
|
+
node_type: "subject", "file", or "netflow"
|
|
447
|
+
label_str: the raw label string from indexid2msg
|
|
448
|
+
|
|
449
|
+
Returns:
|
|
450
|
+
A plain string class name (e.g. "webserver", "log_system", "port_ssh").
|
|
451
|
+
"""
|
|
452
|
+
if node_type == "subject":
|
|
453
|
+
cls = classify_proc(label_str)
|
|
454
|
+
elif node_type == "file":
|
|
455
|
+
cls = classify_file(label_str)
|
|
456
|
+
elif node_type == "netflow":
|
|
457
|
+
cls = classify_sock(label_str)
|
|
458
|
+
else:
|
|
459
|
+
cls = "unknown"
|
|
460
|
+
return _CLASS_MERGE.get(cls, cls)
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def get_all_entity_classes():
|
|
464
|
+
"""Return the complete set of known entity class names.
|
|
465
|
+
|
|
466
|
+
Used to build the behavior signature label vocabulary.
|
|
467
|
+
"""
|
|
468
|
+
classes = set()
|
|
469
|
+
classes.update(_PROC_CLASS_SET)
|
|
470
|
+
classes.update(_FILE_CLASS_SET)
|
|
471
|
+
classes.update({_cat_token_to_class(f"[{v.strip('[]')}]") for v in _SOCK_PORT_CLASSES.values()})
|
|
472
|
+
# Extension-based file classes
|
|
473
|
+
classes.update(set(_FILE_EXT_CLASSES.values()))
|
|
474
|
+
# Range buckets + special
|
|
475
|
+
classes.update({"port_low", "port_reg", "port_eph", "unix_socket", "unknown"})
|
|
476
|
+
return sorted(classes)
|