LinuxT1059

>python

Python is a high-level interpreted programming language. Frequently pre-installed on Linux systems and abused by adversaries for full-fledged reverse shells, PTY spawning, local port forwarding, and script execution.

Default Executable Paths

/usr/bin/python3
/usr/bin/python
/bin/python3

Integrity & Metadata

Original Name: python3
File Version: Python 3.x
Category Count: 1 weaponized patterns
Forensics & Triage Insight

Python is commonly used to upgrade a dumb reverse shell to a full PTY shell using pty.spawn("/bin/bash").

Detection Engineering Notes

Monitor python executions with -c containing socket, pty, subprocess, or os.system invocations.

Executive Summary & AI Quick Reference

High-Fidelity Telemetry Profile

python is a native utility pre-installed on Linux systems. Threat actors and red teams abuse python as a Living-off-the-Land Binary (LOLBin) to achieve Execute without triggering traditional antivirus file-hash alerts. Legitimate system administrators use it for routine administration, making behavioral command-line telemetry essential for differentiation.

Primary Abused Tactics
Execute
Minimum Privilege
User
Key Telemetry Source
auditd EXECVE
ATT&CK Mapping
T1059

Weaponized Parameters & Proof-of-Concepts

Documented attack commands, parameter flags, and privilege prerequisites.

1 documented methods
Filter Purpose:

Spawns an interactive pseudo-terminal shell from an existing low-privilege command session.

python3 -c "import pty; pty.spawn('/bin/bash')"

SIEM & EDR Detection Rules

Production telemetry rules configured for Microsoft Defender, Sigma, and Splunk.

Telemetry & SIEM Detection Suite (python)

Validated against MITRE T1059
python Microsoft Defender Querykql
1DeviceProcessEvents
2| where FileName in~ ("python", "python3", "python2")
3| where ProcessCommandLine has_all ("-c", "pty", "spawn")
4| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine

Mitigation, Hardening & Prevention

Recommended defensive controls to block or constrain python abuse.

Application Whitelisting

Audit and remove unnecessary SUID / SGID bits (`chmod u-s /path/to/$python`) and restrict sudoers NOPASSWD execution grants.

Attack Surface Reduction

Implement AppArmor or SELinux profiles restricting python network socket creation and read access to sensitive user directories.

Behavioral Alerting

Deploy the KQL, Sigma, and Splunk detection queries below. Alert on anomalous child processes, web requests to unrated external IPs, or encoded payload strings.

Frequently Asked Questions (FAQ) • python

Key operational questions and defensive answers about python LOLBin tradecraft.

What is python and why is it classified as a LOLBin?

python is a legitimate, pre-installed or trusted utility on Linux. It is classified as a Living-off-the-Land Binary (LOLBin) because adversaries abuse its built-in functionality to perform malicious operations—such as Execute—without dropping custom malware binaries on disk.

How do threat actors abuse python in cyber intrusions?

Adversaries leverage python to execute stealthy actions while evading signature-based security controls. For example, attackers execute commands like "python3 -c "import pty; pty.spawn('/bin/bash')"" to achieve Execute, masquerading behind legitimate system process lineage.

How can SOC analysts detect suspicious python activity?

Detection engineers monitor process creation events (Windows Event ID 4688 or Sysmon Event ID 1; Linux auditd EXECVE; macOS Endpoint Security) inspecting anomalous command line arguments, unusual parent-child process relationships (e.g. Office apps or web servers spawning python), and unexpected network connections.

What MITRE ATT&CK techniques does python map to?

python maps to MITRE ATT&CK technique(s): T1059. These techniques cover adversary actions across tactics such as Defense Evasion, Execution, Persistence, and Command and Control.

How can organizations mitigate and restrict python?

Mitigation strategies include implementing Application Control policies (AppLocker or Windows Defender Application Control - WDAC), enforcing Attack Surface Reduction (ASR) rules, configuring strict privilege separation (disallowing standard users from running sensitive switches), and alerting on execution from non-standard directories.

Sharon Ben Moshe
Curated & Verified by
Sharon Ben Moshe
Cybersecurity Researcher & Detection EngineerCheck Point