Skip to content

Instantly share code, notes, and snippets.

@bitRAKE
Last active May 24, 2022 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitRAKE/d4c7e6d91adc963af8486d0abefc9e65 to your computer and use it in GitHub Desktop.
Save bitRAKE/d4c7e6d91adc963af8486d0abefc9e65 to your computer and use it in GitHub Desktop.
Checks if the current process in running with elevation ...
; kernel32.dll, advapi32.dll, 79 bytes
CheckElevation:
virtual at RBP-.FRAME
rq 4
.P5 dq ?
.hTok dq ? ; HANDLE
.tLen dd ?
.tInfo TOKEN_ELEVATION
_align 16
.FRAME := $ - $$
end virtual
enter .FRAME,0
GetCurrentProcess
xchg rcx,rax
OpenProcessToken rcx, TOKEN_QUERY, ADDR .hTok
xchg ecx,eax ; BOOL
jrcxz .fail
GetTokenInformation [.hTok], TokenElevation,\
ADDR .tInfo, sizeof TOKEN_ELEVATION, ADDR .tLen
test eax,eax ; BOOL
jnz .close_handle
; forward function fail
mov [.tInfo.TokenIsElevated],eax
.close_handle:
CloseHandle [.hTok]
mov ecx,[.tInfo.TokenIsElevated]
.fail:
leave
retn
; result in ECX, use JRCXZ to respond to boolean value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment