Skip to content

Impacket services.py

Back to the category index / Back to the command index

Uses Service Control Manager RPC to list services, check status, create or reconfigure services, and start, stop, or delete them.

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

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

Subcommands: start, stop, delete, status, config, list, create, change

ArgumentDescription
target[[domain/]username[:password]@]
-debugEnable debug output
-tsAdd a timestamp to each log message
-nameService name; required
-displayDisplay name; required
-pathBinary path; required
-service_typeService type
-start_typeService start type
-start_nameName of the account under which the service runs
-passwordPassword for the account specified by -start_name
-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
-target-ipTarget machine IP address; if omitted, use the target value. Useful when a NetBIOS target name cannot be resolved
-portDestination SMB server port (choices: 139, 445; default: 445)

The tool binds to SCMR through an SMB/RPC transport and opens a manager handle. Depending on the subcommand, it opens a service handle, queries status, sends control codes, or creates or changes configuration. It displays the result and closes each handle.

A Windows service has an entry in the Service Control Manager database and a current execution state. This command binds to SCMR and opens a manager handle, then a service handle for actions that need one. Start and stop change state; create, delete, and change modify the database; status, config, and list only read it.

start passes an argument array in a service start request, while stop sends a control code. Acceptance of a request does not mean the service has reached its final state, so interpret pending, running, and stopped status fields. create and change convert service type, start type, account, and binary path to RPC enums and Unicode fields.

The service account password must be encrypted in a protocol-specific form with the RPC session key rather than placed as plaintext directly in a structure. Access masks on handles can be minimized by action. Handle list pagination, services that already exist or were deleted, and stop failures caused by dependent services separately.

SymbolLocationWhere to trace its responsibility
SVCCTL38__init__(), run(), doStuff()
ModuleMain names used
impacket.exampleslogger
impacket.examples.utilsparse_target
impacketversion
impacket.dcerpc.v5scmr, transport
impacket.dcerpc.v5.ndrNULL
impacket.cryptoencryptSecret

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.
  • On failure, use protocol status codes to determine whether name resolution, connection, authentication, service state, or permissions caused the stop.

The code depends on dcerpc.v5.scmr, transport, NDR NULL, and encryptSecret for service passwords. SVCCTL.run() and doStuff() handle dispatch and protocol operations. Converting service and start types from CLI values to RPC constants is the main extension point.