Windows Kernel Documentation

Security Descriptors

A security descriptor is a data structure that defines the security properties of an object. It contains the security information that protects the object from unauthorized access. In the Windows operating system, almost all securable objects, such as processes, threads, files, directories, registry keys, and named pipes, have an associated security descriptor.

Structure of a Security Descriptor

A security descriptor can contain the following components:

The structure is typically represented by the SECURITY_DESCRIPTOR structure in the Windows API.

typedef struct _SECURITY_DESCRIPTOR {
    DWORD Revision;
    DWORD Sbz1;
    DWORD Control;
    PSID Owner;
    PSID Group;
    PACL Sacl;
    PACL Dacl;
} SECURITY_DESCRIPTOR, *PSECURITY_DESCRIPTOR;

Security Identifier (SID)

A SID is a unique, variable-length structure that identifies a security principal (like a user or group) or security authority. It is the fundamental way Windows identifies security subjects.

Access Control Lists (ACLs)

An ACL is a collection of ACEs. There are two types of ACLs:

Access Control Entries (ACEs)

Each ACE contains a SID and a set of permissions. An ACE can either grant or deny specific permissions to the SID it contains. ACEs within an ACL are processed in a specific order, with explicit deny ACEs typically taking precedence over grant ACEs.

Note: The DACL is the primary mechanism for controlling access to an object. If an object has no DACL or a NULL DACL, access is typically unrestricted (though this is rare for system objects).

Security Descriptor Control Bits

The Control member of the SECURITY_DESCRIPTOR structure contains flags that indicate the presence or absence of certain components (like SACL or owner) and other characteristics of the security descriptor. These flags are important for interpreting the descriptor correctly.

Creating and Modifying Security Descriptors

Developers can use Windows API functions such as InitializeSecurityDescriptor, SetSecurityDescriptorOwner, AddAccessAllowedAce, and SetKernelObjectSecurity to create and modify security descriptors for kernel objects.

Warning: Improperly configured security descriptors can lead to severe security vulnerabilities, allowing unauthorized access or preventing legitimate access. Always adhere to best practices and thoroughly test security configurations.

Inheritance

Security descriptors can be inherited by child objects from their parent objects. This is managed through specific flags within ACEs and the security descriptor's control bits, simplifying security management for hierarchical structures like file systems.