Skip to content

Impacket mqtt_check.py

Back to the Category Index / Back to the Command Index

Sends CONNECT to an MQTT broker and checks whether anonymous connections are accepted and what the broker returns.

ItemDetails
Implementationexamples/mqtt_check.py
CategoryMSSQL / Exchange / MQTT
Size84 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Check python examples/mqtt_check.py -h for the current option definitions.

ArgumentDescription
--helpShow the help message and exit.
target[[domain/]username[:password]@]<targetName>
-client-idClient ID used for authentication (random by default).
-sslEnable SSL.
-portConnection port (default: 1883).
-debugEnable debug logging.
-tsAdd timestamps to log output.

The command creates a socket from the target, client ID, port, and TLS option, then sends an MQTT CONNECT packet. It receives and parses CONNACK, reports connection status from the return code, and closes the socket.

An MQTT client sends CONNECT as its first packet, and the broker replies with CONNACK to indicate protocol acceptance and the authentication result. This command does not attempt username/password authentication. It checks anonymous access with a minimal CONNECT containing a client ID and clean-session setting.

The MQTT fixed header uses variable-length encoding for remaining length. The CONNECT payload contains the protocol name and version, connect flags, keepalive, and UTF-8 client ID in order. The impacket.mqtt structure builds the packet, which the socket or TLS path sends to the specified port. On receipt, read at least a complete CONNACK frame before interpreting its return code.

A successful TCP connection, TLS handshake, MQTT protocol acceptance, and anonymous authorization are separate stages. Do not mistake an old/new MQTT version mismatch or rejected identifier for “authentication required.” Treat short packets, excessive remaining lengths, and an immediate broker close as explicit outcomes.

SymbolLocationEntry Point for Tracing Behavior
MQTT_LOGIN32__init__(), run()
ModuleMain Names Used
impacketversion
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.mqttCONNECT_ACK_ERROR_MSGS, MQTTConnection

Output, Side Effects, and Required Privileges

Section titled “Output, Side Effects, and Required Privileges”
  • Primarily queries and authentication attempts. Repeated runs can affect audit logs, account lockouts, and target load.
  • Distinguish missing input files, damaged files, truncated reads, and unsupported formats.

This command depends on impacket.mqtt and standard sockets/TLS; MQTT_LOGIN.run() handles the packet exchange. Validate MQTT remaining length and short or malformed responses, and distinguish TLS handshake errors from broker rejections.

  • Syntax: python -m py_compile examples/mqtt_check.py
  • CLI: python examples/mqtt_check.py -h
  • No test specific to this command was found. Choose shared-module tests and, if needed, a run in an isolated environment.