
背景 2018年6月,国外安全研究人员公开了利用windows 10下才被引入的新文件类型“.SettingContent-ms”执行任意命令的攻击技巧,并公开了POC(详见参考[1])。而该新型攻击方式被公开后就立刻被黑客和APT组织纳入攻击武器库用于针对性攻击,并衍生出各种利用方式:诱导执行、利用Office文档执行、利用PDF文档执行。
2018年8月14日,微软发布了针对该缺陷的系统补丁,对应的漏洞编号为:CVE-2018-8414。360威胁情报中心在该攻击技术公开的第一时间便密切跟踪相关的在野攻击样本,由于漏洞相关的技术细节和验证程序已经公开,且漏洞已被微软修复。因此,360威胁情报中心发布针对该漏洞的分析以及跟踪到的在野攻击分析,提醒用户采取应对措施。
360威胁情报中心云沙箱第一时间支持该特殊文件格式的检测和恶意行为的识别,由于文件格式为XML,且此类攻击只针对Windows 10,所以大多数沙箱并不支持对此恶意文件的检测。以下为360云沙箱对此类恶意样本的检测结果:

CVE-2018-8414漏洞分析 漏洞成因
Windows 10下执行.SettingContent-ms后缀的文件,系统并未判断该类文件所在的路径是否在控制面板相关目录下,便直接执行了文件中用于控制面板设置相关的DeepLink标签指定的任意程序,导致用户执行系统任意目录下的此类文件或者从网络上下载的经过精心设计的.SettingContent-ms文件也会直接执行其中指定的恶意程序对象,导致任意代码执行。
SettingContent-ms介绍SettingContent-ms是Windows 10中引入的新文件类型,主要用于创建Windows设置页面的快捷方式,相关文件后缀即为“.SettingContent-ms”。表面上看SettingContent-ms只是一个XML文件,正常的SettingContent-ms文件内容如下所示:

SettingContent-ms文件包含<DeepLink>标签,比如我们在Windows 10上双击打开一个指向任务管理器的SettingContent-ms文件,则会执行DeepLink标签中指定的对象:

可以看到Windows 10下有大量默认的SettingContent-ms文件及其包含的DeepLink标签:

不幸的是,如果攻击者将SettingContent-ms文件中DeepLink标记指向其它恶意程序或者可以执行的脚本代码(比如PowerShell),并诱导用户在Windows 10下执行该文件,或者通过其它载体(Office、PDF)执行该文件,都可能执行恶意代码从而导致电脑被控制。
并且通过浏览器超链接或者直接从Internet下载/执行SettingContent-ms文件,由于该文件不在SmartScreen拦截范围内,执行过程中也不会出现安全提示,大大增加了这类攻击的风险。
360威胁情报中心针对该漏洞以及未被SmartScreen拦截的原因进行了分析,并进一步分析了微软补丁的修复方式,过程如下。
SettingContent-ms执行任意命令漏洞分析双击执行一个SettingContent-ms文件后系统会调用windows.storage.dll模块的函数CBindAndInvokeStaticVerb::Execute执行:

在该函数中将调用一系列检查函数,诸如EDP(Enterprise Data Protection)保护(见参考[3]):

随后将调用SmartScreen过滤器:

其中,windows_storage!CBindAndInvokeStaticVerb::CheckSmartScreen函数会首先调用windows_storage!CBindAndInvokeStaticVerb::ShouldInvokeSmartScreen函数检查是否需要调用SmartScreen进行保护,如下图:

然后调用windows_storage!CBindAndInvokeStaticVerb::ZoneCheckFile函数进行Zone.Identifier检查:

其函数内部其实是调用windows.storage!ZoneCheckUrlExW函数进行Zone.Identifier检查:

继续跟进windows.storage!ZoneCheckUrlExW函数,最后定位到关键函数urlmon!GetZoneFromAlternateDataStreamEx,该函数读取Zone.Identifier文件中的ZoneId:

随后调用_GetZoneTrust函数转换ZoneId得到另一种ID,ZoneId等于3时转换后的ID为1,然后一路返回:

由于ZoneId此处为3,即URLZONE_INTERNET,标记该文件是从网络下载,所以需要使用SmartScreen筛选器过滤:

随后将调用SafeOpenPromptForShellExec函数,如果执行的文件是被标记为从网络下载(URLZONE_INTERNET),且该文件后缀为SmartScreen筛选器黑名单内的文件,那么将会看到以下弹窗,问询用户是否执行该文件:

而SettingContent-ms文件通过了windows_storage!CBindAndInvokeStaticVerb::CheckSmartScreen函数检查后则会调用windows_storage!CBindAndInvokeStaticVerb::_TryExecuteCommandHandler函数执行该文件:

函数内部调用CBindAndInvokeStaticVerb::_DoCommand,该函数通过一些查询操作,获取SettingContent-ms处理接口,然后调用该接口执行SettingContent-ms文件,最终执行shell32!CExecuteAppIDAndActivationContext::Execute函数:

shell32!CExecuteAppIDAndActivationContext::Execute又会调用shell32!CExecuteAppIDAndActivationContext::_ExecuteSettingActivationContext函数,在该函数中会调用GetPCSettingsPathForCurrentUser和GetPCSettingsFilePath获取当前用户控制面板设置目录和系统控制面板设置目录,然后与需要执行的SettingContent-ms文件所在目录进行比较,而“漏洞”就出现在这里,按理这类控制面板相关的“快捷方式”文件应该只允许在控制面板相关的目录内执行DeepLink标签中指定的命令,而此处仅仅做了比较,而没有对比较后的结果进行相应处理,导致该文件在Windows 10任意目录下都会执行SettingContent-ms文件指定的任意命令,导致“漏洞”产生:

最后根据PCSetting::HostID的值调用相应函数执行DeepLink标签中的命令:


未被SmartScreen拦截
我们通过浏览器超链接或者直接从Internet下载/执行SettingContent-ms文件,下载的文件虽然被标记为ZoneId=3(URLZONE_INTERNET),但在执行过程中并不会出现安全提示,这大大增加了这类攻击的风险。360威胁情报中心分析后发现,原来SettingContent-ms后缀的文件并未被包含在SmartScreen筛选器的风险文件后缀列表中,分析过程如下:
前面分析的判断文件域并打开的SafeOpenPromptForShellExec函数将依次调用shlwapi!AssocIsDangerous->shlwapi!AssocGetUrlAction->shlwapi!_AssocIsDangerous->shlwapi!IsTypeInList:

wapi!IsTypeInList函数将查询黑名单,黑名单列表有100个,而其中没有包含.SettingContent-ms类型文件,所以当执行网络上下载的.SettingContent-ms文件时不会被SmartScreen拦截:


缺陷利用
攻击者可将精心构造的SettingContent-ms文件(如在DeepLink标签中指定执行带恶意
参数的程序PowerShell等)发送给受害者并诱导其打开,也可以将恶意SettingContent-ms文件插入到Office、PDF等文档中诱骗受害者打开,最终执行DeepLink标签中指定的恶意代码。
补丁分析 微软发布的补丁程序对执行路径做了判断,只有在%AppData%\Local\Packages\windows.immersivecontrolpanel_cw5n1h2txyewy\LocalState\Indexed\Settings\[GetUserPreferredUILanguages]或%WinDir%\immersivecontrolpanel\settings子目录内打开SettingContent-ms后缀文件才能进入执行控制面板设置分支执行命令。以下是补丁前后的代码对比图:
PathComparePaths函数的两个参数分别传入两个路径,用于判别第二个参数是否是第一个参数的子目录,如果不是子目录则返回1或2,同8相与结果为0;如果是子目录返回8或12,同8相与结果为8。以下是函数实现:

两次调用PathComparePaths后将结果与8相与,以达到判断是否是子目录的目的,如果是子目录iResult赋值为0,否则赋值为0x80070005,最终通过判断iResult来决定是否执行命令。
我们在打上补丁的环境中将PoC拷贝至:
%AppData%\Local\Packages\windows.immersivecontrolpanel_cw5n1h2txyewy\LocalState\Indexed\Settings\en-US目录则能正常执行PoC。
在野攻击样本分析360威胁情报中心云沙箱第一时间支持对该类攻击样本的检测,并通过360云沙箱检测到大量用于实际攻击的SettingContent-ms样本,这里列举一些利用该漏洞进行在野攻击的典型案例进行分析。
疑似摩诃草APT组织使用的攻击样本Md5:cef9671085c0b23293826ebfc608326c
对应的样本如下,通过PowerShell直接下载样本再运行:

对应的CC地址:

Payload为Cobalt Strike生成的样本
Md5:964af724370dacbdb73958cbab63b822
该.SettingContent-ms文件中调用了PowerShell,解密后如下:

随后访问46.101.141.96并下载一个名为Disgdp的文件执行:

Disgdp文件同样为一个PowerShell脚本,如下所示:

和第一层样本不同,该样本通过gzip进行了压缩,解压后如下所示:

样本的主要功能为通过PowerShell在内存中加载var_code运行,之后再运行var_code返回的结果var_buffer:

而var_code本身为一段ShellCode,用于和CC通信,并下载最终的恶意样本:

下载的Payload(ShellCode)如下:

该ShellCode实际上是由Cobalt Strike生成的样本,偏移0的位置为对应的解密算法:

