运行PowerShell命令作为NT AUTHORITY \ SYSTEM

有没有办法从脚本运行一个PowerShell命令作为NT AUTHORITY\SYSTEM
我知道我可以使用psexec并得到一个作为NT AUTHORITY\SYSTEM运行的PowerShell提示符,但我想知道是否有办法从“普通”脚本执行它。

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

此脚本需要pipe理员权限。 它可以枚举可用的login令牌并使用它们来创build新的进程。 这使您可以通过使用其login标记创build进程来在networking上使用其他用户凭据。 即使使用Windows 8.1 LSASS保护,这也可以工作。

复制粘贴或与脚本一起保存为Invoke-TokenManipulation.ps1并使用dot-sourcing加载:

 $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path . (Join-Path -Path $ScriptDir -ChildPath 'Invoke-TokenManipulation.ps1') 

然后你可以使用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