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/modules/auxiliary/scanner/mqtt/connect.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'metasploit/framework/credential_collection'6require 'metasploit/framework/login_scanner/mqtt'78class MetasploitModule < Msf::Auxiliary9include Msf::Exploit::Remote::Tcp10include Msf::Auxiliary::Scanner11include Msf::Auxiliary::MQTT12include Msf::Auxiliary::Report13include Msf::Auxiliary::AuthBrute1415def initialize16super(17'Name' => 'MQTT Authentication Scanner',18'Description' => %q(19This module attempts to authenticate to MQTT.20),21'Author' =>22[23'Jon Hart <jon_hart[at]rapid7.com>'24],25'References' =>26[27['URL', 'http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Table_3.1_-']28],29'License' => MSF_LICENSE,30'DefaultOptions' =>31{32'BLANK_PASSWORDS' => false,33'USER_AS_PASS' => true,34'USER_FILE' => 'data/wordlists/unix_users.txt',35'PASS_FILE' => 'data/wordlists/unix_passwords.txt'36}37)38end3940def test_login(username, password)41client_opts = {42username: username,43password: password,44read_timeout: read_timeout,45client_id: client_id46}47connect48client = Rex::Proto::MQTT::Client.new(sock, client_opts)49connect_res = client.connect50client.disconnect51connect_res.return_code.zero?52end5354def default_login55vprint_status("Testing without credentials")56if test_login('', '')57print_good("Does not require authentication")58end5960end6162def run_host(_ip)63unless default_login64brute65end66end6768def brute69vprint_status("Starting MQTT login sweep")70cred_collection = build_credential_collection(71username: datastore['USERNAME'],72password: datastore['PASSWORD']73)7475scanner = Metasploit::Framework::LoginScanner::MQTT.new(76configure_login_scanner(77host: rhost,78port: rport,79read_timeout: datastore['READ_TIMEOUT'],80client_id: client_id,81proxies: datastore['PROXIES'],82cred_details: cred_collection,83stop_on_success: datastore['STOP_ON_SUCCESS'],84bruteforce_speed: datastore['BRUTEFORCE_SPEED'],85connection_timeout: datastore['ConnectTimeout'],86max_send_size: datastore['TCP::max_send_size'],87send_delay: datastore['TCP::send_delay'],88framework: framework,89framework_module: self,90ssl: datastore['SSL'],91ssl_version: datastore['SSLVersion'],92ssl_verify_mode: datastore['SSLVerifyMode'],93ssl_cipher: datastore['SSLCipher'],94local_port: datastore['CPORT'],95local_host: datastore['CHOST']96)97)9899scanner.scan! do |result|100credential_data = result.to_h101credential_data.merge!(102module_fullname: fullname,103workspace_id: myworkspace_id104)105password = result.credential.private106username = result.credential.public107if result.success?108credential_core = create_credential(credential_data)109credential_data[:core] = credential_core110create_credential_login(credential_data)111print_good("MQTT Login Successful: #{username}/#{password}")112else113invalidate_login(credential_data)114vprint_error("MQTT LOGIN FAILED: #{username}/#{password} (#{result.proof})")115end116end117end118end119120121