AdPentestAI-Python
Active Directory penetration testing framework with automatic Domain Controller detection.
Examples
See examples/sample-dry-run-output.json for a sample of the JSON output produced by:
python -m adpentest --target corp.local --mode dry-run --scope-confirmed
Contributing
Contributions are welcome! See CONTRIBUTING.md for setup instructions and CODE_OF_CONDUCT.md for community guidelines. Check the open issues for tasks labeled good-first-issue or help-wanted.
Features
- Auto DC Detection — discovers Domain Controllers via DNS SRV records, LDAP RootDSE probes, and port fingerprinting
- Subnet expansion — scans /24 first, widens to /23 if no DC found
- Domain auto-discovery — extracts domain name from LDAP RootDSE defaultNamingContext
- DC FQDN resolution — multi-source FQDN lookup with live LDAP probe fallback, forward DNS verification
- DC-aware tool execution — passes discovered domain, DC IP, and FQDN to tools
- 29 AD/SMB/Kerberos/ADCS/Email tools — 12 cross-platform binaries + 3 Windows-native PowerShell + 3 Kerberos attack + 4 ADCS certificate attacks + 5 Email protocol enumeration
- SMB pentesting — null session detection, share enumeration, SMB signing detection, credential testing
- Windows-native tools — built-in PowerShell enumeration for LDAP, SMB, and AD forest discovery (no external dependencies on Windows)
- Cross-platform — runs on Linux, macOS, and Windows with platform-specific optimizations
- Auto-install — missing tools installed automatically via apt/pip/git (or native on Windows)
- Safety —
dry-runis the default;--scope-confirmedrequired for authorization
DC Detection Strategies
- DNS SRV — queries
_ldap._tcp.dc._msdcs.<domain>,_kerberos._tcp.dc._msdcs.<domain>, etc. - LDAP RootDSE — anonymous bind to extract domain, forest level, hostname
- Port fingerprint — checks Kerberos (88), LDAP (389/636), Global Catalog (3268/3269)
- Subnet sweep — Kerberos port 88 quick-scan on /24, expands to /23, then /22 if no DCs found
SMB Pentesting Capabilities
- Null session detection — checks if targets allow anonymous SMB access (IPC$)
- Share enumeration — discovers available SMB shares via CrackMapExec and smbmap
- SMB signing detection — identifies if SMB message signing is enforced (via nmap scripts)
- Credential testing — attempts connection with guest/empty credentials via impacket tools
- Secretsdump — extracts NTLM hashes and session keys when null credentials work
- PsExec simulation — tests command execution capability via impacket psexec
Kerberos/Kerberoasting Attack Vectors
- GetUserSPNs — enumerates service principal names (SPN) via LDAP (custom implementation, no impacket needed)
- AS-REP Roasting — targets accounts with DONT_REQUIRE_PREAUTH flag for offline cracking
- Kerberoasting — extracts and cracks service account tickets via TGS-REQ requests
- Requires: null/guest credentials or valid domain account (LDAP access for SPN enumeration)
- Output formats: .txt files compatible with Hashcat/John for cracking
- Implementation: Pure Python LDAP-based tools (ldap3, no external binaries)
ADCS Certificate Attack Vectors
- Shadow Credentials — exploits ADCS to inject shadow credentials for account takeover via certificate-based authentication
- ESC1 — template misconfiguration allowing client authentication without enrollment agent
- ESC3 — enrollment agent misconfig enabling privilege escalation via certificate requests
- ESC9 — object control abuse via ADCS certificate manipulation
- Tools: Certipy-AD automated enumeration and exploitation
- Attack chain: certificate enumeration → template analysis → credential extraction → privilege escalation
Windows-Native Tools
PowerShell enumeration (built-in, no external dependencies on Windows):
- powershell_ldap_enum — LDAP RootDSE queries via .NET DirectoryServices
- powershell_smb_enum — SMB share enumeration via Get-SmbShare
- powershell_ad_recon — Forest/domain/DC discovery via AD API
Python-based Enumeration Engines:
-
enum_windows_py — Pure Python enum4linux-ng replacement (LDAP + SMB + policy enumeration)
- Null session detection and exploitation
- Domain policy extraction (password complexity, lockout settings)
- SMB share discovery via impacket
- Works on Windows, Linux, macOS
- Uses ldap3 + impacket (already required dependencies)
-
SPNEnumerator — Custom LDAP-based Service Principal Name enumeration
- Direct LDAP queries to extract SPNs without impacket.examples.GetUserSPNs
- Anonymous LDAP bind capability
- Hashcat/John compatible output format
- Pure Python implementation (ldap3 only)
Cross-platform Tools:
- 12 binary tools (nmap, masscan, crackmapexec, smbmap, bloodhound, etc.)
- All tools auto-install via apt/pip/git based on platform
Email Protocol Enumeration & Credential Testing
Pure Python email enumeration (no external dependencies):
-
SMTP User Enumeration — Discover valid email addresses via:
- SMTP VRFY command (traditional user discovery)
- SMTP RCPT TO validation (validate recipient addresses)
- Service banner detection (Exchange/Postfix/Sendmail identification)
- Ports: 25 (plain), 465 (SMTPS), 587 (SMTP TLS)
-
Credential Testing with Protocol Fallback — Automatic fallback chain:
- Primary: SMTP AUTH (ports 25, 465, 587)
- Fallback: POP3 AUTH (ports 110, 995)
- Fallback: IMAP AUTH (ports 143, 993)
- Tests multiple credentials until success or all protocols exhausted
- Supports TLS/SSL connections for secure ports
-
Email Service Detection — Identify email infrastructure:
- Exchange on-premises (2016, 2019, 2021)
- Office 365 cloud detection (outlook.office365.com routing)
- Server banner parsing and version detection
- Concurrent port scanning for email services
-
Implementation: Pure Python using standard library (smtplib, poplib, imaplib)
- No external tool dependencies
- Cross-platform (Windows, Linux, macOS)
- Works on any Python 3.10+ environment
Output Format:
- Valid users discovered via SMTP enumeration
- Working credentials (username, password, protocol, server, port)
- Email service type and version
- Protocol availability (which protocols respond on target)
- Comprehensive failure logging for debugging
Run
# Dry-run (check tools, detect DCs, preview commands)
python -m adpentest --target 10.0.0.1 --mode dry-run --scope-confirmed
# Active scan with auto DC detection
python -m adpentest --target corp.local --mode active --scope-confirmed
# With custom timeout, no auto-install
python -m adpentest --target 192.168.1.10 --mode active --scope-confirmed --timeout 600 --no-auto-install
# With custom DNS servers (fallback to public DNS on failure)
python -m adpentest --target 192.168.1.10 --mode active --scope-confirmed --dns-server 1.1.1.1,1.0.0.1
# With custom DNS timeout (in seconds)
python -m adpentest --target 192.168.1.10 --mode active --scope-confirmed --dns-timeout 5.0
DNS Configuration
The framework supports flexible DNS resolver configuration with automatic fallback:
CLI Arguments
--dns-server <servers>— Comma-separated list of custom DNS servers (e.g.,8.8.8.8,8.8.4.4)--dns-timeout <seconds>— DNS query timeout in seconds (default: 3.0)
Environment Variables
DNS_SERVERS— Comma-separated DNS servers (e.g.,export DNS_SERVERS=8.8.8.8,8.8.4.4)DNS_TIMEOUT— DNS query timeout in seconds (e.g.,export DNS_TIMEOUT=5.0)
Priority Order
- CLI Arguments (
--dns-server,--dns-timeout) — Highest priority - Environment Variables (
DNS_SERVERS,DNS_TIMEOUT) - System Default DNS — Automatically detected from system configuration
- Public DNS Fallback — Automatically uses
8.8.8.8,8.8.4.4,1.1.1.1,1.0.0.1if others fail
Examples
# Use custom DNS servers from CLI
python -m adpentest --target corp.local --mode active --scope-confirmed --dns-server 192.168.1.1,8.8.8.8
# Use environment variables for DNS
export DNS_SERVERS=192.168.1.1,1.1.1.1
export DNS_TIMEOUT=5.0
python -m adpentest --target corp.local --mode active --scope-confirmed
# Combine CLI with custom timeout
python -m adpentest --target corp.local --mode active --scope-confirmed --dns-server 8.8.8.8 --dns-timeout 10.0
Resolver Behavior
- System DNS is queried first by default
- Automatic fallback to public DNS (Cloudflare, Google) on timeout or resolution failure
- Detailed logging shows which resolver is used and why (system, environment, CLI, or fallback)
- All DNS functions (SRV records, PTR lookups, forward resolution) use centralized configuration
Requirements
- Python 3.10+
dnspython,ldap3,httpx
This project does not authorize testing by itself. Operators must supply an explicitly authorized scope.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adpentest-1.1.1.2.tar.gz.
File metadata
- Download URL: adpentest-1.1.1.2.tar.gz
- Upload date:
- Size: 73.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13c573d94888dc07a12fa6cce66f30659994ce0969c504c1e6fffedc1366f86d
|
|
| MD5 |
673f8979f224cc6da04c397430e701d0
|
|
| BLAKE2b-256 |
b29299ab9f36a89befbae7a2edbd383cb0a64a7efa360379e58a0eab55698fde
|
File details
Details for the file adpentest-1.1.1.2-py3-none-any.whl.
File metadata
- Download URL: adpentest-1.1.1.2-py3-none-any.whl
- Upload date:
- Size: 70.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0d91cadd5b000c62fe206ade6830e484742a3946ad1025a5818d594f5ea2704
|
|
| MD5 |
fed3cb49cd3289b003e7700a7d8be890
|
|
| BLAKE2b-256 |
22e99a12bbd498bfc9718d9170b6cdeb05a56ec164bc5a9d124e47d84467d39c
|