Example #1
0
        ////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////
        public Tokens()
        {
            phNewToken     = new IntPtr();
            hExistingToken = new IntPtr();
            processes      = new Dictionary <UInt32, String>();
            WindowsPrincipal windowsPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());

            if (!windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
            {
                Console.WriteLine("[-] Administrator privileges required");
            }

            currentProcessToken = new IntPtr();
            Unmanaged.OpenProcessToken(Process.GetCurrentProcess().Handle, Constants.TOKEN_ALL_ACCESS, out currentProcessToken);
            SetTokenPrivilege(ref currentProcessToken, Constants.SE_DEBUG_NAME);
        }
Example #2
0
        ////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////
        public void GetPrimaryToken(UInt32 processId, String name)
        {
            //Originally Set to true
            IntPtr hProcess = Unmanaged.OpenProcess(Constants.PROCESS_QUERY_INFORMATION, true, processId);

            if (hProcess == IntPtr.Zero)
            {
                return;
            }
            Console.WriteLine("[+] Recieved Handle for: " + name + " (" + processId + ")");
            Console.WriteLine(" [+] Process Handle: " + hProcess.ToInt32());

            if (Unmanaged.OpenProcessToken(hProcess, Constants.TOKEN_ALT, out hExistingToken))
            {
                Console.WriteLine(" [+] Primary Token Handle: " + hExistingToken.ToInt32());
            }
            Unmanaged.CloseHandle(hProcess);
        }