无法从 LocalSystem 帐户创建具有提升权限的进程

无法从 LocalSystem 帐户创建具有提升权限的进程

我正在 Windows Server 2008 (Team City) 上运行构建服务器。构建由 Team City 代理运行,该代理作为 LocalService 帐户下的 Windows 服务运行。

其中一个构建需要将其创建的 zip 文件复制到远程共享,为此,我有一个 powershell 脚本,该脚本尝试使用具有适当权限的用户凭据来 shell 一个新进程以写入共享。问题是该脚本无法创建该进程。我可以从我的管理员用户那里顺利运行该脚本(因此脚本本身似乎没有问题),这让我认为 LocalSystem 帐户没有权限使用不同的凭据或类似的东西来 shell 新进程?

知道这个错误到底意味着什么吗?注意:我在安全事件日志中看不到任何错误,这似乎很奇怪(?)

$userName = "domain\user"
$password = "password"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $secstr
$command = "Copy-Item d:\file.zip \\remote\share\file.zip"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)

Start-Process powershell -NoNewWindow -ArgumentList "-encodedCommand", $encodedCommand -credential $credentials -wait

在 Start-Process 行抛出错误

System.InvalidOperationException: This command cannot be executed due to the error: Access is denied.
    at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)

答案1

我的答案通过本地系统帐户使用 powershell 提升信用在 StackOverflow 上:

在以下环境中运行脚本时,某些命令似乎受到限制:本地系统。从安全角度来看,这是合理的,因为本地系统

可以完全不受限制地访问本地资源。这也是 LocalSystem 的缺点,因为 LocalSystem 服务可以执行一些会导致整个系统崩溃的操作。

参考:MSDN,本地系统帐户

相关内容