渗透测试中的Application Compatibility Shims - 嘶吼 RoarTalk – 网络安全行业综合服务平台,4hou.com

渗透测试中的Application Compatibility Shims

3gstudent 技术 2016-11-20 16:57:17
466872
收藏

导语:Application Compatibility是一个框架,主要用来解决应用程序在版Windows系统上的兼容性问题。然而在渗透测试中它却有着更多的用处,本文将对公开资料进行整理。

Application Compatibility是一个框架,主要用来解决应用程序在版Windows系统上的兼容性问题。然而在渗透测试中它却有着更多的用处,本文将对公开资料进行整理,介绍在渗透测试中的具体利用技术,帮助大家更好的认识它,防御它。


1,简介

Shim:

相当于是在应用程序和Windows API之间的逻辑层。

当应用程序创建进程的时候,WindowsLoader首先会检查sysmain.sdb(位于%windir%AppPatch),如果存在已注册的sdb文件,IAT将被重定向到Shim,实现功能替换。

本文将介绍以下内容:

创建Shim文件
实际利用方法
相关开源工具
检测和防御

2,创建Shim文件

1.Microsoft Application CompatibilityToolkit(ACT)

下载地址:https://www.microsoft.com/enus/download/details.aspx?id=7352

默认修复方式种类个数为365

启动时加入/x 参数可获得更多修复方式,总数807

根据提示创建后生成.sdb文件,需要安装使其生效

可在Microsoft Application Compatibility Toolkit中直接选择安装,如图



3,实际利用方法


1.Hiding in the Registry

选择VirtualRegistry

Command line填入:

ADDREDIRECT(HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun^HKL
MSOFTWAREMicrosoftWindowsCurrentVersionRunHidden)

安装shim

启动regedit

HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun下键值无法查看,如图

1480669234240112.jpg

但在cmd下执行如下命令可以查看:

reg query HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun

45c58a1.jpg

2.Hiding in the File System

选择CorrectFilePaths

Command line填入:

c:test;c:users

Module name 填入*.exe ,点击add

安装shim

启动cmd.exe,无法查看c:test下的文件

e734daf.jpg

注:类似的还有VirtualizeDeleteFile 和RedirectShortcut

3.Persistence

可供选择的Fix有:


InjectDll
LoadLibraryRedirect
RedirectShortcut
RedirectEXE
ShimViaEAT
LoadLibraryfromCWD
Hijacking DLL

4.Disable Security Features of the OS


可供选择的Fix有:

Disable NX
Disable ASLR
DisableSEH
Prevent the Loading of DLLs
Disable Windows Resource Protection
Elevate to Administrator
DisableWindowsDefender
DisableAdvancedRPCClientHardening


4,安装和卸载Shim


1.sdbinst.exe

用来安装和卸载.sdb文件

微软官方提供,默认位于c:windowssystem32下,运行需要管理员权限

usage:

-? - print this help text.
-p - Allow SDBs containing patches.
-q - Quiet mode: prompts are autoaccepted.
-u - Uninstall.
-g - {guid} GUID of file (uninstall only).
-n - “name” Internal name of file (uninstall only).

卸载:

sdbinst.exe - u - n “name”

安装过程中sdbinst.exe做了如下操作:

在如下注册表位置创建键值保存Shim信息:


HKLMSOFTWAREMicrosoftWindows
NTCurrentVersionAppCompatFlagsCustom
HKLMSOFTWAREMicrosoftWindows
NTCurrentVersionAppCompatFlagsInstalledSDB

将sdb文件复制到如下文件路径:


C:WindowsAppPatchCustom
C:WindowsAppPatchCustomCustom64

添加到已安装的应用程序列表中

依次打开控制面板-程序-程序和功能-卸载程序,可看到安装的Shim名称

2.sdbexplorer

下载地址:https://github.com/evile/sdbexplorer

同样可用来安装.sdb文件,相比于sdbinst.exe多了如下特征:

源代码开源
支持InMemory
patch
安装过程不将sdb文件复制到C:WindowsAppPatchCustom下
安装过程不在已安装的应用程序列表中显示安装的Shim名称

usage:

Print full sdb tree
sdbexplorer.exe-t filename.sdb
Print patch details
sdbexplorer.exe [i]-p filename.sdb (patch | patchid | patchref |patchbin)-i-create
IDAPython Script (optional)
Print patch details for checksum
sdbexplorer.exe [i]-s filename.sdb
Create file containing the leaked memory
sdbexplorer.exe -l filename.sdb
Print Match Entries
sdbexplorer.exe - d filename.sdb
Create Patch From file
sdbexplorer.exe -C config.dat [o filename.sdb]
Register sdb file
sdbexplorer.exe - r filename.sdb [aapplication.exe]
Display usage
sdbexplorer.exe - h

演示如图

1.jpg

执行以下命令注册sdb文件:

sdb-explorer.exe -rC:UsersaDesktoptest1.sdb -a putty.exe

注:

-a的参数指定程序的名称,不能填入程序的绝对路径

通过sdbexplorer.exe注册的sdb文件无法通过sdbinst.exe来删除,会显示sbd文件不存在,如图

11.jpg

卸载可通过删除注册表键值的方式实现

注:通过sdbexplorer可以创建一个InMemory patch的shim,接着编译成sdb文件,进而安装使用,关于InMemory patch的学习心得将在以后分享

In Memory patch:


可以替换或写入内存中的某个区域的任意字节
可用来绕过应用程序白名单
5,查看Shim信息


1.sdb2xml

从.sdb文件提取出xml格式的数据,可用来分析sdb文件

作者:Heath Stewart

下载地址:https://blogs.msdn.microsoft.com/heaths/2007/11/03/shimdatabasetoxml/

usage:

sdb2xml sdb [out report] [base64 | extract] [?]
sdb Path to the shim database to process.
base64 Base64 encode data in the XML report.
extract Extract binary data to current or reportdirectory.
out report Path to the XML file to generate;otherwise, output to console.

如图,使用sdb2xml查看test1.sdb文件中的数据

111.jpg

2.Compatibility Database Dumper (CDD)

作者:Alex Ionesceu

usage:


cdd.exe [s][e][l][f][p][dkernelmodedatabase file][ausermode database file]
s Show shims
e Show executables
l Show layers
f Show flags
p Show patches
d Use Blocked Driver Database from this path
a Use Application Compatibility Database fromthis path

参考地址:http://www.alexionescu.com/?p=40

但作者Alex Ionescu目前尚未将其开源

3.Shim Database Tool (sdb)

作者:Jochen Kalmbach

下载地址:http://blog.kalmbachsoftware.de/2010/02/22/theshimdatabase/

注:该工具源代码开源

Usage:


sdb.exe [noids][match][PathToShimDatabse] [PathToFileName]
noids Will prevent the output of the TagIds
match Will match the provided file with theinstalled databases
and displays the activated shims
In this case ‘PathToFileName’ is required
NOTE: If no shim database path is provided,
the default database will be used.

从.sdb文件提取出xml格式的数据,演示如图


QQ图片20161202171015.png

显示指定程序是否被添加Shim,如图,找到putty.exe已被添加了一个Shim,guid

为8F9DA6E2-5A7C-41E1-B89F8B72D63DEBA8

2.jpg


6,检测和防御


禁用Shim的方法:

英文系统:

打开gpedit.msc,选择Administrative TemplatesWindows ComponentsApplication

CompatibilityTurn off Application Compatibility Engine

中文系统:

打开gpedit.msc,选择计算机配置-管理模板Windows组件-应用程序兼容性-关闭应用程序兼容性引擎

但不建议关闭Shim,原因如下:

导致EMET无法使用

无法更新补丁

检测和防御:

AutoRuns不会检测到Shim
Shim的安装需要管理员权限,注意权限控制
监控特定注册表键值
HKLMSOFTWAREMicrosoftWindows
NTCurrentVersionAppCompatFlagsCustom
HKLMSOFTWAREMicrosoftWindows
NTCurrentVersionAppCompatFlagsInstalledSDB
注意系统中未签名的sdb文件
使用检测脚本,如https://github.com/securesean/ShimProcessScanner和https://github.com/securesean/ShimProcessScannerLite


7,小结


本文对Application Compatibility Shims在渗透测试中的相关技巧做了整理,希望对大家有所帮助。对于InMemory patch,值得研究的还有很多,学习心得将在以后分享。

更多关于Shim的研究资料可访问:http://sdb.tools/index.html

本文参考链接:

http://blacksunhackers.club/2016/08/postexploitationpersistencewithapplicationshimsintro/
https://www.blackhat.com/docs/asia14/materials/Erickson/Asia14EricksonPersistItUsingAndAbusingMicrosoftsFixItPatches.pdf
http://www.irongeek.com/i.phppage=videos/derbycon3/4206windows0wn3dbydefaultmarkbaggett
http://sdb.io/ericksoncodeblue.pdf
  • 分享至
取消

感谢您的支持,我会继续努力的!

扫码支持

打开微信扫一扫后点击右上角即可分享哟

发表评论

 
本站4hou.com,所使用的字体和图片文字等素材部分来源于原作者或互联网共享平台。如使用任何字体和图片文字有侵犯其版权所有方的,嘶吼将配合联系原作者核实,并做出删除处理。
©2022 北京嘶吼文化传媒有限公司 京ICP备16063439号-1 本站由 提供云计算服务