Skip to content

Instantly share code, notes, and snippets.

@shelld0n
Created February 1, 2020 13:49
Show Gist options
  • Save shelld0n/405ea7ad34309d56becd6c807fcdd91d to your computer and use it in GitHub Desktop.
Save shelld0n/405ea7ad34309d56becd6c807fcdd91d to your computer and use it in GitHub Desktop.

Revisions

  1. shelld0n created this gist Feb 1, 2020.
    8 changes: 8 additions & 0 deletions OpenProcessToken_codeblock.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    // Duplicate Tokens for system process and store them in tokenHandle
    Console.WriteLine("your journey just started");
    IntPtr test = myAPI.OpenProcess(myAPI.ProcessAccessFlags.QueryInformation, true, pid);
    if (test == IntPtr.Zero) Console.WriteLine("No Handle to process !");
    IntPtr tokenHandle;
    bool result_token = myAPI.OpenProcessToken(test, myAPI.TOKEN_READ | myAPI.TOKEN_IMPERSONATE | myAPI.TOKEN_DUPLICATE, out tokenHandle);
    Console.WriteLine(result_token);
    //End of getting the handle of token of SYSTEM process