以 NT AUTHORITY\SYSTEM 身份运行 PowerShell 命令

Pao*_*sco 5 powershell

有没有办法NT AUTHORITY\SYSTEM从脚本中运行 PowerShell 命令?
我知道我可以使用psexec并让 PowerShell 提示符作为 运行NT AUTHORITY\SYSTEM,但我想知道是否有办法从“正常”脚本中执行此操作。

bea*_*ker 7

您可以使用Invoke-TokenManipulation.ps1脚本:

此脚本需要管理员权限。它可以枚举可用的登录令牌并使用它们来创建新进程。这允许您通过使用其他用户的登录令牌创建进程来使用网络上的其他用户凭据。这甚至适用于 Windows 8.1 LSASS 保护。

将其复制粘贴或与您的脚本一起保存为Invoke-TokenManipulation.ps1并使用点源加载:

$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
. (Join-Path -Path $ScriptDir -ChildPath 'Invoke-TokenManipulation.ps1')
Run Code Online (Sandbox Code Playgroud)

然后你就可以使用Invoke-TokenManipulation函数了。

例子:

# This command fails on my machine, even with admin rights
Get-ChildItem C:\Windows\CSC

# Makes the current PowerShell thread impersonate SYSTEM.
Invoke-TokenManipulation -ImpersonateUser -Username "nt authority\system"

# Now we can get contents of this folder
Get-ChildItem C:\Windows\CSC

# Stop impersonating an alternate users Token
Invoke-TokenManipulation -RevToSelf

# Check again
Get-ChildItem C:\Windows\CSC
Run Code Online (Sandbox Code Playgroud)