Detect Unix Shell in IBM QRadar
Adversaries may abuse Unix shell commands and scripts for execution. Unix shells are the primary command prompt on Linux, macOS, and ESXi systems, though many variations exist (sh, ash, bash, zsh, etc.). Unix shells can control every aspect of a system, with certain commands requiring elevated privileges. Adversaries may abuse Unix shells to execute various commands or payloads, access interactive shells through C2 channels, leverage shell scripts for persistence, or use stripped-down shells via Busybox on embedded devices and ESXi servers.
MITRE ATT&CK
- Tactic
- Execution
- Technique
- T1059 Command and Scripting Interpreter
- Sub-technique
- T1059.004 Unix Shell
- Canonical reference
- https://attack.mitre.org/techniques/T1059/004/
QRadar Detection Query
SELECT
DATEFORMAT(starttime, 'yyyy-MM-dd HH:mm:ss') AS event_time,
sourceip,
username,
LOGSOURCENAME(logsourceid) AS log_source,
CATEGORYNAME(category) AS category_name,
"Process Name",
"Command",
CASE
WHEN "Command" ILIKE '%/dev/tcp/%' OR "Command" ILIKE '%nc -e /bin/%' OR "Command" ILIKE '%ncat -e%' OR "Command" ILIKE '%socat exec:%' THEN 3
ELSE 0
END +
CASE
WHEN "Command" ILIKE '%curl%|%bash%' OR "Command" ILIKE '%curl%|%sh%' OR "Command" ILIKE '%wget%|%bash%' OR "Command" ILIKE '%wget%|%sh%' THEN 2
ELSE 0
END +
CASE
WHEN "Command" ILIKE '%base64 -d%' OR "Command" ILIKE '%base64 --decode%' THEN 1
ELSE 0
END +
CASE
WHEN "Command" ILIKE '%chmod +s%' OR "Command" ILIKE '%chmod 4755%' OR "Command" ILIKE '%useradd%' OR "Command" ILIKE '%usermod -aG%' THEN 2
ELSE 0
END AS suspicion_score
FROM events
WHERE
starttime > NOW() - 1 DAYS
AND LOGSOURCETYPEID IN (13, 14, 105, 191)
AND ("Process Name" ILIKE '%bash%' OR "Process Name" ILIKE '%/bin/sh%' OR "Process Name" ILIKE '%zsh%' OR "Process Name" ILIKE '%dash%' OR "Process Name" ILIKE '%busybox%')
AND (
"Command" ILIKE '%/dev/tcp/%' OR
"Command" ILIKE '%/dev/udp/%' OR
"Command" ILIKE '%nc -e /bin/%' OR
"Command" ILIKE '%ncat -e%' OR
"Command" ILIKE '%socat exec:%' OR
"Command" ILIKE '%curl%|%bash%' OR
"Command" ILIKE '%wget%|%bash%' OR
"Command" ILIKE '%base64 -d%' OR
"Command" ILIKE '%base64 --decode%' OR
"Command" ILIKE '%mkfifo /tmp/%' OR
"Command" ILIKE '%chmod +s%' OR
"Command" ILIKE '%chmod 4755%' OR
"Command" ILIKE '%useradd%' OR
"Command" ILIKE '%usermod -aG%' OR
"Command" ILIKE '%iptables -F%' OR
"Command" ILIKE '%python%import socket%' OR
"Command" ILIKE '%perl -e%use Socket%'
)
HAVING suspicion_score > 0
ORDER BY suspicion_score DESC, starttime DESC Detects suspicious Unix shell commands across Linux syslog and auditd log sources. Applies a weighted suspicion score (reverse shell=3, pipe-to-shell=2, privilege escalation=2, base64=1) and surfaces events with any non-zero score. Covers /dev/tcp reverse shells, netcat/socat, curl/wget pipe execution, base64 payload decoding, SUID manipulation, and firewall flush.
Data Sources
Required Tables
False Positives & Tuning
- Legitimate bootstrap scripts in CI/CD environments that use curl | bash to install build agents or language runtimes
- Security teams running authorized red team exercises that deliberately trigger these patterns as part of purple team testing
- System hardening scripts that flush and rebuild iptables rules during scheduled maintenance windows
Other platforms for T1059.004
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.
- Test 1Bash Reverse Shell via /dev/tcp
Expected signal: Auditd: EXECVE record for bash with /dev/tcp in arguments. Syslog: bash process creation. Network connection attempt to 127.0.0.1:4444 (will fail without listener). MDE DeviceProcessEvents on managed Linux endpoints.
- Test 2Curl Pipe to Bash
Expected signal: Auditd: EXECVE records for curl and bash. Process tree shows curl piped to bash. Network connection attempt to 127.0.0.1:8080 (will fail without listener). The curl failure means no content reaches bash.
- Test 3Base64 Encoded Command Execution
Expected signal: Auditd: EXECVE records for echo, base64, and bash. The decoded content 'whoami' will be executed. Syslog captures the process chain.
Unlock Pro Content
Get the full detection package for T1059.004 including response playbook, investigation guide, and atomic red team tests.