CroweCybersecurity/ad-ldap-enum

GitHub: CroweCybersecurity/ad-ldap-enum

基于 LDAP 的 Active Directory 枚举工具,通过多种认证方式快速收集域用户、计算机和组成员资格信息。

Stars: 308 | Forks: 66

# ad-ldap-enum ad-ldap-enum 是一个 Python 脚本,旨在从 Active Directory 收集用户/计算机及其组成员资格。在大型 Active Directory 环境中,像 NBTEnum 这样的工具速度不够快。通过向域控制器执行 LDAP 查询,ad-ldap-enum 能够定位特定的 Active Directory 属性并快速构建组成员资格。 ## 输出文件 - `Domain_Group_Membership.csv` - `Extended_Domain_User_Information.csv` - `Extended_Domain_Computer_Information.csv` - 可选:使用 `-x/--excel` 时生成单个 Excel 工作簿 ## 系统要求 该工具已在 Windows 和 Linux 上使用 Python 3.10+ 构建并测试。它使用 [msldap](https://github.com/skelsec/msldap) Python 包进行 LDAP 连接和查询。要安装依赖项,请运行: ``` python -m pip install -r requirements.txt ``` ## 用法 ``` usage: ad-ldap-enum.py [-h] (-n | -u USERNAME | -dn DISTINGUISHED_NAME) [-k] [-p PASSWORD] [-P] [--ccache CCACHE_FILE] [--kirbi KIRBI_FILE] [--method {ldap,ldaps}] [--channel-binding {none,tls-server-end-point,tls-unique}] [-t TIMEOUT] [-ql QUERY_LIMIT] [--debug] [--legacy] [-x] [-o FILENAME_PREPEND] [--delay DELAY] [--jitter JITTER] [--page-size PAGE_SIZE] -l LDAP_SERVER [--port PORT] -d DOMAIN [-a ALT_DOMAIN] [-e] [-4] [-6] Active Directory LDAP Enumerator optional arguments: -h, --help show this help message and exit -n, --null Use anonymous/null authentication -u USERNAME, --username USERNAME Username for authentication -dn DISTINGUISHED_NAME, --distinguished_name DISTINGUISHED_NAME Distinguished name for simple bind authentication -k, --kerberos Use Kerberos authentication -p PASSWORD, --password PASSWORD Password, "LM:NT" hash, AES-128 key (32 hex), or AES-256 key (64 hex) -P, --prompt Prompt for password --ccache CCACHE_FILE Path to Kerberos credential cache file (.ccache) --kirbi KIRBI_FILE Path to Kerberos ticket file (.kirbi) --method {ldap,ldaps} Connection method: ldap (port 389) or ldaps (port 636) --channel-binding {none,tls-server-end-point,tls-unique} Channel binding for secure connections (default: tls-server-end-point) -t TIMEOUT, --timeout TIMEOUT Connection timeout in seconds (default: 10) -ql QUERY_LIMIT, --query_limit QUERY_LIMIT Query timeout in seconds (default: 30) --debug Enable debug logging (shows detailed msldap internal operations) --legacy Use legacy TSV format (fewer attributes) -x, --excel Output Excel file with all worksheets -o FILENAME_PREPEND, --prepend FILENAME_PREPEND Prepend string to output filenames (default: ad-ldap-enum_) OPSEC Parameters: --delay DELAY Delay in seconds between LDAP queries (default: 0.0) --jitter JITTER Random jitter percentage for delays (0.0-1.0, e.g., 0.3 = ±30%) --page-size PAGE_SIZE LDAP page size (default: 1000) Server Parameters: -l LDAP_SERVER, --server LDAP_SERVER LDAP server FQDN or IP address --port PORT Custom TCP port -d DOMAIN, --domain DOMAIN Domain name (also used as Base DN) -a ALT_DOMAIN, --alt-domain ALT_DOMAIN Alternative Base DN for LDAP searches -e, --nested Expand nested groups -4, --inet Use IPv4 only -6, --inet6 Use IPv6 only ``` 快速示例: ``` # 带内联密码的 NTLM python ad-ldap-enum.py domain.tld/username:Password123!@dc.domain.tld # 带密码提示的 NTLM(省略密码,不使用 -no-pass) python ad-ldap-enum.py domain.tld/username@dc.domain.tld -p 'Password123!' # 带密码的 Kerberos python ad-ldap-enum.py domain.tld/username:Password123!@dc.domain.tld -k # 带 NT 哈希的 Kerberos (LM:NT) python ad-ldap-enum.py domain.tld/username@dc.domain.tld -k -hashes aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0 # LDAPS + 通道绑定 python ad-ldap-enum.py domain.tld/username:Password123!@dc.domain.tld --method ldaps --channel-binding tls-server-end-point ``` ## 版本历史 ### v3.0 - msldap - **新认证方法**:在现有 NTLM 基础上增加了完整的 Kerberos 支持 - **AES 密钥支持**:支持用于 Kerberos 认证的 AES-128(32 位十六进制)和 AES-256(64 位十六进制)密钥 - **高级 Kerberos**:通过 `-k`、`-hashes` 和 `-aesKey` 支持密码、NT 哈希、AES-128 和 AES-256 密钥认证 - **Windows 缓存凭据**:支持 Kerberos 凭据缓存(通过 KRB5CCNAME,如果可用) - **安全标识符 (SID) 支持**:自动检索并显示用户和计算机的 SID - **增强的计算机属性**:增加了计算机的 lastLogon 和 pwdLastSet 时间戳支持 - **OPSEC 功能**:用于隐蔽操作的网络级操作安全控制 - **时间控制**:`--delay` 参数用于在 LDAP 查询之间引入暂停 - **随机化**:`--jitter` 参数用于为时间模式增加随机性 - **查询优化**:`--page-size` 参数用于控制 LDAP 结果批处理 - **简化界面**:用于凭据和可选 DC 主机的 Impacket 风格 TARGET 格式 - **增强安全性**:Kerberos 的 FQDN 验证,防止 SPN 解析问题 - **通道绑定**:增强加密连接的安全性 (RFC 5929) - **统一界面**:专用的认证标志,用于密码、LM:NT 哈希和 AES 密钥 - **提高可靠性**:更好的错误处理和 Windows asyncio 兼容性 - **库迁移**:从 [ldap3](https://github.com/cannatag/ldap3) 迁移到 [msldap](https://github.com/skelsec/msldap) 以增强功能 ### v2.X - ldap3 - 迁移到 [ldap3](https://github.com/cannatag/ldap3) - 增加了 argcomplete - 增加了 IPv6 支持 - 扩展了 LDAP 属性 - 增加了 CSV 和 XLSX 输出 - 增加了 PtH 和 DN 认证 ### v1.X - Python-LDAP - 初始提交 - 基本 NTLM 认证和匿名连接 - 使用了 [python-ldap](https://github.com/python-ldap/python-ldap) ## 参考链接 ### Active Directory 资源 - [All Active Directory Attributes](https://learn.microsoft.com/en-us/windows/win32/adschema/attributes-all) - [Membership Ranges in Active Directory](https://msdn.microsoft.com/en-us/library/Aa367017) - [Active Directory Paging](https://technet.microsoft.com/en-us/library/Cc755809(v=WS.10).aspx#w2k3tr_adsrh_how_lhjt) - [Kerberos Authentication Overview](https://docs.microsoft.com/en-us/windows-server/security/kerberos/kerberos-authentication-overview) ### 安全与协议参考 - [RFC 5929 - Channel Bindings for TLS](https://tools.ietf.org/html/rfc5929) - [LDAP over SSL/TLS (LDAPS)](https://tools.ietf.org/html/rfc4513) - [Pass-the-Hash Attack Mitigation](https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/network-security-restrict-ntlm-outgoing-ntlm-traffic-to-remote-servers) ### 库与依赖项 - [msldap - Modern LDAP client library](https://github.com/skelsec/msldap) - [asyauth - Asynchronous authentication library](https://github.com/skelsec/asyauth) ### 类似项目 - [LDAPDomainDumper](https://github.com/dirkjanm/ldapdomaindump) - [ADRecon](https://github.com/adrecon/ADRecon) - [ADSearch](https://github.com/tomcarver16/ADSearch) - [BloodHound](https://github.com/BloodHoundAD/BloodHound) - [ldeep](https://github.com/franc-pentest/ldeep)
标签:Active Directory, Checkov, Conpot, HTTP, Kerberos认证, LDAP, msldap, Plaso, Python, Windows安全, 代码示例, 域渗透, 数据分析, 数据展示, 无后门, 权限分析, 用户枚举, 电子数据取证, 目录服务, 红队, 组枚举, 脚本工具, 逆向工具