Last active
December 9, 2023 01:59
-
-
Save r00t-3xp10it/d6048639fd8233cdda30f4dff0498471 to your computer and use it in GitHub Desktop.
PS1 AutoElevate Demo Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If a script needs to be run elevated, then you can ensure it will only | |
# ever be run elevated by including the logic within the script. | |
## Check privileges | |
If(-not([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) | |
{ | |
## Not-ADMIN = Relaunch as an elevated process: | |
Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs | |
exit | |
} | |
## Everything that follow the 'Check privileges' ( above ) function | |
# will be executed with ADMIN privs... the next function its just | |
# for us to visially check the privileges that we current have .. | |
## COPY Update-KB303933.PS1 source code here ... | |
## Check privileges again | |
$IsClientAdmin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -Match "S-1-5-32-544") | |
If($IsClientAdmin -iMatch 'True') | |
{ | |
Write-host "Administrator" -ForegroundColor Green | |
Start-Process calc.exe | |
} | |
Else | |
{ | |
Write-host "UserLand" -ForegroundColor red -BackgroundColor Black | |
Start-Process mspaint.exe | |
} | |
Start-Sleep -Seconds 2 |
Author
r00t-3xp10it
commented
Mar 1, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment