Skip to content

Commit 2405bcb

Browse files
w0rk3rtradebot-elastic
authored andcommitted
[Rule Tuning] ES|QL PowerShell Rules (#4984)
(cherry picked from commit 0507bcd)
1 parent be62004 commit 2405bcb

7 files changed

+43
-17
lines changed

rules/windows/defense_evasion_posh_obfuscation_backtick.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2025/04/15"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2025/07/16"
5+
updated_date = "2025/08/14"
66

77
[rule]
88
author = ["Elastic"]
@@ -107,6 +107,7 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
107107
powershell.file.script_block_text,
108108
powershell.file.script_block_id,
109109
file.name,
110+
file.directory,
110111
file.path,
111112
powershell.sequence,
112113
powershell.total,
@@ -119,11 +120,16 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
119120
// Filter for scripts that match the pattern at least 10 times
120121
| where Esql.script_block_pattern_count >= 10
121122
122-
// Filter FPs, and due to the behavior of the like operator, allow null values
123-
| where (file.name not like "TSS_*.psm1" or file.name is null)
123+
| where file.name not like "TSS_*.psm1"
124+
// ESQL requires this condition, otherwise it only returns matches where file.name exists.
125+
or file.name is null
124126
125127
// VSCode Shell integration
126128
| where not powershell.file.script_block_text like "*$([char]0x1b)]633*"
129+
130+
| where not file.directory == "C:\\Program Files\\MVPSI\\JAMS\\Agent\\Temp"
131+
// ESQL requires this condition, otherwise it only returns matches where file.directory exists.
132+
or file.directory is null
127133
'''
128134

129135

rules/windows/defense_evasion_posh_obfuscation_high_number_proportion.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2025/04/16"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2025/07/16"
5+
updated_date = "2025/08/14"
66

77
[rule]
88
author = ["Elastic"]
@@ -108,6 +108,7 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
108108
Esql.script_block_tmp,
109109
powershell.file.script_block_text,
110110
powershell.file.script_block_id,
111+
file.directory,
111112
file.path,
112113
powershell.sequence,
113114
powershell.total,
@@ -120,8 +121,15 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
120121
// Filter for scripts with high numeric character ratio
121122
| where Esql.script_block_ratio > 0.30
122123
123-
// Exclude noisy patterns such as 64-character hash lists
124-
| where not powershell.file.script_block_text rlike """.*\"[a-fA-F0-9]{64}\"\,.*"""
124+
// Exclude Windows Defender Noisy Patterns
125+
| where not (
126+
file.directory == "C:\\ProgramData\\Microsoft\\Windows Defender Advanced Threat Protection\\Downloads" or
127+
file.directory like "C:\\\\ProgramData\\\\Microsoft\\\\Windows Defender Advanced Threat Protection\\\\DataCollection*"
128+
)
129+
// ESQL requires this condition, otherwise it only returns matches where file.directory exists.
130+
or file.directory is null
131+
| where not powershell.file.script_block_text like "*[System.IO.File]::Open('C:\\\\ProgramData\\\\Microsoft\\\\Windows Defender Advanced Threat Protection\\\\DataCollection*"
132+
| where not powershell.file.script_block_text : "26a24ae4-039d-4ca4-87b4-2f64180311f0"
125133
'''
126134

127135

rules/windows/defense_evasion_posh_obfuscation_iex_env_vars_reconstruction.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2025/04/16"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2025/07/16"
5+
updated_date = "2025/08/14"
66

77
[rule]
88
author = ["Elastic"]
@@ -50,7 +50,7 @@ PowerShell's Invoke-Expression (IEX) command is a powerful tool for executing st
5050
- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if additional systems are affected.
5151
- Implement additional monitoring for unusual PowerShell activity and environment variable manipulations to enhance detection of similar threats in the future.
5252
"""
53-
risk_score = 21
53+
risk_score = 47
5454
rule_id = "b0c98cfb-0745-4513-b6f9-08dddb033490"
5555
setup = """## Setup
5656
@@ -70,7 +70,7 @@ Steps to implement the logging policy via registry:
7070
reg add "hklm\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell\\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1
7171
```
7272
"""
73-
severity = "low"
73+
severity = "medium"
7474
tags = [
7575
"Domain: Endpoint",
7676
"OS: Windows",

rules/windows/defense_evasion_posh_obfuscation_iex_string_reconstruction.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2025/04/16"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2025/07/16"
5+
updated_date = "2025/08/14"
66

77
[rule]
88
author = ["Elastic"]
@@ -110,6 +110,7 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
110110
powershell.file.script_block_text,
111111
powershell.file.script_block_id,
112112
file.path,
113+
file.directory,
113114
powershell.sequence,
114115
powershell.total,
115116
_id,
@@ -120,6 +121,13 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
120121
121122
// Filter for scripts that match the pattern at least once
122123
| where Esql.script_block_pattern_count >= 1
124+
125+
| where not (
126+
file.directory like "C:\\\\Program Files\\\\WindowsPowerShell\\\\Modules\\\\Maester\\\\1.1.0*" or
127+
file.directory like "C:\\\\Users\\\\*\\\\Documents\\\\WindowsPowerShell\\\\Modules\\\\Maester\\\\1.1.0*"
128+
)
129+
// ESQL requires this condition, otherwise it only returns matches where file.directory exists.
130+
or file.directory is null
123131
'''
124132

125133

rules/windows/defense_evasion_posh_obfuscation_reverse_keyword.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2025/04/14"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2025/07/16"
5+
updated_date = "2025/08/14"
66

77
[rule]
88
author = ["Elastic"]
@@ -93,7 +93,7 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
9393
// The emoji is used because it's unlikely to appear in scripts and has a consistent character length of 1
9494
| eval Esql.script_block_tmp = replace(
9595
powershell.file.script_block_text,
96-
"""(?i)(rahc|metsys|stekcos|tcejboimw|ecalper|ecnerferpe|noitcennoc|nioj|eman\.|:vne|gnirts|tcejbo-wen|_23niw|noisserpxe|ekovni|daolnwod)""",
96+
"""(?i)(rahc|metsys|stekcos|tcejboimw|ecalper|ecnerferpe|noitcennoc|nioj|eman\.|:vne$|gnirts|tcejbo-wen|_23niw|noisserpxe|ekovni|daolnwod)""",
9797
"🔥"
9898
)
9999

rules/windows/defense_evasion_posh_obfuscation_string_format.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2025/04/03"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2025/07/16"
5+
updated_date = "2025/08/14"
66

77
[rule]
88
author = ["Elastic"]
@@ -108,7 +108,7 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
108108
powershell.file.script_block_text,
109109
powershell.file.script_block_id,
110110
file.path,
111-
file.name,
111+
file.directory,
112112
powershell.sequence,
113113
powershell.total,
114114
_id,
@@ -123,8 +123,12 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
123123
// Exclude Noisy Patterns
124124
125125
// Icinga Framework
126-
| where (file.name not like "framework_cache.psm1" or file.name is null)
126+
| where not file.directory == "C:\\Program Files\\WindowsPowerShell\\Modules\\icinga-powershell-framework\\cache"
127+
// ESQL requires this condition, otherwise it only returns matches where file.directory exists.
128+
or file.directory IS NULL
127129
130+
| where not (powershell.file.script_block_text LIKE "*GitBranchStatus*" AND
131+
powershell.file.script_block_text LIKE "*$s.BranchBehindStatusSymbol.Text*")
128132
| where not
129133
// https://wtfbins.wtf/17
130134
(

rules_building_block/defense_evasion_posh_obfuscation_proportion_special_chars.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ bypass_bbr_timing = true
33
creation_date = "2025/04/16"
44
integration = ["windows"]
55
maturity = "production"
6-
updated_date = "2025/07/16"
6+
updated_date = "2025/08/14"
77

88
[rule]
99
author = ["Elastic"]
@@ -85,7 +85,7 @@ from logs-windows.powershell_operational* metadata _id, _version, _index
8585
user.id
8686
8787
// Filter for scripts with high special character ratio
88-
| where Esql.script_block_ratio > 0.25
88+
| where Esql.script_block_ratio > 0.30
8989
'''
9090

9191

0 commit comments

Comments
 (0)