@@ -49,7 +49,8 @@ Author: Joe Bialek, Twitter: @JosephBialek
49
49
License: BSD 3-Clause
50
50
Required Dependencies: None
51
51
Optional Dependencies: None
52
- Version: 1.1
52
+ Version: 1.11
53
+ (1.1 -> 1.11: PassThru of System.Diagnostics.Process object added by Rune Mariboe, https://www.linkedin.com/in/runemariboe)
53
54
54
55
. DESCRIPTION
55
56
@@ -106,6 +107,10 @@ If you are creating a process which doesn't need a UI to be rendered, use this f
106
107
current user. If this flag isn't set and -CreateProcess is used, this script will modify the ACL's of the current users desktop to allow full control
107
108
to "Everyone".
108
109
110
+ . PARAMETER PassThru
111
+
112
+ If you are creating a process, this will pass the System.Diagnostics.Process object to the pipeline.
113
+
109
114
110
115
. EXAMPLE
111
116
@@ -151,6 +156,12 @@ Spawns cmd.exe using the primary token of LSASS.exe. This pipes the output of Ge
151
156
152
157
. EXAMPLE
153
158
159
+ (Get-Process wininit | Invoke-TokenManipulation -CreateProcess "cmd.exe" -PassThru).WaitForExit()
160
+
161
+ Spawns cmd.exe using the primary token of LSASS.exe. Then holds the spawning PowerShell session until that process has exited.
162
+
163
+ . EXAMPLE
164
+
154
165
Get-Process wininit | Invoke-TokenManipulation -ImpersonateUser
155
166
156
167
Makes the current thread impersonate the lsass security token.
@@ -220,7 +231,11 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
220
231
221
232
[Parameter (ParameterSetName = " CreateProcess" )]
222
233
[Switch ]
223
- $NoUI
234
+ $NoUI ,
235
+
236
+ [Parameter (ParameterSetName = " CreateProcess" )]
237
+ [Switch ]
238
+ $PassThru
224
239
)
225
240
226
241
Set-StrictMode - Version 2
@@ -1549,7 +1564,11 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
1549
1564
1550
1565
[Parameter (Position = 2 )]
1551
1566
[String ]
1552
- $ProcessArgs
1567
+ $ProcessArgs ,
1568
+
1569
+ [Parameter (Position = 3 )]
1570
+ [Switch ]
1571
+ $PassThru
1553
1572
)
1554
1573
Write-Verbose " Entering Create-ProcessWithToken"
1555
1574
# Duplicate the token so it can be used to create a new process
@@ -1600,6 +1619,18 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
1600
1619
$ProcessInfo = [System.Runtime.InteropServices.Marshal ]::PtrToStructure($ProcessInfoPtr , [Type ]$PROCESS_INFORMATION )
1601
1620
$CloseHandle.Invoke ($ProcessInfo.hProcess ) | Out-Null
1602
1621
$CloseHandle.Invoke ($ProcessInfo.hThread ) | Out-Null
1622
+
1623
+ # Pass created System.Diagnostics.Process object to pipeline
1624
+ if ($PassThru ) {
1625
+ # Retrieving created System.Diagnostics.Process object
1626
+ $returnProcess = Get-Process - Id $ProcessInfo.dwProcessId
1627
+
1628
+ # Caching process handle so we don't lose it when the process exits
1629
+ $null = $returnProcess.Handle
1630
+
1631
+ # Passing System.Diagnostics.Process object to pipeline
1632
+ $returnProcess
1633
+ }
1603
1634
}
1604
1635
else
1605
1636
{
@@ -1841,7 +1872,7 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
1841
1872
Set-DesktopACLs
1842
1873
}
1843
1874
1844
- Create- ProcessWithToken - hToken $hToken - ProcessName $CreateProcess - ProcessArgs $ProcessArgs
1875
+ Create- ProcessWithToken - hToken $hToken - ProcessName $CreateProcess - ProcessArgs $ProcessArgs - PassThru: $PassThru
1845
1876
1846
1877
Invoke-RevertToSelf
1847
1878
}
@@ -1880,4 +1911,3 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
1880
1911
# Start the main function
1881
1912
Main
1882
1913
}
1883
-
0 commit comments