Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/core/auxiliary/mqtt.rb
Views: 11784
# -*- coding: binary -*-123module Msf4module Auxiliary::MQTT5def initialize(info = {})6super78register_options(9[10Opt::RPORT(Rex::Proto::MQTT::DEFAULT_PORT)11]12)1314register_advanced_options(15[16OptString.new('CLIENT_ID', [false, 'The client ID to send if necessary for bypassing clientid_prefixes']),17OptInt.new('READ_TIMEOUT', [true, 'Seconds to wait while reading MQTT responses', 5])18]19)2021register_autofilter_ports([Rex::Proto::MQTT::DEFAULT_PORT, Rex::Proto::MQTT::DEFAULT_SSL_PORT])22end2324def setup25fail_with(Msf::Exploit::Failure::BadConfig, 'READ_TIMEOUT must be > 0') if read_timeout <= 02627client_id_arg = datastore['CLIENT_ID']28if client_id_arg && client_id_arg.blank?29fail_with(Msf::Exploit::Failure::BadConfig, 'CLIENT_ID must be a non-empty string')30end31end3233def read_timeout34datastore['READ_TIMEOUT']35end3637def client_id38datastore['CLIENT_ID'] || 'mqtt-' + Rex::Text.rand_text_alpha(1 + rand(10))39end4041# creates a new mqtt client for use against the connected socket42def mqtt_client43client_opts = {44client_id: client_id,45username: datastore['USERNAME'],46password: datastore['PASSWORD'],47read_timeout: read_timeout48}49Rex::Proto::MQTT::Client.new(sock, client_opts)50end5152def mqtt_connect(client)53client.connect54end5556def mqtt_connect?(client)57client.connect?58end5960def mqtt_disconnect(client)61client.disconnect62end63end64end656667