Created
February 1, 2020 12:34
-
-
Save shelld0n/be0ad4fc091b1fc0326d1cd424174172 to your computer and use it in GitHub Desktop.
adjusttokenpriv_block
This file contains hidden or 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
// Enable SeDebugPrivilege Routine | |
string Privilege = "SeDebugPrivilege"; | |
myAPI.LUID luid = new myAPI.LUID(); | |
IntPtr hProcess = myAPI.GetCurrentProcess(); | |
IntPtr hToken; | |
if (!myAPI.OpenProcessToken(hProcess, myAPI.TOKEN_QUERY | myAPI.TOKEN_ADJUST_PRIVILEGES, out hToken)) { Console.WriteLine("No tokens for current process"); Environment.Exit(2); }; | |
if (!myAPI.LookupPrivilegeValue(null, Privilege, out luid)) { Console.WriteLine("No handle for privilege"); Environment.Exit(2); }; | |
myAPI.LUID_AND_ATTRIBUTES luAttr = new myAPI.LUID_AND_ATTRIBUTES { Luid = luid, Attributes = myAPI.LUID_AND_ATTRIBUTES.SE_PRIVILEGE_ENABLED }; | |
myAPI.TOKEN_PRIVILEGES tp = new myAPI.TOKEN_PRIVILEGES { PrivilegeCount = 1, Privileges = new myAPI.LUID_AND_ATTRIBUTES[1] }; | |
tp.Privileges[0] = luAttr; | |
myAPI.TOKEN_PRIVILEGES oldState = new myAPI.TOKEN_PRIVILEGES(); // Our old state. | |
UInt32 trash; | |
if (!myAPI.AdjustTokenPrivileges(hToken, false, ref tp, (UInt32)Marshal.SizeOf(tp), ref oldState, out trash)) { Console.WriteLine("Can't Adjust access Token"); Environment.Exit(2); }; | |
// End of SeDebugPrivileges Routine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment