【问题标题】:Powershell provide credentials for RunAsPowershell 为 RunAs 提供凭据
【发布时间】:2021-02-15 02:09:44
【问题描述】:

我正在尝试编写一个 PowerShell 脚本以使用用户/密码进行自我提升。 问题是,runas 和 -Credential 不能在 Start-Process 中一起使用。 我尝试在 powershell 中运行 powershell,但它不起作用。 这个想法是用 user/pass 绕过 UAC。 有人有什么建议吗?

编辑:这是不可能的!

$username = "test"
$password = "123456"
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))


     # Self-elevate the script if required
    if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
     if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
     
        Write-Host -ForegroundColor 'Red' "Bypassing UAC..."
        Start-Sleep -s 2
        
     
      $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
      $CommandLine = "Start-Process -FilePath PowerShell.exe -verb runas -ArgumentList " + $CommandLine
      Start-Process powershell.exe -Credential $credentials -ArgumentList $CommandLine
      
        Write-Host -ForegroundColor 'Red' "Bypassing UAC..." $CommandLine
        Start-Sleep -s 30
      
      Exit
     }
    }


Write-Host -ForegroundColor 'Green' "Admin mode..."
Write-Host -ForegroundColor 'Gray' "Shell will exit in 15 seconds..."
Start-Sleep -s 15

【问题讨论】:

  • 这能回答你的问题吗? elevate without prompt - verb runas start-process
  • @marsze 绝对不是。我已经看过那个了。它甚至没有选定的答案。
  • 最受好评的评论完全没有抓住重点。这不是要欺骗 UAC,而是要以管理员身份进行身份验证,因此 UAC 没有理由做出反应。
  • 如果您不是提升的用户并且启​​用了 UAC,则无法绕过(或者如果您愿意,“以编程方式接受”)UAC 提示。 UAC 提示将始终出现。
  • 如果启用了 UAC,那么不,你想做的事情是不可能的。这是设计使然。您将需要使用不同的方法来解决您的问题。

标签: windows powershell


【解决方案1】:

UAC 旨在在尝试提升到管理权限时显示确认提示。 (当进程已经在提升运行时,不会出现提示。)如果启用了 UAC(并且强烈建议您保持启用状态),提升提示将始终出现。您不能绕过(或者,如果您更喜欢替代术语,“以编程方式接受”)UAC 提示。这是设计使然。

【讨论】:

  • 如果您以编程方式提供凭据,则没有理由出现提示。 UAC 提供的是一种以管理员权限执行的方法,基于用户登录的凭据,这需要用户同意。如果您不使用登录凭据,则无需同意。
  • 我可以使用powershell.exe-Credential 参数使用管理员凭据启动一个进程。即使凭据是针对属于Administrators 成员的用户,生成的进程也不会提升。从该过程提升仍然会触发 UAC 提示。
  • 嗯,这是对您的操作方式的限制,而不是操作系统
  • 我愿意同意这可能仅使用管理凭据即可完成(我无法确认或验证这一点)。即使它在技术上是可行的,我也绝对推荐它(适当地保护凭证,在这种情况下,管理凭证并不是微不足道的这个问题的范围)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-03
相关资源
最近更新 更多