Linux: Detect Python .pth Path Configuration File Creation in site-packages

Alerts on creation of Python .pth files in /lib/python3.X/site-packages on Linux, which can trigger code at Python startup.

FreeReviewedSigma · Medium · v5
Product
linux
Category
file_event
Author
Andreas Braathen (mnemonic.io) (SigmaHQ), DRL 1.1
Published
2024-04-25
Updated
2026-07-31

ATT&CK techniques

Execution
  1. Recon

  2. Resource Dev

  3. Initial Access

  4. Persistence

  5. Priv Esc

  6. Defense Evasion

  7. Cred Access

  8. Discovery

  9. Lateral Movement

  10. Collection

  11. C2

  12. Exfiltration

  13. Impact

What it detects

This rule flags creation of Python path configuration files (.pth) under Python’s site-packages directories on Linux. Attackers can abuse .pth files because their contents are evaluated during Python startup (v3.5+), enabling code execution or persistence without requiring the script to explicitly import the referenced module. It relies on file creation telemetry that includes the created filename and full path, matching for *.pth files within /lib/pythonX.Y/site-packages.

Related detections9 linkedT1059.006 — drag to rearrange
Suspicious Python Execution from Windows Store App Path
Possible Trojanised Python Native Extension Load of gradient Module
Malicious AI CLI Anti-Attribution and Permission Bypass Flags
Suspicious Python HTTP Server Staging for Payload Delivery
Suspicious Python Base64 Encoded Command Execution (via process_creation)
Suspicious __init__.py Drop in Public Directory by Slow Pisces (via file_event)
Malicious Python Reverse Shell One-Liner Execution (via process_creation)
Suspicious Silver Fox Backdoor Execution via pythonw appclient Module (via process_creation)
Suspicious Malicious MCP Package devtools-assistant Execution (via process_creation)
Linux: Detect Python .pth Path Configuration File Creation in site-packages
Pivot detection · T1059.006 · 9 related

Changelog

v5
  1. v5
    Candidate ingested via manual entry.2026-07-31
  2. v4
    Candidate ingested via manual entry.2026-07-31
  3. v3
    Candidate ingested via manual entry.2026-07-31
  4. v2
    Candidate ingested via manual entry.2026-07-31
  5. v1
    No changelog recorded for this version.2026-07-30

Detection content is published as a reviewed draft. Tune thresholds and exclusions against your own telemetry before enabling this rule for alerting.