Summery

psexec.py in Impacket allows remote command execution on a Windows system using SMB and valid credentials. It mimics Microsoft’s PsExec tool, creating a service on the target to execute commands with SYSTEM privileges.

The tool creates a remote service by uploading a randomly-named executable to the ADMIN$ share on the target host. It then registers the service via RPC and the Windows Service Control Manager. Once established, communication happens over a named pipe, providing an interactive remote shell as SYSTEM on the victim host.

Regular authentication
To connect to a host with psexec.py, we need credentials for a user with local administrator privileges.
psexec.py inlanefreight.local/user:'password'@1.3.3.7

Kerberos authentication
You can also authenticate using kerberos without providing regular credentials if the right ticket is assigned to your account.
psexec.py LOGISTICS.INLANEFREIGHT.LOCAL/user@academy-ea-dc01.inlanefreight.local -k -no-pass -target-ip 1.3.3.7
As you can see you can also provide hostname, rather than the IP (I think it only works in domains)

Pass-the-hash authentication
psexec.py user@1.3.3.7 -hashes :30B3783CE2ABF1AF70F77D0660CF3453

There are two smaller variants of this script:

  • Impacket SMBExec - A similar approach to PsExec without using RemComSvc. This implementation goes one step further, instantiating a local SMB server to receive the output of the commands. This is useful when the target machine does NOT have a writeable share available.
  • Impacket atexec - This example executes a command on the target machine through the Task Scheduler service and returns the output of the executed command.

This script is also used with other ones like secretsdump.py lookupsid.py and ticketer.py to try to get access to a parent domain. This process is well described in Attacking Domain Trusts - Child & Parent Trusts - from Linux

Fun note:
This is a very stable shell so it will let you run Pentesting/The Grimoire/Tools/Mimikatz with it!