First Time Python Spawned a Shell on Host

Last updated 23 days ago on 2026-02-23
Created 23 days ago on 2026-02-23

About

Detects the first time a Python process spawns a shell on a given host. Malicious Python scripts, compromised dependencies, or model file deserialization can result in shell spawns that would not occur during normal workflows. Since legitimate Python processes rarely shell out to interactive shells, a first occurrence of this behavior on a host is a strong signal of potential compromise.
Tags
Domain: EndpointOS: macOSUse Case: Threat DetectionTactic: ExecutionData Source: Elastic DefendDomain: LLMLanguage: kuery
Severity
medium
Risk Score
47
MITRE ATT&CK™

Execution (TA0002)(external, opens in a new tab or window)

License
Elastic License v2(external, opens in a new tab or window)

Definition

Rule Type
New Terms Rule
Integration Pack
Prebuilt Security Detection Rules
Index Patterns
logs-endpoint.events.process-*
Related Integrations

endpoint(external, opens in a new tab or window)

Query
text code block:
event.category:process and host.os.type:macos and event.type:start and event.action:exec and process.parent.name:python* and process.name:(bash or dash or sh or tcsh or csh or zsh or ksh or fish) and process.args:"-c" and not process.command_line:(*pip* or *conda* or *brew* or *jupyter*)

Install detection rules in Elastic Security

Detect First Time Python Spawned a Shell on Host in the Elastic Security detection engine by installing this rule into your Elastic Stack.

To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).