Skip to content

T1546.018 Python Startup Hooks

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.3

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.1

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

Item Value
ID T1546.018
Sub-techniques T1546.001, T1546.002, T1546.003, T1546.004, T1546.005, T1546.006, T1546.007, T1546.008, T1546.009, T1546.010, T1546.011, T1546.012, T1546.013, T1546.014, T1546.015, T1546.016, T1546.017, T1546.018
Tactics TA0003, TA0004
Platforms Linux, Windows, macOS
Version 1.0
Created 22 May 2025
Last Modified 21 October 2025

References