用户被 DC 锁定,由管理员自动解锁

用户被 DC 锁定,由管理员自动解锁



我正在研究一个典型的 Windows 架构,其中包含 DC、Exchange 服务器等...
最近我设置了一个脚本,用于在用户被锁定时接收通知。它运行完美,但我注意到一些非常奇怪的事情。

我报告了一些信息,例如用户被锁定的机器、负责该操作的 DC 等...(我可以在 DC 上的日志中获取所有这些信息。ID 4740 表示锁定,4767 表示解锁)。
问题是,一些用户经常(每天大约 1 或 2 次)被锁定在域控制器上(例如,如果他在此 DC 上多次输入密码失败)。当然,用户无法访问 DC,所以这是第一件奇怪的事情。更奇怪的是,大约 1 秒钟后,这些用户会被管理员自动解锁。

你知道是什么原因造成的吗?我很确定这不是恶意的。

请注意:

  • 用户不可能访问 DC(或者我有一个非常优秀的黑客隐藏在他们之中,我不知道他如何能够做到这一点 ^^)
  • 被锁定的用户永远不会是同一个人,似乎是随机的
  • 锁定和解锁之间的延迟非常短(略少于 1 秒),以至于人工需要在帐户锁定后立即准备解锁帐户,因此必须自动完成
  • 被锁定的用户将一直处于锁定状态,这是理所应当的。只有当锁定事件由 DC 完成时,才会自动解锁。
  • 脚本调用/执行过程中绝不会以任何方式使用或引用管理员账户

谢谢你的时间 ! :)


这是脚本的代码(但我认为它没有任何用处)

#Get security user lockout events.  61 seconds should be sufficient, as the scheduled task run every minute.
#It leaves 1 sec for execution time.
#EventID 4740 is user lockout. 4767 is unlock.

$startTime = (get-date).addseconds(-61)

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$DomainControllers = (Get-ADDomainController -Filter *)

foreach ($DC in $DomainControllers) {

    $eventList = Get-WinEvent -ComputerName $DC.Name -filterhashtable @{logname="security";starttime=$startTime;id="4740"} -ErrorAction SilentlyContinue
    $emailBody = $null

    if ($eventList) {

        #Start a walk through the events to collect data.

        $eventList | foreach-object {
            [string]$lockoutTime = $_.timecreated
            $userName = $_.Properties[0].Value
            $user = Get-ADUser -Identity $userName -Properties *
            $name = $user.Name
            $department = $user.Department
            $site = $user.City
            $mail = $user.PrimarySmtpAddress
            $userSID = $_.Properties[2].Value
            $computerName = $_.Properties[1].Value -creplace '^\\+',''
            $IPAddress = [System.Net.Dns]::GetHostAddresses($computerName).IPAddressToString

            #Compile the alert text from each event

            $emailBody += "Utilisateur : $name`nDepartment : $department`nSite : $site`nLogin : $userName`nEmail : $mail`nOrdinateur fautif : $computerName`nAdresses IP : $IPAddress`nDate de verrouillage : $lockoutTime`nDC responsable du verrouillage : $($DC.Name)`nSID de l'utilisateur : $userSID"

            #Send mail to report the lockout
            Send-MailMessage -To "<####>" -From "<####>" -Subject "Blocage compte AD" -Body $emailBody -SmtpServer "####"


            #Create a popup on desktop
            $objForm = New-Object System.Windows.Forms.Form 
            $objForm.Text = "Unlocked AD accounts"
            $objForm.Size = New-Object System.Drawing.Size(300,115) 
            $objForm.StartPosition = "CenterScreen"

            $objLabel = New-Object System.Windows.Forms.Label
            $objLabel.Size = New-Object System.Drawing.Size(280,20)
            $objLabel.Location = New-Object System.Drawing.Size(10,15) 
            $objLabel.Text = "Compte de $name verrouillé."
            $objForm.Controls.Add($objLabel)

            $OKButton = New-Object System.Windows.Forms.Button
            $OKButton.Location = New-Object System.Drawing.Size(160,50)
            $OKButton.Size = New-Object System.Drawing.Size(85,23)
            $OKButton.Text = "Tant pis"
            $OKButton.Add_Click({$objForm.Close()})
            $objForm.Controls.Add($OKButton)

            $UnlockButton = New-Object System.Windows.Forms.Button
            $UnlockButton.Location = New-Object System.Drawing.Size(60,50)
            $UnlockButton.Size = New-Object System.Drawing.Size(85,23)
            $UnlockButton.Text = "Déverrouiller"
            $UnlockButton.Add_Click({Unlock-ADAccount $userName; $objForm.Close()})
            $objForm.Controls.Add($UnlockButton)
            if ((Get-ADUser $userName -Properties Lockedout).Lockedout) {
                [void] $objForm.ShowDialog()
            }
        }
    }
}

答案1

万一 11 个月后您仍在寻找答案,通常“呼叫者计算机名称”是域控制器的原因是该特定 DC 是报告锁定的 DC。

DC1 有事件 4740,表示 DC2 报告用户帐户已被锁定。

如果您转到 DC2 并查找相同的 4740 事件,您将看到“呼叫者计算机名称”现在显示的是用户被锁定的实际计算机。

我曾遇到过来自我现场 Exchange 服务器的事件,这让我感到很困惑,就像您遇到的一样,直到我登录到 Exchange 服务器并查找相同的锁定事件并看到它们来自何处。

自动解锁可能是 DC2 在默认的 30 分钟锁定延迟后解锁帐户,并将其报告给 DC1。

答案2

它可能就像一个服务帐户,因为在大多数默认策略中,如果服务帐户被锁定,它会自动解锁。我在我的环境中也观察到了同样的情况。希望这对您有所帮助,如果您有任何意见/建议,请随时分享

相关内容