对应的数据格式如下:

解密后的Loader如下,通过ReflectivLoader的方式在内存中加载DllEntryPoint:

进入DllEntryPoint后通过XOR 0x69解码加密的config:

解密前的config:

解密后如下所示,CC同样还是46.101.141.96这个IP:

利用PDF文档执行的恶意样本
Md5(1):3ee36ec66cd8bfc540b80d2eb9a2face
Md5(2):57a50b3c473d20f9791c17ad5d2512aa
攻击者将恶意.SettingContent-ms文件嵌入到PDF文档中:

打开恶意PDF文档后提示是否执行内嵌的SettingContent-ms文件,一旦用户允许执行,则会无任何提示执行SettingContent-ms文件中内置的恶意代码:

投递带有正常数字签名木马的样本
Md5:2f7cec0f91a5fd23d706dc53a82b2db7
该样本同样将SettingContent-ms包含到PDF文件中进行投递:

Stage1
下载执行的样本通过正常的签名进行签发,签名为DIGI MICROSERVICE LIMITED:

编译时间如下所示:

样本运行之后检测杀软进程是否开启:

检测是否有调试:

之后从资源中获取第二阶段的样本,并通过XOR进行解密:

判断PE头,并加载:

Stage2
第二阶段的样本没有进行数字签名:

Fun_GetfunAddress通过传入的参数和HASH动态返回API地址:

检测系统环境是否有ammyy木马的相关痕迹,并删除:

链接http://169.239.129.117/Yjdfel765Hs,下载第三阶段样本,并通过RC4解密,秘钥为aaf0c0db4863f,之后写入到wsus中运行:

Stage3
第三阶段的样本如下所示,同样通过证书签名:

可以看到对应的ammyy字符串,表明这是一个开源的恶意代码:

CC为:185.99.132.119:443

对应的开源软件链接如下所示:

Darkhydrus 团伙用于投递DNS隧道通信的攻击样本
Md5:9dd647d509a3306cb11dbdb3cd8968cc
该样本会到 http://micrrosoft.net/winupdate.ps1 下载一个ps1文件执行:

下载的PS如下所示,内置的代码通过Base64,gzip压缩:

解码后如下所示,内置了8个DNS:

对沙箱虚拟机环境进行检测:

之后释放名为OneDrive.ps1、OneDrive.bat、OneDrive.lnk的三个文件,OneDrive.lnk释放在启动目录下,加载BAT文件,BAT文件启动ps1:

对应的Lnk文件如下所示:

Bat脚本如下:

之后获取环境相关信息:

样本的一大亮点在于和CC的通信使用了DNS隧道,如下所示通过nslookup发起的DNS请求:

Quary被封装到split函数中:

如下所示样本包含的其他相关的功能,如文件管理、SHELL、PowerShell模块插件安装、截屏等:

有意思的是样本投递的域名 http://micrrosoft.net/winupdate.ps1 在几天之后paloaltonetworks 披露的darkhydrus团伙中被用于iqy的投递攻击。

通过wmic加载远程list文件的攻击样本
Md5:624ed71872fe7dc5fa952c5cfd49e46b
该样本如下所示,DeepLink字段中通过wmic os get /format的形式加载一个远程的list文件:

list是githubgist上的一个测试脚本,通过js运行一个CMD:

分享的人为caseysmithrc,目前看来这只是一个测试样本:

经过测试确实通过该方式能启动运行CMD:

虽然只是测试样本,但是不排除之后会被大范围使用。
总结及安全建议企业用户可以通过禁止邮件附件携带.SettingContent-ms类型的附件接收,尽量不要点击打开来源不明的以及不常见的文件。用户侧需要尽快升级对应的补丁程序:
https://portal.msrc.microsoft.com/en-us/security-guidance/advisory/CVE-2018-8414
目前,基于360威胁情报中心的威胁情报数据的全线产品,包括360威胁情报平台(TIP)、天眼高级威胁检测系统、360 NGSOC等,都已经支持对此类攻击以及利用该漏洞进行攻击活动的检测。
IOC46.101.141.96
myaccount.dropsend.com
lanitida.net
micrrosoft.net
参考 [1]. https://posts.specterops.io/the-tale-of-settingcontent-ms-files-f1ea253e4d39 [2]. https://portal.msrc.microsoft.com/en-us/security-guidance/advisory/CVE-2018-8414 [3]. https://docs.microsoft.com/en-us/windows/security/information-protection/windows-information-protection/protect-enterprise-data-using-wip [4]. https://sandbox.ti.360.net/sandbox/page [5]. https://researchcenter.paloaltonetworks.com/2018/07/unit42-new-threat-actor-group-darkhydrus-targets-middle-east-government/