Microsoft has always been pretty terrible at documenting new and interesting features for their System Integrity Policy used to enable security features like UMCI, Device Guard/Windows Defender Application Control etc. This short blog post is about another feature which seems to be totally undocumented*, but is available in Windows 10 since 1803, Adminless mode.
* No doubt Alex Ionescu will correct me on this point if I'm wrong.
TL;DR; Windows 10 SMode has an Adminless mode which fails any access check which relies on the BUILTIN\Administrators group. This is somewhat similar to macOS's System Integrity Protection in that the Administrator user cannot easily modify system resources. You can enable it by setting the DWORD value SeAdminlessEnforcementModeEnabled in HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Kernel to 1 on Windows 10 1809 SMode. I'd not recommend setting this value on a working SMode system as you might lock yourself out of the computer.
If you look at the kernel 1803 and above at the API SeAccessCheck (and similar) you'll see it now calls the method SeAccessCheckWithHintWithAdminlessChecks. The Adminless part is new, but what is Adminless and how is it enabled? Let's see some code, this is derived from 1809 [complexity reduced for clarity]:
BOOLEAN SeAccessCheck(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
BOOLEAN SubjectContextLocked,
ACCESS_MASK DesiredAccess,
ACCESS_MASK PreviouslyGrantedAccess,
PPRIVILEGE_SET *Privileges,
PGENERIC_MAPPING GenericMapping,
KPROCESSOR_MODE AccessMode,
PACCESS_MASK GrantedAccess,
PNTSTATUS AccessStatus) {
BOOLEAN AdminlessCheck = FALSE;
PTOKEN Token = SeQuerySubjectContextToken(SubjectSecurityContext);
DWORD Flags;
BOOLEAN Result
SeCodeIntegrityQueryPolicyInformation(205, &Flags, sizeof(Flags));
if (Flags & 0xA0000000) {
AdminlessCheck = SeTokenIsAdmin(Token) &&
!RtlEqualSid(SeLocalSystemSid, Token->UserAndGroups->Sid);
}
if (AdminlessCheck) {
Result = SeAccessCheckWithHintWithAdminlessChecks(
...,
GrantedAccess,
AccessStatus,
TRUE);
if (Result) {
return TRUE;
}
if (SepAccessStatusHasAccessDenied(GrantedAccess, AccessStatus)
&& SeAdminlessEnforcementModeEnabled) {
SepLogAdminlessAccessFailure(...);
return FALSE;
}
}
return SeAccessCheckWithHintWithAdminlessChecks(
..., FALSE);
}
The code has three main parts. First a call is made to SeCodeIntegrityQueryPolicyInformation to look up system information class 205 from the CI module. Normally these information classes are also accessible through NtQuerySystemInformation, however 205 is not actually wired up in 1809 therefore you can't query the flags from user-mode directly. If the flags returned have the bits 31 or 29 set, then the code tries to determine if the token being used for the access check is an admin (it the token a member of the the BUILTIN\Administrators group) and it's not a SYSTEM token based on the user SID.
If this token is not an admin, or it's a SYSTEM token then the second block is skipped. The SeAccessCheckWithHintWithAdminlessChecks method is called with the access check arguments and a final argument of FALSE and the result returned. This is the normal control flow for the access check. If the second block is instead entered SeAccessCheckWithHintWithAdminlessChecks is called with the final argument set to TRUE. This final argument is what determines whether Adminless checks are enabled or not, but not whether the checks are enforced. We'll see what the checks are are in a minute, but first let's continue here. Finally in this block SepAccessStatusHasAccessDenied is called which takes the granted access and the NTSTATUS code from the check and determines whether the access check failed with access denied. If the global variable SeAdminlessEnforcementModeEnabled is also TRUE then the code will log an optional ETW event and return FALSE indicating the check has failed. If Adminless mode is not enabled the normal non Adminless check is made.
There's two immediate questions you might ask, first where do the CI flags get set and how do you set SeAdminlessEnforcementModeEnabled to TRUE? The latter is easy, by creating a DWORD registry value set to 1 in "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Kernel" with the name AdminlessEnforcementModeEnabled the kernel will set that global variable to TRUE. The CI flags is slightly more complicated, the call to SeCodeIntegrityQueryPolicyInformation drills down to SIPolicyQueryWindowsLockdownMode inside the CI module. Which looks like the following:
void SIPolicyQueryWindowsLockdownMode(PULONG LockdownMode) {
SIPolicyHandle Policy;
if (SIPolicyIsPolicyActive(7, &Policy)) {
ULONG Options;
SIPolicyGetOptions(Policy, &Options, NULL);
if ((Options >> 6) & 1)
*LockdownMode |= 0x80000000;
else
*LockdownMode |= 0x20000000;
}
else {
*LockdownMode |= 0x40000000;
}
}
The code queries whether policy 7 is active. Policy 7 corresponds to the system integrity policy file loaded from WinSIPolicy.p7b (see g_SiPolicyTypeInfo in the CI module) which is the policy file used by SMode (what used to be Windows 10S). If 7 is active then the depending on an additional option flag either bit 31 or bit 29 is set in the LockdownMode parameter. If policy 7 is not active then bit 30 is set. Therefore what the call in SeAccessCheck is checking for is basically whether the current system is running Windows in SMode. We can see this more clearly by looking at 1803 which has slightly different code:
if (!g_sModeChecked) {
SYSTEM_CODE_INTEGRITY_POLICY Policy = {};
ZwQuerySystemInformation(SystemCodeIntegrityPolicyInformation,
&Policy, sizeof(Policy));
g_inSMode = Policy.Options & 0xA0000000;
g_sModeChecked = TRUE;
}
The code in 1803 makes it clear that if bit 29 or 31 is set then it's consider to be SMode. This code also uses ZwQuerySystemInformation instead of SeCodeIntegrityQueryPolicyInformation to extract the flags via the SystemCodeIntegrityPolicyInformation information class. We can call this instead of information class 205 using NtObjectManager. We can see in the screenshot below that on a non-SMode system calling NtSystemInfo::CodeIntegrityPolicy has Flag40000000 set which would not be considered SMode.
In contrast on an SMode installation we can see Flag20000000 is set instead. This means it's ready to enable Adminless mode.
We now know how to enable Adminless mode, but what is the mode enforcing? The final parameter to SeAccessCheckWithHintWithAdminlessChecks is forwarded to other methods. For example the method SepSidInTokenSidHash has been changed. This method checks whether a specific SID is in the list of a token's group SIDs. This is used for various purposes. For example when checking the DACL each ACE is enumerated and SepSidInTokenSidHash is called with the SID from the ACE and the token's group list. If the SID is in the group list the access check handles the ACE according to type and updates the current granted access. The change for Adminless looks like the following:
BOOLEAN SepSidInTokenSidHash(PSID_AND_ATTRIBUTES_HASH SidAndHash,
PSID Sid,
BOOLEAN AdminlessCheck) {
if (AdminlessCheck && RtlEqualSid(SeAliasAdminsSid, Sid) )
return FALSE;
// ...
return TRUE;
}
Basically if the AdminlessCheck argument is TRUE and the SID to check is BUILTIN\Administrators then fail immediately. This checks in repeated in a number of other places as well. The net result is Administrators (except for SYSTEM which is needed for system operation) can no longer access a resource based on being a member of the Administrators group. As far as I can tell it doesn't block privilege checks, so if you were able to run under a token with "GOD" privileges such as SeDebugPrivilege you could still circumvent the OS security. However you need to be running with High Integrity to use the most dangerous privileges which you won't get as a normal user.
I don't really know what the use case for this mode is, at least it's not currently on by default on SMode. As it's not documented anywhere I could find then I assume it's also not something Microsoft are expecting users/admins to enable. The only thoughts I had were kiosk style systems or in Hyper-V containers to block all administrators access. If you were managing a fleet of SMode devices you could also enable this to make it harder for a user to run code as admin, however it wouldn't do much if you had a privilege escalation to SYSTEM.
This sounds similar in some ways to System Integrity Protection/SIP/rootless on macOS in that it limits the ability for a user modify the system except rather than a flag which indicates a resource can be modified like on macOS and administrator could still modify a resource as long as they have another group to use. Perhaps eventually Microsoft might document this feature, considering the deep changes to access checking it required. Then again, knowing Microsoft, probably not.