【发布时间】: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
【问题讨论】:
-
@marsze 绝对不是。我已经看过那个了。它甚至没有选定的答案。
-
最受好评的评论完全没有抓住重点。这不是要欺骗 UAC,而是要以管理员身份进行身份验证,因此 UAC 没有理由做出反应。
-
如果您不是提升的用户并且启用了 UAC,则无法绕过(或者如果您愿意,“以编程方式接受”)UAC 提示。 UAC 提示将始终出现。
-
如果启用了 UAC,那么不,你想做的事情是不可能的。这是设计使然。您将需要使用不同的方法来解决您的问题。
标签: windows powershell