ATT&CKing Koadic with EQL
Daniel Stepanic
11/2/2019
1
Bio
��Security Engineer at Elastic
�@DanielStepanic
2
Agenda
3
01 Recent Trends
4
4
Recent Trends
5
Benefits for Attackers
6
6
Benefits for Defenders
7
7
02 Koadic� Introduction
8
8
Koadic
Post-exploitation framework similar to Empire
9
Koadic
Stagers��
Implants
Threat Groups�
6
44
4
Mshta
Regsvr32
Rundll32_js
Disk
Wmic
Bitsadmin
Credential Dumping
Collection
Discovery/Recon
Lateral Movement
Persistence
Privilege Escalation
MuddyWater
APT10/Stone Panda
APT28/Sofacy
FakeUpdates Campaign
10
Koadic
11
03 EQL
12
12
EQL: Event Query Language
Simple and concise language for threat researchers
13
Simple Queries
and or not < <= == != >= >
process where process_name == "svchost.exe" and
(command_line != "* -k *" or parent_process_name != "services.exe")
14
Sequences
sequence with maxspan=1m
[file where file_path == "*\\AppData\\*"] by file_path
[process where user_name == "SYSTEM"] by process_path
15
Joins
join
[file where file_path == "*\\System32\\Tasks\\h4x0r.xml"]
[registry where registry_path == "*\\runonce\\h4xor"]
16
Pipes and Outliers
count filter head sort tail unique unique_count
process where true
// Remove duplicate pairs
| unique process_name, command_line
// Count per process_name to get unique # of commands
| count process_name
| filter count < 5
17
Process Lineage
network where process_name == "powershell.exe"
and not descendant of
[process where process_name == "explorer.exe"]
18
04 Detecting� Koadic Using� EQL
19
19
MITRE ATT&CK™ Framework
20
MITRE ATT&CK™ Software
21
Initial Access & Execution
22
Initial Access & Execution
process where process_name == "mshta.exe"
and descendant of � [process where process_name == "outlook.exe"]
23
Initial Access & Execution
sequence with maxspan=5m� [file where file_name == "*.exe" and � process_name in ("winword.exe", "excel.exe", "powerpnt.exe")] by file_path� [process where true] by process_path
24
Defense Evasion & Execution
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
HTML Application
25
Defense Evasion & Execution
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
MSHTA Stager - Execution Chain
26
Defense Evasion & Execution
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
sequence by unique_pid� [process where subtype.create and process_name in � ("mshta.exe", "regsvr32.exe", "rundll32.exe", "wmic.exe")]� [network where process_name in� ("mshta.exe", "regsvr32.exe", "rundll32.exe", "wmic.exe")]
27
Defense Evasion & Execution
file where process_name in � ("mshta.exe","regsvr32.exe", "rundll32.exe", "wmic.exe") � and subtype.create and file_path == "*Content.IE5*"
28
Koadic Command and Control (C2)
29
Discovery
macro KOADIC_DISCOVERY(name)
name in (
"arp.exe", "findstr.exe", "hostname.exe", "ipconfig.exe",
"nbtstat.exe", "net.exe", "net1.exe", "netsh.exe",
"nltest.exe", "ping.exe", "systeminfo.exe", "tasklist.exe", � "tracert.exe", "whoami.exe"
)
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
30
Discovery
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
sequence by user_name with maxspan=10m
[process where subtype.create and KOADIC_DISCOVERY(process_name)]� [process where subtype.create and KOADIC_DISCOVERY(process_name)]� [process where subtype.create and KOADIC_DISCOVERY(process_name)]
| unique user_name
31
sequence by user_name with maxspan=10m
[process where child of [process where parent_process_name == "rundll32.exe"] and � KOADIC_DISCOVERY(process_name)]
[process where child of [process where parent_process_name == "rundll32.exe"] and � KOADIC_DISCOVERY(process_name)]
[process where child of [process where parent_process_name == "rundll32.exe"] and � KOADIC_DISCOVERY(process_name)]� | unique user_name
32
sequence by user_name with maxspan=10m
[process where child of [process where parent_process_name == "rundll32.exe"] � and KOADIC_DISCOVERY(process_name) and � descendant of [process where parent_process_name == "wmiprvse.exe"]]
[process where child of [process where parent_process_name == "rundll32.exe"] � and KOADIC_DISCOVERY(process_name) and � descendant of [process where parent_process_name == "wmiprvse.exe"]]
| unique user_name
33
Command and Control (C2)
join by source_ip
[network where process_name == "rundll32.exe"]
[network where process_name == "mshta.exe"]
[file where process_name == "rundll32.exe" and file_path == "*Content.IE5*"]� [process where process_name == "rundll32.exe" and parent_process_name = "wmiprvse.exe"]� [process where process_name == "cmd.exe" and parent_process_name = "rundll32.exe"]�
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
34
UAC Bypass
Attackers can’t choose where they land
35
UAC Bypass
36
Privilege Escalation
sequence with maxspan=10s � [registry where length(bytes_written_string) > 0 and key_type in� ("sz", "expandSz") and key_path == "*\\mscfile\\shell\\open\\command\\" � and user_name != "SYSTEM"]
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
37
Privilege Escalation
sequence with maxspan=10s � [registry where length(bytes_written_string) > 0 and key_type in� ("sz", "expandSz") and key_path == "*\\mscfile\\shell\\open\\command\\" � and user_name != "SYSTEM"]� [process where process_path == "C:\\Windows\\System32\\CompMgmtLauncher.exe"]
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
38
Privilege Escalation
sequence with maxspan=10s � [registry where length(bytes_written_string) > 0 and key_type in� ("sz", "expandSz") and key_path == "*\\mscfile\\shell\\open\\command\\" � and user_name != "SYSTEM"]� [process where process_path == "C:\\Windows\\System32\\CompMgmtLauncher.exe"]� [process where process_name in ("mshta.exe","rundll32.exe") and� integrity_level == "high"]
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
39
Collection & Exfiltration
cmd.exe" /q /c chcp 437 & time 1> C:\Users\IEUser\AppData\Local\Temp\95fe63d2-e79d-2706-2e89-2084a225343e.txt 2>&1
cmd.exe /q /c chcp 437 & hostname 1> C:\Users\IEUser\AppData\Local\Temp\9909f618-4fb5-eb66-745d-f40143687330.txt 2>&1
cmd.exe" /q /c chcp 437 & whoami /groups 1> C:\Users\IEUser\AppData\Local\Temp\2a0f4991-b684-afe0-63e6-207e58ac4af8.txt 2>&1
File Write Example - 95fe63d2-e79d-2706-2e89-2084a225343e.txt
40
Collection & Exfiltration
file where file_name == "*.txt" and
event of [process where process_name == "cmd.exe" and command_line == "*>*"]
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
41
Collection & Exfiltration
sequence with maxspan=5s by unique_pid
[process where process_name == "cmd.exe" and command_line == "*>*"] � [file where file_name == "*.txt" and
event of [process where process_name == "cmd.exe" and command_line == "*>*"]] �
42
Collection & Exfiltration
sequence with maxspan=5s by unique_pid
[process where process_name == "cmd.exe" and command_line == "*>*"] � [file where file_name == "*.txt" and
event of [process where process_name == "cmd.exe" and command_line == "*>*"] � and descendant of [process where parent_process_name == "wmiprvse.exe"]]�
43
Execution
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
44
Execution
sequence by unique_pid
[process where process_name in ("mshta.exe", "rundll32.exe")]
[image_load where image_name in ("jscript9.dll", "msxml6.dll", � "npmproxy.dll", "winhttp.dll", "wmiutils.dll")]
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
45
Lateral Movement
join by pid, arguments.ClientProcessId
[process where true]� [wmi where arguments.Operation == "*Win32_Process::Create*"]�| filter events[0].hostname != events[1].hostname
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
46
Lateral Movement
join by pid, arguments.ClientProcessId
[process where true] //Source Host � [wmi where arguments.Operation == "*Win32_Process::Create*"] //Dest Host�| filter events[0].hostname != events[1].hostname
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
47
Persistence
join by unique_pid
[wmi where arguments.Operation == "*IWbemServices::PutInstance*EventFilter*"]
[wmi where arguments.Operation == "*IWbemServices::PutInstance*EventConsumer*"]
[wmi where arguments.Operation == "*IWbemServices::PutInstance*FilterToConsumerBinding*"]
Initial Access
Execution
Persistence
Privilege Escalation
Command and Control
Defense Evasion
Credential Access
Discovery
Lateral Movement
Collection
Exfiltration
Impact
48
05 EQL Community
49
49
Download EQL
pip install eql
50
Eqllib
Eqllib Analytic - Bypass UAC via Fodhelper.exe
51
Resources
52
Questions?
53