diff --git a/CHANGELOG.md b/CHANGELOG.md index 530a795..f416d5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Releases are tagged `vX.Y.Z` and published with a zip and a SHA256 checksum. - 🖧 **SMB server guest logons and security events are collected.** The server side of insecure guest-logon auditing is now on too (event 3023), with the two server logs it can land in: SMBServer/Security (Microsoft's docs; also session authentication failures 551, access denied 1006/1007/1009, weak session keys 1906) and SMBServer/Operational (where current Windows 11 builds write 3023). Both logs are raised from 8 MB to 128 MB. Mapped on the Settings catalog and Group Policy pages and carried in the GPO pack. Windows 11 24H2 / Server 2025 and later. +### Fixed + +- 🏛️ **Group Policy-forced "do not overwrite" is reported, not fought.** When Group Policy sets a classic log to "do not overwrite" (Event Log Service > "Control Event Log behavior when the log file reaches its maximum size" = Enabled, as some published GPO baselines do), Enable's repair was undone at the next policy refresh and Test failed forever. Enable now leaves that log's retention alone, and both scripts name the policy to change. The Group Policy paths page says to leave it Disabled or Not configured. + ## [2.2.0] - 2026-09-24 Tighter checks on what the kit already claims, from a review of Yamato WELA's open issues: advanced audit policy can't be silently overridden, Test flags CrashOnAuditFail and empty AppLocker logs, SMB guest logons are audited, "do not overwrite" logs are repaired, and failed log changes are no longer reported as success. diff --git a/Enable-LoggingBaseline.ps1 b/Enable-LoggingBaseline.ps1 index 969ec10..f7ab65d 100644 --- a/Enable-LoggingBaseline.ps1 +++ b/Enable-LoggingBaseline.ps1 @@ -468,8 +468,14 @@ try { # fails it (#73). Only Retain is changed: AutoBackup keeps logging by # archiving full logs, which is a deliberate choice. $needCircular = ("$($log.LogMode)" -eq 'Retain') + # Forced by Group Policy: a local change would be undone at the next + # refresh, so report where to change it instead. + $policyRetain = ($needCircular -and (Test-RetentionForcedByPolicy $ch.Name)) + $policyNote = "retention 'do not overwrite' is set by Group Policy (Event Log Service > $($ch.Name) > Control Event Log behavior when the log file reaches its maximum size): set it to Disabled or Not configured there" + if ($policyRetain) { $needCircular = $false } if (-not $needSize -and -not $needEnable -and -not $needCircular) { + if ($policyRetain) { Add-Result 'Channel' $ch.Name 'PendingDecision' $policyNote; continue } Add-Result 'Channel' $ch.Name 'AlreadyCorrect' "$([math]::Round($log.MaximumSizeInBytes/1MB)) MB, enabled=$($log.IsEnabled)" continue } @@ -478,6 +484,7 @@ try { if ($needSize) { $desc += "size $([math]::Round($log.MaximumSizeInBytes/1MB)) MB -> $([math]::Round($ch.TargetBytes/1MB)) MB" } if ($needEnable) { $desc += 'enable (currently disabled)' } if ($needCircular) { $desc += 'retention "do not overwrite" -> overwrite as needed' } + if ($policyRetain) { $desc += $policyNote } $descText = $desc -join ', ' if ($PSCmdlet.ShouldProcess($ch.Name, $descText)) { diff --git a/Test-LoggingBaseline.ps1 b/Test-LoggingBaseline.ps1 index 476b475..ed85a44 100644 --- a/Test-LoggingBaseline.ps1 +++ b/Test-LoggingBaseline.ps1 @@ -150,7 +150,13 @@ foreach ($ch in $script:BaselineChannels) { $problems = @() if ($ch.MustEnable -and -not $log.IsEnabled) { $problems += 'disabled' } if ($log.MaximumSizeInBytes -lt $ch.TargetBytes) { $problems += "size $actualMB MB below target $targetMB MB" } - if ($log.LogMode -eq 'Retain') { $problems += 'retention set to "do not overwrite" - log will stop recording when full (Enable-LoggingBaseline.ps1 sets it to overwrite as needed)' } + if ($log.LogMode -eq 'Retain') { + if (Test-RetentionForcedByPolicy $ch.Name) { + $problems += "retention set to 'do not overwrite' by Group Policy - log will stop recording when full. Change it in the policy (Event Log Service > $($ch.Name) > Control Event Log behavior when the log file reaches its maximum size: Disabled or Not configured); Enable won't override Group Policy" + } else { + $problems += 'retention set to "do not overwrite" - log will stop recording when full (Enable-LoggingBaseline.ps1 sets it to overwrite as needed)' + } + } $actual = "enabled=$($log.IsEnabled), $actualMB MB, mode=$($log.LogMode)" if ($problems.Count -eq 0) { diff --git a/WinLogKit.Common.ps1 b/WinLogKit.Common.ps1 index 34884f6..4c5990d 100644 --- a/WinLogKit.Common.ps1 +++ b/WinLogKit.Common.ps1 @@ -127,6 +127,19 @@ function Format-AuditSetting { # Current state of the SMB audit settings (Windows 11 24H2 / Server 2025+). # Returns a hashtable Id -> current bool; items missing from the hashtable are # unsupported on this OS (the properties only exist on Server 2025 / Win11 24H2+). +# Whether Group Policy forces a classic log to "do not overwrite": Event +# Log Service > > "Control Event Log behavior when the log file +# reaches its maximum size" = Enabled (registry value Retention, per +# Microsoft's EventLogService CSP). Only the classic logs have that policy. +# A local change would be undone at the next refresh, so the kit reports it +# instead of fighting it. Compared as text: DWORD or string both read as 1. +function Test-RetentionForcedByPolicy { + param([string]$LogName) + if (@('Application', 'Security', 'Setup', 'System') -notcontains $LogName) { return $false } + $v = Get-RegValue -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\EventLog\$LogName" -Name 'Retention' + return ("$v" -eq '1') +} + # The Set-/Get-Smb*Configuration property an SMB audit item maps to: its # Setting when it has one (the same setting exists on client and server, # and Ids must be unique), otherwise its Id. Works for settings-table diff --git a/docs/commands.md b/docs/commands.md index 20febd0..80304fa 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -38,7 +38,8 @@ left alone; log sizes are only ever raised. only; see [Disk space](safety.md#disk-space)). - A kit log set to "do not overwrite" (logging stops when it fills) is switched to overwrite as needed, with a warning; "archive when full" is - left alone. + left alone, and so is a classic log whose retention Group Policy forces + (Enable says which policy to change). - First real run captures the rollback baseline; `-Rollback` restores it, including a log's original "do not overwrite" setting. - Never reboots, never restarts services; the one setting needing a service diff --git a/docs/gpo-paths.md b/docs/gpo-paths.md index c829a6f..5efed39 100644 --- a/docs/gpo-paths.md +++ b/docs/gpo-paths.md @@ -30,6 +30,10 @@ Things to know before you start: that ships with PowerShell 7 installs them on the local machine only. - **SMB auditing needs Windows 11 24H2 or Windows Server 2025**; older versions ignore those settings. +- **Leave "Control Event Log behavior when the log file reaches its + maximum size" Disabled or Not configured** (Event Log Service > each + classic log). Enabled means "do not overwrite": logging stops when the + log fills. Test fails it, and Enable won't override Group Policy. - **Only the classic logs have a size template.** The other kit logs are in the second table: size them with a computer startup script, or run `Enable-LoggingBaseline.ps1` on the host. diff --git a/docs/safety.md b/docs/safety.md index 1e59fcc..5012ad0 100644 --- a/docs/safety.md +++ b/docs/safety.md @@ -12,7 +12,7 @@ kit never touches them, in any mode: | Never touched | Why | |---|---| | `CrashOnAuditFail` ("Audit: Shut down system immediately if unable to log security audits") | A full Security log **halts the machine** with `STOP C0000244`; until reset, only Administrators can log on - IIS fails, AD replication fails. ([Microsoft KB832981](https://learn.microsoft.com/troubleshoot/developer/webapps/iis/health-diagnostic-performance/users-cannot-access-web-sites-when-log-full)) The test **fails** if another policy has turned it on. | -| "Do not overwrite events" retention | Logging silently stops when the log fills; with CrashOnAuditFail it crashes the host. The test **fails** this mode on the kit's logs, and Enable sets them back to overwrite as needed, with a warning (`-Rollback` restores the original). | +| "Do not overwrite events" retention | Logging silently stops when the log fills; with CrashOnAuditFail it crashes the host. The test **fails** this mode on the kit's logs, and Enable sets them back to overwrite as needed, with a warning (`-Rollback` restores the original). When Group Policy forces it (Event Log Service > "Control Event Log behavior when the log file reaches its maximum size" = Enabled), Enable leaves it and both scripts say to change the policy instead. | | Global object access auditing | SACLs on every kernel/file/registry object - extreme volume, measurable performance degradation. | | Blanket File System / Registry SACLs | A careless wildcard SACL can bury a file server. Scoping SACLs is a design decision, never a default. | | Shrinking logs, rebooting, restarting services | Sizes are only raised; the one restart-requiring setting (AD CS AuditFilter) is set with a warning and left to your change window. | diff --git a/tests/Kit.Tests.ps1 b/tests/Kit.Tests.ps1 index 0d26c7e..65919c4 100644 --- a/tests/Kit.Tests.ps1 +++ b/tests/Kit.Tests.ps1 @@ -423,6 +423,29 @@ Describe 'SMB audit items' { Get-SmbSettingName ([pscustomobject]@{ Id = 'X' }) | Should -Be 'X' } } +# "Do not overwrite" forced by Group Policy: report, don't fight it. +Describe 'Retention forced by policy' { + It 'reads the Event Log Service policy for the classic logs only' { + Mock Get-RegValue { 1 } + Test-RetentionForcedByPolicy 'Security' | Should -BeTrue + Test-RetentionForcedByPolicy 'Microsoft-Windows-PowerShell/Operational' | Should -BeFalse + } + + It 'treats DWORD and string 1 alike, and absent or 0 as not forced' { + Mock Get-RegValue { '1' } + Test-RetentionForcedByPolicy 'System' | Should -BeTrue + Mock Get-RegValue { 0 } + Test-RetentionForcedByPolicy 'System' | Should -BeFalse + Mock Get-RegValue { $null } + Test-RetentionForcedByPolicy 'Application' | Should -BeFalse + } + + It 'is checked by Enable before changing retention, and by Test' { + foreach ($rel in 'Enable-LoggingBaseline.ps1', 'Test-LoggingBaseline.ps1') { + Select-String -Path (Join-Path $KitRoot $rel) -Pattern 'Test-RetentionForcedByPolicy' -Quiet | Should -BeTrue -Because $rel + } + } +} Describe 'Rollback baseline' { BeforeAll { $enableAst = [System.Management.Automation.Language.Parser]::ParseFile((Join-Path $KitRoot 'Enable-LoggingBaseline.ps1'), [ref]$null, [ref]$null) diff --git a/tools/Export-PolicyTables.ps1 b/tools/Export-PolicyTables.ps1 index 3d693d1..7a79986 100644 --- a/tools/Export-PolicyTables.ps1 +++ b/tools/Export-PolicyTables.ps1 @@ -198,6 +198,10 @@ Things to know before you start: that ships with PowerShell 7 installs them on the local machine only. - **SMB auditing needs Windows 11 24H2 or Windows Server 2025**; older versions ignore those settings. +- **Leave "Control Event Log behavior when the log file reaches its + maximum size" Disabled or Not configured** (Event Log Service > each + classic log). Enabled means "do not overwrite": logging stops when the + log fills. Test fails it, and Enable won't override Group Policy. - **Only the classic logs have a size template.** The other kit logs are in the second table: size them with a computer startup script, or run `Enable-LoggingBaseline.ps1` on the host.