Python startup hook file written on Linux
Matches the file-modification leg of AN0713: an auditd PATH record naming one of the files the Python interpreter processes on its own during startup. Two arms cover the two mechanisms MITRE describes. The first requires both a `.pth` suffix and a `site-packages` or `dist-packages` component in the same path, because a `.pth` file only executes its `import` lines when it sits in a site directory — matching `.pth` anywhere would fire on unrelated files and matching the directory alone would fire on every package file installed. The second arm needs no directory constraint: `sitecustomize.py` and `usercustomize.py` are imported from anywhere on `sys.path`, so the filename is the whole signal. Both are anchored on the filename with `endswith` rather than on an absolute path, because auditd records `name=` exactly as it was handed to the syscall, so a write performed from inside the directory logs a bare `sitecustomize.py` with no leading path at all. This is MITRE's `HookFilePathPatterns` knob, populated here with the Debian and RHEL site directory names and the two customize modules rather than taken from MITRE; a site that keeps virtual environments under a fixed root can tighten the first arm to that root and cut most of the noise below. Scope and limits. Only the write is a single event. The analytic's second half — a python3 execve shortly afterwards, with anomalous children or outbound connections, inside MITRE's `TimeWindow` knob — is a cross-event correlation lib/sigma has no way to express, and its `InterpreterWhitelist` knob applies to that execution rather than to this write. MITRE's `UserContext` knob cannot be applied inside this selection either: auditd emits PATH and SYSCALL as separate records for one event and the writing process's `exe`, `uid` and `auid` live only on the SYSCALL side. The technique is listed for Windows and macOS as well, but the brief carries one analytic and it is Linux-only, so neither platform is attempted here. Prerequisite: auditd watches none of these paths by default, so this rule returns zero rows until watches such as `-w /usr/lib/python3/dist-packages -p wa -k python_hooks` and one per additional interpreter or virtual-environment root are loaded — and zero rows reads as quiet when it actually means blind. Virtual environments created in user home directories are the practical gap: they hold their own site-packages and no fleet-wide watch list can enumerate them in advance. UNVERIFIED AS AUTHORED — derived from MITRE ATT&CK DET0258, not hand-written and not tested by its author. Any lab result is on this rule's own page.Full descriptionShow less
The detection
The 3 SIEM queries below are previews produced by Siemphony’s own translator, not pySigma, and none has been executed against a real backend — review before you deploy.
detection.yml
Splunk · SPL
Run this as a search.
index=* (((type="PATH" AND (name="*/site-packages/*" OR name="*/dist-packages/*")) AND (type="PATH" AND name="*.pth")) OR (type="PATH" AND (name="*sitecustomize.py" OR name="*usercustomize.py")))Elastic · ES|QL
Run this as a search.
FROM logs-*| WHERE (((TO_LOWER(type) == "path" AND (TO_LOWER(name) LIKE "*/site-packages/*" OR TO_LOWER(name) LIKE "*/dist-packages/*")) AND (TO_LOWER(type) == "path" AND TO_LOWER(name) LIKE "*.pth")) OR (TO_LOWER(type) == "path" AND (TO_LOWER(name) LIKE "*sitecustomize.py" OR TO_LOWER(name) LIKE "*usercustomize.py")))
Wazuh · XML rule
Deploy to your manager — this is a rule, not a search.
<group name="sigma,linux,"> <!-- Rule ids must be unique on your manager; 100000+ is the user range. --> <!-- 2 rules: the Sigma condition ORs across different fields, which one rule cannot express. Any one matching is a hit. --> <rule id="100000" level="5"> <!-- Set <if_sid> to the decoder/base rule for linux so this only evaluates relevant events. --> <field name="type" type="pcre2">(?i)^PATH$</field> <field name="name" type="pcre2">(?i)(/site-packages/|/dist-packages/)</field> <field name="type" type="pcre2">(?i)^PATH$</field> <field name="name" type="pcre2">(?i)\.pth$</field> <description>Python startup hook file written on Linux (1/2)</description> <mitre> <id>T1546.018</id> </mitre> </rule> <rule id="100001" level="5"> <!-- Set <if_sid> to the decoder/base rule for linux so this only evaluates relevant events. --> <field name="type" type="pcre2">(?i)^PATH$</field> <field name="name" type="pcre2">(?i)(sitecustomize\.py$|usercustomize\.py$)</field> <description>Python startup hook file written on Linux (2/2)</description> <mitre> <id>T1546.018</id> </mitre> </rule></group>
Sentinel · KQL
Run this as a search.
Sentinel cannot express this construct. No Sentinel table is modelled for this logsource ({"product":"linux","service":"auditd"}), so there is nothing honest to query. Pick a logsource this translator maps, or write the KQL by hand. The Sigma source is on the first tab, unchanged.
Verdicts · reactions · comments
Community
Verdicts from engineers who actually deployed it, and the conversation around it.
Nobody has run this in a real environment and said what happened.
Verdicts from engineers who deployed it
0 castNo verdicts reported yet. The first one is worth more than the tenth — say what you ran it against.
Log in to report a verdict.
Log in to join the discussion.
No comments yet. Someone who deploys this will have something to say about it.