Skip to content

Back to the category index / Back to the command index

Uses DCOM objects to run a command or a semi-interactive shell on the target host.

ItemDetails
Implementationexamples/dcomexec.py
CategoryRemote execution / WMI / services
Size656 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Run python examples/dcomexec.py -h for the current option definitions.

ArgumentDescription
target[[domain/]username[:password]@]
-shareShare from which to retrieve output (default: ADMIN$)
-nooutputDo not print output (no SMB connection is created)
-tsAdd a timestamp to each log message
-debugEnable debug output
-codecHelp text generated dynamically from the runtime value
-objectDCOM object used to run the shell command (default: ShellWindows; choices: ShellWindows, ShellBrowserWindow, MMC20)
-com-versionDCOM version in MAJOR_VERSION:MINOR_VERSION format, for example 5.7
-shell-typeCommand processor for the semi-interactive shell (choices: cmd, powershell; default: cmd)
commandCommand to run on the target; if empty, launch a semi-interactive shell
-silentcommandRun the given command without cmd.exe (no output; shell built-ins such as dir and cd cannot run)
-hashesNTLM hashes in LMHASH:NTHASH format
-no-passDo not prompt for a password (useful with -k)
-kUse Kerberos authentication. Look for matching credentials in the ccache file named by KRB5CCNAME; if none are valid, use those specified on the command line
-aesKeyAES key for Kerberos authentication (128 or 256 bits)
-dc-ipDomain controller IP address; if omitted, use the domain name (FQDN) from the target parameter
-Asmbclient/mount.cifs-style authentication file; see smbclient manual page option -A
-keytabRead SPN keys from a keytab file

The tool establishes a DCOM connection and obtains the selected object’s COM interface. It passes commands to a dispatch method. With output enabled, it redirects output to a temporary file on a share and retrieves it over a separate SMB connection. For the interactive shell, cmd.Cmd dispatches local and remote commands, uploads, and downloads.

DCOM activates a remote COM object and calls its interface methods through RPC. This command creates a ShellWindows, ShellBrowserWindow, or MMC20.Application object and reaches shell execution through IDispatch. Each object has a different property and method chain, so getInterface() and RemoteShellMMC20 handle the differences.

A command’s return value alone does not provide stdout. Normally, the remote shell writes output to a temporary file on a share, and a separate SMBConnection reads it. The interactive shell keeps the current directory as a command prefix. Only lget/lput use SMB file transfer; other input goes to DCOM process execution. With -nooutput, no SMB connection is needed, and the meaning of execution confirmation changes.

COM objects have interface references and a DCOM connection lifecycle. Release interfaces and disconnect even when a method call fails, and prevent polling for the temporary file from continuing indefinitely. Distinguish differences caused by COM versions, object availability, or desktop/session isolation from credential errors.

SymbolLocationWhere to trace its responsibility
DCOMEXEC65__init__(), getInterface(), run()
RemoteShell206__init__(), do_shell(), do_help(), do_lcd(), do_lget(), do_lput(), do_exit(), do_EOF(), emptyline(), do_cd(), default(), get_output(), and others
RemoteShellMMC20444execute_remote()
AuthFileSyntaxError497__init__()
load_smbclient_auth_file()511Module function
ModuleMain names used
impacketversion
impacket.dcerpc.v5.dcom.oautDISPATCH_METHOD, DISPATCH_PROPERTYGET, DISPPARAMS, IDispatch, IID_IDispatch, VARENUM, VARIANT, string_to_bin
impacket.dcerpc.v5.dcomrtCOMVERSION, DCOMConnection, FLAGS_OBJREF_CUSTOM, FLAGS_OBJREF_EXTENDED, FLAGS_OBJREF_HANDLER, FLAGS_OBJREF_STANDARD, INTERFACE, IRemUnknown2, OBJREF, OBJREF_CUSTOM, OBJREF_EXTENDED, OBJREF_HANDLER, OBJREF_STANDARD
impacket.dcerpc.v5.dtypesNULL
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.smbconnectionSMB2_DIALECT_002, SMB2_DIALECT_21, SMBConnection, SMB_DIALECT
impacket.krb5.keytabKeytab
Import nameDistribution packageImport path and declaration status
sixsixImported directly; declared

Output, side effects, and required privileges

Section titled “Output, side effects, and required privileges”
  • Some operations change the target’s state. Check the target name, SID, and path before making changes.
  • Some paths use temporary resources such as remote services, tasks, files, shares, and WMI/RPC resources. Cleaning them up after an abnormal exit is part of the behavior contract.
  • On failure, use protocol status codes to determine whether name resolution, connection, authentication, service state, or permissions caused the stop.
  • Even without an explicit cleanup function, check for finally-equivalent paths and closure or deletion of protocol handles.

The code depends on dcerpc.v5.dcomrt, DCOM OAUT structures, SMBConnection, and keytabs. DCOMEXEC handles object activation; RemoteShell and its related classes handle commands and output. Always release COM interfaces and disconnect.