Event Triggered Execution: Python Startup Hooks T1546.018

Tactics: Persistence, Privilege Escalation

Adversaries may achieve persistence by leveraging Python’s startup mechanisms, including path configuration (`.pth`) files and the `sitecustomize.py` or `usercustomize.py` modules. These files are automatically processed during the initialization of the Python interpreter, allowing for the execution of arbitrary code whenever Python is invoked.

Authoring guide

Patterns shared across the 2 rules above: which fields they filter on, what specific values they look for, and what they exclude. The catalog normalizes field names across vendors so Sigma's Image, Elastic's process.name, and Splunk's process_name collapse into one row. Each rule contributes at most once per row.

Fields filtered most (6 distinct)

The fields most rules look at when detecting this technique. The How column shows the operators authors use (eq, wildcard, regex_match, match) and how often each appears. Sample values are concrete examples to start from, not an exhaustive list.

FieldRulesHowSample values
Image2is_not_null 2
TargetFilename2wildcard 2/home/*/.config/python/usercustomize.py, /home/*/.local/lib/python*/site-packages/*, /home/*/.local/lib/python*/site-packages/usercustomize.py, /opt/*/lib/python*/site-packages/*, /opt/*/lib/python*/sitecustomize.py
host.os.type2eq 2
EventType1eq 1creation
event.type1eq 1creation
file.extension1eq 1pth

Top indicator values (16 distinct)

Specific (field, operator, value) combinations the rules check for, ranked by how many rules under this technique use each one. The Corpus reach column counts how many rules across the entire catalog (any technique) check the same combination. High numbers point to widely-used indicators that are likely noisy on their own; combine them with another condition for useful signal. Blank means the combination is specific to rules under this technique. Click a value to expand the rules under this technique that use it.

FieldKindValueRules (here)Corpus reach
EventTypeeq
creation
125
TargetFilenamewildcard
/home/*/.config/python/usercustomize.py
1
TargetFilenamewildcard
/home/*/.local/lib/python*/site-packages/*
1
TargetFilenamewildcard
/home/*/.local/lib/python*/site-packages/usercustomize.py
1
TargetFilenamewildcard
/opt/*/lib/python*/site-packages/*
1
TargetFilenamewildcard
/opt/*/lib/python*/sitecustomize.py
1
TargetFilenamewildcard
/usr/lib/python*/dist-packages/*
1
TargetFilenamewildcard
/usr/lib/python*/dist-packages/sitecustomize.py
1
TargetFilenamewildcard
/usr/lib/python*/site-packages/*
1
TargetFilenamewildcard
/usr/lib/python*/sitecustomize.py
1
TargetFilenamewildcard
/usr/local/lib/python*/dist-packages/*
1
TargetFilenamewildcard
/usr/local/lib/python*/dist-packages/sitecustomize.py
1
TargetFilenamewildcard
/usr/local/lib/python*/site-packages/*
1
TargetFilenamewildcard
/usr/local/lib/python*/sitecustomize.py
1
event.typeeq
creation
145
file.extensioneq
pth
1

Exclusions (27 distinct)

Field/operator/value combinations excluded by rules under this technique (top-level not() clauses), sorted by how many rules exclude each. These are the false-positive paths the community has learned to filter out. A new rule that ignores the high-count entries here will likely fire on the same noisy paths. Click a value to expand the rules under this technique that exclude it.

FieldKindValueRules excluding
Imagein
./usr/bin/podman
2
Imagein
/kaniko/executor
2
Imagein
/usr/bin/crio
2
Imagein
/usr/bin/dockerd
2
Imagein
/usr/bin/pacman
2
Imagein
/usr/bin/pamac-daemon
2
Imagein
/usr/bin/podman
2
Imagein
/usr/bin/restic
2
Imagein
/bin/dnf5
1
Imagein
/bin/podman
1
Imagein
/dev/fd/3
1
Imagein
/opt/conda/_conda
1
Imagein
/opt/miniforge3/bin/mamba
1
Imagewildcard
/nix/store/*libexec/docker/dockerd
2
Imagewildcard
/snap/docker/*dockerd
2

Rules under this technique

Every rule in the catalog tagged with this technique, grouped by vendor. Click a rule title for its full predicates, exclusions, and indicators.

Platform (all)
Domain (all)

Elastic 2 rules