Skip to content

Commit aaa4ce2

Browse files
eric-forte-elasticterrancedejesusMikaayenson
authored
[BUG] test_all_rule_queries_optimized does not run on rules (#2823)
* Fixed kql -> kuery in test_all_rule_queries_opt... * all queries optimized * manually reconciled all rules that failed due to toml escaped chars * merge rules from main * Rules needing optimization * Fix optimized note * fix another note * another note fix * fixing whitespace * Updated for readability --------- Co-authored-by: terrancedejesus <[email protected]> Co-authored-by: Mika Ayenson <[email protected]>
1 parent d829b14 commit aaa4ce2

14 files changed

+200
-189
lines changed

rules/cross-platform/execution_pentest_eggshell_remote_admin_tool.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ timestamp_override = "event.ingested"
2323
type = "query"
2424

2525
query = '''
26-
event.category:process and event.type:(start or process_started) and process.name:espl and process.args:eyJkZWJ1ZyI6*
26+
event.category:process and event.type:(process_started or start) and process.name:espl and process.args:eyJkZWJ1ZyI6*
2727
'''
2828

2929

rules/cross-platform/guided_onboarding_sample_rule.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ timestamp_override = "event.ingested"
4949
type = "threshold"
5050

5151
query = '''
52-
event.kind:"event"
52+
event.kind:event
5353
'''
5454

5555

rules/integrations/kubernetes/initial_access_anonymous_request_authorized.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ timestamp_override = "event.ingested"
3838
type = "query"
3939

4040
query = '''
41-
event.dataset : "kubernetes.audit_logs"
42-
and kubernetes.audit.annotations.authorization_k8s_io/decision:"allow"
43-
and (kubernetes.audit.user.username:("system:anonymous" or "system:unauthenticated") or not kubernetes.audit.user.username:*)
44-
and not kubernetes.audit.objectRef.resource:("healthz" or "livez" or "readyz")
41+
event.dataset:kubernetes.audit_logs
42+
and kubernetes.audit.annotations.authorization_k8s_io/decision:allow
43+
and kubernetes.audit.user.username:("system:anonymous" or "system:unauthenticated" or not *)
44+
and not kubernetes.audit.objectRef.resource:(healthz or livez or readyz)
4545
'''
4646

4747

rules/linux/command_and_control_suspicious_network_activity_from_unknown_executable.toml

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ integration = ["endpoint"]
44
maturity = "production"
55
min_stack_comments = "Multiple field support in the New Terms rule type was added in Elastic 8.6"
66
min_stack_version = "8.6.0"
7-
updated_date = "2023/06/14"
7+
updated_date = "2023/06/22"
88

99
[rule]
1010
author = ["Elastic"]
1111
description = """
1212
This rule monitors for network connectivity to the internet from a previously unknown executable located in a suspicious
13-
directory to a previously unknown destination ip. An alert from this rule can indicate the presence of potentially
14-
malicious activity, such as the execution of unauthorized or suspicious processes attempting to establish connections to
15-
unknown or suspicious destinations such as a command and control server. Detecting and investigating such behavior can
13+
directory to a previously unknown destination ip. An alert from this rule can indicate the presence of potentially
14+
malicious activity, such as the execution of unauthorized or suspicious processes attempting to establish connections to
15+
unknown or suspicious destinations such as a command and control server. Detecting and investigating such behavior can
1616
help identify and mitigate potential security threats, protecting the system and its data from potential compromise.
1717
"""
1818
from = "now-59m"
@@ -26,64 +26,77 @@ severity = "low"
2626
tags = ["Domain: Endpoint", "OS: Linux", "Use Case: Threat Detection", "Tactic: Command and Control", "Data Source: Elastic Endgame"]
2727
timestamp_override = "event.ingested"
2828
type = "new_terms"
29+
2930
query = '''
30-
host.os.type : "linux" and event.category : "network" and
31-
event.action : ("connection_attempted" or "ipv4_connection_attempt_event") and
31+
host.os.type:linux and event.category:network and
32+
event.action:(connection_attempted or ipv4_connection_attempt_event) and
3233
process.executable : (
33-
/tmp/* or /var/tmp/* or /dev/shm/* or /etc/init.d/* or /etc/rc*.d/* or /etc/crontab or /etc/cron.*/* or
34-
/etc/update-motd.d/* or /usr/lib/update-notifier/* or /home/*/.* or /boot/* or /srv/* or /run/* or /etc/rc.local) and
35-
source.ip : (
36-
127.0.0.0/8 or
37-
10.0.0.0/8 or
38-
172.16.0.0/12 or
39-
192.168.0.0/16
40-
) and not destination.ip : (
41-
10.0.0.0/8 or
42-
127.0.0.0/8 or
43-
169.254.0.0/16 or
44-
172.16.0.0/12 or
45-
192.0.0.0/24 or
46-
192.0.0.0/29 or
47-
192.0.0.8/32 or
48-
192.0.0.9/32 or
49-
192.0.0.10/32 or
50-
192.0.0.170/32 or
51-
192.0.0.171/32 or
52-
192.0.2.0/24 or
53-
192.31.196.0/24 or
54-
192.52.193.0/24 or
55-
192.168.0.0/16 or
56-
192.88.99.0/24 or
57-
224.0.0.0/4 or
58-
100.64.0.0/10 or
59-
192.175.48.0/24 or
60-
198.18.0.0/15 or
61-
198.51.100.0/24 or
62-
203.0.113.0/24 or
63-
240.0.0.0/4 or
64-
"::1" or
65-
"FE80::/10" or
66-
"FF00::/8"
67-
) and not process.executable : (
68-
"/usr/bin/wget" or
69-
"/usr/bin/curl" or
70-
"/usr/bin/apt" or
71-
"/usr/bin/dpkg" or
72-
"/usr/bin/yum" or
73-
"/usr/bin/rpm" or
74-
"/usr/bin/dnf" or
75-
"/usr/bin/dockerd"
76-
)
34+
(/etc/crontab or
35+
/etc/rc.local or
36+
/boot/* or
37+
/dev/shm/* or
38+
/etc/cron.*/* or
39+
/etc/init.d/* or
40+
/etc/rc*.d/* or
41+
/etc/update-motd.d/* or
42+
/home/*/.* or
43+
/run/* or
44+
/srv/* or
45+
/tmp/* or
46+
/usr/lib/update-notifier/* or
47+
/var/tmp/*) and
48+
not (/usr/bin/apt or
49+
/usr/bin/curl or
50+
/usr/bin/dnf or
51+
/usr/bin/dockerd or
52+
/usr/bin/dpkg or
53+
/usr/bin/rpm or
54+
/usr/bin/wget or
55+
/usr/bin/yum)
56+
)
57+
and source.ip : (
58+
10.0.0.0/8 or
59+
127.0.0.0/8 or
60+
172.16.0.0/12 or
61+
192.168.0.0/16) and
62+
not destination.ip : (
63+
10.0.0.0/8 or
64+
100.64.0.0/10 or
65+
127.0.0.0/8 or
66+
169.254.0.0/16 or
67+
172.16.0.0/12 or
68+
192.0.0.0/24 or
69+
192.0.0.0/29 or
70+
192.0.0.10/32 or
71+
192.0.0.170/32 or
72+
192.0.0.171/32 or
73+
192.0.0.8/32 or
74+
192.0.0.9/32 or
75+
192.0.2.0/24 or
76+
192.168.0.0/16 or
77+
192.175.48.0/24 or
78+
192.31.196.0/24 or
79+
192.52.193.0/24 or
80+
192.88.99.0/24 or
81+
198.18.0.0/15 or
82+
198.51.100.0/24 or
83+
203.0.113.0/24 or
84+
224.0.0.0/4 or
85+
240.0.0.0/4 or
86+
"::1" or
87+
"FE80::/10" or
88+
"FF00::/8")
7789
'''
7890

91+
7992
[[rule.threat]]
8093
framework = "MITRE ATT&CK"
81-
8294
[[rule.threat.technique]]
8395
id = "T1071"
8496
name = "Application Layer Protocol"
8597
reference = "https://attack.mitre.org/techniques/T1071/"
8698

99+
87100
[rule.threat.tactic]
88101
id = "TA0011"
89102
name = "Command and Control"
@@ -92,7 +105,8 @@ reference = "https://attack.mitre.org/tactics/TA0011/"
92105
[rule.new_terms]
93106
field = "new_terms_fields"
94107
value = ["destination.ip", "process.executable"]
95-
96108
[[rule.new_terms.history_window_start]]
97109
field = "history_window_start"
98110
value = "now-2d"
111+
112+

rules/linux/persistence_credential_access_modify_ssh_binaries.toml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ timestamp_override = "event.ingested"
2929
type = "query"
3030

3131
query = '''
32-
event.category:file and host.os.type:linux and event.type:change and
33-
process.name:* and
34-
(file.path:(/usr/sbin/sshd or /usr/bin/ssh or /usr/bin/sftp or /usr/bin/scp) or file.name:libkeyutils.so) and
35-
not process.name:("dpkg" or "yum" or "dnf" or "dnf-automatic")
32+
event.category:file and host.os.type:linux and event.type:change and
33+
process.name:(* and not (dnf or dnf-automatic or dpkg or yum)) and
34+
(file.path:(/usr/bin/scp or
35+
/usr/bin/sftp or
36+
/usr/bin/ssh or
37+
/usr/sbin/sshd) or
38+
file.name:libkeyutils.so)
3639
'''
3740

3841

@@ -48,7 +51,6 @@ reference = "https://attack.mitre.org/techniques/T1543/"
4851
id = "TA0003"
4952
name = "Persistence"
5053
reference = "https://attack.mitre.org/tactics/TA0003/"
51-
5254
[[rule.threat]]
5355
framework = "MITRE ATT&CK"
5456
[[rule.threat.technique]]
@@ -61,12 +63,18 @@ reference = "https://attack.mitre.org/techniques/T1556/"
6163
id = "TA0006"
6264
name = "Credential Access"
6365
reference = "https://attack.mitre.org/tactics/TA0006/"
64-
65-
66-
67-
6866
[[rule.threat]]
6967
framework = "MITRE ATT&CK"
68+
[[rule.threat.technique]]
69+
id = "T1021"
70+
name = "Remote Services"
71+
reference = "https://attack.mitre.org/techniques/T1021/"
72+
[[rule.threat.technique.subtechnique]]
73+
id = "T1021.004"
74+
name = "SSH"
75+
reference = "https://attack.mitre.org/techniques/T1021/004/"
76+
77+
7078
[[rule.threat.technique]]
7179
id = "T1563"
7280
name = "Remote Service Session Hijacking"
@@ -76,16 +84,10 @@ id = "T1563.001"
7684
name = "SSH Hijacking"
7785
reference = "https://attack.mitre.org/techniques/T1563/001/"
7886

79-
[[rule.threat.technique]]
80-
id = "T1021"
81-
name = "Remote Services"
82-
reference = "https://attack.mitre.org/techniques/T1021/"
83-
[[rule.threat.technique.subtechnique]]
84-
id = "T1021.004"
85-
name = "SSH"
86-
reference = "https://attack.mitre.org/techniques/T1021/004/"
87+
8788

8889
[rule.threat.tactic]
8990
id = "TA0008"
9091
name = "Lateral Movement"
9192
reference = "https://attack.mitre.org/tactics/TA0008/"
93+

rules/linux/persistence_shared_object_creation.toml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@ integration = ["endpoint"]
44
maturity = "production"
55
min_stack_comments = "New fields added: required_fields, related_integrations, setup, New Term"
66
min_stack_version = "8.6.0"
7-
updated_date = "2023/06/09"
7+
updated_date = "2023/06/22"
88

99
[rule]
1010
author = ["Elastic"]
1111
description = """
12-
This rule monitors the creation of shared object files by previously unknown processes. The creation of a shared object
13-
file involves compiling code into a dynamically linked library that can be loaded by other programs at runtime. While
14-
this process is typically used for legitimate purposes, malicious actors can leverage shared object files to execute
15-
unauthorized code, inject malicious functionality into legitimate processes, or bypass security controls. This allows
16-
malware to persist on the system, evade detection, and potentially compromise the integrity and confidentiality of the
12+
This rule monitors the creation of shared object files by previously unknown processes. The creation of a shared object
13+
file involves compiling code into a dynamically linked library that can be loaded by other programs at runtime. While
14+
this process is typically used for legitimate purposes, malicious actors can leverage shared object files to execute
15+
unauthorized code, inject malicious functionality into legitimate processes, or bypass security controls. This allows
16+
malware to persist on the system, evade detection, and potentially compromise the integrity and confidentiality of the
1717
affected system and its data.
1818
"""
1919
from = "now-9m"
2020
index = ["logs-endpoint.events.*", "endgame-*"]
2121
language = "kuery"
2222
license = "Elastic License v2"
2323
name = "Shared Object Created or Changed by Previously Unknown Process"
24-
references = [
25-
"https://threatpost.com/sneaky-malware-backdoors-linux/180158/"
26-
]
24+
references = ["https://threatpost.com/sneaky-malware-backdoors-linux/180158/"]
2725
risk_score = 47
2826
rule_id = "aebaa51f-2a91-4f6a-850b-b601db2293f4"
2927
severity = "medium"
@@ -32,23 +30,25 @@ timestamp_override = "event.ingested"
3230
type = "new_terms"
3331

3432
query = '''
35-
host.os.type : "linux" and event.action:("creation" or "file_create_event" or "rename" or "file_rename_event") and
36-
file.path : (/usr/lib/* or /dev/shm/*) and file.extension : "so" and process.name : * and not
37-
process.name : ("dpkg" or "dockerd" or "rpm" or "snapd" or "5")
33+
host.os.type:linux and event.action:(creation or file_create_event or file_rename_event or rename) and
34+
file.path:(/dev/shm/* or /usr/lib/*) and file.extension:so and
35+
process.name:(* and not (5 or dockerd or dpkg or rpm or snapd))
3836
'''
3937

38+
4039
[[rule.threat]]
4140
framework = "MITRE ATT&CK"
4241
[[rule.threat.technique]]
4342
id = "T1574"
4443
name = "Hijack Execution Flow"
4544
reference = "https://attack.mitre.org/techniques/T1574/"
46-
4745
[[rule.threat.technique.subtechnique]]
4846
id = "T1574.006"
4947
name = "Dynamic Linker Hijacking"
5048
reference = "https://attack.mitre.org/techniques/T1574/006/"
5149

50+
51+
5252
[rule.threat.tactic]
5353
id = "TA0003"
5454
name = "Persistence"
@@ -57,7 +57,8 @@ reference = "https://attack.mitre.org/tactics/TA0003/"
5757
[rule.new_terms]
5858
field = "new_terms_fields"
5959
value = ["file.path", "process.name"]
60-
6160
[[rule.new_terms.history_window_start]]
6261
field = "history_window_start"
6362
value = "now-7d"
63+
64+

rules/macos/defense_evasion_modify_environment_launchctl.toml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,20 @@ timestamp_override = "event.ingested"
2929
type = "query"
3030

3131
query = '''
32-
event.category:process and host.os.type:macos and event.type:start and
33-
process.name:launchctl and
34-
process.args:(setenv and not (JAVA*_HOME or
35-
RUNTIME_JAVA_HOME or
36-
DBUS_LAUNCHD_SESSION_BUS_SOCKET or
37-
ANT_HOME or
38-
LG_WEBOS_TV_SDK_HOME or
39-
WEBOS_CLI_TV or
40-
EDEN_ENV)
41-
) and
42-
not process.parent.executable:("/Applications/NoMachine.app/Contents/Frameworks/bin/nxserver.bin" or
43-
"/usr/local/bin/kr" or
44-
"/Applications/NoMachine.app/Contents/Frameworks/bin/nxserver.bin" or
45-
"/Applications/IntelliJ IDEA CE.app/Contents/jbr/Contents/Home/lib/jspawnhelper") and
46-
not process.args : "*.vmoptions"
32+
event.category:process and host.os.type:macos and event.type:start and
33+
process.name:launchctl and
34+
process.args:(setenv and not (ANT_HOME or
35+
DBUS_LAUNCHD_SESSION_BUS_SOCKET or
36+
EDEN_ENV or
37+
LG_WEBOS_TV_SDK_HOME or
38+
RUNTIME_JAVA_HOME or
39+
WEBOS_CLI_TV or
40+
JAVA*_HOME) and
41+
not *.vmoptions) and
42+
not process.parent.executable:("/Applications/IntelliJ IDEA CE.app/Contents/jbr/Contents/Home/lib/jspawnhelper" or
43+
/Applications/NoMachine.app/Contents/Frameworks/bin/nxserver.bin or
44+
/Applications/NoMachine.app/Contents/Frameworks/bin/nxserver.bin or
45+
/usr/local/bin/kr)
4746
'''
4847

4948

rules/macos/defense_evasion_sandboxed_office_app_suspicious_zip_file.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ timestamp_override = "event.ingested"
3131
type = "query"
3232

3333
query = '''
34-
event.category:file and host.os.type:macos and not event.type:deletion and file.name:~$*.zip and host.os.type:macos
34+
event.category:file and host.os.type:(macos and macos) and not event.type:deletion and file.name:~$*.zip
3535
'''
3636

3737

0 commit comments

Comments
 (0)