Active Directory – primaryGroupID

๐Ÿ’ก ๐—ฆ๐—ฒ๐—ฐ๐˜‚๐—ฟ๐—ฒ ๐—•๐—ถ๐˜๐˜€ ๐Ÿ”’

๐—”๐—ฐ๐˜๐—ถ๐˜ƒ๐—ฒ ๐——๐—ถ๐—ฟ๐—ฒ๐—ฐ๐˜๐—ผ๐—ฟ๐˜† ๐—ฝ๐—ฟ๐—ถ๐—บ๐—ฎ๐—ฟ๐˜†๐—š๐—ฟ๐—ผ๐˜‚๐—ฝ๐—œ๐——: ๐—ฐ๐—ต๐—ฒ๐—ฐ๐—ธ ๐˜„๐—ต๐—ฎ๐˜ ๐˜†๐—ผ๐˜‚๐—ฟ ๐˜๐—ผ๐—ผ๐—น๐˜€ ๐—ฎ๐—ฟ๐—ฒ ๐—ฎ๐—ฐ๐˜๐˜‚๐—ฎ๐—น๐—น๐˜† ๐—ฟ๐—ฒ๐—ฝ๐—ผ๐—ฟ๐˜๐—ถ๐—ป๐—ด

Active Directory group membership is not only defined by the member / memberOf attributes. A user can also be a member of a group through their primaryGroupID.

๐—ง๐—ต๐—ถ๐˜€ ๐—ฐ๐—ฟ๐—ฒ๐—ฎ๐˜๐—ฒ๐˜€ ๐˜€๐—ผ๐—บ๐—ฒ ๐—ถ๐—ป๐˜๐—ฒ๐—ฟ๐—ฒ๐˜€๐˜๐—ถ๐—ป๐—ด ๐—ถ๐—ป๐—ฐ๐—ผ๐—ป๐˜€๐—ถ๐˜€๐˜๐—ฒ๐—ป๐—ฐ๐—ถ๐—ฒ๐˜€:

๐Ÿ”น Get-ADGroupMember returns users whose primaryGroupID points to the group.

๐Ÿ”น Get-ADGroup -Properties member does not.

๐Ÿ”น Get-ADUser -Properties memberOf does not show the primary group either.

๐Ÿ”น net group does include these users.

It gets even more interesting with nested groups: recursive queries can miss users whose membership exists through primaryGroupID.

This matters especially for monitoring privileged groups. If your scripts or security tools look only at the group objectโ€™s member attribute, you may not be seeing the complete membership.

โš ๏ธ There is also a technique where an attacker can deny read access to primaryGroupID on an unprotected user object, making the relationship even harder to discover through common AD and PowerShell tooling.

๐—ฃ๐—ฟ๐—ฎ๐—ฐ๐˜๐—ถ๐—ฐ๐—ฎ๐—น ๐—ฐ๐—ต๐—ฒ๐—ฐ๐—ธ:

Get-ADUser -Property primaryGroup,primaryGroupID -Filter {-not(primaryGroupID -like “513”)} |

Select-Object Name,primaryGroupID,primaryGroup

For normal user accounts, 513 represents Domain Users. Non-standard values are therefore worth reviewing rather than assuming your normal group-membership enumeration has caught everything.

โžก๏ธ ๐—ง๐—ต๐—ฒ ๐—ฏ๐—ถ๐—ด๐—ด๐—ฒ๐—ฟ ๐˜๐—ฎ๐—ธ๐—ฒ๐—ฎ๐˜„๐—ฎ๐˜†: test how your monitoring actually enumerates AD group membership. Different methods can return different answers.

Author: Brandon Colley (๐Ÿ”—https://trustedsec.com/blog/adventures-in-primary-group-behavior-reporting-and-exploitation)