The key security offset of a key node points at a key
security item (sk). Many keys share one item, so a hive holds far fewer items than keys. The record
is from Maxim Suhanov’s Windows registry file format specification. The layout of the security descriptor
inside it is not part of that specification: it is the self-relative form defined in Microsoft’s MS-DTYP, and the
registry access rights are from Microsoft’s Registry Key Security and Access Rights.
Key security item
| Offset | Length | Field | Meaning |
|---|---|---|---|
| 0 | 2 | Signature | sk |
| 2 | 2 | Reserved | |
| 4 | 4 | Flink | Offset of the next item in the list |
| 8 | 4 | Blink | Offset of the previous item in the list |
| 12 | 4 | Reference count | The number of key nodes that point at this item |
| 16 | 4 | Security descriptor size | Bytes |
| 20 | … | Security descriptor | Self-relative, below |
The items form a doubly linked list, and an item can act as the list header or as an entry; the two differ only in the meaning of Flink and Blink. In a header, Flink and Blink point at the first and last entries; an empty list points the header at itself. In an entry, Flink points at the next entry and Blink at the previous one; the last entry’s Flink and the first entry’s Blink point back at the header.
The security descriptor
The descriptor is in self-relative form: one block with offsets from its own start. Its fixed part is 20 bytes:
| Offset | Length | Field | Meaning |
|---|---|---|---|
| 0 | 1 | Revision | Must be 1 |
| 1 | 1 | Sbz1 | Resource manager control bits when the RM control flag is set |
| 2 | 2 | Control | Flag bits, below; the self-relative bit must be set |
| 4 | 4 | OffsetOwner | Offset of the owner SID; 0 means none |
| 8 | 4 | OffsetGroup | Offset of the group SID; 0 means none |
| 12 | 4 | OffsetSacl | Offset of the SACL; 0 unless the SACL present flag is set |
| 16 | 4 | OffsetDacl | Offset of the DACL; 0 unless the DACL present flag is set |
The owner, group, SACL and DACL follow in any order; only the offsets say where they are.
| Control mask | Name | Meaning |
|---|---|---|
0x0001 | OD | Owner defaulted |
0x0002 | GD | Group defaulted |
0x0004 | DP | DACL present |
0x0008 | DD | DACL defaulted |
0x0010 | SP | SACL present |
0x0020 | SD | SACL defaulted |
0x0040 | DT | DACL trusted |
0x0080 | SS | Server security |
0x0100 | DC | DACL computed inheritance required |
0x0200 | SC | SACL computed inheritance required |
0x0400 | DI | DACL auto-inherited |
0x0800 | SI | SACL auto-inherited |
0x1000 | PD | DACL protected from inheritance |
0x2000 | PS | SACL protected from inheritance |
0x4000 | RM | RM control valid: Sbz1 holds resource manager bits |
0x8000 | SR | Self-relative |
ACLs and ACEs
An ACL (a DACL, which controls access, or a SACL, which audits it) starts with 8 bytes: AclRevision (1 byte: 2, or 4 for directory-service ACLs), Sbz1 (1 byte, zero), AclSize (2 bytes, the whole ACL including its entries), AceCount (2 bytes) and Sbz2 (2 bytes, zero). Then come AceCount entries, each starting with a 4-byte header:
| Offset | Length | Field | Meaning |
|---|---|---|---|
| 0 | 1 | AceType | Below |
| 1 | 1 | AceFlags | Below |
| 2 | 2 | AceSize | Size of the entry; a multiple of 4 |
The common types (access allowed, 0; access denied, 1; system audit, 2) continue with a 4-byte access mask and a SID. The object types (5, 6, 7) continue with a mask, 4 bytes of flags, a 16-byte object type GUID present when bit 0 of the flags is set, a 16-byte inherited object type GUID present when bit 1 is set, and a SID. The callback types (9, 10, 13) continue like the common ones and may end with application data. Other types are listed below and are not taken apart further here.
| AceType | Name |
|---|---|
0x00 | ACCESS_ALLOWED |
0x01 | ACCESS_DENIED |
0x02 | SYSTEM_AUDIT |
0x03 | SYSTEM_ALARM (reserved) |
0x04 | ACCESS_ALLOWED_COMPOUND (reserved) |
0x05, 0x06, 0x07, 0x08 | ACCESS_ALLOWED_OBJECT, ACCESS_DENIED_OBJECT, SYSTEM_AUDIT_OBJECT, SYSTEM_ALARM_OBJECT (reserved) |
0x09, 0x0A, 0x0B, 0x0C | ACCESS_ALLOWED_CALLBACK, ACCESS_DENIED_CALLBACK, ACCESS_ALLOWED_CALLBACK_OBJECT, ACCESS_DENIED_CALLBACK_OBJECT |
0x0D, 0x0E, 0x0F, 0x10 | SYSTEM_AUDIT_CALLBACK, SYSTEM_ALARM_CALLBACK (reserved), SYSTEM_AUDIT_CALLBACK_OBJECT, SYSTEM_ALARM_CALLBACK_OBJECT (reserved) |
0x11, 0x12, 0x13 | SYSTEM_MANDATORY_LABEL, SYSTEM_RESOURCE_ATTRIBUTE, SYSTEM_SCOPED_POLICY_ID |
| AceFlags mask | Name |
|---|---|
0x01 | OBJECT_INHERIT_ACE: non-container children inherit it |
0x02 | CONTAINER_INHERIT_ACE: container children inherit it |
0x04 | NO_PROPAGATE_INHERIT_ACE: inheritance stops after one generation |
0x08 | INHERIT_ONLY_ACE: does not control access to the object it is on |
0x10 | INHERITED_ACE: the entry was inherited |
0x40 | SUCCESSFUL_ACCESS_ACE_FLAG: audit successful access (SACL) |
0x80 | FAILED_ACCESS_ACE_FLAG: audit failed access (SACL) |
SIDs
A SID is: a revision (1 byte, 1), a count of sub-authorities (1 byte), a 6-byte identifier authority (big-endian)
and that many 4-byte little-endian sub-authorities. It is written S-1-authority-sub-authority…,
for example S-1-5-18. Some well-known values: S-1-0-0 Null, S-1-1-0 World
(Everyone), S-1-3-0 Creator Owner, S-1-3-1 Creator Group, S-1-5-4
Interactive, S-1-5-11 Authenticated users, S-1-5-12 Restricted code,
S-1-5-18 Local System, S-1-5-32-544 Administrators, S-1-5-32-545 Users,
S-1-5-32-546 Guests, S-1-5-32-547 Power Users.
Access rights for keys
An access mask of a registry key combines these bits (the standard rights are DELETE, READ_CONTROL, WRITE_DAC and WRITE_OWNER; keys do not support SYNCHRONIZE):
| Mask | Name |
|---|---|
0x0001 | KEY_QUERY_VALUE |
0x0002 | KEY_SET_VALUE |
0x0004 | KEY_CREATE_SUB_KEY |
0x0008 | KEY_ENUMERATE_SUB_KEYS |
0x0010 | KEY_NOTIFY |
0x0020 | KEY_CREATE_LINK (reserved for system use) |
0x0100, 0x0200 | KEY_WOW64_64KEY, KEY_WOW64_32KEY (used when opening a key, not in a stored entry) |
0x20019 | KEY_READ (also KEY_EXECUTE) |
0x20006 | KEY_WRITE |
0xF003F | KEY_ALL_ACCESS |