MITRE ATT&CK / Techniques / T1546.018

Event Triggered Execution: Python Startup Hooks

ID
T1546.018
Tactics
TA0003 Persistence, TA0004 Privilege Escalation
Sub-technique of
T1546 Event Triggered Execution
Platforms
Linux, macOS, Windows
Data sources
Process Creation, File Modification, File Metadata, Network Traffic Content
Source
attack.mitre.org
MITRE last modified
21 Oct 2025

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]

Path configuration files are designed to extend Python’s module search paths through the use of import statements. If a .pth file is placed in Python's site-packages or dist-packages directories, any lines beginning with import will be executed automatically on Python invocation.[2] Similarly, if sitecustomize.py or usercustomize.py is present in the Python path, these files will be imported during interpreter startup, and any code they contain will be executed.[3]

Adversaries may abuse these mechanisms to establish persistence on systems where Python is widely used (e.g., for automation or scripting in production environments).

Detection

Software (2)

References

  1. Volexity GlobalProtect CVE 2024
  2. DFIR Python Persistence 2025
  3. Python Site Configuration Hook