Safeguard
Application Security•

Detecting and Mitigating Python Abuse (T1059.006)

Python is installed almost everywhere, which makes it a handy execution tool for intruders. See how MITRE describes it and how to inventory, limit and watch it.

Safeguard Security Team
3 min read

Python abuse (MITRE ATT&CK T1059.006) belongs to the Execution tactic. MITRE lists ESXi, Linux, macOS and Windows as platforms.

Python can run interactively from the command line or from .py scripts that are easy to copy between systems. It can also be compiled into binary executables. Its built-in packages cover file operations and device I/O, so a short script can do a lot without any extra install.

How attackers use it

MITRE's description is brief and to the point. Adversaries use Python's libraries to download and execute commands or other scripts, and to perform a range of other malicious behaviors on the host. Because Python is a general purpose language, there is no single signature for "bad Python". Intent lives in what the script does.

How to detect it

MITRE's detection strategy is cross-platform and behavioral:

  • Windows: python.exe or py.exe with odd parent lineage (for example an Office macro), execution from unusual directories, or chained network, PowerShell or system-level activity.
  • macOS: Python run from Terminal, embedded apps or launchd jobs, followed by network calls, persistence writes or system enumeration.
  • Linux: Python from non-standard user contexts or cron jobs that start outbound traffic, access sensitive files, or inject into processes through ptrace or /proc memory maps.
  • ESXi: Python on hosts through embedded BusyBox shells, nested installations, or files dropped over SSH or datastore mounts.

So the log sources to have in place are process creation with parent and command line, network connections tied to a process, and file creation events.

How to reduce the risk

MITRE lists four mitigations, all plain:

  1. Audit. Inventory systems for unauthorized Python installations.
  2. Limit software installation. Prevent users from installing Python where it is not required.
  3. Execution prevention. Denylist Python where it is not required.
  4. Antivirus or antimalware. Quarantine suspicious files automatically.

Servers that never need an interpreter are the easiest wins. Developer laptops need Python, so rely on detection there.

Check your own environment

# Linux or macOS: where is Python installed?
command -v python python3

# Linux: cron jobs that mention python (read only)
grep -rl python /etc/cron* /var/spool/cron 2>/dev/null
# Windows PowerShell: find Python launchers on PATH
Get-Command python.exe, py.exe -ErrorAction SilentlyContinue

If the same installs show up on hosts that have no business running Python, you have an inventory finding, not just a detection finding.

Quick check

Why is a rule that alerts on any Python execution a poor idea on developer machines?

Python is a normal tool there. Better signals are odd parent processes, unusual directories, and network or system activity chained after launch.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.