Module: Msf::Auxiliary::MQTT

Defined in:
lib/msf/core/auxiliary/mqtt.rb

Instance Method Summary collapse

Instance Method Details

#client_idObject


40
41
42
# File 'lib/msf/core/auxiliary/mqtt.rb', line 40

def client_id
  datastore['CLIENT_ID'] || 'mqtt-' + Rex::Text.rand_text_alpha(1 + rand(10))
end

#initialize(info = {}) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/msf/core/auxiliary/mqtt.rb', line 8

def initialize(info = {})
  super

  register_options(
    [
      Opt::RPORT(Rex::Proto::MQTT::DEFAULT_PORT)
    ]
  )

  register_advanced_options(
    [
      OptString.new('CLIENT_ID', [false, 'The client ID to send if necessary for bypassing clientid_prefixes']),
      OptInt.new('READ_TIMEOUT', [true, 'Seconds to wait while reading MQTT responses', 5])
    ]
  )

  register_autofilter_ports([Rex::Proto::MQTT::DEFAULT_PORT, Rex::Proto::MQTT::DEFAULT_SSL_PORT])
end

#mqtt_clientObject

creates a new mqtt client for use against the connected socket


45
46
47
48
49
50
51
52
53
# File 'lib/msf/core/auxiliary/mqtt.rb', line 45

def mqtt_client
  client_opts = {
    client_id: client_id,
    username: datastore['USERNAME'],
    password: datastore['PASSWORD'],
    read_timeout: read_timeout
  }
  Rex::Proto::MQTT::Client.new(sock, client_opts)
end

#mqtt_connect(client) ⇒ Object


55
56
57
# File 'lib/msf/core/auxiliary/mqtt.rb', line 55

def mqtt_connect(client)
  client.connect
end

#mqtt_connect?(client) ⇒ Boolean

Returns:

  • (Boolean)

59
60
61
# File 'lib/msf/core/auxiliary/mqtt.rb', line 59

def mqtt_connect?(client)
  client.connect?
end

#mqtt_disconnect(client) ⇒ Object


63
64
65
# File 'lib/msf/core/auxiliary/mqtt.rb', line 63

def mqtt_disconnect(client)
  client.disconnect
end

#read_timeoutObject


36
37
38
# File 'lib/msf/core/auxiliary/mqtt.rb', line 36

def read_timeout
  datastore['READ_TIMEOUT']
end

#setupObject


27
28
29
30
31
32
33
34
# File 'lib/msf/core/auxiliary/mqtt.rb', line 27

def setup
  fail_with(Failure::BadConfig, 'READ_TIMEOUT must be > 0') if read_timeout <= 0

  client_id_arg = datastore['CLIENT_ID']
  if client_id_arg && client_id_arg.blank?
    fail_with(Failure::BadConfig, 'CLIENT_ID must be a non-empty string')
  end
end