[玩转系统] Windows Server DomainController 查找 LDAP 绑定
作者:精品下载站 日期:2024-12-14 07:13:12 浏览:14 分类:玩电脑
Windows Server DomainController 查找 LDAP 绑定
不久前,Microsoft 宣布更改 LDAP 和 LDAP 签名的默认域控制器行为。请参阅链接。
这会影响每个受支持的 Windows Server 版本(从 2008R2 到 2019)。还有另一个链接ADV190023有详细的解释。
我认为不应该讨论将域控制器更改为仅 LDAP 签名。但是第三方软件呢?如何找到这些软件访问您的 DC 并使用未签名的 ldap?
如果您的域控制器上没有 LDAP 的任何证书,请查看要求,这很重要。如何通过 SSL 启用 LDAP。
我建议在您环境中的每个域控制器上激活 LDAP 登录,并扩展事件日志“目录服务”,以便您可以返回过去查看大多数 LDAP 连接。
当 LDAP 连接被记录为未签名时,它看起来如何:
应用程序和服务日志 -> 目录服务 -> 事件 ID 2889
如您所见,记录了执行 ldap 绑定的 IP 地址和用户。
首先,您必须在 DC 上启用 LDAP 登录。
我将使用 gpo 在测试环境中的所有 DC 上设置注册表项,但您也可以手动设置该注册表项:
REGKEY LDAP 登录(应该已经存在,但设置为 0): HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NTDS\Diagnostics -> DWORD -> “16 LDAP Interface Events” -> 值“2”
REGKEY 扩展事件日志:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet \Services\EventLog\Directory Service -> DWORD -> “MaxSize” -> Value= “2147483648” (2GB)
您还可以使用 reg add 命令:
Reg Add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NTDS\Diagnostics /v "16 LDAP Interface Events" /t REG_DWORD /d 2
Reg Add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Directory Service" /v "MaxSize" /t REG_DWORD /d "2147483648"
添加此注册表项后,需要一些时间,以便 DC 可以记录连接并希望看到所有未签名的 ldap 连接。 (最好的情况是看不到 LDAP 连接)
如果您想尝试 ldap 和 ldaps 连接,您可以转到您的 dc 或任何其他 Windows 服务器并使用 LDP.exe 进行检查。它位于 C:\Windows\SYSTEM32\ 文件夹中。
如果您还进行了简单的绑定,则连接将记录在您的事件日志中
另请检查您是否可以使用 SSL 端口 636 连接 LDAP
完成后,您可以确保您的 DC 接受 LDAPS 并记录 LDAP 连接。现在您必须等待几天才能看到大部分 LDAP 连接(您可能看不到全部,因为如果设备不执行 LDAP 查询,则无需进行任何协议)。
现在是编写脚本的时间,因为搜索事件日志并查找事件消息中包含 IP 地址的所有事件可能非常痛苦。
请参阅以下脚本:
<#
#### requires ps-version 3.0 ####
<#
.SYNOPSIS
Analyses Eventlog from DomainControllers and searches for LDAP access
.DESCRIPTION
Creates a working directory on your specified path. After creation it copies evtx files from all Domaincontrollers via robocopy into this working directory.
Every domaincontroller eventlog creates four files (cleared and raw)
.PARAMETER WorkDir
Path where you want to have your logs and results (please check diskspace, evtx file may have some GBs)
.INPUTS
-
.OUTPUTS
YYYY-MM-DD-HH-MM-SS-NameofDC.evtx (copied but untouched)
YYYY-MM-DD-HH-MM-SS-NameofDC-LDAP-cleared.csv
YYYY-MM-DD-HH-MM-SS-NameofDC-LDAP-raw.csv
YYYY-MM-DD-HH-MM-SS-NameofDC-LDAP-time.csv
YYYY-MM-DD-HH-MM-SS-NameofDC-LDAP-time-cleared.csv
.NOTES
Version: 0.1
Author: Alexander Koehler
Creation Date: Tuesday, March 10th 2020, 11:07:01 pm
File: ad-ldap-audit-0-1.ps1
Copyright (c) 2020 blog.it-koehler.com
HISTORY:
Date By Comments
---------- --- ----------------------------------------------------------
.LINK
blog.it-koehler.com/en/Archive/2951
.COMPONENT
Required Modules: none
.LICENSE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the Software), to deal
in the Software without restriction, including without limitation the rights
to use copy, modify, merge, publish, distribute sublicense and /or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
.EXAMPLE
C:\temp\ad-ldap-audit-0-1.ps1 -WorkDir "C:\temp\ldapaudit"
#
#>
# define parameters (Working Directory) and check if it's a directory and if it does not exist, create it.
[CmdletBinding()]
Param(
[Parameter(Mandatory = $True)]
[String] $WorkDir)
if (-not (Test-Path $WorkDir -PathType Container)) {
try {
New-Item -Path $WorkDir -ItemType Directory -ErrorAction Stop | Out-Null
}
catch {
Write-Error -Message "Unable to create directory '$WorkDir'. Error was: $_" -ErrorAction Stop
}
"Successfully created directory '$WorkDir'."
}
else {
"Directory already existes"
}
#get date as string (is needed for filenames)
$date=((Get-Date).ToString('yyyy-MM-dd-HH-mm-ss'))
#getting all DCs in environment without AD PowerSehll Module
$DCs = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites | % { $_.Servers } | select Name).Name
#executing code for every domaincontroller
foreach($DC in $DCs){
#copy evtx file in working dir with robocopy
$path = "\$DC\c$\Windows\System32\winevt\Logs\"
robocopy "$path" "$workdir" "Directory Service.evtx"
Rename-Item "$workdir\Directory Service.evtx" "$date-$DC.evtx"
$evtxfile = "$workdir$date-$DC.evtx"
#define output file prefix
$csvoutputpath = "$workdir$date-$DC-LDAP"
#searching for event 2889
$Events = Get-WinEvent @{Path=$evtxfile;Id=2889}
#define array for outputs
$eventarraytime = @()
$eventarrayraw =@()
ForEach ($Event in $Events) {
# Convert the event to XML
#see https://docs.microsoft.com/de-de/archive/blogs/ashleymcglone/powershell-get-winevent-xml-madness-getting-details-from-event-logs
$eventXML = [xml]$Event.ToXml()
#getting timestamp
$time = ($Event.TimeCreated)
#getting user from eventlog
$ldapconn = ($eventXML.Event.EventData.Data)
#creating custom object and put all together
#customobject with timestamp
$eventobj = New-Object System.Object
$eventobj | Add-Member -type NoteProperty -name AccessTime -Value $time
$eventobj | Add-Member -type NoteProperty -name LDAPAccess -Value (@($ldapconn) -join " ")
#custom object witout timestamp
$eventraw = New-Object System.Object
$eventraw | Add-Member -type NoteProperty -name LDAPAccess -Value (@($ldapconn) -join " ")
#appending content to array
$eventarraytime += $eventobj
$eventarrayraw += $eventraw
}
#output data in rawformat to csv
$eventarraytime | Export-Csv -Path "$csvoutputpath-time.csv" -Encoding UTF8 -Delimiter ";" -NoTypeInformation
$eventarrayraw | Export-Csv -Path "$csvoutputpath-raw.csv" -Encoding UTF8 -Delimiter ";" -NoTypeInformation
#cleaning up double entries
$eventstimecleared = $eventarraytime | Sort-Object -Unique LDAPAccess -Descending
$eventstimecleared | Export-Csv -Path "$csvoutputpath-time-cleared.csv" -Encoding UTF8 -Delimiter ";" -NoTypeInformation
$eventarraycleared = $eventarrayraw | Sort-Object -Unique LDAPAccess -Descending
$eventarraycleared | Export-Csv -Path "$csvoutputpath-cleared.csv" -Encoding UTF8 -Delimiter ";" -NoTypeInformation
}
您可以将完整的脚本复制到 ps1 文件中,并使用其参数 -WorkDir“指定复制所有 outpout 和 evtx 文件的路径”来触发它
注意:如果 evtx 文件非常大(1-2GB),则此脚本的执行可能需要几个小时,请耐心等待!
如果您是 powershell 专业人士,您可以在此处停止阅读,但如果您想知道它是如何工作的,我会给出一些解释。
第 82 行:
$DCs = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites | % { $_.Servers } | 选择名称).Name
这是一个 .Net 函数,用于查找所有 DC 及其 FQDN,此行之后的所有代码都将为变量 $DCs 中的每个 dc 执行(ForEach 循环)
LINE93:
$Events = Get-WinEvent @{Path=$evtxfile;Id=2889}
在 evtx 文件中搜索事件 ID 2889 并将其获取到变量 $Events
此变量可用后,我们需要使用另一个 foreach 循环查看每个事件。
第 100 行:
$eventXML=[xml]$Event.ToXml()
我们需要将事件转换为 XML,以便获得可以通过 PowerShell 搜索和过滤的对象。
LINE 104:
$ldapconn = ($eventXML.Event.EventData.Data)
在这种情况下,ldap 连接的信息位于此对象中(取决于结构)
所有其他代码主要负责转换数据并为 CSV 文件创建可读内容
在我的测试环境中,手动生成的 LDAP 连接很少。
IP 和用户用分号分隔,因此在 Excel 中导入和排序应该很容易。
也可以多次运行该脚本,因为它将时间戳添加到每个文件中,不会覆盖任何内容。如果您有任何疑问,请随时与我联系,如果您喜欢这篇文章,请点击“有帮助”。
锁定您的 AD 并关闭 LDAP!
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag