How the attack works
Every user and computer account has a primary group. It is stored on the account, in the primaryGroupID attribute, as the relative identifier (RID) of the group: 513 (Domain Users) for users, 515 (Domain Computers) for member computers, 516 (Domain Controllers) and 521 (Read-only Domain Controllers) for domain controllers. The account is a full member of its primary group.
What makes the attribute interesting to an attacker is where that membership is kept. It is not in the member attribute of the group and not in the memberOf attribute of the account. When a group becomes the primary group of an account, the account is taken out of the member list of that group, and the membership exists only as the RID on the account. A review that lists the members of Domain Admins from member therefore does not show an account whose primary group is Domain Admins. Microsoft Defender for Identity describes the attribute as a way to hide group membership and to escalate privileges without the usual auditing of membership changes.
A group normally becomes the primary group only of an account that is already a member of it, so the change follows an ordinary membership addition, which is logged. An attacker who injects the value through replication (see DCShadow) is not bound by that, and such a change does not appear in the events used here. A change made as a normal update is reported by the domain controller that processes it. The new RID is in the Primary Group ID field of event 4738 for users and of event 4742 for computers, and the field is a dash when the attribute did not change.
What an attacker needs
- Write access to the account, and membership of the account in the target group, which in turn takes the right to add members to that group.
- For a privileged target group this means the attacker already controls the group or the domain. The change is a way to keep and hide access, not to gain it.
Impact
The account holds all rights of the group while it stays out of the visible member list of the group, out of membership reports and out of clean-ups based on them. With Domain Admins or Enterprise Admins as primary group it is a hidden administrator. With Domain Controllers as primary group, a computer account is counted among the domain controllers and receives what that group is granted, including the directory replication rights.
Detection rules
Primary Group ID of an Account Changed
Detects a change of the primary group of a user account (event 4738) or a computer account (event 4742). The Primary Group ID field of these events holds the RID of the new primary group when the primaryGroupID attribute was changed, and a dash when it was not. Membership through the primary group is not stored in the member attribute of the group, so it is not seen by reviews that read that attribute. The rule reports every change, including the return to a default value. A value injected through replication is not logged in these events. Apply the rule to domain controllers, because on other computers event 4738 for a local account always carries the current value. Requires the audit subcategories Audit User Account Management and Audit Computer Account Management.
title: Primary Group ID of an Account Changed
id: 068da0c8-5795-47de-b5f8-d9e1ba804289
status: experimental
description: >-
Detects a change of the primary group of a user account (event 4738) or a
computer account (event 4742). The Primary Group ID field of these events
holds the RID of the new primary group when the primaryGroupID attribute was
changed, and a dash when it was not. Membership through the primary group is
not stored in the member attribute of the group, so it is not seen by
reviews that read that attribute. The rule reports every change, including
the return to a default value. A value injected through replication is not
logged in these events. Apply the rule to domain controllers, because on
other computers event 4738 for a local account always carries the current
value. Requires the audit subcategories Audit User Account Management and
Audit Computer Account Management.
references:
- https://attack.mitre.org/techniques/T1098/
- https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4738
- https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4742
- https://learn.microsoft.com/en-us/defender-for-identity/security-posture-assessments/accounts
author: Forestall
date: 2026-11-14
tags:
- attack.persistence
- attack.privilege-escalation
- attack.t1098
logsource:
product: windows
service: security
detection:
selection:
EventID:
- 4738
- 4742
filter_not_changed:
PrimaryGroupId: '-'
condition: selection and not 1 of filter_*
falsepositives:
- Promotion of a server to a domain controller and demotion, which move the computer account between 515, 516 and 521.
- Accounts that are deliberately given another primary group, for example for applications that rely on POSIX group semantics, and the later return of an account to its default group. Confirm the group and the reason.
level: low
False positives
- Promotion of a server to a domain controller and demotion, which move the computer account between 515, 516 and 521.
- Accounts that are deliberately given another primary group, for example for applications that rely on POSIX group semantics, and the later return of an account to its default group. Confirm the group and the reason.
Primary Group of an Account Set to a Privileged Group
Detects a user account (event 4738) or computer account (event 4742) whose primary group was changed to Domain Admins (RID 512), Domain Controllers (516), Schema Admins (518), Enterprise Admins (519), Key Admins (526) or Enterprise Key Admins (527). The account then holds the rights of the group without appearing in the member attribute of the group, which hides it from membership reviews. The promotion of a domain controller sets 516 on its computer account and matches as well. The field holds the RID as text, so the six values are matched as whole strings with a regular expression. A value injected through replication is not logged in these events. Requires the audit subcategories Audit User Account Management and Audit Computer Account Management on domain controllers.
title: Primary Group of an Account Set to a Privileged Group
id: 690fe830-e825-4f41-9e0f-6dff57ddd8ad
status: experimental
description: >-
Detects a user account (event 4738) or computer account (event 4742) whose
primary group was changed to Domain Admins (RID 512), Domain Controllers
(516), Schema Admins (518), Enterprise Admins (519), Key Admins (526) or
Enterprise Key Admins (527). The account then holds the rights of the group
without appearing in the member attribute of the group, which hides it from
membership reviews. The promotion of a domain controller sets 516 on its
computer account and matches as well. The field holds the RID as text, so
the six values are matched as whole strings with a regular expression. A
value injected through replication is not logged in these events. Requires
the audit subcategories Audit User Account Management and Audit Computer
Account Management on domain controllers.
references:
- https://attack.mitre.org/techniques/T1098/
- https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4738
- https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4742
- https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/understand-security-identifiers
- https://learn.microsoft.com/en-us/defender-for-identity/security-posture-assessments/accounts
author: Forestall
date: 2026-11-14
tags:
- attack.persistence
- attack.privilege-escalation
- attack.t1098
logsource:
product: windows
service: security
detection:
selection:
EventID:
- 4738
- 4742
PrimaryGroupId|re: '^(512|516|518|519|526|527)$'
condition: selection
falsepositives:
- Promotion of a server to a domain controller, which sets the primary group of its computer account to 516. Confirm that the computer named in the event is a domain controller that was being promoted at that time.
level: high
False positives
- Promotion of a server to a domain controller, which sets the primary group of its computer account to 516. Confirm that the computer named in the event is a domain controller that was being promoted at that time.
Triage
- Translate the RID in the Primary Group ID field into the group. 512, 518, 519, 526 and 527 are administrative groups, and 516 on anything but a domain controller is as serious.
- For a computer account check whether the machine was being promoted to a domain controller or demoted at that time. Promotion sets 516, or 521 for a read-only domain controller, and demotion sets 515.
- Identify who made the change (SubjectUserName) and look for the membership addition that came first (4728 or 4756 for the same account and group).
- List the effective members of the group, including accounts whose primaryGroupID is the RID of the group, and compare them with the approved list.
- If the change is not explained, set the primary group back to the default, remove the membership, and review what the account did while it held the rights of the group.
Response
Once the attack is confirmed:
- Disable the account whose primary group was changed and end its sessions. It holds every right of the group for as long as the RID is on it.
- Set the primary group back to its default (513 for a user, 515 for a member computer), then remove the account from the privileged group.
- Reset the credentials of the account that made the change. Whoever made it could add members to the privileged group, so look for the compromise that gave them that right.
- If the group was Domain Controllers and the account is not a real domain controller, check for directory replication requested by that account and handle a positive result as described for DCSync.
- Repeat the membership check for all privileged groups, not only the one in the alert. An attacker who hid one account this way may have hidden more.
Mitigation
- Leave primary groups at their defaults (513 for users, 514 for the Guest account, 515 for computers, 516 and 521 for domain controllers) and add accounts to other groups as ordinary members.
- Review accounts with a non-default primaryGroupID regularly and reset them, as the Defender for Identity posture assessment for this setting recommends.
- Count the members of privileged groups with a query that also matches primaryGroupID, so that hidden members show up in reviews.
- Limit write access to privileged groups and to the accounts in them to Tier 0 administrators.
- Enable the audit subcategories Audit User Account Management and Audit Computer Account Management on domain controllers.
Frequently asked questions
Why does the account not appear when I list the members of Domain Admins?
Membership through the primary group is stored on the account, as the RID of the group in primaryGroupID. It is not in the member attribute of the group and not in memberOf of the account, so a review that reads only member misses it. Count members with a query that also matches accounts whose primaryGroupID is the RID of the group.
Can the primary group be changed without event 4738 or 4742?
Yes. A value injected through replication, as in DCShadow, is not logged in these events. They report only a change made as a normal update on a domain controller. Regular reviews of accounts with a non-default primaryGroupID cover what the events cannot.
Which primary group changes are normal?
Promotion of a server to a domain controller sets 516, or 521 for a read-only domain controller, and demotion sets 515 again. A few applications that rely on POSIX group semantics need another primary group on purpose. Outside those cases, user accounts stay at 513 and member computers at 515.
Why should these rules run on domain controller logs only?
On other computers, event 4738 for a local account always carries the current value of the primary group and not a dash. The general rule would then report every change of a local account as a primary group change. On domain controllers the field is a dash unless the attribute was changed.
References
- MITRE ATT&CK T1098: Account Manipulation
- Event 4738: A user account was changed
- Event 4742: A computer account was changed
- Defender for Identity posture assessment: Accounts with non-default Primary Group ID
- Primary-Group-ID attribute
- User security attributes: memberOf does not contain the primary group
- Microsoft Entra Connect excludes the primary group of a user from its group membership
- Security identifiers: well-known SIDs and RIDs