Do this on your AD Domain Controller:
# Define the list of executable file paths to log
$ExecutablePaths = @(
"C:\Windows\System32\ntdsutil.exe",
"C:\Windows\System32\dsa.msc",
"C:\Windows\System32\dsac.exe",
"C:\Windows\System32\gpmc.msc",
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe",
"C:\Windows\System32\mstsc.exe",
"C:\Windows\System32\wbem\wmiprvse.exe",
"C:\Windows\System32\eventvwr.msc",
"C:\Windows\System32\secpol.msc",
"C:\Windows\System32\dsquery.exe",
"C:\Windows\System32\dsadd.exe",
"C:\Windows\System32\dsrm.exe"
)
# Enable Object Access auditing
$AuditPolicy = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit"
$AuditPolicy.ObjectAccess = 1
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit" -Name ObjectAccess -Value 1
# Loop through each executable path and configure audit settings
foreach ($Path in $ExecutablePaths) {
$AuditRule = New-Object
System.Security.AccessControl.FileSystemAuditRule("Everyone", "ExecuteFile", "Success,Failure")
$AuditRulePath = New-Object
System.Security.AccessControl.FileSystemAuditRule("Everyone", "ReadAttributes", "Success,Failure")
$Acl = Get-Acl -Path
$Path
$Acl.AddAuditRule($AuditRule)
$Acl.AddAuditRule($AuditRulePath)
Set-Acl -Path
$Path -AclObject
$Acl
}
# Verify the audit settings
Get-AuditLogConfiguration | Format-Table -Property IsObjectAccessAuditEnabled, IsAuditEnabled
--- Part 2: watch this log carefully ---
# Define the list of executable file paths
$ExecutablePaths = @(
"C:\Windows\System32\ntdsutil.exe",
"C:\Windows\System32\dsa.msc",
"C:\Windows\System32\dsac.exe",
"C:\Windows\System32\gpmc.msc",
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe",
"C:\Windows\System32\mstsc.exe",
"C:\Windows\System32\wbem\wmiprvse.exe",
"C:\Windows\System32\eventvwr.msc",
"C:\Windows\System32\secpol.msc",
"C:\Windows\System32\dsquery.exe",
"C:\Windows\System32\dsadd.exe",
"C:\Windows\System32\dsrm.exe"
)
# Define the log name and event IDs for Object Access auditing
$LogName = "Security"
$EventIDs = @(4663, 4670, 5136)
# Define the filter XML to filter events related to executable paths
$FilterXML = @"
<QueryList>
<Query Id="0" Path="$LogName">
<Select Path="$LogName">
*[System[(EventID=$($EventIDs -join " or EventID="))]]
and
*[EventData[Data[
@Name='ObjectType'] and (Data='File')]]
and
(
*[EventData[Data[
@Name='ObjectName'] and ($(foreach ($Path in $ExecutablePaths) { "Data='$Path' or " })'false')]]
)
</Select>
</Query>
</QueryList>
"@
# Register the event log filter
Register-WinEvent -LogName $LogName -ProviderName 'Microsoft-Windows-Security-Auditing' -FilterXPath $FilterXML -Verbose