Created
February 1, 2020 14:20
-
-
Save shelld0n/807975737d0726b455deed924acb7de3 to your computer and use it in GitHub Desktop.
CreateProcessWithTokenW_code
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
// Duplicate token and spawn a new cmd.exe process | |
myAPI.SECURITY_IMPERSONATION_LEVEL seImpersonateLevel = myAPI.SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation; | |
myAPI.TOKEN_TYPE tokenType = myAPI.TOKEN_TYPE.TokenPrimary; | |
IntPtr pNewToken = new IntPtr(); | |
myAPI.SECURITY_ATTRIBUTES sec_att = new myAPI.SECURITY_ATTRIBUTES(); | |
if (!myAPI.DuplicateTokenEx(tokenHandle, myAPI.TOKEN_ALL_ACCESS, ref sec_att, seImpersonateLevel, tokenType, out pNewToken)) { Console.WriteLine("Can't Adjust access Token"); Environment.Exit(2); }; | |
myAPI.STARTUPINFO si = new myAPI.STARTUPINFO(); | |
myAPI.PROCESS_INFORMATION pi; | |
bool ret; | |
ret = myAPI.CreateProcessWithTokenW(pNewToken, myAPI.LogonFlags.NetCredentialsOnly, "C:\\Windows\\System32\\cmd.exe", null, myAPI.CreationFlags.NewConsole, IntPtr.Zero, null, ref si, out pi); | |
Console.WriteLine(ret); | |
// End the routine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment