Has utilized Python startup hooks to include the .pth import mechanism for execution.1
Python Startup Hooks T1546.018
- Tactics
- Persistence, Privilege Escalation
- Platforms
- Linux, macOS, Windows
- Version
- 1.0
- Created
- 22 May 2025
- Last modified
- 21 October 2025
- Contributors
- Ruben Groenewoud (@RFGroenewoud); Pyae Heinn Kyaw, CSIRT @ Salesforce
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.[1]
Python Startup Hooks MITRE reference T1546.018
2 software entries are documented implementing this technique. MITRE files each as a tool or as malware; newest first, then by how many groups carry them.
Has used .pth files to establish persistence on compromised hosts due to the Python interpreter's automatic processing of .pth files at startup.1
All 2 software entries for this technique
Offense vs defense T1546.018
Is defensive coverage keeping up with adversary use? Eight counts, each ranked against all 697 ATT&CK techniques. Attack sits left, defense right, so a shape leaning left means adversaries are better documented here than defenders are equipped. Hover any spoke for its percentile and the share of techniques that have more. The timeline below shows when each side arrived.
Python Startup Hooks detection strategy DET0258
MITRE names one behaviour worth catching for this technique and breaks it into 1 analytic, one per platform. Each carries the log sources it needs and the fields you tune per environment.
Linux Python Startup Hook Persistence via .pth and Customize Files (T1546.018)
AN0713 · Linux
Defender observes unauthorized modification or creation of Python hook files such as .pth, sitecustomize.py, or usercustomize.py in Python site-packages, dist-packages, or user paths. This is often correlated with subsequent unexpected interpreter execution (e.g., python3 running without user interaction), changes in interpreter behavior (e.g., malicious imports), and outbound connections initiated from Python. Defender links write/modify actions on hook files with execve of python process and/or anomalous child process or network activity.
Log sources
The data this analytic draws on. You do not need every component — each one you already collect covers part of it. Each links to its ATT&CK record.
| Data component | Name | Channel |
|---|---|---|
| Process CreationDC0032 | auditd:SYSCALL | execve: execve where exe=/usr/bin/python3 or similar interpreter |
| File MetadataDC0059 | auditd:CONFIG_CHANGE | chmod or chown of hook files indicating privilege escalation or execution permission change |
| File ModificationDC0061 | auditd:PATH | write or create events on *.pth, sitecustomize.py, usercustomize.py in site-packages or dist-packages |
| Network Traffic ContentDC0085 | NSM:Flow | http::request: Outbound HTTP initiated by Python interpreter |
Tunable fields
MITRE calls these the analytic’s mutable elements: the thresholds and filters you set for your own environment.
| Field | What you tune |
|---|---|
| HookFilePathPatterns | Absolute or regex paths to Python startup files (.pth, customize.py); vary by distro or virtual environment location |
| UserContext | Restrict alerts to non-root users, service accounts, or interactive shell sessions |
| TimeWindow | Correlate file modification and Python execution within short time span (default: 2–5 minutes) |
| InterpreterWhitelist | Filter out known legitimate Python executions tied to expected cron jobs or automation |
Tests from Atomic Red Team (MIT licence) · technique definition