-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlateral_movement.yml
More file actions
350 lines (340 loc) · 17 KB
/
Copy pathlateral_movement.yml
File metadata and controls
350 lines (340 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
title: ADRedTeam - Lateral Movement Detection Rules
id: sast-lateral-001
status: production
description: |
SAST detection rules for lateral movement techniques including
PSExec, WMIExec, SMBExec, Evil-WinRM, DCOM, Pass-the-Hash,
RDP, AtExec, and WinRS.
author: ADRedTeam SAST Module
date: 2026-04-24
mitre_attack:
- T1021.001 # Remote Desktop Protocol
- T1021.002 # SMB/Windows Admin Shares
- T1021.003 # Distributed Component Object Model
- T1021.006 # Windows Remote Management
- T1047 # Windows Management Instrumentation
- T1550.002 # Pass the Hash
rules:
# ─────────────────────────────────────────────────────────────────────────────
# TECHNIQUE: PSExec — SMB + Service Creation (T1021.002 / T1569.002)
# ─────────────────────────────────────────────────────────────────────────────
- id: lateral-psexec-001
title: PSExec-Style Lateral Movement — Remote Service Creation via SMB
technique: T1021.002
severity: critical
description: >
Detects PSExec-style execution via SMB IPC$ share and Windows Service
Manager. Creates a random-named service, executes payload, then removes.
impacket-psexec, sysinternals psexec, and Cobalt Strike use this pattern.
event_sources:
- windows_security_eventlog:
event_ids: [4697, 7045]
conditions:
- field: ServiceFileName
contains_any: ["%TEMP%", "\\Windows\\Temp", "ADMIN$", "C$\\Windows"]
- system_eventlog:
event_ids: [7045] # Service installation
conditions:
- field: ServiceType
value: "16" # Win32OwnProcess
- field: StartType
value: "3" # Demand Start
- windows_security_eventlog:
event_ids: [5145]
conditions:
- field: ShareName
values: ["\\\\*\\ADMIN$", "\\\\*\\IPC$"]
- field: RelativeTargetName
contains: "svcctl"
detection:
sigma_condition: |
(EventID=7045 AND ServiceFileName CONTAINS ANY ["%TEMP%","\\Temp\\"])
OR
(EventID=4697 AND ServiceFileName MATCHES "^[A-Z0-9]{8}\.exe$")
OR
(EventID=5145 AND ShareName ENDSWITH "\\IPC$" AND
RelativeTargetName="svcctl" AND SubjectUserName NOT IN service_accounts)
anomaly:
- Short service name (random alphanumeric)
- Service created and deleted within seconds
- Service binary in temp directory
tools_used:
- "impacket-psexec {dom}/{user}:{pass}@{dc}"
- "impacket-psexec {dom}/{user}@{dc} -hashes :{ntlm_hash}"
false_positives:
- Legitimate software deployment tools (SCCM, Ansible, PDQ)
- IT automation creating remote services
remediation:
- Restrict admin shares (ADMIN$, C$) access
- Block lateral movement via host-based firewall rules
- Monitor Event ID 7045 for short-lived random services
- Enable Windows Defender "Block process creations from PSExec" ASR rule
# ─────────────────────────────────────────────────────────────────────────────
# TECHNIQUE: WMIExec — Windows Management Instrumentation (T1047)
# ─────────────────────────────────────────────────────────────────────────────
- id: lateral-wmiexec-001
title: WMI Remote Command Execution — Lateral Movement
technique: T1047
severity: high
description: >
Detects WMI-based remote command execution (impacket-wmiexec, CrackMapExec
WMI). WMI semi-interactive shell spawns cmd.exe via WmiPrvSE.exe.
Harder to detect than PSExec — no service creation.
event_sources:
- windows_security_eventlog:
event_ids: [4624, 4688]
conditions:
- field: LogonType
value: "3" # Network logon
- field: ParentProcessName
endswith: "WmiPrvSE.exe"
- sysmon_eventlog:
event_ids: [1, 20] # Process creation, WMI activity
conditions:
- field: ParentImage
endswith: "\\WmiPrvSE.exe"
detection:
sigma_condition: |
EventID=1 AND ParentImage ENDSWITH "\\WmiPrvSE.exe" AND
Image IN ["cmd.exe", "powershell.exe", "whoami.exe", "net.exe"] AND
User NOT IN ["NT AUTHORITY\\NETWORK SERVICE", "NT AUTHORITY\\LOCAL SERVICE"]
tools_used:
- "impacket-wmiexec {dom}/{user}:{pass}@{dc}"
- "impacket-wmiexec {dom}/{user}@{dc} -hashes :{ntlm}"
- "crackmapexec smb {dc} -u {user} -p {pass} -x 'whoami'"
remediation:
- Disable WMI remote access via Windows Firewall
- Monitor WmiPrvSE.exe child processes
- Restrict DCOM permissions (Component Services)
- Enable WMI activity logging
# ─────────────────────────────────────────────────────────────────────────────
# TECHNIQUE: Evil-WinRM — WinRM Remote Shell (T1021.006)
# ─────────────────────────────────────────────────────────────────────────────
- id: lateral-evil-winrm-001
title: Evil-WinRM — Windows Remote Management Shell Access
technique: T1021.006
severity: high
description: >
Detects Evil-WinRM connections for remote PowerShell shell access.
Uses WinRM (TCP 5985/5986). Supports Pass-the-Hash and certificate auth.
event_sources:
- windows_security_eventlog:
event_ids: [4624]
conditions:
- field: LogonType
value: "3"
- field: AuthenticationPackage
value: "NTLM"
- windows_remote_management_eventlog:
event_ids: [91, 168]
network_indicators:
- port: 5985
protocol: HTTP
path: "/wsman"
- port: 5986
protocol: HTTPS
path: "/wsman"
detection:
sigma_condition: |
(EventID=91 OR EventID=168) AND
(SourceAddress NOT IN trusted_management_hosts)
user_agent_indicators:
- "Ruby"
- "EVIL-WINRM"
tools_used:
- "evil-winrm -i {dc} -u {user} -p {pass}"
- "evil-winrm -i {dc} -u {user} -H {ntlm_hash}"
remediation:
- Restrict WinRM access via firewall (only from management hosts)
- Enable WinRM HTTPS only (port 5986)
- Monitor Event ID 4624 LogonType=3 from unexpected sources
- Require MFA for remote management access
# ─────────────────────────────────────────────────────────────────────────────
# TECHNIQUE: DCOM Execution (T1021.003)
# ─────────────────────────────────────────────────────────────────────────────
- id: lateral-dcom-001
title: DCOM Remote Execution — MMC20 Application Object Abuse
technique: T1021.003
severity: high
description: >
Detects DCOM-based lateral movement via MMC20.Application, ShellWindows,
ShellBrowserWindow, or ExcelDDE. Leaves minimal artifacts — no service
creation or WMI events.
event_sources:
- sysmon_eventlog:
event_ids: [1]
conditions:
- field: Image
endswith: "\\mmc.exe"
- field: ParentImage
contains: "svchost"
network_indicators:
- destination_port: 135 # RPC endpoint mapper
- destination_port_range: "49152-65535" # Dynamic RPC ports
detection:
sigma_condition: |
EventID=1 AND Image ENDSWITH "\\mmc.exe" AND
CommandLine CONTAINS "-Embedding" AND
ParentImage ENDSWITH "\\svchost.exe"
tools_used:
- "impacket-dcomexec {dom}/{user}:{pass}@{dc} 'whoami'"
remediation:
- Restrict DCOM permissions via DCOMCNFG
- Block outbound RPC (135, 49152-65535) between workstations
# ─────────────────────────────────────────────────────────────────────────────
# TECHNIQUE: Pass-the-Hash (T1550.002)
# ─────────────────────────────────────────────────────────────────────────────
- id: lateral-pth-001
title: Pass-the-Hash — NTLM Authentication with Stolen Hash
technique: T1550.002
severity: critical
description: >
Detects Pass-the-Hash attacks where NTLM hash is used instead of
password for authentication. Pattern: NewCredentials logon (type 9)
followed by network authentication, or CrackMapExec -H flag usage.
event_sources:
- windows_security_eventlog:
event_ids: [4624]
conditions:
- field: LogonType
value: "9" # NewCredentials — used for PtH
- field: AuthenticationPackage
value: "NTLM"
detection:
sigma_condition: |
EventID=4624 AND LogonType=9 AND
AuthenticationPackage="NTLM" AND
ImpersonationLevel="Impersonation" AND
SubjectUserName != TargetUserName
behavioral_indicators:
- Admin login from workstation that user has never logged into
- Multiple hosts accessed within seconds using same NTLM hash
- sekurlsa::pth spawning new process
tools_used:
- "crackmapexec smb {dc} -u {user} -H {ntlm} -d {dom} -x 'whoami'"
- "impacket-psexec {dom}/{user}@{dc} -hashes :{ntlm}"
- "mimikatz sekurlsa::pth /user:{user} /domain:{dom} /ntlm:{hash} /run:powershell.exe"
- "evil-winrm -i {dc} -u {user} -H {ntlm}"
remediation:
- Enforce Protected Users group for privileged accounts (blocks NTLM)
- Disable NTLM authentication where possible (use Kerberos)
- Enable Network access: Restrict NTLM (Group Policy)
- Implement Local Administrator Password Solution (LAPS) to prevent hash reuse
# ─────────────────────────────────────────────────────────────────────────────
# TECHNIQUE: WinRS — Windows Remote Shell (T1021.006)
# ─────────────────────────────────────────────────────────────────────────────
- id: lateral-winrs-001
title: WinRS Lateral Movement — Low-Footprint Remote Shell
technique: T1021.006
severity: high
description: >
WinRS (winrshost.exe) provides remote shell via WinRM without creating
PowerShell process. Lower detection profile than Evil-WinRM. Used in
CRTP curriculum for stealthy lateral movement.
event_sources:
- sysmon_eventlog:
event_ids: [1]
conditions:
- field: Image
endswith: "\\winrshost.exe"
- windows_security_eventlog:
event_ids: [4624]
conditions:
- field: LogonType
value: "3"
process_indicators:
- winrshost.exe spawning cmd.exe, powershell.exe, or any executable
detection:
sigma_condition: |
EventID=1 AND ParentImage ENDSWITH "\\winrshost.exe" AND
Image NOT IN ["\\conhost.exe"]
tools_used:
- "winrs -r:{target} -u:{dom}\\{user} -p:{pass} cmd.exe"
- "winrs -r:{target} -u:{dom}\\{user} -p:{pass} 'whoami /all'"
remediation:
- Monitor winrshost.exe process creation events
- Restrict WinRM access to management jump servers only
- Audit Event ID 91 (WinRM session start)
# ─────────────────────────────────────────────────────────────────────────────
# TECHNIQUE: AtExec — Task Scheduler Remote Execution (T1053.005)
# ─────────────────────────────────────────────────────────────────────────────
- id: lateral-atexec-001
title: AtExec — Scheduled Task Remote Execution
technique: T1053.005
severity: high
description: >
impacket-atexec creates a remote scheduled task, executes command,
retrieves output, then deletes the task. Leaves Event ID 4698 (task creation)
and 4699 (task deletion) within seconds.
event_sources:
- windows_security_eventlog:
event_ids: [4698, 4699, 4700, 4701, 4702]
detection:
sigma_condition: |
EventID=4698 AND
SubjectUserName != "SYSTEM" AND
TaskName MATCHES "^\\[0-9A-F]{8}-[0-9A-F]{4}.*$" # Random GUID name
FOLLOWED_BY EventID=4699 WITHIN 60s WHERE TaskName == previous.TaskName
anomaly:
- Task created and deleted within 60 seconds
- Task with GUID-like or random name
- Task running as SYSTEM but created via network logon
tools_used:
- "impacket-atexec {dom}/{user}:{pass}@{dc} '{command}'"
remediation:
- Monitor Event IDs 4698/4699 pairs with short intervals
- Audit scheduled task creation by non-administrative accounts
- Restrict Task Scheduler remote access
# ─────────────────────────────────────────────────────────────────────────────
# TECHNIQUE: RDP with Pass-the-Hash (T1021.001)
# ─────────────────────────────────────────────────────────────────────────────
- id: lateral-rdp-pth-001
title: RDP Access with Pass-the-Hash via xfreerdp
technique: T1021.001
severity: high
description: >
Detects RDP Pass-the-Hash using xfreerdp /pth flag or enabling RDP
via CrackMapExec rdp module followed by restricted admin mode connection.
event_sources:
- windows_security_eventlog:
event_ids: [4624]
conditions:
- field: LogonType
value: "10" # RemoteInteractive
- system_eventlog:
event_ids: [1149] # RDP connection start
detection:
sigma_condition: |
EventID=4624 AND LogonType=10 AND
AuthenticationPackage="NTLM" AND
(ImpersonationLevel="Impersonation" OR KeyLength=0)
tools_used:
- "crackmapexec smb {dc} -u {user} -p {pass} -M rdp -o ACTION=enable"
- "xfreerdp /u:{user} /pth:{ntlm} /v:{dc}"
remediation:
- Enable Network Level Authentication (NLA)
- Disable Restricted Admin Mode
- Monitor RDP connections via NTLM authentication
# ─────────────────────────────────────────────────────────────────────────────
# SAST CODE ANALYSIS
# ─────────────────────────────────────────────────────────────────────────────
sast_code_analysis:
file: modules/lateral_movement.py
rules:
- id: sast-code-lateral-001
title: Auth String Construction Exposes Credentials in Process List
severity: high
pattern: |
f"{dom}/{user}:'{pw}'@{dc}"
description: >
Authentication string with plaintext password visible in /proc/cmdline
and process list. Any local user can read running impacket command lines.
recommendation: "Use environment variables or impacket's -hashes flag where possible; avoid plaintext in command args"
- id: sast-code-lateral-002
title: Conditional Auth String Leaks Hash in Command
severity: medium
pattern: |
f"-u '{user}' -H {nth} -d {dom}"
description: >
NTLM hash exposed in command line arguments visible in process list.
Consider using stdin or config files for sensitive auth material.