Skip to content

Commit a805136

Browse files
w0rk3rgithub-actions[bot]
authored andcommitted
[Rule Tuning] PowerShell Rules (#3903)
(cherry picked from commit 6bc1913)
1 parent fffdb57 commit a805136

14 files changed

+82
-42
lines changed

rules/windows/collection_posh_keylogger.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2021/10/15"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2024/05/21"
5+
updated_date = "2024/07/17"
66

77
[rule]
88
author = ["Elastic"]
@@ -57,7 +57,7 @@ references = [
5757
"https://github.com/EmpireProject/Empire/blob/master/data/module_source/collection/Get-Keystrokes.ps1",
5858
"https://github.com/MojtabaTajik/FunnyKeylogger/blob/master/FunnyLogger.ps1",
5959
]
60-
risk_score = 47
60+
risk_score = 73
6161
rule_id = "bd2c86a0-8b61-4457-ab38-96943984e889"
6262
setup = """## Setup
6363
@@ -77,7 +77,7 @@ Steps to implement the logging policy via registry:
7777
reg add "hklm\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell\\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1
7878
```
7979
"""
80-
severity = "medium"
80+
severity = "high"
8181
tags = [
8282
"Domain: Endpoint",
8383
"OS: Windows",

rules/windows/credential_access_posh_invoke_ninjacopy.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2023/01/23"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2024/05/21"
5+
updated_date = "2024/07/17"
66

77
[rule]
88
author = ["Elastic"]
@@ -50,9 +50,9 @@ Invoke-NinjaCopy is a PowerShell script capable of reading SYSTEM files that wer
5050
references = [
5151
"https://github.com/BC-SECURITY/Empire/blob/main/empire/server/data/module_source/collection/Invoke-NinjaCopy.ps1",
5252
]
53-
risk_score = 47
53+
risk_score = 73
5454
rule_id = "b8386923-b02c-4b94-986a-d223d9b01f88"
55-
severity = "medium"
55+
severity = "high"
5656
tags = [
5757
"Domain: Endpoint",
5858
"OS: Windows",

rules/windows/credential_access_posh_kerb_ticket_dump.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2023/07/26"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2024/05/21"
5+
updated_date = "2024/07/17"
66

77
[rule]
88
author = ["Elastic"]
@@ -61,7 +61,7 @@ This rule indicates the use of scripts that contain code capable of dumping Kerb
6161
- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
6262
"""
6363
references = ["https://github.com/MzHmO/PowershellKerberos/blob/main/dumper.ps1"]
64-
risk_score = 47
64+
risk_score = 73
6565
rule_id = "fddff193-48a3-484d-8d35-90bb3d323a56"
6666
setup = """## Setup
6767
@@ -81,7 +81,7 @@ Steps to implement the logging policy via registry:
8181
reg add "hklm\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell\\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1
8282
```
8383
"""
84-
severity = "medium"
84+
severity = "high"
8585
tags = [
8686
"Domain: Endpoint",
8787
"OS: Windows",

rules/windows/credential_access_posh_relay_tools.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2024/03/27"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2024/05/21"
5+
updated_date = "2024/07/17"
66

77
[rule]
88
author = ["Elastic"]
@@ -22,7 +22,7 @@ references = [
2222
"https://github.com/nettitude/PoshC2/blob/master/resources/modules/Invoke-Tater.ps1",
2323
"https://github.com/Kevin-Robertson/Inveigh/blob/master/Inveigh.ps1",
2424
]
25-
risk_score = 47
25+
risk_score = 73
2626
rule_id = "951779c2-82ad-4a6c-82b8-296c1f691449"
2727
setup = """## Setup
2828
@@ -42,7 +42,7 @@ Steps to implement the logging policy via registry:
4242
reg add "hklm\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell\\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1
4343
```
4444
"""
45-
severity = "medium"
45+
severity = "high"
4646
tags = [
4747
"Domain: Endpoint",
4848
"OS: Windows",
@@ -63,7 +63,8 @@ event.category:process and host.os.type:windows and
6363
"0x4e,0x54,0x20,0x4c,0x4d" or
6464
"0x53,0x4d,0x42,0x20,0x32" or
6565
"0x81,0xbb,0x7a,0x36,0x44,0x98,0xf1,0x35,0xad,0x32,0x98,0xf0,0x38"
66-
)
66+
) and
67+
not file.directory : "C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\Downloads"
6768
'''
6869

6970

rules/windows/defense_evasion_posh_assembly_load.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ integration = ["windows"]
44
maturity = "production"
55
min_stack_comments = "KQL handles backslash and ? characters differently in 8.12+."
66
min_stack_version = "8.12.0"
7-
updated_date = "2024/03/12"
7+
updated_date = "2024/07/17"
88

99
[transform]
1010
[[transform.osquery]]
@@ -142,6 +142,9 @@ event.category:process and host.os.type:windows and
142142
("Get-SolutionFiles" or "Get-VisualStudio" or "Select-MSBuildPath") and
143143
file.name : "PathFunctions.ps1"
144144
) and
145+
not powershell.file.script_block_text : (
146+
"Microsoft.PowerShell.Workflow.ServiceCore" and "ExtractPluginProperties([string]$pluginDir"
147+
) and
145148
not user.id : "S-1-5-18"
146149
'''
147150

rules/windows/defense_evasion_posh_compressed.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ integration = ["windows"]
44
maturity = "production"
55
min_stack_comments = "KQL handles backslash and ? characters differently in 8.12+."
66
min_stack_version = "8.12.0"
7-
updated_date = "2024/03/12"
7+
updated_date = "2024/07/17"
88

99
[transform]
1010
[[transform.osquery]]
@@ -103,7 +103,7 @@ Attackers can embed compressed and encoded payloads in scripts to load directly
103103
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
104104
- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
105105
"""
106-
risk_score = 47
106+
risk_score = 73
107107
rule_id = "81fe9dc6-a2d7-4192-a2d8-eed98afc766a"
108108
setup = """## Setup
109109
@@ -123,7 +123,7 @@ Steps to implement the logging policy via registry:
123123
reg add "hklm\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell\\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1
124124
```
125125
"""
126-
severity = "medium"
126+
severity = "high"
127127
tags = ["Domain: Endpoint", "OS: Windows", "Use Case: Threat Detection", "Tactic: Defense Evasion", "Resources: Investigation Guide", "Data Source: PowerShell Logs"]
128128
timestamp_override = "event.ingested"
129129
type = "query"

rules/windows/defense_evasion_posh_encryption.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2023/01/23"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2024/05/21"
5+
updated_date = "2024/07/17"
66

77
[rule]
88
author = ["Elastic"]
@@ -81,7 +81,12 @@ event.category:process and host.os.type:windows and
8181
".CreateEncryptor" or
8282
".CreateDecryptor"
8383
)
84-
) and not user.id : "S-1-5-18"
84+
) and
85+
not user.id : "S-1-5-18" and
86+
not (
87+
file.name : "Bootstrap.Octopus.FunctionAppenderContext.ps1" and
88+
powershell.file.script_block_text : ("function Decrypt-Variables" or "github.com/OctopusDeploy")
89+
)
8590
'''
8691

8792

rules/windows/defense_evasion_posh_process_injection.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2021/10/14"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2024/05/21"
5+
updated_date = "2024/07/17"
66

77
[rule]
88
author = ["Elastic"]
@@ -60,7 +60,7 @@ references = [
6060
"https://github.com/BC-SECURITY/Empire/blob/master/empire/server/data/module_source/credentials/Invoke-Mimikatz.ps1",
6161
"https://www.elastic.co/security-labs/detect-credential-access",
6262
]
63-
risk_score = 47
63+
risk_score = 73
6464
rule_id = "2e29e96a-b67c-455a-afe4-de6183431d0d"
6565
setup = """## Setup
6666
@@ -80,7 +80,7 @@ Steps to implement the logging policy via registry:
8080
reg add "hklm\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell\\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1
8181
```
8282
"""
83-
severity = "medium"
83+
severity = "high"
8484
tags = [
8585
"Domain: Endpoint",
8686
"OS: Windows",
@@ -101,8 +101,10 @@ event.category:process and host.os.type:windows and
101101
(WriteProcessMemory or CreateRemoteThread or NtCreateThreadEx or CreateThread or QueueUserAPC or
102102
SuspendThread or ResumeThread or GetDelegateForFunctionPointer)
103103
) and not
104-
(user.id:("S-1-5-18" or "S-1-5-19") and
105-
file.directory: "C:\\ProgramData\\Microsoft\\Windows Defender Advanced Threat Protection\\SenseCM")
104+
file.directory: (
105+
"C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\SenseCM" or
106+
"C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\Downloads"
107+
)
106108
'''
107109

108110

rules/windows/discovery_posh_suspicious_api_functions.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ integration = ["windows"]
44
maturity = "production"
55
min_stack_comments = "KQL handles backslash and ? characters differently in 8.12+."
66
min_stack_version = "8.12.0"
7-
updated_date = "2024/03/12"
7+
updated_date = "2024/07/17"
88

99
[rule]
1010
author = ["Elastic"]
@@ -57,7 +57,7 @@ references = [
5757
"https://github.com/BC-SECURITY/Empire/blob/9259e5106986847d2bb770c4289c0c0f1adf2344/data/module_source/situational_awareness/network/powerview.ps1#L21413",
5858
"https://github.com/atc-project/atc-data/blob/master/docs/Logging_Policies/LP_0109_windows_powershell_script_block_log.md",
5959
]
60-
risk_score = 47
60+
risk_score = 21
6161
rule_id = "61ac3638-40a3-44b2-855a-985636ca985e"
6262
setup = """## Setup
6363
@@ -77,7 +77,7 @@ Steps to implement the logging policy via registry:
7777
reg add "hklm\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell\\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1
7878
```
7979
"""
80-
severity = "medium"
80+
severity = "low"
8181
tags = ["Domain: Endpoint", "OS: Windows", "Use Case: Threat Detection", "Tactic: Discovery", "Tactic: Collection", "Tactic: Execution", "Resources: Investigation Guide", "Data Source: PowerShell Logs"]
8282
timestamp_override = "event.ingested"
8383
type = "query"
@@ -109,6 +109,11 @@ event.category:process and host.os.type:windows and
109109
LsaEnumerateTrustedDomains or
110110
NetScheduleJobEnum or
111111
NetUserModalsGet
112+
) and
113+
not powershell.file.script_block_text : (
114+
("DsGetSiteName" and ("DiscoverWindowsComputerProperties.ps1" and "param($SourceType, $SourceId, $ManagedEntityId, $ComputerIdentity)")) or
115+
("# Copyright: (c) 2018, Ansible Project" and "#Requires -Module Ansible.ModuleUtils.AddType" and "#AnsibleRequires -CSharpUtil Ansible.Basic") or
116+
("Ansible.Windows.Setup" and "Ansible.Windows.Setup" and "NativeMethods.NetWkstaGetInfo(null, 100, out netBuffer);")
112117
)
113118
'''
114119

rules/windows/execution_posh_hacktool_authors.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2024/05/08"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2024/05/21"
5+
updated_date = "2024/07/17"
66

77
[rule]
88
author = ["Elastic"]
@@ -73,9 +73,9 @@ host.os.type:windows and event.category:process and
7373
"itm4n" or "nurfed1" or
7474
"cfalta" or "Scott Sutherland" or
7575
"_nullbind" or "_tmenochet" or
76-
"Boe Prox" or "jaredcatkinson" or
77-
"ChrisTruncer" or "monoxgas" or
78-
"TheRealWover" or "splinter_code"
76+
"jaredcatkinson" or "ChrisTruncer" or
77+
"monoxgas" or "TheRealWover" or
78+
"splinter_code"
7979
)
8080
'''
8181

rules/windows/execution_posh_psreflect.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ integration = ["windows"]
44
maturity = "production"
55
min_stack_comments = "KQL handles backslash and ? characters differently in 8.12+."
66
min_stack_version = "8.12.0"
7-
updated_date = "2024/03/12"
7+
updated_date = "2024/07/17"
88

99
[transform]
1010
[[transform.osquery]]
@@ -114,7 +114,7 @@ references = [
114114
"https://github.com/mattifestation/PSReflect/blob/master/PSReflect.psm1",
115115
"https://github.com/atc-project/atc-data/blob/master/docs/Logging_Policies/LP_0109_windows_powershell_script_block_log.md",
116116
]
117-
risk_score = 47
117+
risk_score = 73
118118
rule_id = "56f2e9b5-4803-4e44-a0a4-a52dc79d57fe"
119119
setup = """## Setup
120120
@@ -135,7 +135,7 @@ Steps to implement the logging policy via registry:
135135
reg add "hklm\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell\\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1
136136
```
137137
"""
138-
severity = "medium"
138+
severity = "high"
139139
tags = ["Domain: Endpoint", "OS: Windows", "Use Case: Threat Detection", "Tactic: Execution", "Resources: Investigation Guide", "Data Source: PowerShell Logs"]
140140
timestamp_override = "event.ingested"
141141
type = "query"

rules/windows/privilege_escalation_posh_token_impersonation.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2022/08/17"
33
integration = ["windows"]
44
maturity = "production"
5-
updated_date = "2024/05/21"
5+
updated_date = "2024/07/17"
66

77
[transform]
88
[[transform.osquery]]
@@ -168,6 +168,10 @@ event.category:process and host.os.type:windows and
168168
) and
169169
not powershell.file.script_block_text : (
170170
"sentinelbreakpoints" and "Set-PSBreakpoint" and "PowerSploitIndicators"
171+
) and
172+
not (
173+
powershell.file.script_block_text : "New-HPPrivateToastNotificationLogo" and
174+
file.path : "C:\Program Files\HPConnect\hp-cmsl-wl\modules\HP.Notifications\HP.Notifications.psm1"
171175
)
172176
'''
173177

rules_building_block/collection_posh_compression.toml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[metadata]
2+
bypass_bbr_timing = true
23
creation_date = "2023/07/06"
34
integration = ["windows"]
45
maturity = "production"
56
min_stack_comments = "KQL handles backslash and ? characters differently in 8.12+."
67
min_stack_version = "8.12.0"
7-
updated_date = "2024/03/12"
8+
updated_date = "2024/07/17"
89

910

1011
[rule]
@@ -13,8 +14,7 @@ description = """
1314
Identifies the use of Cmdlets and methods related to archive compression activities. Adversaries will often compress and
1415
encrypt data in preparation for exfiltration.
1516
"""
16-
from = "now-119m"
17-
interval = "60m"
17+
from = "now-9m"
1818
index = ["winlogbeat-*", "logs-windows.powershell*"]
1919
language = "kuery"
2020
license = "Elastic License v2"
@@ -63,7 +63,12 @@ event.category:process and host.os.type:windows and
6363
"ZipArchiveMode"
6464
) or
6565
powershell.file.script_block_text : "Compress-Archive"
66-
)
66+
) and
67+
not powershell.file.script_block_text : (
68+
"Compress-Archive -Path 'C:\ProgramData\Lenovo\Udc\diagnostics\latest" or
69+
("Copyright: (c) 2017, Ansible Project" and "Ansible.ModuleUtils.Backup")
70+
) and
71+
not file.directory : "C:\Program Files\Microsoft Dependency Agent\plugins\lib"
6772
'''
6873

6974
[[rule.filters]]
@@ -85,7 +90,14 @@ negate = true
8590
negate = true
8691
[rule.filters.query.wildcard."file.path"]
8792
"case_insensitive" = true
88-
"value" = "?:\\\\Program Files\\\\Microsoft Dependency Agent\\\\plugins\\\\*"
93+
"value" = "?:\\\\Program Files\\\\WindowsPowerShell\\\\Modules\\\\dbatools\\\\*\\\\optional\\\\Expand-Archive.ps1"
94+
95+
[[rule.filters]]
96+
[rule.filters.meta]
97+
negate = true
98+
[rule.filters.query.wildcard."file.path"]
99+
"case_insensitive" = true
100+
"value" = "?:\\\\Program Files\\\\WindowsPowerShell\\\\Modules\\\\dbatools\\\\*\\\\optional\\\\Compress-Archive.ps1"
89101

90102
[[rule.filters]]
91103
[rule.filters.meta]

0 commit comments

Comments
 (0)