Skip to content

Commit 8f73b88

Browse files
SamirbousMikaayensonAegrah
authored
[Tuning / New] Execution of a downloaded windows script (#4434)
* [New] Execution of a downloaded windows script using 8.15 file events with MOTW info we can focus on js/vbs/wsh/vbe/jse/hta downloaded from internet followed by execution * Update defense_evasion_posh_assembly_load.toml * Update execution_powershell_susp_args_via_winscript.toml * Update guides * Update defense_evasion_network_connection_from_windows_binary.toml * Update execution_windows_script_from_internet.toml * Update execution_windows_script_from_internet.toml * Update rules/windows/execution_windows_script_from_internet.toml * Update rules/windows/execution_powershell_susp_args_via_winscript.toml Co-authored-by: Ruben Groenewoud <[email protected]> * Update rules/windows/execution_windows_script_from_internet.toml Co-authored-by: Ruben Groenewoud <[email protected]> * Update execution_windows_script_from_internet.toml * Create command_and_control_tool_transfer_via_curl.toml * Update command_and_control_tool_transfer_via_curl.toml * Update command_and_control_tool_transfer_via_curl.toml * Update execution_windows_script_from_internet.toml * Create defense_evasion_indirect_exec_forfiles.toml * Update execution_windows_script_from_internet.toml --------- Co-authored-by: Mika Ayenson <[email protected]> Co-authored-by: Ruben Groenewoud <[email protected]>
1 parent aba793f commit 8f73b88

6 files changed

+347
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
[metadata]
2+
creation_date = "2025/02/03"
3+
integration = ["endpoint", "windows", "system", "m365_defender", "sentinel_one_cloud_funnel", "crowdstrike"]
4+
maturity = "production"
5+
updated_date = "2025/02/03"
6+
min_stack_version = "8.14.0"
7+
min_stack_comments = "Breaking change at 8.14.0 for the Windows Integration."
8+
9+
[rule]
10+
author = ["Elastic"]
11+
description = """
12+
Identifies Curl for Windows making an HTTP request. Adversaries could abuse Curl to download files or upload data to a remote URL.
13+
"""
14+
from = "now-9m"
15+
index = [
16+
"winlogbeat-*",
17+
"logs-endpoint.events.process-*",
18+
"logs-windows.forwarded*",
19+
"logs-windows.sysmon_operational-*",
20+
"endgame-*",
21+
"logs-system.security*",
22+
"logs-m365_defender.event-*",
23+
"logs-sentinel_one_cloud_funnel.*",
24+
"logs-crowdstrike.fdr*",
25+
]
26+
language = "eql"
27+
license = "Elastic License v2"
28+
name = "Potential File Transfer via Curl for Windows"
29+
note = """## Triage and analysis
30+
31+
### Investigating Potential File Transfer via Curl for Windows
32+
33+
This rule identifies the use of Curl for Windows to download files from a remote URL or post data to a remote site.
34+
35+
#### Possible investigation steps
36+
37+
- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
38+
- Identify the user account that performed the action and whether it should perform this kind of action.
39+
- Contact the account owner and confirm whether they are aware of this activity.
40+
- Investigate other alerts associated with the user/host during the past 48 hours.
41+
- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
42+
- Examine the details of the dropped file, and whether it was executed.
43+
- Check the reputation of the domain or IP address used to host the downloaded file or if the user downloaded the file from an internal system.
44+
- Retrieve the files' SHA-256 hash values using the PowerShell `Get-FileHash` cmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
45+
46+
### False positive analysis
47+
48+
- This activity is unusual but can be done by administrators. Benign true positives (B-TPs) can be added as exceptions if necessary.
49+
50+
### Response and remediation
51+
52+
- Initiate the incident response process based on the outcome of the triage.
53+
- Isolate the involved host to prevent further post-compromise behavior.
54+
- If the triage identified malware, search the environment for additional compromised hosts.
55+
- Implement temporary network rules, procedures, and segmentation to contain the malware.
56+
- Stop suspicious processes.
57+
- Immediately block the identified indicators of compromise (IoCs).
58+
- Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
59+
- Remove and block malicious artifacts identified during triage.
60+
- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
61+
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
62+
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
63+
- 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).
64+
"""
65+
references = ["https://attack.mitre.org/techniques/T1105/"]
66+
risk_score = 21
67+
rule_id = "2e0051cb-51f8-492f-9d90-174e16b5e96b"
68+
severity = "low"
69+
tags = [
70+
"Domain: Endpoint",
71+
"OS: Windows",
72+
"Use Case: Threat Detection",
73+
"Tactic: Command and Control",
74+
"Data Source: Elastic Endgame",
75+
"Data Source: Elastic Defend",
76+
"Data Source: System",
77+
"Data Source: Microsoft Defender for Endpoint",
78+
"Data Source: Sysmon",
79+
"Data Source: SentinelOne",
80+
"Data Source: Crowdstrike",
81+
"Resources: Investigation Guide",
82+
]
83+
timestamp_override = "event.ingested"
84+
type = "eql"
85+
86+
query = '''
87+
process where host.os.type == "windows" and event.type == "start" and user.id != "S-1-5-18" and
88+
process.executable : ("?:\\Windows\\System32\\curl.exe", "?:\\Windows\\SysWOW64\\curl.exe") and
89+
process.command_line : "*http*" and
90+
process.parent.name : ("cmd.exe", "powershell.exe", "rundll32.exe", "explorer.exe", "conhost.exe", "forfiles.exe", "wscript.exe", "cscript.exe", "mshta.exe", "hh.exe", "mmc.exe")
91+
'''
92+
93+
94+
[[rule.threat]]
95+
framework = "MITRE ATT&CK"
96+
[[rule.threat.technique]]
97+
id = "T1105"
98+
name = "Ingress Tool Transfer"
99+
reference = "https://attack.mitre.org/techniques/T1105/"
100+
101+
102+
[rule.threat.tactic]
103+
id = "TA0011"
104+
name = "Command and Control"
105+
reference = "https://attack.mitre.org/tactics/TA0011/"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[metadata]
2+
creation_date = "2025/02/03"
3+
integration = ["endpoint", "windows", "system", "m365_defender", "sentinel_one_cloud_funnel", "crowdstrike"]
4+
maturity = "production"
5+
updated_date = "2025/02/03"
6+
min_stack_version = "8.14.0"
7+
min_stack_comments = "Breaking change at 8.14.0 for the Windows Integration."
8+
9+
[rule]
10+
author = ["Elastic"]
11+
description = """
12+
Detects attempts to execute a command via the forfiles Windows utility. Adversaries may use this utility to proxy execution via
13+
a trusted parent process.
14+
"""
15+
from = "now-9m"
16+
index = [
17+
"winlogbeat-*",
18+
"logs-endpoint.events.process-*",
19+
"logs-windows.forwarded*",
20+
"logs-windows.sysmon_operational-*",
21+
"endgame-*",
22+
"logs-system.security*",
23+
"logs-m365_defender.event-*",
24+
"logs-sentinel_one_cloud_funnel.*",
25+
"logs-crowdstrike.fdr*",
26+
]
27+
language = "eql"
28+
license = "Elastic License v2"
29+
name = "Command Execution via ForFiles"
30+
note = """## Triage and analysis
31+
32+
### Investigating Command Execution via ForFiles
33+
34+
### Possible investigation steps
35+
36+
- Identify the user account that performed the action and whether it should perform this kind of action.
37+
- Contact the account owner and confirm whether they are aware of this activity.
38+
- Investigate other alerts associated with the user/host during the past 48 hours.
39+
- Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
40+
- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
41+
42+
### False positive analysis
43+
44+
- This is a dual-use tool, meaning its usage is not inherently malicious. Analysts can dismiss the alert if the administrator is aware of the activity, no other suspicious activity was identified.
45+
46+
### Response and Remediation
47+
48+
- Initiate the incident response process based on the outcome of the triage.
49+
- Isolate the involved host to prevent further post-compromise behavior.
50+
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
51+
- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
52+
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
53+
- 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).
54+
"""
55+
references = ["https://lolbas-project.github.io/lolbas/Binaries/Forfiles/"]
56+
risk_score = 47
57+
rule_id = "3f7bd5ac-9711-44b4-82c1-fa246d829f15"
58+
severity = "medium"
59+
tags = [
60+
"Domain: Endpoint",
61+
"OS: Windows",
62+
"Use Case: Threat Detection",
63+
"Tactic: Defense Evasion",
64+
"Data Source: Elastic Endgame",
65+
"Data Source: Elastic Defend",
66+
"Data Source: System",
67+
"Data Source: Microsoft Defender for Endpoint",
68+
"Data Source: Sysmon",
69+
"Data Source: SentinelOne",
70+
"Data Source: Crowdstrike",
71+
"Resources: Investigation Guide",
72+
]
73+
timestamp_override = "event.ingested"
74+
type = "eql"
75+
76+
query = '''
77+
process where host.os.type == "windows" and event.type == "start" and
78+
(process.name : "forfiles.exe" or ?process.pe.original_file_name == "forfiles.exe") and process.args : ("/c", "-c")
79+
'''
80+
81+
82+
[[rule.threat]]
83+
framework = "MITRE ATT&CK"
84+
[[rule.threat.technique]]
85+
id = "T1202"
86+
name = "Indirect Command Execution"
87+
reference = "https://attack.mitre.org/techniques/T1202/"
88+
89+
90+
[rule.threat.tactic]
91+
id = "TA0005"
92+
name = "Defense Evasion"
93+
reference = "https://attack.mitre.org/tactics/TA0005/"
94+

rules/windows/defense_evasion_network_connection_from_windows_binary.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2020/09/02"
33
integration = ["endpoint", "windows"]
44
maturity = "production"
5-
updated_date = "2024/10/15"
5+
updated_date = "2025/01/31"
66
min_stack_version = "8.14.0"
77
min_stack_comments = "Breaking change at 8.14.0 for the Windows Integration."
88

@@ -135,6 +135,7 @@ sequence by process.entity_id with maxspan=5m
135135
process.name : "MSBuild.exe" or
136136
process.name : "msdt.exe" or
137137
process.name : "mshta.exe" or
138+
process.name : "wscript.exe" or
138139
process.name : "msiexec.exe" or
139140
process.name : "msxsl.exe" or
140141
process.name : "odbcconf.exe" or

rules/windows/defense_evasion_posh_assembly_load.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ integration = ["windows"]
44
maturity = "production"
55
min_stack_comments = "Breaking change at 8.14.0 for the Windows Integration."
66
min_stack_version = "8.14.0"
7-
updated_date = "2024/10/28"
7+
updated_date = "2025/01/31"
88

99
[transform]
1010
[[transform.osquery]]
@@ -132,7 +132,9 @@ query = '''
132132
event.category:process and host.os.type:windows and
133133
powershell.file.script_block_text : (
134134
"[System.Reflection.Assembly]::Load" or
135-
"[Reflection.Assembly]::Load"
135+
"[Reflection.Assembly]::Load" or
136+
"Assembly.Load(" or
137+
"System.Reflection"
136138
) and
137139
not powershell.file.script_block_text : (
138140
("CommonWorkflowParameters" or "RelatedLinksHelpInfo") and

rules/windows/execution_powershell_susp_args_via_winscript.toml

+11-60
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ integration = ["windows", "system", "sentinel_one_cloud_funnel", "m365_defender"
44
maturity = "production"
55
min_stack_comments = "Breaking change at 8.14.0 for the Windows Integration."
66
min_stack_version = "8.14.0"
7-
updated_date = "2025/01/15"
7+
updated_date = "2025/01/31"
88

99
[rule]
1010
author = ["Elastic"]
1111
description = """
12-
Identifies suspicious PowerShell execution spawning from Windows Script Host processes (cscript or wscript.exe).
12+
Identifies PowerShell.exe or Cmd.exe execution spawning from Windows Script Host processes Wscript.exe.
1313
"""
1414
from = "now-9m"
1515
index = [
@@ -22,7 +22,7 @@ index = [
2222
]
2323
language = "eql"
2424
license = "Elastic License v2"
25-
name = "Suspicious PowerShell Execution via Windows Scripts"
25+
name = "Command and Scripting Interpreter via Windows Scripts"
2626
risk_score = 73
2727
rule_id = "2d62889e-e758-4c5e-b57e-c735914ee32a"
2828
severity = "high"
@@ -42,69 +42,15 @@ type = "eql"
4242

4343
query = '''
4444
process where host.os.type == "windows" and event.action == "start" and
45-
process.name : ("powershell.exe", "pwsh.exe") and
46-
process.parent.name : ("wscript.exe", "cscript.exe", "mshta.exe") and
47-
(
48-
process.args_count == 1 or
49-
process.command_line :
50-
("*^*^*^*^*^*^*^*^*^*",
51-
"*''*''*''*",
52-
"*`*`*`*`*",
53-
"*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*",
54-
"*+*+*+*+*+*",
55-
"*$*$*$*$*",
56-
"*[char[]](*)*-join",
57-
"*Base64String*",
58-
"*[*Convert]*",
59-
"*.Text.Encoding*",
60-
"*.Compression.*",
61-
"*.replace(*",
62-
"*MemoryStream*",
63-
"*WriteAllBytes*",
64-
"* -en* *",
65-
"* -ec *",
66-
"* -e *",
67-
"* -ep *",
68-
"* /e *",
69-
"* /en* *",
70-
"* /ec *",
71-
"* /ep *",
72-
"*WebClient*",
73-
"*DownloadFile*",
74-
"*DownloadString*",
75-
"*BitsTransfer*",
76-
"*Invoke-Exp*",
77-
"*invoke-web*",
78-
"*iex*",
79-
"*iwr*",
80-
"*Reflection.Assembly*",
81-
"*Assembly.GetType*",
82-
"*.Sockets.*",
83-
"*Add-MpPreference*ExclusionPath*",
84-
"*raw.githubusercontent*")
85-
) and
86-
87-
/* many legit powershell commands uses those non shortened execution flags excluding Sync-AppvPublishingServer lolbas */
88-
not (process.args : ("-EncodedCommand", "Import-Module*", "-NonInteractive") and
89-
process.args : "-ExecutionPolicy" and not process.args : "Sync-AppvPublishingServer") and
90-
91-
/* third party installation related FPs */
92-
not ?process.parent.args : "?:\\Windows\\system32\\gatherNetworkInfo.vbs" and
93-
not (?process.parent.args : "Microsoft.SystemCenter.ICMPProbe.WithConsecutiveSamples.vbs" and process.args : "Get-SCOMAgent") and
94-
not (process.command_line : "*WEBLOGIC_ARGS_CURRENT_1.DATA*" and ?process.parent.command_line : "*Impact360*") and
95-
not process.args : "$package = Get-AppxPackage Microsoft.Office.Desktop -allUsers;*" and
96-
not process.command_line : ("*.Access.IdentityReference*win32_SID.SID*", "*AGIAbQB4AC0AYQBwAC4AcwAzAC4AdQBzAC0AZQBhAHMAd*") and
97-
not (?process.parent.args : "?:\\Users\\Prestige\\AppData\\Local\\Temp\\Rar$*\\KMS_VL_ALL_AIO.cmd -elevated" and process.command_line : "*KMS_VL_ALL_AIO.cmd*") and
98-
not process.args : "iwr https://*.s3.us-east-1.amazonaws.com/scripts/Start-SpeedTest.ps1 -UserAgent * -UseBasicParsing | invoke-expression" and
99-
not (process.parent.name : "wscript.exe" and
100-
?process.parent.args : "C:\\Program Files (x86)\\Telivy\\Telivy Agent\\telivy.js")
45+
process.name : ("powershell.exe", "pwsh.exe", "cmd.exe") and
46+
process.parent.name : ("wscript.exe", "mshta.exe") and ?process.parent.args : "?:\\Users\\*"
10147
'''
10248
note = """## Triage and analysis
10349
10450
> **Disclaimer**:
10551
> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
10652
107-
### Investigating Suspicious PowerShell Execution via Windows Scripts
53+
### Investigating Command and Scripting Interpreter via Windows Scripts
10854
10955
PowerShell, a powerful scripting language in Windows, is often targeted by adversaries for executing malicious scripts. Attackers exploit Windows Script Host processes like cscript or wscript to launch PowerShell with obfuscated commands, evading detection. The detection rule identifies such suspicious activity by monitoring PowerShell executions with specific patterns and parent processes, while filtering out known legitimate use cases to reduce false positives.
11056
@@ -146,6 +92,11 @@ id = "T1059.001"
14692
name = "PowerShell"
14793
reference = "https://attack.mitre.org/techniques/T1059/001/"
14894

95+
[[rule.threat.technique.subtechnique]]
96+
id = "T1059.003"
97+
name = "Windows Command Shell"
98+
reference = "https://attack.mitre.org/techniques/T1059/003/"
99+
149100
[[rule.threat.technique.subtechnique]]
150101
id = "T1059.005"
151102
name = "Visual Basic"

0 commit comments

Comments
 (0)