Grants full control of the domain, is a member of the built-in administrators group on all domain controllers in a domain, and are administrators on the domain-joined machines
Enterprise Admins
Grants full control of all domains in a forest and is a member of the built-in administrators group on all domain controllers in a forest
Administrators
Grants full control of all the domain controllers in a domain
Group scope definitions
Scope Name
Definition
Universal
Can be assigned in any domain in the same forest or trusting forests
Global
Can be assigned in any domain in the same forest or trusting domains or forests
Domain Local
Can only be assigned in the current domain
Listing account management audit policy settings
PS C:\Windows\system32> auditpol /get /category:"Account Management"
System audit policy
Category/Subcategory Setting
Account Management
Computer Account Management Success
Security Group Management Success
Distribution Group Management No Auditing
Application Group Management No Auditing
Other Account Management Events No Auditing
User Account Management Success
There are three conditions that will trigger an alert from this audit policy:
A security group is created, changed, or deleted
A security group has a member added or removed
A security group is changed to a distribution group or vice versa
Event IDs for group membership changes
Event ID
Description
4728
A member was added to a security-enabled global group
4729
A member was removed from a security-enabled global group
4732
A member was added to a security-enabled local group
4733
A member was removed from a security-enabled local group
4756
A member was added to a security-enabled universal group
4757
A member was removed from a security-enabled universal group
XPath XML filter for all security group changes
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4728 or EventID=4729 or EventID=4732 or EventID=4733 or EventID=4756 or EventID=4757)]]</Select>
</Query>
</QueryList>
XPath XML filter for targeted security group changes
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4728 or EventID=4729 or EventID=4732 or EventID=4733 or EventID=4756 or EventID=4757)]]
And
*[EventData[Data[@Name='TargetUserName'] and (Data='Domain Admins' or Data='Administrators' or Data='Enterprise Admins')]]
</Select>
</Query>
</QueryList>
XPath filter for all security group changes for three named groups
$FilterXML = @'
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4728 or EventID=4729 or EventID=4732 or EventID=4733 or EventID=4756 or EventID=4757)]]
and
*[EventData[Data[@Name='TargetUserName'] and (Data='Administrators' or Data='Domain Admins' or Data='Enterprise Admins')]]
</Select>
</Query>
</QueryList>
'@
$Logs = Get-WinEvent -FilterXml $FilterXML
ForEach ($L in $Logs) {
[xml]$XML = $L.toXml()
$TimeStamp = $XML.Event.System.TimeCreated.SystemTime
$MemberName = $XML.Event.EventData.Data[0].'#text'
$GroupName = $XML.Event.EventData.Data[2].'#text'
$SubjectUserName = $XML.Event.EventData.Data[6].'#text'
[PSCustomObject]@{'TimeStamp' = $TimeStamp; 'MemberName' = $MemberName; 'GroupName' = $GroupName; 'SubjectUserName' = $SubjectUserName; 'ChangeType' = "($EventID) $ChangeType" }
}
Function to provide event descriptions
Function Get-ChangeType ([System.String]$Id) {
Begin {
$ChangeTable = @{
'4728' = '(4728) A member was added to a security-enabled global group.'
'4729' = '(4729) A member was removed from a security-enabled global group.'
'4732' = '(4732) A member was added to a security-enabled local group.'
'4733' = '(4733) A member was removed from a security-enabled local group.'
'4756' = '(4756) A member was added to a security-enabled universal group.'
'4757' = '(4757) A member was removed from a security-enabled universal group.'
}
}
Process {
$Value = $ChangeTable[$Id]
If (!$Value) {
$Value = $Id
}
}
End {
return $Value
}
}
Complete output from the security group audit script
PS C:\Users\offsec\Desktop\Persistence> .\Get-SecurityGroupChanges.ps1
TimeStamp : 2022-01-19T18:46:30.146129500Z
MemberName : CN=John Doe,OU=Staff,DC=corp,DC=com
GroupName : Enterprise Admins
SubjectUserName : Administrator
ChangeType : (4756) A member was added to a security-enabled universal group.
TimeStamp : 2022-01-19T18:42:45.830841000Z
MemberName : cn=dadmin,ou=Staff,DC=corp,DC=com
GroupName : Domain Admins
SubjectUserName : Administrator
ChangeType : (4728) A member was added to a security-enabled global group.
Domain User Modifications
Listing the account management sub-categories
PS C:\Windows\system32> auditpol /get /category:"Account Management"
System audit policy
Category/Subcategory Setting
Account Management
Computer Account Management Success
Security Group Management Success
Distribution Group Management No Auditing
Application Group Management No Auditing
Other Account Management Events No Auditing
User Account Management Success
XPath XML filter for user account management events
<QueryList>
<Query Id="0" Path="Security">
<Select
Path="Security">*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and Task = 13824]]
and
*[EventData[Data[@Name='SubjectUserName'] and
(Data='dadmin')]]
</Select>
</Query>
</QueryList>
Function to provide user account management event descriptions
Function Get-ChangeType ([System.String]$EventId) {
Begin {
$ChangeTable = @{
'4720' = “($EventId) A user account was created.”
'4722' = “($EventId) A user account was enabled.”
'4723' = “($EventId) An attempt was made to change an account''s password.”
'4724' = “($EventId) An attempt was made to reset an account''s password.”
'4738' = “($EventId) A user account was changed.”
'4740' = “($EventId) A user account was locked out.”
'4765' = “($EventId) SID History was added to an account.”
'4766' = “($EventId) An attempt to add SID History to an account failed.”
'4767' = “($EventId) A user account was unlocked.”
'4780' = “($EventId) The ACL was set on accounts which are members of administrators groups.”
'4781' = “($EventId) The name of an account was changed.”
'4794' = “($EventId) An attempt was made to set the Directory Services Restore Mode administrator password.”
'4798' = “($EventId) A user''s local group membership was enumerated.”
'5376' = “($EventId) Credential Manager credentials were backed up.”
'5377' = “($EventId) Credential Manager credentials were restored from a backup.”
'5379' = 'Credential Manager credentials were read'
}
}
Process {
$Value = $ChangeTable[$EventId]
If (!$Value) {
$Value = $EventId
}
}
End {
return $Value
}
}
Running the user change audit script
PS C:\Users\offsec\Desktop\Persistence> .\Get-UserChanges.ps1
TimeStamp SubjectUserName TargetUserName ChangeType
--------- --------------- -------------- ----------
2022-03-09T19:57:30.859931700Z dadmin notahacker (4724) An attempt was made to reset an account's passw...
2022-03-09T19:57:30.859864400Z dadmin notahacker (4738) A user account was changed.
...
Kerberos tickets are assigned to logon sessions, identified by logon IDs. Executing klistwithout any parameters only displays cached tickets for the current session
Running the klist command
PS C:\Users\offsec\Desktop\Persistence> klist
Current LogonId is 0:0x1fa47a
...