T1059.006 IBM QRadar · QRadar

Detect Python in IBM QRadar

Adversaries may abuse Python commands and scripts for execution. Python is a cross-platform scripting language that can be executed interactively from the command-line (via python.exe/python3), via scripts (.py), or compiled into binary executables. Python's built-in libraries for file operations, networking (socket, urllib, requests), and system interaction make it a powerful tool for adversaries. Threat actors including APT31, APT37, MuddyWater, and Contagious Interview have used Python-based implants, reverse shells, and backdoors across Windows, Linux, macOS, and ESXi environments.

MITRE ATT&CK

Tactic
Execution
Technique
T1059 Command and Scripting Interpreter
Sub-technique
T1059.006 Python
Canonical reference
https://attack.mitre.org/techniques/T1059/006/

QRadar Detection Query

IBM QRadar (QRadar)
sql
SELECT
  DATEFORMAT(starttime, 'yyyy-MM-dd HH:mm:ss') AS event_time,
  logsourcename(logsourceid) AS log_source,
  username,
  sourceip,
  "hostname",
  QIDNAME(qid) AS event_name,
  "Process Name" AS process_name,
  "Command" AS command_line,
  "Parent Process Name" AS parent_process
FROM events
WHERE LOGSOURCETYPEID IN (12, 352, 433)
  AND (
    LOWER("Process Name") LIKE '%python%'
    OR LOWER("Process Name") LIKE '%python3%'
    OR LOWER("Process Name") LIKE '%pythonw%'
  )
  AND (
    LOWER("Command") LIKE '%socket.socket%'
    OR LOWER("Command") LIKE '%pty.spawn%'
    OR LOWER("Command") LIKE '%subprocess.popen%'
    OR LOWER("Command") LIKE '%subprocess.call%'
    OR LOWER("Command") LIKE '%os.system%'
    OR LOWER("Command") LIKE '%os.popen%'
    OR LOWER("Command") LIKE '%exec(%'
    OR LOWER("Command") LIKE '%eval(%'
    OR LOWER("Command") LIKE '%compile(%'
    OR LOWER("Command") LIKE '%__import__%'
    OR LOWER("Command") LIKE '%base64.b64decode%'
    OR LOWER("Command") LIKE '%codecs.decode%'
    OR LOWER("Command") LIKE '%reverse_shell%'
    OR LOWER("Command") LIKE '%/bin/sh%'
    OR LOWER("Command") LIKE '%urllib%'
    OR LOWER("Command") LIKE '%requests%'
  )
  AND starttime > NOW() - 86400000
ORDER BY starttime DESC
LIMIT 500
high severity medium confidence

Detects suspicious Python interpreter execution for T1059.006 by querying QRadar events from Windows Sysmon (LOGSOURCETYPEID 352), Linux auditd (LOGSOURCETYPEID 433), and Microsoft Windows Security Event Log (LOGSOURCETYPEID 12). Matches process command lines containing patterns associated with reverse shells, download-and-execute behavior, subprocess abuse, and dynamic code execution via Python.

Data Sources

Windows Sysmon Event ID 1 (Process Create)Linux auditd EXECVE recordsMicrosoft Windows Security Event Log (Event ID 4688 with command line auditing enabled)

Required Tables

events

False Positives & Tuning

  • Python-based monitoring agents (Datadog, New Relic, etc.) that use subprocess or socket for metrics collection
  • DevOps tooling such as Fabric, Invoke, or Ansible runner scripts executed from CI/CD pipelines
  • Data science workloads running Jupyter notebooks or ML training jobs that legitimately use urllib and requests for dataset downloads
Download portable Sigma rule (.yml)

Other platforms for T1059.006


Testing Methodology

Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.

  1. Test 1Python Reverse Shell One-Liner

    Expected signal: Auditd: EXECVE record for python3 with -c flag and socket.socket in arguments. Network connection attempt to 127.0.0.1:4444. MDE DeviceProcessEvents and DeviceNetworkEvents on managed endpoints.

  2. Test 2Python Download and Execute

    Expected signal: Sysmon Event ID 1: Process Create for python.exe with urllib in CommandLine. Sysmon Event ID 3: Network Connection to 127.0.0.1:8080 (will fail without listener). The exec() call triggers even though download fails.

  3. Test 3Python Subprocess Command Execution

    Expected signal: Sysmon Event ID 1: Process Create for python.exe with subprocess.Popen in CommandLine. Child process event for cmd.exe spawned by python.exe.

Unlock Pro Content

Get the full detection package for T1059.006 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections