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/module/external.rb
Views: 11784
1module Msf::Module::External2include Msf::Auxiliary::Report3include Msf::Module::Auth45def execute_module(path, method: :run, args: datastore, fail_on_exit: true)6mod = Msf::Modules::External.new(path, framework: framework)7success = mod.exec(method: method, args: args) do |m|8begin9case m.method10when :message11log_output(m)12when :report13process_report(m, mod)14when :reply15return m.params['return']16end17rescue Interrupt => e18raise e19rescue Exception => e20elog('Unable to execute External Module', error: e)21fail_with Msf::Module::Failure::Unknown, e.message22end23end2425fail_with Msf::Module::Failure::Unknown, "Module exited abnormally" if fail_on_exit && !success26end2728def log_output(m)29message = m.params['message']3031case m.params['level']32when 'error'33print_error message34when 'warning'35print_warning message36when 'good'37print_good message38when 'info'39print_status message40when 'debug'41vprint_status message42else43print_status message44end45end4647def process_report(m, mod)48data = m.params['data']4950case m.params['type']51when 'host'52# Required53host = {host: data['host']}5455# Optional56host[:state] = data['state'] if data['state'] # TODO: validate -- one of the Msf::HostState constants (unknown, alive, dead)57host[:os_name] = data['os_name'] if data['os_name']58host[:os_flavor] = data['os_flavor'] if data['os_flavor']59host[:os_sp] = data['os_sp'] if data['os_sp']60host[:os_lang] = data['os_lang'] if data['os_lang']61host[:arch] = data['arch'] if data['arch'] # TODO: validate -- one of the ARCH_* constants62host[:mac] = data['mac'] if data['mac']63host[:scope] = data['scope'] if data['scope']64host[:virtual_host] = data['virtual_host'] if data['virtual_host']6566report_host(host)67when 'service'68# Required69service = {host: data['host'], port: data['port'], proto: data['proto']}7071# Optional72service[:name] = data['name'] || mod.meta['service_name'] if data['name'] || mod.meta['service_name']7374report_service(service)75when 'vuln'76# Required77vuln = {host: data['host'], name: data['name']}7879# Optional80vuln[:info] = data['info'] if data['info']81vuln[:refs] = data['refs'] if data['refs']82vuln[:port] = data['port'] if data['port']83vuln[:proto] = data['port'] if data['port']8485# Metasploit magic86vuln[:refs] = self.references8788report_vuln(vuln)89when 'correct_password'90# Required91cred = {user: data['username'], private: data['password']}9293# Optional94cred[:proof] = data['proof'] if data['proof']95cred[:service_data] =96{97origin_type: :service,98protocol: data['protocol'] || 'tcp',99service_name: data['service_name'] || mod.meta['service_name'],100address: data['host'] || datastore['rhost'] || rhost,101port: data['port'] || datastore['rport'] || rport102}103104cred[:private_type] = :password105106# Optional107if data.has_key?('domain')108cred[:service_data][:realm_value] = data['domain']109cred[:service_data][:realm_key] = Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN110end111112store_valid_credential(**cred)113when 'wrong_password'114# Required115cred = {public: data['username'], private: data['password']}116117# Optional118cred.merge!({119address: data['host'] || datastore['rhost'] || rhost,120port: data['port'] || datastore['rport'] || rport,121protocol: data['protocol'] || 'tcp',122status: Metasploit::Model::Login::Status::INCORRECT123})124125invalidate_login(**cred)126127when 'credential_login'128handle_credential_login(data, mod)129else130print_warning "Skipping unrecognized report type #{m.params['type']}"131end132end133end134135#136# Handles login report that does not necessarily need to include a password137#138def handle_credential_login(data, mod)139# Required140service_data = {141address: data['address'],142port: data['port'],143protocol: data['protocol'],144service_name: data['service_name'],145module_fullname: self.fullname,146workspace_id: myworkspace_id147}148# Optional149credential_data = {150origin_type: :service,151username: data['username']152}.merge(service_data)153154if data.has_key?(:password)155credential_data[:private_data] = data['password']156credential_data[:private_type] = :password157end158159if data.has_key?('domain')160credential_data[:realm_value] = data['domain']161credential_data[:realm_key] = Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN162end163164login_data = {165core: create_credential(credential_data),166last_attempted_at: DateTime.now,167status: Metasploit::Model::Login::Status::SUCCESSFUL,168}.merge(service_data)169create_credential_login(login_data)170end171172173