diff --git a/Diagnose-RdpLoginMonitor.ps1 b/Diagnose-RdpLoginMonitor.ps1 index 4587192..03136f3 100644 --- a/Diagnose-RdpLoginMonitor.ps1 +++ b/Diagnose-RdpLoginMonitor.ps1 @@ -399,6 +399,7 @@ if ($notifyable.Count -eq 0 -and $recent4624.Count -gt 0) { [void]$report.AppendLine('') [void]$report.AppendLine('UseSAC=exclusive: Telegram по rdp.login.success только из SAC (не локально агентом).') +[void]$report.AppendLine('На сервере RDS без аудита Security 4624 — смотрите RCM Operational 1149 (с 2.1.4-SAC мониторится на сервере).') [void]$report.AppendLine('rdp.login.success = severity info; при SAC min_severity=warning Telegram не уйдёт, но событие в UI SAC должно быть.') [void]$report.AppendLine('Проверьте SAC: type=rdp.login.success, hostname ITIS198, время входа, event_id из login_monitor.log.') diff --git a/Login_Monitor.ps1 b/Login_Monitor.ps1 index 4aca44b..6624255 100644 --- a/Login_Monitor.ps1 +++ b/Login_Monitor.ps1 @@ -16,7 +16,7 @@ - Добавлены исключения шума: DWM-*, UMFD-*, HealthMailbox*, Font Driver Host*, NtLmSsp и др. - Heartbeat без дрейфа: используется nextHeartbeatTime (а не "прошло N секунд"). - Win32_OperatingSystem.ProductType: 1 = рабочая станция (4624/4625 только LogonType 10 + при наличии журнала событие 1149 RCM); - 2/3 = сервер/КД — прежняя логика (типы 2, 3, 10). + 2/3 = сервер/КД — Security 4624/4625 (типы 2, 3, 10) + при наличии журнала RCM — 1149 (на RDS часто нет 4624 без аудита входа). Секреты Telegram (DPAPI LocalMachine): на ЭТОЙ машине, под админом, выполните: Add-Type -AssemblyName System.Security $p=[Text.Encoding]::UTF8.GetBytes('<токен>') @@ -90,7 +90,7 @@ $script:SkipLogDetailLimit = 15 # строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах). # Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только # исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1). -$ScriptVersion = "2.1.3-SAC" +$ScriptVersion = "2.1.4-SAC" # Логи (все под InstallRoot) $LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log" @@ -139,7 +139,8 @@ $GatewayEventsLookbackMinutes = 60 # Security 4624/4625/4648: персистентный cursor + replay не старше N мин (медленный boot / поздний старт агента). $SecurityEventsLookbackMinutes = 60 -# RDP Remote Connection Manager (workstations): User authentication succeeded — событие 1149 +# RDP Remote Connection Manager: User authentication succeeded — событие 1149 (workstation + RDS server) +$EnableRcm1149Monitoring = 1 $RcmLogName = "Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational" $RcmEventId = 1149 @@ -2637,7 +2638,7 @@ function Send-Heartbeat { if ($script:IsWorkstation) { $message += "`r`n📌 Режим: рабочая станция — Security 4624/4625 только LogonType 10 (RDP); при наличии журнала — также 1149 (Remote Connection Manager)." } else { - $message += "`r`n📌 Режим: сервер — Security 4624/4625, типы входа 2, 3, 10." + $message += "`r`n📌 Режим: сервер — Security 4624/4625, типы входа 2, 3, 10; при журнале RCM — также 1149 (RDS без аудита 4624)." } $ignoreEntries = @(Get-RdpMonitorIgnoreListEntries) if ($ignoreEntries.Count -gt 0) { @@ -4328,7 +4329,7 @@ function Start-LoginMonitor { if ($osKind.IsWorkstation) { Write-Log "Режим рабочей станции: Security — только LogonType 10 (RDP); при наличии журнала — событие 1149 (Remote Connection Manager)." } else { - Write-Log "Режим сервера: Security — LogonType 2, 3, 10" + Write-Log "Режим сервера: Security — LogonType 2, 3, 10; при журнале RCM — 1149 (если `$EnableRcm1149Monitoring)." } if (Test-MonitorFeatureEnabled -Value $EnableAdminShareMonitoring) { Write-Log "Admin share: Security 5140 для $($AdminShareMonitorSuffixes -join ', ') (audit File Share; workstation + server)." @@ -4395,9 +4396,15 @@ function Start-LoginMonitor { $rdGatewayAvailable = $false if ($EnableRDGatewayMonitoring) { $rdGatewayAvailable = Test-RDGatewayLog } - $rcmMonitoringEnabled = ($osKind.IsWorkstation -and (Test-RcmLogAvailable)) - if ($osKind.IsWorkstation -and -not $rcmMonitoringEnabled) { - Write-Log "Рабочая станция: журнал Remote Connection Manager недоступен — уведомления только по Security 4624/4625 (LogonType 10). Проверьте, что включён удалённый рабочий стол." + $rcmMonitoringEnabled = (Test-MonitorFeatureEnabled -Value $EnableRcm1149Monitoring) -and (Test-RcmLogAvailable) + if (Test-MonitorFeatureEnabled -Value $EnableRcm1149Monitoring) { + if ($rcmMonitoringEnabled) { + Write-Log "RCM 1149: опрос включён ($RcmLogName)." + } elseif ($osKind.IsWorkstation) { + Write-Log "Рабочая станция: журнал Remote Connection Manager недоступен — уведомления только по Security 4624/4625 (LogonType 10). Проверьте, что включён удалённый рабочий стол." + } else { + Write-Log "Сервер: журнал Remote Connection Manager недоступен — RCM 1149 отключён; только Security 4624/4625." + } } $rcmShadowMonitoringEnabled = (Test-MonitorFeatureEnabled -Value $EnableRcmShadowControlMonitoring) -and (Test-RcmLogAvailable) @@ -4697,6 +4704,13 @@ function Start-LoginMonitor { if (Should-IgnoreEvent -Username $rcmInfo.Username -ProcessName "-" ` -ComputerName "-" -EventID 1149 -LogonType 10 -SourceIP $rcmInfo.ClientIP) { continue } + $dedupKey1149 = Get-RdpLoginSuccessNotifyDedupKey -SecurityLogComputerName $event.MachineName ` + -Username $rcmInfo.Username -SourceIP $rcmInfo.ClientIP -LogonType 10 + if (-not (Test-RdpLoginSuccessNotifyDedupAllow -DedupKey $dedupKey1149)) { + Write-Log "Notify dedup 1149: User=$($rcmInfo.Username) IP=$($rcmInfo.ClientIP) (window ${LoginSuccessNotifyDedupSeconds}s)" + continue + } + $msg = Format-Rcm1149Event -Username $rcmInfo.Username -ClientIP $rcmInfo.ClientIP ` -TimeCreated $rcmInfo.TimeCreated -SecurityLogComputerName $event.MachineName Write-Log "Notify RCM 1149: User=$($rcmInfo.Username) IP=$($rcmInfo.ClientIP)" diff --git a/login_monitor.settings.example.ps1 b/login_monitor.settings.example.ps1 index 9d49b09..29151bc 100644 --- a/login_monitor.settings.example.ps1 +++ b/login_monitor.settings.example.ps1 @@ -58,6 +58,7 @@ $StartupRebootDetectMinutes = 5 $GetInventory = $true # --- RDS Shadow Control + WinRM inbound (Enter-PSSession), severity warning --- +# $EnableRcm1149Monitoring = 1 # RCM Operational 1149 (RDP auth; workstation + RDS server) # $EnableRcmShadowControlMonitoring = 1 # RCM Operational 20506/20507/20510 # $EnableWinRmInboundMonitoring = 1 # WinRM Operational 91 (+ correlate Security 4624) # $EnableAdminShareMonitoring = 1 # Security 5140 C$/ADMIN$ (audit File Share) diff --git a/version.txt b/version.txt index aead1fb..bd1caf3 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.1.3-SAC +2.1.4-SAC