当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 审核 Active Directory 中的弱密码

作者:精品下载站 日期:2024-12-14 22:55:56 浏览:12 分类:玩电脑

审核 Active Directory 中的弱密码


Active Directory 域中用户密码的复杂性是用户数据和整个域基础设施的关键安全要素之一。尽管建议不要使用个人信息、字典单词和简单组合作为密码,但许多用户更喜欢使用简单且易于记住的密码。在本文中,我们将向您展示如何使用 PowerShell 审核 Active Directory 用户密码、查找弱密码和简单密码。

即使使用复杂的域密码策略,用户也可以在技术上设置弱密码或默认密码,例如

Pa$$w0rd

或者

P@ssw0rd

如何安装 DSInternals(目录服务内部)PowerShell 模块?

为了将 Active Directory 数据库(ntds.dit 文件)中存储的用户密码哈希值与简单和常见密码的字典进行比较,您可以使用第三方 PowerShell 模块 - DSInternals。该模块包含许多 cmdlet,允许在在线或离线模式下(直接使用 ntds.dit)对 AD 数据库执行不同的操作。我们特别对 Test-PasswordQuality cmdlet 感兴趣,它允许检测具有弱密码、相似密码、标准密码、空白密码(不需要密码)或其密码永不过期的用户。

注意。 自然,用户密码无法从AD数据库中以明文形式获取。存储在 Active Directory 中的密码经过哈希处理。但是,您可以将 AD 用户的密码哈希值与字典文件中的单词哈希值进行比较,并找到弱密码。

在 PowerShell 版本 5(及更高版本)中,您可以从官方 PowerShell 脚本库在线安装 DSInternals 模块,如下所示:

Install-Module DSInternals

在早期的 PowerShell 版本或断开连接的环境中,您必须从 GitHub (https://github.com/MichaelGrafnetter/DSInternals/releases) 下载包含最新模块版本的 .zip 存档。在撰写本文时,最新版本是 DSInternals v4.4.1。 将此存档解压到包含 PowerShell 模块的目录之一:

  • C:\Windows\system32\WindowsPowerShell 1.0\Modules\DSInternals

  • C:\Users\%用户名%\Documents\WindowsPowerShell\Modules\DSInternals

或者使用以下命令将 DSInternals 模块导入到当前的 PowerShell 会话中:

Import-Module C:\distr\PS\DSInternals\DSInternals.psd1

如果出现错误“

cannot be loaded because running scripts is disabled on this system

导入模块时出现”,需要更改当前PowerShell执行策略,并允许外部PS脚本至少在当前会话中运行:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force

可用模块 cmdlet 的列表可以通过以下方式获取:

Get-Command -Module DSInternals

[玩转系统] 审核 Active Directory 中的弱密码

使用 Test-PasswordQuality Cmdlet 查找弱 Active Directory 密码

接下来,您需要创建密码字典。它将是一个简单的文本文件,其中包含常用密码、弱密码和其他不良密码的列表。您可以从 Internet 下载密码字典文件或自行创建。 DSInternal 模块允许您将 Active Directory 中用户密码的哈希值与该文件中单词的哈希值进行比较。将密码保存到文本文件 PasswordDict.txt

[玩转系统] 审核 Active Directory 中的弱密码

现在创建一个小型 PowerShell 脚本。在以下变量中,指定密码文件的路径、域名和域控制器名称:

$DictFile = "C:\distr\PS\DSInternals\PasswordDict.txt"
$DC = "lon-dc01"
$Domain = "DC=a-d,DC=loc"

然后使用 Get-ADReplAccount cmdlet 获取 AD 中的用户列表(如 Get-ADUser)。此外,此 cmdlet 返回其 NT 和 LM 哈希值以及哈希历史记录。然后,对于每个用户,将密码的哈希值与字典文件中的哈希值进行比较(也会对禁用的用户帐户执行检查):

Get-ADReplAccount -All -Server $DC -NamingContext $Domain | Test-PasswordQuality -WeakPasswordsFile $DictFile -IncludeDisabledAccounts

运行脚本的结果可能如下所示:

Active Directory Password Quality Report
----------------------------------------
Passwords of these accounts are stored using reversible encryption:
LM hashes of passwords of these accounts are present:
These accounts have no password set:
TEST\DefaultAccount
TEST\Guest
Passwords of these accounts have been found in the dictionary:
TEST\a.adams
TEST\jbrion
TEST\jsanti
These groups of accounts have the same passwords:
Group 1:
TEST\a.novak
TEST\Administrator
TEST\amuller
TEST\k.brown
Group 2:
TEST\a.adams
TEST\jbrion
TEST\jsanti
These computer accounts have default passwords:
Kerberos AES keys are missing from these accounts:
Kerberos pre-authentication is not required for these accounts:
Only DES encryption is allowed to be used with these accounts:
These administrative accounts are allowed to be delegated to a service:
TEST\a.adams
TEST\a.novak
TEST\Administrator
TEST\jbrion
TEST\jsanti
TEST\k.brown
TEST\krbtgt
Passwords of these accounts will never expire:
TEST\a.adams
TEST\Administrator
TEST\DefaultAccount
TEST\Guest
TEST\k.brown
TEST\krbtgt
TEST\web
These accounts are not required to have a password:
TEST\ADFS1$
TEST\DefaultAccount
TEST\Guest
These accounts that require smart card authentication have a password:

[玩转系统] 审核 Active Directory 中的弱密码

在 DSInternal 模块的早期版本中,

ShowPlainText

如果在字典中找到了用户密码的哈希值,则参数可用于以明文形式显示用户密码。当前版本的 Test-PasswordQuality 中缺少它。如果您想使用旧版本的 DSInternals 模块,请使用以下命令安装它:

Install-Module -Name DSInternals -RequiredVersion 2.23

执行哈希搜索,包括存储在 AD 中的用户密码历史记录。可以看到,密码简单的AD用户被成功找到(密码与字典匹配)。还发现了多个具有相同密码的用户。此脚本将帮助您查找具有简单密码且受自定义细粒度密码策略约束的帐户。

对于密码较弱的用户,您可以生成强随机密码并通过 PowerShell 在 AD 中强制更改密码。

您还可以对 Active Directory 数据库文件 (ntds.dit) 执行脱机扫描。您可以从卷影副本或域控制器备份中获取 ntds.dit 文件的副本。

要离线检查 ntds.dit 文件中的用户哈希值,请使用以下命令:

$keyboot= Get-BootKey -SystemHiveFilePath 'C:\ADBackup\registry\SYSTEM'
Get-ADDBAccount -All -DatabasePath 'C:\ADBackup\ntds.dit -BootKey $keyboot | Test-PasswordQuality -WeakPasswordsFile $DictFile

您还可以将所有哈希值列表导出到文本文件:

Get-ADDBAccount -All -DBPath 'C:\ADBackup\ntds.dit' -Bootkey $keyboot | Format-Custom -View HashcatNT | Out-File c:\ps\ad_hashes.txt -Encoding ASCII

没有内置工具可以设置 Active Directory 域服务的错误密码列表。但是,借助 Azure AD 密码保护,即使在本地 Active Directory 中,您也可以阻止某些密码(黑名单)。

因此,使用此场景您可以轻松分析AD用户密码的质量、其对暴力攻击的抵抗力、得出当前域密码策略的复杂性并做出必要的结论。 Active Directory 管理员可以(并且应该)定期执行此审核。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