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

Commit 9d2b9d7

Browse files
author
Jon Cave
committed
PowerUp: Allocate enough space for TOKEN_GROUPS
Make an initial call to GetTokenInformation() with a NULL buffer to get the actual buffer size required. Prevents "The data area passed to a system call is too small" error being thrown.
1 parent 81ac124 commit 9d2b9d7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Privesc/PowerUp.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -974,17 +974,16 @@ function Get-CurrentUserTokenGroupSid {
974974
$Success = $Advapi32::OpenProcessToken($CurrentProcess, $TOKEN_QUERY, [ref]$hProcToken);$LastError = [Runtime.InteropServices.Marshal]::GetLastWin32Error()
975975

976976
if($Success) {
977-
978-
$TokenGroupsPtrSize = $TOKEN_GROUPS::GetSize()
977+
$TokenGroupsPtrSize = 0
978+
# Initial query to determine the necessary buffer size
979+
$Success = $Advapi32::GetTokenInformation($hProcToken, 2, 0, $TokenGroupsPtrSize, [ref]$TokenGroupsPtrSize)
979980

980981
[IntPtr]$TokenGroupsPtr = [System.Runtime.InteropServices.Marshal]::AllocHGlobal($TokenGroupsPtrSize)
981982

982-
[UInt32]$RealSize = 0
983-
984983
# query the current process token with the 'TokenGroups=2' TOKEN_INFORMATION_CLASS enum to retrieve a TOKEN_GROUPS structure
985-
$Success2 = $Advapi32::GetTokenInformation($hProcToken, 2, $TokenGroupsPtr, $TokenGroupsPtrSize, [ref]$TokenGroupsPtrSize);$LastError = [Runtime.InteropServices.Marshal]::GetLastWin32Error()
984+
$Success = $Advapi32::GetTokenInformation($hProcToken, 2, $TokenGroupsPtr, $TokenGroupsPtrSize, [ref]$TokenGroupsPtrSize);$LastError = [Runtime.InteropServices.Marshal]::GetLastWin32Error()
986985

987-
if($Success2) {
986+
if($Success) {
988987

989988
$TokenGroups = $TokenGroupsPtr -as $TOKEN_GROUPS
990989

0 commit comments

Comments
 (0)