是否可以在Powershell远程处理上启动一个“nt authority \ system”进程?

时间:2015-11-06 03:05:42

标签: powershell impersonation psexec powershell-remoting

我正在自动测试某些Windows应用程序的安装,检测和卸载。为了以静默方式运行大多数安装程序,它们必须以Sub multiplyRowsByCellValue() Dim rangeInventory As Range Dim rangeSingleCell As Range Dim numberOfRepeats As Integer Dim n As Integer Dim lastRow As Long 'Set rangeInventory to all of the Inventory Data Set rangeInventory = Sheets("Sheet1").Range("A2", Sheets("Sheet1").Range("D2").End(xlDown)) 'Iterate each row of the Inventory Data For Each rangeSingleCell In rangeInventory.Rows 'number of times to be repeated copied from Sheet1 column 4 ("C") numberOfRepeats = rangeSingleCell.Cells(1, 3).Value 'check if numberOfRepeats is greater than 0 If numberOfRepeats > 0 Then With Sheets("Sheet2") 'copy each invetory item in Sheet1 and paste "numberOfRepeat" times in Sheet2 For n = 1 To numberOfRepeats lastRow = Sheets("Sheet1").Range("A1048576").End(xlUp).Row r.Copy Sheets("Sheet1").Range("A" & lastRow + 1).PasteSpecial xlPasteValues Next End With End If Next End Sub 运行。通过调用nt authority\system这样的东西,很容易在本地机器上完成:

psexec

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

尝试1:远程会话中的psexec

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

psexec -s setup.exe /S

问题是,这个过程只是暂停了。

尝试2:[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 Start-Process

-Verb RunAs动词与Start-Process一起使用可能会提升一个进程,但似乎不会将其作为RunAs运行:

WHOAMI到file.bat

nt authority\system

PowerShell会话

whoami > out.txt

该过程[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 启动。

问题

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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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

针对本地/远程计算机,以系统或提供的凭据的功能使Invoke-Command成为可能。返回PSObject,处理网络中断并解决任何Double-Hop问题。

尝试一下,让我知道这是否可以解决您的问题。

相关问题