【问题标题】:Is it possible to start a process as "nt authority\system" over Powershell remoting?是否可以通过 Powershell 远程处理以“nt authority\system”的身份启动进程?
【发布时间】:2016-02-07 03:02:25
【问题描述】:

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

psexec -s setup.exe /S

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

尝试 1:来自远程会话的 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 会话

[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

进程没有nt authority\system启动。

问题

是否可以通过 PowerShell 远程处理以 nt authority\system 的身份启动进程?如果有,怎么做?

【问题讨论】:

  • 你试过C:\PsTools\PsExec.exe -s -accepteula whoami吗?
  • @LievenKeersmaekers 不错的建议。我刚刚尝试过,它不再挂起。我仍然看到一个错误,但现在有希望了。感谢您的帮助。
  • 在远程系统上运行 procmon,执行您的命令,停止 procmon,您很可能会在跟踪中看到类似 whoami not found 的内容。
  • @LievenKeersmaekers psexec -s 甚至没有走那么远。它无法启动它的帮助服务,这是有道理的,因为远程处理 + 模拟可能加起来是双跳。见my answer

标签: powershell impersonation psexec powershell-remoting


【解决方案1】:

注意:我不是 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    

【讨论】:

  • 也不是安全专家,但我认为您是对的。很好的发现,很高兴知道。
【解决方案2】:

https://github.com/mkellerman/Invoke-CommandAs

针对本地/远程计算机创建了一个函数以作为 SYSTEM 调用命令,或提供凭据。返回 PSObject,处理网络中断并解决任何双跳问题。

试试看,如果这能解决您的问题,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    相关资源
    最近更新 更多