Python PYTHONPATH Modification During Package Installation
The following analytic detects modification of the PYTHONPATH environment variable in conjunction with a package installation process. Python looks up the `sys.path` variable, which is generated by combining user and…
Description
The following analytic detects modification of the PYTHONPATH environment variable in conjunction with a package installation process. Python looks up the `sys.path` variable, which is generated by combining user and site folders with `.pth` files and the value of the PYTHONPATH environment variable, to determine which directories to use for importing modules. If an adversary is able to control the value of PYTHONPATH, they can point it to an attacker-controlled directory and hijack imported packages, achieving user-level persistence across future Python invocations and new shell sessions. If confirmed malicious, this could result in arbitrary code execution every time Python is invoked by the affected user.
Detection logic
Detection requirements
- Platform
- LinuxmacOSWindows
The rule states no platform. This is derived from the 2 ATT&CK techniques it maps to.
- Log source category
- sysmon_eventid_1_and_sysmon_eventid_13
Known benign triggers
- Developers and legitimate installers may modify PYTHONPATH as part of normal environment configuration. Investigate the new value and parent process to determine legitimacy.
MITRE ATT&CK mappings
0 exclusive techniques.This is coverage no other published rule has; it is not this rule's total technique count.
References
| Reference | Cited by |
|---|---|
| blog.talosintelligence.com/the-serpents-tongue-luring-the-python-out-of-its-den/ | 4 |
From the source
- At source
- Open at source
- Upstream identifier
- 00f01ba4-df01-4caa-90f6-187e4563a516
- Tagged by the source as
- Compromised Windows HostMalicious Python Package InstallationSuspicious Windows Registry ActivitiesWindows Persistence TechniquesWindows Registry AbuseEndpointendpointSplunk CloudSplunk EnterpriseSplunk Enterprise Securityendpoint
Licence
- Published under
- Apache License 2.0Read the licence
- Attribution
- Required
- Obtained under
- Apache-2.0Read the origin licence
Authorship
- Written by
- Published
- Aug 26, 2026
- Version
- 1