首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell为RunAs提供凭据

Powershell为RunAs提供凭据
EN

Stack Overflow用户
提问于 2020-11-02 12:00:35
回答 1查看 1.4K关注 0票数 1

我正在尝试使用用户/pass编写一个PowerShell脚本,以实现自举。问题是,在启动进程中不能同时使用runas和-Credential。我尝试在powershell中运行powershell,但它不起作用。其想法是通过用户/pass绕过UAC。有人有什么建议吗?

编辑:不可能!

代码语言:javascript
复制
$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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-02 23:14:04

UAC旨在在尝试提升到管理权限时提供确认提示。(当进程已被提升时,提示符不会出现。)如果UAC已启用(强烈建议将其保留为已启用),则始终会出现提升提示符。您不能绕过UAC提示符(或者,如果您更喜欢其他术语,“以编程方式接受”)。这是故意的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64645211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档