SMB Remote Code Execution – psexec smbexec wmiexec
With valid credentials or hashes and local admin access on the target, several Impacket tools give you remote code execution over SMB. Each uses a different mechanism with different stealth and reliability trade-offs. Pick based on what is available and how much noise you can afford.
For Pass-the-Hash specifics see https://hackindex.io/services/smb/exploitation/pass-the-hash. The commands here apply equally to plaintext passwords and hashes.
impacket-psexec
psexec uploads a renamed binary to ADMIN$, creates a service to execute it, and drops you into a SYSTEM shell. It is the most reliable but the noisiest — it writes to disk and creates a service entry.
With a hash:
[*] Requesting shares on 10.10.10.10..... [*] Found writable share ADMIN$ [*] Uploading file XkTqbCpL.exe [*] Opening SVCManager on 10.10.10.10..... [*] Creating service zqJX on 10.10.10.10..... [*] Starting service zqJX..... Microsoft Windows [Version 10.0.17763.2114] (c) 2018 Microsoft Corporation. All rights reserved. C:\Windows\system32>whoami nt authority\system
Requires ADMIN$ share access and the ability to create services.
impacket-smbexec
smbexec executes commands by creating a temporary service that runs each command via cmd.exe /Q /c and redirects output to a share. No binary is uploaded to disk. Slower than psexec but leaves less on the filesystem.
With a hash:
Runs as SYSTEM. Each command creates and deletes a service — this is still visible in Windows event logs.
impacket-wmiexec
wmiexec uses WMI over a DCOM/RPC connection tunnelled through SMB named pipes. No service is created. Output is written to a temporary file on a share and read back. The most operationally quiet of the three.
With a hash:
Runs as the authenticated user, not SYSTEM. If you need SYSTEM use psexec or smbexec.
Execute a single command without opening an interactive shell:
impacket-atexec
atexec schedules a task via the Task Scheduler service over SMB, executes a single command, and retrieves output. Useful when psexec and wmiexec are blocked but the scheduler is accessible.
With a hash:
Output is returned as a string, not an interactive shell. Use it for one-shot commands — drop a payload or add a user, then connect back via another method.
nxc for Bulk Execution
nxc wraps wmiexec-style execution for running commands across multiple hosts:
PowerShell execution with -X:
Getting a Reverse Shell
From any of the interactive shells above, drop a reverse shell. Start a listener first:
From the SMB shell, use PowerShell to call back:
Choosing the Right Tool
Use psexec when you need SYSTEM and reliability matters more than stealth. Use wmiexec as the default — it is quieter and runs as the target user which is sometimes needed for accessing user-context resources. Use smbexec when psexec fails due to AV blocking the binary drop. Use atexec for single-command execution when everything else is blocked.
References
-
Fortra psexec.py, smbexec.py, wmiexec.py, and atexec.py source and documentation.
Was this helpful?
Your feedback helps improve this page.