Detection rules › Elastic
DNS Request by Recently Created Executable
This rule detects DNS requests initiated by recently created executables in world/user-writable directories. Malware authors may use these requests to communicate with command and control infrastructure or to exfiltrate data from the target system.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | |
| Command & Control |
Rule body
[rule]
description = """
This rule detects DNS requests initiated by recently created executables in world/user-writable directories. Malware
authors may use these requests to communicate with command and control infrastructure or to exfiltrate data from the
target system.
"""
id = "0c393c67-6eb3-4936-ab44-b807ef8af0f7"
license = "Elastic License v2"
name = "DNS Request by Recently Created Executable"
os_list = ["linux"]
version = "1.0.3"
query = '''
sequence by process.parent.entity_id with maxspan=10s
[file where event.type == "creation" and (
process.name in ("curl", "wget", "bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish", "busybox", "timeout", "env") or
process.name like (".*", "python*", "perl*", "php*", "ruby*", "lua*", "node", "deno") or
process.executable like (
"./*", "/tmp/*", "/var/tmp/*", "/dev/shm/*", "/run/*", "/var/run/*", "/boot/*", "/sys/*",
"/lost+found/*", "/proc/*", "/var/mail/*", "/var/www/*", "/home/*/*", "/root/*"
)
) and
file.path like ("/tmp/*", "/var/tmp/*", "/dev/shm/*", "/home/*/*", "/root/*", "/var/www/*") and
not (
file.path like (
"/home/*/.claude/downloads/claude-*-linux-x64", "/home/*/.aimee-code/bin/aimee-code"
) or
(
process.executable like "/home/*/go/pkg/mod/golang.org/*/pkg/tool/linux_amd64/link" and
file.path like "/tmp/go-*/exe/vuln-stats"
) or
process.executable like (
"/home/*/.local/share/claude/versions/*", "/home/*/.vscode-server/cli/servers/Stable-*/server/node",
"/tmp/*/.vscode-server/.vscode-server/cli/servers/Stable-*/server/node", "/home/*/.vscode-server/bin/*/node"
)
)] as event0
[dns where event.action == "lookup_result" and startswith~(process.executable, event0.file.path) and
dns.question.name != "localhost"]
'''
min_endpoint_version = "9.3.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 1
[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0
[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 1
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1204"
name = "User Execution"
reference = "https://attack.mitre.org/techniques/T1204/"
[[threat.technique.subtechnique]]
id = "T1204.002"
name = "Malicious File"
reference = "https://attack.mitre.org/techniques/T1204/002/"
[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.technique.subtechnique]]
id = "T1071.004"
name = "DNS"
reference = "https://attack.mitre.org/techniques/T1071/004/"
[[threat.technique]]
id = "T1102"
name = "Web Service"
reference = "https://attack.mitre.org/techniques/T1102/"
[threat.tactic]
id = "TA0011"
name = "Command and Control"
reference = "https://attack.mitre.org/tactics/TA0011/"
[internal]
min_endpoint_version = "9.3.0"
Stages and Predicates
Ordered sequence: each step below must occur in order within 10s, correlated by process.parent.entity_id.
Stage 1: file
[file where event.type == "creation" and (
process.name in ("curl", "wget", "bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish", "busybox", "timeout", "env") or
process.name like (".*", "python*", "perl*", "php*", "ruby*", "lua*", "node", "deno") or
process.executable like (
"./*", "/tmp/*", "/var/tmp/*", "/dev/shm/*", "/run/*", "/var/run/*", "/boot/*", "/sys/*",
"/lost+found/*", "/proc/*", "/var/mail/*", "/var/www/*", "/home/*/*", "/root/*"
)
) and
file.path like ("/tmp/*", "/var/tmp/*", "/dev/shm/*", "/home/*/*", "/root/*", "/var/www/*") and
not (
file.path like (
"/home/*/.claude/downloads/claude-*-linux-x64", "/home/*/.aimee-code/bin/aimee-code"
) or
(
process.executable like "/home/*/go/pkg/mod/golang.org/*/pkg/tool/linux_amd64/link" and
file.path like "/tmp/go-*/exe/vuln-stats"
) or
process.executable like (
"/home/*/.local/share/claude/versions/*", "/home/*/.vscode-server/cli/servers/Stable-*/server/node",
"/tmp/*/.vscode-server/.vscode-server/cli/servers/Stable-*/server/node", "/home/*/.vscode-server/bin/*/node"
)
)] as event0
Stage 2: dns
[dns where event.action == "lookup_result" and startswith~(process.executable, event0.file.path) and
dns.question.name != "localhost"]
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
file.path | wildcard | /tmp/go-*/exe/vuln-stats | excludes:file.path field:"file.path" value:"/tmp/go-*/exe/vuln-stats" |
process.executable | wildcard | /home/*/go/pkg/mod/golang.org/*/pkg/tool/linux_amd64/link | excludes:process.executable field:"process.executable" value:"/home/*/go/pkg/mod/golang.org/*/pkg/tool/linux_amd64/link" |
file.path | wildcard | /home/*/.claude/downloads/claude-*-linux-x64, /home/*/.aimee-code/bin/aimee-code | excludes:file.path field:"file.path" value:"/home/*/.claude/downloads/claude-*-linux-x64" field:"file.path" value:"/home/*/.aimee-code/bin/aimee-code" |
process.executable | wildcard | /home/*/.local/share/claude/versions/*, /home/*/.vscode-server/cli/servers/Stable-*/server/node, /tmp/*/.vscode-server/.vscode-server/cli/servers/Stable-*/server/node, /home/*/.vscode-server/bin/*/node | excludes:process.executable |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
dns.question.name | ne |
| field:"QueryName" kind:ne value:"localhost" |
event.action | eq |
| field:"EventType" kind:eq value:"lookup_result" |
event.type | eq |
| field:"event.type" kind:eq value:"creation" |
file.path | wildcard |
| field:"TargetFilename" kind:wildcard |
process.executable | starts_with |
| field:"Image" kind:starts_with value:"event0.file.path" |
process.executable | wildcard |
| field:"Image" kind:wildcard |
process.name | in |
| field:"process_name" kind:in |
process.name | wildcard |
| field:"process_name" kind:wildcard |