MichaelGrafnetter/DSInternals

GitHub: MichaelGrafnetter/DSInternals

DSInternals 是一个用于 Active Directory 内部操作与安全审计的 PowerShell 模块和 .NET 框架,支持密码哈希转储、离线 ntds.dit 解析、DPAPI 解密及域安全评估等功能。

Stars: 1961 | Forks: 277

![DSInternals Logo](https://raw.githubusercontent.com/MichaelGrafnetter/DSInternals/master/DSInternals-Dark.png#gh-light-mode-only) ![DSInternals Logo](https://raw.githubusercontent.com/MichaelGrafnetter/DSInternals/master/DSInternals-Light.png#gh-dark-mode-only) # 目录服务内部机制
PowerShell 模块与框架 [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](../LICENSE.md) [![PowerShell 5.1 | 7](https://badgen.net/badge/icon/5.1%20|%207?icon=terminal&label=PowerShell)](#) [![Windows Server 2008 R2 | 2012 R2 | 2016 | 2019 | 2022 | 2025](https://badgen.net/badge/icon/2008%20R2%20|%202012%20R2%20|%202016%20|%202019%20|%202022%20|%202025?icon=windows&label=Windows%20Server)](#) [![.NET Framework 4.8+](https://img.shields.io/badge/Framework-4.8%2B-007FFF.svg?logo=.net)](#) [![.NET 8.0+](https://img.shields.io/badge/Runtime-8.0%2B-007FFF.svg?logo=.net)](#) [![Architecture x64 | x86 | ARM64](https://img.shields.io/badge/Architecture-x64%20|%20x86%20|%20ARM64-0071c5.svg?logo=cplusplus)](#) ## 简介 DSInternals 项目由以下两部分组成: - [DSInternals Framework](https://www.nuget.org/profiles/DSInternals) 公开了 *Active Directory* 的几项内部功能,可以从任何 .NET 应用程序中使用。该代码库已经被集成到多个第三方商业产品中,应用于 Active Directory 灾难恢复、身份管理、跨林迁移和密码强度审计等场景。 - [DSInternals PowerShell Module](https://www.powershellgallery.com/packages/DSInternals/) 提供了基于该 Framework 构建的易用 cmdlet。其主要功能如下: - [Active Directory 密码审计](../Documentation/PowerShell/Test-PasswordQuality.md#test-passwordquality),可发现使用相同密码的账户,或密码出现在 [HaveIBeenPwned](https://haveibeenpwned.com) 等公开数据库及自定义字典中的账户。 - DPAPI-NG (CNG DPAPI) [数据保护与解密](../Documentation/PowerShell/Protect-DpapiNgData.md#protect-dpapingdata)、[命名保护描述符](../Documentation/PowerShell/New-DpapiNgNamedDescriptor.md#new-dpapingnameddescriptor)管理、[受 SID 保护的 PFX 证书](../Documentation/PowerShell/Unprotect-DpapiNgPfxCertificate.md#unprotect-dpapingpfxcertificate)解密,以及通过从 KDS 根密钥派生 DPAPI-NG 组密钥来实现 [BitLocker 基于 SID 的密钥保护器离线解锁](../Documentation/PowerShell/Save-DpapiNgSidKey.md#save-dpapingsidkey)。 - [密钥凭据审计与生成](../Documentation/PowerShell/Get-ADKeyCredential.md#get-adkeycredential),包括对 NGC、FIDO2 和 STK 密钥的支持。还可以针对 [ROCA 漏洞](https://portal.msrc.microsoft.com/en-us/security-guidance/advisory/ADV190026)测试密钥。新的 NGC 密钥也可以[通过 MS-DRSR 协议注册](../Documentation/PowerShell/Add-ADReplNgcKey.md#add-adreplngckey)。 - 仅通过 IFM 备份(ntds.dit + SYSVOL)进行[域控制器的裸机恢复](../Documentation/PowerShell/New-ADDBRestoreFromMediaScript.md#new-addbrestorefrommediascript)。 - 离线 ntds.dit 文件操作,包括 [hash 转储](../Documentation/PowerShell/Get-ADDBAccount.md#get-addbaccount)、[密码重置](../Documentation/PowerShell/Set-ADDBAccountPassword.md#set-addbaccountpassword)、[组成员身份更改](../Documentation/PowerShell/Set-ADDBPrimaryGroup.md#set-addbprimarygroup)、[信任密码提取](../Documentation/PowerShell/Get-ADDBTrust.md#get-addbtrust)、[Golden gMSA 和 dMSA 攻击](../Documentation/PowerShell/Get-ADDBServiceAccount.md#get-addbserviceaccount)、[启用](../Documentation/PowerShell/Enable-ADDBAccount.md#enable-addbaccount)/[禁用](../Documentation/PowerShell/Disable-ADDBAccount.md#disable-addbaccount)账户、[LAPS 密码解密](../Documentation/PowerShell/Get-ADDBAccount.md#example-9)以及 [BitLocker 恢复密钥提取](../Documentation/PowerShell/Get-ADDBBitLockerRecoveryInformation.md#get-addbbitlockerrecoveryinformation)。 - 从 [`ntds.dit`](../Documentation/PowerShell/Get-ADDBDnsServerZone.md#get-addbdnsserverzone) 和[通过 LDAP 实时读取目录](../Documentation/PowerShell/Get-ADSIDnsServerZone.md#get-adsidnsserverzone)中读取 Active Directory 集成的 DNS 区域和资源记录,[导出为标准区域文件](../Documentation/PowerShell/Save-DnsServerResourceRecord.md#save-dnsserverresourcerecord),以及提取 [DNSSEC 密钥签名密钥 (KSK) 和区域签名密钥 (ZSK)](../Documentation/PowerShell/Export-ADDBDnsServerSigningKey.md#export-addbdnsserversigningkey)),其中私钥使用 KDS 根密钥进行解密。 - 通过目录复制服务 (DRS) 远程协议 (MS-DRSR) 进行[在线密码 hash 转储](../Documentation/PowerShell/Get-ADReplAccount.md#get-adreplaccount)。此功能通常被称为 DCSync。 - 通过安全账户管理器 (SAM) 远程协议 (MS-SAMR) 或[直接写入数据库](../Documentation/PowerShell/Set-ADDBAccountPasswordHash.md#set-addbaccountpasswordhash)来[注入域或本地账户密码 hash](../Documentation/PowerShell/Set-SamAccountPasswordHash.md#set-samaccountpasswordhash)。 - 通过本地安全机构(域策略)远程协议 (MS-LSAD / LSARPC) 修改 [LSA 策略](../Documentation/PowerShell/Set-LsaPolicyInformation.md#set-lsapolicyinformation)。 - [提取凭据漫游数据](../Documentation/PowerShell/Save-DPAPIBlob.md#save-dpapiblob)和 DPAPI 域备份密钥,可通过[目录复制](../Documentation/PowerShell/Get-ADReplBackupKey.md#get-adreplbackupkey)、[LSARPC](../Documentation/PowerShell/Get-LsaBackupKey.md#get-lsabackupkey)在线提取,也可[离线从 ntds.dit 提取](../Documentation/PowerShell/Get-ADDBBackupKey.md#get-addbbackupkey)。 - 密码 hash 计算,包括 [NT hash](../Documentation/PowerShell/ConvertTo-NTHash.md#convertto-nthash)、[LM hash](../Documentation/PowerShell/ConvertTo-LMHash.md#convertto-lmhash) 和 [kerberos 密钥](../Documentation/PowerShell/ConvertTo-KerberosKey.md#convertto-kerberoskey)。 ## 作者 ### Michael Grafnetter [![Twitter](https://img.shields.io/twitter/follow/MGrafnetter.svg?label=Twitter%20@MGrafnetter&style=social)](https://x.com/MGrafnetter) [![Blog](https://img.shields.io/badge/Blog-www.dsinternals.com-2A6496.svg)](https://www.dsinternals.com/en) [![LinkedIn](https://img.shields.io/badge/LinkedIn-grafnetter-0077B5.svg)](https://www.linkedin.com/in/grafnetter) 我在业余时间创建了这些工具,在进行 AD 安全审计时使用它们,并在我的课程中用来演示 Active Directory 的内部工作原理。 ## 下载 [![PowerShell Gallery Downloads](https://img.shields.io/powershellgallery/dt/DSInternals.svg?label=PowerShell%20Gallery%20Downloads&logo=NuGet)](https://www.powershellgallery.com/packages/DSInternals/) [![Chocolatey Downloads](https://img.shields.io/chocolatey/dt/dsinternals-psmodule.svg?label=Chocolatey%20Downloads&logo=NuGet)](https://chocolatey.org/packages/dsinternals-psmodule) [![GitHub Downloads](https://img.shields.io/github/downloads/MichaelGrafnetter/DSInternals/total.svg?label=GitHub%20Downloads&logo=GitHub)](https://github.com/MichaelGrafnetter/DSInternals/releases) [![NuGet Gallery Downloads](https://img.shields.io/nuget/dt/DSInternals.Common.svg?label=NuGet%20Gallery%20Downloads&logo=NuGet)](https://www.nuget.org/profiles/DSInternals) ### PowerShell Gallery 你可以通过运行以下命令,直接从官方 [PowerShell Gallery](https://www.powershellgallery.com/packages/DSInternals/) 安装 DSInternals 模块: ``` Install-Module DSInternals -Force ``` 在一些全新安装的计算机上,在下载 DSInternals 之前可能还需要执行一些额外的步骤: ``` # 必须在旧版本的 Windows 上启用 TLS 1.2。 [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12 # 下载 NuGet 包管理器二进制文件。 Install-PackageProvider -Name NuGet -Force # 如果由于任何原因缺少 PowerShell Gallery,请将其注册为包存储库。 if($null -eq (Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) { Register-PSRepository -Default } # 下载 DSInternals PowerShell 模块。 Install-Module -Name DSInternals -Force ``` ### Chocolatey 包 也可以通过执行以下 Chocolatey 命令,使用官方 [Chocolatey 包](https://chocolatey.org/packages/dsinternals-psmodule)来安装 DSInternals PowerShell Module: ``` choco install dsinternals-psmodule --confirm ``` 该包是独立的,并且也会安装所有依赖项。请注意,3.5 之前的包版本是非官方的。 ### WAPT 包 也可以使用 [WAPT 包](https://wapt.tranquil.it/store/en/tis-dsinternals)来安装 DSInternals PowerShell Module。 可以通过 [WAPT 控制台](https://www.wapt.fr/en/doc/wapt-console-usage.html)或 [WAPT 命令行界面](https://www.wapt.fr/en/doc/wapt-command-line-interface.html)来安装该包,如下所示: ``` wapt-get install dsinternals ``` 该包是独立的,并且也会安装所有依赖项。 ### 离线模块分发 1. 从 GitHub 下载[当前版本](https://github.com/MichaelGrafnetter/DSInternals/releases)。 2. 使用*属性对话框*或 `Unblock-File` cmdlet *解除锁定*该 ZIP 文件。如果未能执行此操作,所有解压出来的 DLL 都将继承此属性,并且 PowerShell 将拒绝加载它们。 3. 将 *DSInternals* 目录解压到你的 PowerShell 模块目录中,例如 *C:\Windows\system32\WindowsPowerShell\v1.0\Modules\DSInternals* 或 *C:\Users\John\Documents\WindowsPowerShell\Modules\DSInternals*。 4. (可选)如果你将模块复制到了与上一步建议位置不同的目录中,则必须使用 `Import-Module` cmdlet 手动导入它。 ### Commando VM DSInternals PowerShell 模块是 FireEye [Commando VM](https://github.com/fireeye/commando-vm) 的一部分,这是基于 Windows 的 Kali Linux 替代方案。 ### NuGet 包 将 DSInternals 功能集成到 .NET 应用程序中的最简单方法是使用 [DSInternals Framework NuGet 包](https://www.nuget.org/profiles/DSInternals): - [DSInternals.Common](https://www.nuget.org/packages/DSInternals.Common/) - [DSInternals.DataStore](https://www.nuget.org/packages/DSInternals.DataStore/) - [DSInternals.Replication](https://www.nuget.org/packages/DSInternals.Replication/) - [DSInternals.SAM](https://www.nuget.org/packages/DSInternals.SAM/) ### 从源代码构建 [![Visual Studio 2026](https://img.shields.io/badge/Visual%20Studio-2026-383278.svg)](CONTRIBUTING.md#building-from-source-code) [![CI Build](https://static.pigsec.cn/wp-content/uploads/repos/cas/39/39f45000ced5988832c0d6562d09ca899eb32007638fd6ccd8cae52ad6645caf.svg)](https://github.com/MichaelGrafnetter/DSInternals/actions/workflows/autobuild.yml) 你当然也可以下载[源代码](https://github.com/MichaelGrafnetter/DSInternals/archive/master.zip), 进行检查,并自行编译该模块/框架。 更多信息请参阅 [CONTRIBUTING](CONTRIBUTING.md#building-from-source-code) 指南。 ## 文档 ### Get-Help [PowerShell Get-Help 文档](../Documentation/PowerShell/Readme.md#dsinternals-powershell-module)的在线版本包含所有 cmdlet 的列表以及一些用法示例。 ### 博客文章 我还在[我的博客](https://www.dsinternals.com/en/)上发布了一系列关于 DSInternals 模块的文章。 以下是其中的几篇: - [将 ntds.dit 文件榨干到最后一滴](https://specterops.io/blog/2025/08/14/juicing-ntds-dit-files-last-drop-dsinternals-powershell-active-directory-offline-attacks/) - [DSInternals 4.11 中的新离线功能](https://www.dsinternals.com/en/dsinternals-v4.11/) - [跨林重复密码发现](https://www.dsinternals.com/en/cross-forest-duplicate-password-discovery/) - [CQLabs – 从 Active Directory 提取漫游私钥](https://cqureacademy.com/blog/extracting-roamed-private-keys) - [CQLabs – 对 Active Directory 的离线攻击](https://cqureacademy.com/cqure-labs/cqlabs-dsinternals-powershell-module) - [审计 Active Directory 密码质量](https://www.dsinternals.com/en/auditing-active-directory-password-quality/) - [转储 ntds.dit 文件](https://www.dsinternals.com/en/dumping-ntds-dit-files-using-powershell/) - [远程获取 Active Directory 密码](https://www.dsinternals.com/en/retrieving-active-directory-passwords-remotely/) - [从 Active Directory 获取 DPAPI 备份密钥](https://www.dsinternals.com/en/retrieving-dpapi-backup-keys-from-active-directory/) - [从 Active Directory 获取明文 GMSA 密码](https://www.dsinternals.com/en/retrieving-cleartext-gmsa-passwords-from-active-directory/) - [探查 Active Directory 数据库](https://www.dsinternals.com/en/peeking-into-the-active-directory-database/) - [使用可启动闪存驱动器转储和修改 Active Directory 数据库](https://www.dsinternals.com/en/dumping-modifying-active-directory-database-bootable-flash-drive/) - [使用 Mimikatz 模拟 Office 365 用户](https://www.dsinternals.com/en/impersonating-office-365-users-mimikatz/) ### 幻灯片 - [Black Hat Europe 2019:DSInternals PowerShell 模块](https://www.dsinternals.com/wp-content/uploads/eu-19-Grafnetter-DSInternals-PowerShell-Module.pdf) - [Black Hat Europe 2019:利用 Windows Hello for Business](https://www.dsinternals.com/wp-content/uploads/eu-19-Grafnetter-Exploiting-Windows-Hello-for-Business.pdf) - [HipConf New York 2018:对 Active Directory 的离线攻击](https://www.dsinternals.com/wp-content/uploads/HIP_AD_Offline_Attacks.pdf) ## 致谢 本项目使用了以下第三方版权材料: - [ManagedEsent](https://github.com/Microsoft/ManagedEsent) - 提供对 esent.dll 的托管访问,这是 Windows 原生的可嵌入数据库引擎。 - [PBKDF2.NET](https://github.com/therealmagicmike/PBKDF2.NET) - 为 .NET Framework 提供 PBKDF2。 - [Bouncy Castle](https://www.bouncycastle.org/csharp/index.html) - 用于 Java 和 C# 的轻量级密码学 API。 ## 相关项目 - [Mimikatz](https://github.com/gentilkiwi/mimikatz) - 排名第一的哈希传递攻击工具。可以使用 DSInternals 模块提取的凭据来执行一些危险的破坏性操作。 - [NTDSXtract](https://github.com/csababarta/ntdsxtract) - 一个使用 Python 编写的 ntds.dit 解析框架。 - [Impacket](https://github.com/SecureAuthCorp/impacket) - 使用 Python 实现的各种基于 MSRPC 的协议。 - [DIT Explorer](https://github.com/trustedsec/DitExplorer) - 一个用于 Active Directory 数据库的图形化检查工具。
标签:Active Directory, AI合规, IPv6, Plaso, PowerShell, Terraform 安全, 密码审计, 目录服务, 运维工具