Process Token Privilege
Last updated
Last updated
Process privilege determines the type of operations that a process can perform. A process running in medium integrity (right) has very few privileges available; whereas a process running in high integrity (left) has more. Some privileges are default enabled, which means they are enabled by default (duh). Others are disabled but are available, which means they can be enabled using the API.
Take SeDebugPrivilege as an example. The high integrity process has it disabled but available (the token::elevate
command in Mimikatz enables this privilege). The medium integrity process cannot enable it at all.
The token of a process is stored within its EPROCESS structure.
This attribute points to another structure called SEP_TOKEN_PRIVILEGES
.
Here we see the familiar fields of Present (or available), Enabled and EnabledByDefault. To actually get a view of the memory region, use the !process
command to list a short summary of every running process.
ffff998f239e8080
is the address of EPROCESS for this process. !process <address> 1
will give a bit more information, including the memory location of the token structure (ffffae8177195060
).
We can read the bytes at this address, plus the 0x40 offset.
These are bitmasks which can be anything from 0x00 to 0xff. Different combinations will enable different privileges.
typedef PVOID PACCESS_TOKEN;
The SEP_TOKEN_PRIVILEGES
structure is not defined at all, so we'll have to create one in driver.h
.
This new IOCTL will still expect to receive a TARGET_PROCESS
structure from the client and it will need to obtain a pointer to its EPROCESS struct as in the previous module.
If we're successful in getting a pointer to the TOKEN_PRIVILEGES, we can enable them all by setting the bitmask of each field to their maximum. We must also ensure to dereference our count on eProcess
and hToken
.
In this example, Mimikatz is running in medium integrity. But because we've granted all token privileges, including SeDebug, it's able to read LSASS.
The provides a description of what each privilege does.
EX_FAST_REF is a type of which, in this case, points to a TOKEN
structure. It's quite large, but the Privileges attribute is the one we're interested in.
Luckily, we don't have to do many additional offset calculations to find the relevant portion of memory thanks to the API. This takes a pointer to an EPROCESS
structure and returns a pointer to its TOKEN
structure. This is also opaque as define in wdm.h
.