Linux Possible Privilege Escalation via PYTHONPATH
The following analytic detects the creation of a malicious shared object at a Python importlib path outside the standard system library directories, a technique used to abuse PYTHONPATH for local privilege escalation. Attackers exploiting vulnerabilities such as the 2024 NeedRestart flaw (CVE-2024-48990) plant a crafted importlib/__init__.so in an attacker-controlled directory, then manipulate the PYTHONPATH environment variable so that a privileged process, such as NeedRestart running as root, loads the rogue module instead of the legitimate one, achieving code execution with elevated privileges. The detection monitors for file writes matching the importlib/__init__.so pattern that do not originate from expected system library paths.
Detection Query
| tstats `security_content_summariesonly`
count min(_time) as firstTime
max(_time) as lastTime
from datamodel=Endpoint.Filesystem where
Filesystem.file_path="*/importlib/__init__.so*"
NOT Filesystem.file_path IN (
"/lib/*",
"/lib64/*",
"/usr/lib/*",
"/usr/lib64/*",
"/usr/local/lib/*",
"/usr/local/lib64/*"
)
by Filesystem.file_path Filesystem.file_name Filesystem.user Filesystem.dest
Filesystem.process_guid Filesystem.process_id
| `drop_dm_object_name(Filesystem)`
| `security_content_ctime(firstTime)`
| `security_content_ctime(lastTime)`
| `linux_possible_privilege_escalation_via_pythonpath_filter`Author
Raven Tait, Splunk
Data Sources
References
Raw Content
name: Linux Possible Privilege Escalation via PYTHONPATH
id: 5edda575-409a-4820-a048-5780796a181e
version: 1
creation_date: '2026-07-08'
modification_date: '2026-07-08'
author: Raven Tait, Splunk
status: production
type: TTP
description: |-
The following analytic detects the creation of a malicious shared object at a Python importlib path outside the standard system library directories, a technique used to abuse PYTHONPATH for local privilege escalation.
Attackers exploiting vulnerabilities such as the 2024 NeedRestart flaw (CVE-2024-48990) plant a crafted importlib/__init__.so in an attacker-controlled directory, then manipulate the PYTHONPATH environment variable so that a privileged process, such as NeedRestart running as root, loads the rogue module instead of the legitimate one, achieving code execution with elevated privileges.
The detection monitors for file writes matching the importlib/__init__.so pattern that do not originate from expected system library paths.
data_source:
- Sysmon for Linux EventID 11
search: |-
| tstats `security_content_summariesonly`
count min(_time) as firstTime
max(_time) as lastTime
from datamodel=Endpoint.Filesystem where
Filesystem.file_path="*/importlib/__init__.so*"
NOT Filesystem.file_path IN (
"/lib/*",
"/lib64/*",
"/usr/lib/*",
"/usr/lib64/*",
"/usr/local/lib/*",
"/usr/local/lib64/*"
)
by Filesystem.file_path Filesystem.file_name Filesystem.user Filesystem.dest
Filesystem.process_guid Filesystem.process_id
| `drop_dm_object_name(Filesystem)`
| `security_content_ctime(firstTime)`
| `security_content_ctime(lastTime)`
| `linux_possible_privilege_escalation_via_pythonpath_filter`
how_to_implement: |-
The detection is based on data that originates from Endpoint Detection and Response (EDR) agents. These agents are designed to provide security-related telemetry from the endpoints where the agent is installed. To implement this search, you must ingest logs that contain file creation events including the file path and user context. These logs must be processed using the appropriate Splunk Technology Add-ons that are specific to the EDR product. The logs must also be mapped to the `Filesystem` node of the `Endpoint` data model. Use the Splunk Common Information Model (CIM) to normalize the field names and speed up the data modeling process.
known_false_positives: |-
Legitimate Python developers or system administrators may modify PYTHONPATH for testing or application configuration purposes. Filter based on known development environments and trusted user activity.
references:
- https://www.bleepingcomputer.com/news/security/ubuntu-linux-impacted-by-decade-old-needrestart-flaw-that-gives-root/
- https://www.qualys.com/2024/11/19/needrestart/needrestart.txt
drilldown_searches:
- earliest_offset: $info_min_time$
latest_offset: $info_max_time$
name: View the detection results for - "$user$" and "$dest$"
search: '%original_detection_search% | search user = "$user$" dest = "$dest$"'
- name: View risk events for the last 7 days for - "$user$" and "$dest$"
search: '| from datamodel Risk.All_Risk | search normalized_risk_object IN ("$user$", "$dest$") | stats count min(_time) as firstTime max(_time) as lastTime values(search_name) as "Search Name" values(risk_message) as "Risk Message" values(analyticstories) as "Analytic Stories" values(annotations._all) as "Annotations" values(annotations.mitre_attack.mitre_tactic) as "ATT&CK Tactics" by normalized_risk_object | `security_content_ctime(firstTime)` | `security_content_ctime(lastTime)`'
earliest_offset: 7d
latest_offset: '0'
finding:
title: Possible Privilege Escalation via PYTHONPATH via [$file_name$] on [$dest$]
entity:
field: dest
type: system
score: 50
threat_objects:
- field: file_name
type: file_name
analytic_story:
- Linux Privilege Escalation
- Linux Post-Exploitation
- Linux Persistence Techniques
asset_type: Endpoint
cve:
- CVE-2024-48990
mitre_attack_id:
- T1068
- T1574.007
product:
- Splunk Enterprise
- Splunk Enterprise Security
- Splunk Cloud
category: endpoint
security_domain: endpoint
tests:
- name: True Positive Test
test_type: unit
attack_data:
- data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/attack_techniques/T1068/linux_possible_privilege_escalation_via_pythonpath/snapattack_linux.log
source: Syslog:Linux-Sysmon/Operational
sourcetype: sysmon:linux