powershell - 是否可以通过 Powershell 远程处理以 "nt authority\system"启动进程?

标签 powershell impersonation psexec powershell-remoting

我正在自动测试某些 Windows 应用程序的安装、检测和卸载。为了以静默方式运行大多数安装程序,它们必须以 nt Authority\system 身份运行。通过调用 psexec ,在本地计算机上很容易完成此操作,如下所示:

psexec -s setup.exe /S

我需要能够自动将测试目标计算机回滚到已知的良好状态,因此我使用另一台计算机来协调这一切。理想情况下,我可以使用 PowerShell 远程处理在目标计算机上启动安装程序。我还没有找到实现这一目标的方法。

尝试 1:从远程 session 中执行 psexec

最明显的事情是使用远程连接到目标计算机并调用 psexec -s 。看起来像这样:

[target.ad.example.com]: PS C:\Users\un1\Documents> C:\PsTools\PsExec.exe -s whoami
C:\PsTools\PsExec.exe :
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com

问题是,进程就在此时挂起。

尝试 2:Start-Process-Verb RunAs

RunAs 动词与 Start-Process 结合使用很可能会运行一个提升的进程,但它似乎并没有以 nt Authority\system 的身份运行它:

whoami-to-file.bat

whoami > out.txt

PowerShell session

[target.ad.example.com]: PS C:\> Start-Process .\whoami-to-file.bat -Verb RunAs -WorkingDirectory
[target.ad.example.com]: PS C:\> Get-Contents out.txt
example\un1

该进程作为ntauthority\system启动。

问题

是否可以通过 PowerShell 远程处理以 nt Authority\system 身份启动进程?如果是这样,怎么办?

最佳答案

注意:我不是 Windows 安全和凭据方面的专家,因此我不了解此技术的确切安全含义。就我而言,唯一有问题的凭据是临时测试计算机,因此没有太大风险。我怀疑这种技术对于生产来说是否是一个好主意。

这是一个双跳(我认为)

clymb3r's article关于 CredSSP,我认为解释了为什么 psexec -s 无法通过 PowerShell 远程处理。 我认为 PowerShell 远程处理算作一跃点,调用 psexec -s 算作第二跃点。如果是这样的话,我们就有 the double-hop authentication problem. 的表现形式。

使用 CredSSP

我认为有多种方法可以克服双跳问题。这是一个测试场景,CredSSP 似乎很合适 ( beware the security risk )。这是概念证明。

首先,您必须在两台计算机上启用 CredSSP:

PS C:\> Enable-WSManCredSSP Client -DelegateComputer target.ad.example.com
PS C:\> Invoke-Command { Enable-WSManCredSSP Server} -ComputerName target.ad.example.com

然后您可以使用 CredSSP 远程到目标:

PS C:\> $credential = Get-Credential example\target-admin
PS C:\> Enter-PSSession target.ad.example.com -Credential $credential -Authentication CredSSP
[target.ad.example.com]: PS C:\> 

并且psexec -s有效:

[target.ad.example.com]: PS C:\> psexec -s whoami
C:\PsTools\PsExec.exe :
+ CategoryInfo          : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
Connecting to local system...Starting PSEXESVC service on local system...Connecting with PsExec service on
target...Starting whoami on target...
whoami exited on target with error code 0.
nt authority\system    

关于powershell - 是否可以通过 Powershell 远程处理以 "nt authority\system"启动进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33558772/

相关文章:

powershell - 相同模块不同外壳。为什么?

powershell - 为什么 PowerShell Core 7 不能识别 UNC 路径,而 Windows PowerShell 和 cmd 可以?

c++ - Vista\Win7 中的模拟和注册表操作

java - 在java中使用PsExec.exe

powershell - EventLogPropertySelector 未从 PowerShell 中的事件对象返回扩展数据

powershell - 如何使用 Powershell 呈现可点击的链接

c++ - 远程启动 C++ 应用程序

创建文件作为系统

c# - 如何在非交互式登录下通过模拟获得提升的权限 (UAC)?

java - 尝试模拟用户访问 HDFS 时出错