Detection rules › Elastic
Suspicious Shell Command Execution via Node.js Parent
This rule detects when a shell command is executed as a child process of a Node.js process. Attackers may use Node.js to run shell commands for various malicious purposes, such as downloading and executing payloads, establishing persistence, or exfiltrating data.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | |
| Command & Control |
Rule body
[rule]
description = """
This rule detects when a shell command is executed as a child process of a Node.js process. Attackers may use Node.js to
run shell commands for various malicious purposes, such as downloading and executing payloads, establishing persistence,
or exfiltrating data.
"""
id = "5f6dbe52-6643-486f-9130-256f58ba9a0c"
license = "Elastic License v2"
name = "Suspicious Shell Command Execution via Node.js Parent"
os_list = ["linux"]
version = "1.0.11"
query = '''
process where event.type == "start" and event.action == "exec" and
process.parent.executable in ("/bin/node", "/usr/bin/node", "/usr/local/bin/node") and
process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and process.args == "-c" and (
(process.command_line like "*echo *" and process.command_line like (
"*./.*", "*http://*", "*https://*", "*/dev/tcp*", "*/dev/udp/*", "*import*pty*spawn*",
"*import*subprocess*call*", "*TCPSocket.new*", "*TCPSocket.open*", "*io.popen*", "*os.execute*",
"*fsockopen*", "*disown*", "*wget*", "*curl*"
)
) or
(
process.command_line like (
"*/etc/cron*", "*/etc/rc.local*", "*/dev/tcp/*", "*/etc/init.d*", "*/etc/update-motd.d*",
"*/etc/ld.so*", "*/etc/sudoers*", "*base64 *", "*base32 *", "*base16 *", "*/etc/profile.d/*",
"*/dev/shm/*", "*/etc/ssh*", "*/home/*/.ssh/*", "*/root/.ssh*" , "*~/.ssh/*", "*autostart*",
"*xxd *", "*/etc/shadow*", "*/var/tmp/*"
)
) or
(process.command_line regex~ """.*http?://[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.*""")
) and
not (
process.executable like "/tmp/newroot/*" or
process.command_line like (
"*169.254.169.254*", "*localhost*", "*127.0.0.1*", "*SNAPSHOT_FILE=*", "*/tmp/claude-shell-snapshot*",
"/home/*/.openclaw/*", "/api.notion.com/*", "/shubble.git/*"
) or
process.args like ("-l SNAPSHOT_FILE*", "-l source*", "NODE_TLS_REJECT_UNAUTHORIZED=0*", "*.claude/*", "ssh-keyscan*", "supergateway --sse*") or
(
process.command_line like "/bin/sh -c rm -rf /dev/shm/streams/*" and
process.parent.args == "/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js"
) or
process.parent.args like ("/home/*/openclaw/*", "openclaw-gateway", "/opt/cursor-agent/node", "/usr/lib/node_modules/openclaw/dist/index.js", "/usr/local/bin/gemini") or
process.parent.command_line like ("*@playwright/cli*", "*playwright-cli*") or
process.command_line in (
"""/bin/sh -c echo BROWSER=none > .env && echo DEMO=true >> .env && echo PORT=3000 >> .env && printf "PUBLIC_URL=http://$(hostname -I | awk '{print $1}'):3000/\n" >> .env && echo WDS_SOCKET_PORT=3000 >> .env && printf "WDS_SOCKET_HOST=$(hostname -I | awk '{print $1}')\n" >> .env && echo JSX_IMPORT_SOURCE=@ac/library-utils/dist/web-components/wc-jsx >> .env""",
"/bin/sh -c chmod +x /etc/init.d/pm2-docker-deployer", """/bin/sh -c grep "^#[ ]*Port[ ]*[0-9]*" /etc/ssh/sshd_config 2>/dev/null"""
) or
(process.command_line like "*shubblecompose-app*" and process.parent.command_line == "node -r dotenv/config dist/server.mjs")
)
'''
min_endpoint_version = "7.15.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0
[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[threat.technique.subtechnique]]
id = "T1059.004"
name = "Unix Shell"
reference = "https://attack.mitre.org/techniques/T1059/004/"
[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1071"
name = "Application Layer Protocol"
reference = "https://attack.mitre.org/techniques/T1071/"
[threat.tactic]
id = "TA0011"
name = "Command and Control"
reference = "https://attack.mitre.org/tactics/TA0011/"
[internal]
min_endpoint_version = "7.15.0"
Stages and Predicates
Stage 1: process
process where event.type == "start" and event.action == "exec" and
process.parent.executable in ("/bin/node", "/usr/bin/node", "/usr/local/bin/node") and
process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and process.args == "-c" and (
(process.command_line like "*echo *" and process.command_line like (
"*./.*", "*http://*", "*https://*", "*/dev/tcp*", "*/dev/udp/*", "*import*pty*spawn*",
"*import*subprocess*call*", "*TCPSocket.new*", "*TCPSocket.open*", "*io.popen*", "*os.execute*",
"*fsockopen*", "*disown*", "*wget*", "*curl*"
)
) or
(
process.command_line like (
"*/etc/cron*", "*/etc/rc.local*", "*/dev/tcp/*", "*/etc/init.d*", "*/etc/update-motd.d*",
"*/etc/ld.so*", "*/etc/sudoers*", "*base64 *", "*base32 *", "*base16 *", "*/etc/profile.d/*",
"*/dev/shm/*", "*/etc/ssh*", "*/home/*/.ssh/*", "*/root/.ssh*" , "*~/.ssh/*", "*autostart*",
"*xxd *", "*/etc/shadow*", "*/var/tmp/*"
)
) or
(process.command_line regex~ """.*http?://[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.*""")
) and
not (
process.executable like "/tmp/newroot/*" or
process.command_line like (
"*169.254.169.254*", "*localhost*", "*127.0.0.1*", "*SNAPSHOT_FILE=*", "*/tmp/claude-shell-snapshot*",
"/home/*/.openclaw/*", "/api.notion.com/*", "/shubble.git/*"
) or
process.args like ("-l SNAPSHOT_FILE*", "-l source*", "NODE_TLS_REJECT_UNAUTHORIZED=0*", "*.claude/*", "ssh-keyscan*", "supergateway --sse*") or
(
process.command_line like "/bin/sh -c rm -rf /dev/shm/streams/*" and
process.parent.args == "/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js"
) or
process.parent.args like ("/home/*/openclaw/*", "openclaw-gateway", "/opt/cursor-agent/node", "/usr/lib/node_modules/openclaw/dist/index.js", "/usr/local/bin/gemini") or
process.parent.command_line like ("*@playwright/cli*", "*playwright-cli*") or
process.command_line in (
"""/bin/sh -c echo BROWSER=none > .env && echo DEMO=true >> .env && echo PORT=3000 >> .env && printf "PUBLIC_URL=http:
"/bin/sh -c chmod +x /etc/init.d/pm2-docker-deployer", """/bin/sh -c grep "^#[ ]*Port[ ]*[0-9]*" /etc/ssh/sshd_config 2>/dev/null"""
) or
(process.command_line like "*shubblecompose-app*" and process.parent.command_line == "node -r dotenv/config dist/server.mjs")
)
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
process.command_line | match | shubblecompose-app | excludes:process.command_line field:"process.command_line" value:"shubblecompose-app" |
process.parent.command_line | eq | node -r dotenv/config dist/server.mjs | excludes:process.parent.command_line field:"process.parent.command_line" value:"node -r dotenv/config dist/server.mjs" |
process.command_line | starts_with | /bin/sh -c rm -rf /dev/shm/streams/ | excludes:process.command_line field:"process.command_line" value:"/bin/sh -c rm -rf /dev/shm/streams/" |
process.parent.args | eq | /usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js | excludes:process.parent.args field:"process.parent.args" value:"/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js" |
process.args | wildcard | -l SNAPSHOT_FILE*, -l source*, NODE_TLS_REJECT_UNAUTHORIZED=0*, *.claude/*, ssh-keyscan*, supergateway --sse* | excludes:process.args |
process.command_line | in | /bin/sh -c chmod +x /etc/init.d/pm2-docker-deployer, /bin/sh -c echo BROWSER=none > .env && echo DEMO=true >> .env && echo PORT=3000 >> .env && printf "PUBLIC_URL=http://$(hostname -I | awk '{print $1}'):3000/\n" >> .env && echo WDS_SOCKET_PORT=3000 >> .env && printf "WDS_SOCKET_HOST=$(hostname -I | awk '{print $1}')\n" >> .env && echo JSX_IMPORT_SOURCE=@ac/library-utils/dist/web-components/wc-jsx >> .env, /bin/sh -c grep "^#[ ]*Port[ ]*[0-9]*" /etc/ssh/sshd_config 2>/dev/null | excludes:process.command_line |
process.command_line | wildcard | *169.254.169.254*, *localhost*, *127.0.0.1*, *SNAPSHOT_FILE=*, */tmp/claude-shell-snapshot*, /home/*/.openclaw/*, /api.notion.com/*, /shubble.git/* | excludes:process.command_line |
process.executable | starts_with | /tmp/newroot/ | excludes:process.executable field:"process.executable" value:"/tmp/newroot/" |
process.parent.args | wildcard | /home/*/openclaw/*, openclaw-gateway, /opt/cursor-agent/node, /usr/lib/node_modules/openclaw/dist/index.js, /usr/local/bin/gemini | excludes:process.parent.args |
process.parent.command_line | match | @playwright/cli, playwright-cli | excludes:process.parent.command_line field:"process.parent.command_line" value:"@playwright/cli" field:"process.parent.command_line" value:"playwright-cli" |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq value:"exec" |
event.type | eq |
| field:"event.type" kind:eq value:"start" |
process.args | eq |
| field:"process.args" kind:eq value:"-c" |
process.command_line | regex_match |
| field:"CommandLine" kind:regex_match value:".*http?://[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.*" |
process.command_line | wildcard |
| field:"CommandLine" kind:wildcard |
process.name | in |
| field:"process_name" kind:in |
process.parent.executable | in |
| field:"ParentImage" kind:in |