Module: Msf::Module::External

Includes:
Auxiliary::Report, Auth
Defined in:
lib/msf/core/module/external.rb

Instance Method Summary collapse

Methods included from Auth

#store_valid_credential

Methods included from Auxiliary::Report

#active_db?, #create_cracked_credential, #create_credential, #create_credential_and_login, #create_credential_login, #db, #db_warning_given?, #get_client, #get_host, #inside_workspace_boundary?, #invalidate_login, #mytask, #myworkspace, #myworkspace_id, #report_auth_info, #report_client, #report_exploit, #report_host, #report_loot, #report_note, #report_service, #report_vuln, #report_web_form, #report_web_page, #report_web_site, #report_web_vuln, #store_cred, #store_local, #store_loot

Methods included from Metasploit::Framework::Require

optionally, optionally_active_record_railtie, optionally_include_metasploit_credential_creation, #optionally_include_metasploit_credential_creation, optionally_require_metasploit_db_gem_engines

Instance Method Details

#execute_module(path, method: :run, args: datastore, fail_on_exit: true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/msf/core/module/external.rb', line 6

def execute_module(path, method: :run, args: datastore, fail_on_exit: true)
  mod = Msf::Modules::External.new(path, framework: framework)
  success = mod.exec(method: method, args: args) do |m|
    begin
      case m.method
      when :message
        log_output(m)
      when :report
        process_report(m, mod)
      when :reply
        return m.params['return']
      end
    rescue Interrupt => e
      raise e
    rescue Exception => e
      elog('Unable to execute External Module', error: e)
      fail_with Msf::Module::Failure::Unknown, e.message
    end
  end

  fail_with Msf::Module::Failure::Unknown, "Module exited abnormally" if fail_on_exit && !success
end

#log_output(m) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/msf/core/module/external.rb', line 29

def log_output(m)
  message = m.params['message']

  case m.params['level']
  when 'error'
    print_error message
  when 'warning'
    print_warning message
  when 'good'
    print_good message
  when 'info'
    print_status message
  when 'debug'
    vprint_status message
  else
    print_status message
  end
end

#process_report(m, mod) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/msf/core/module/external.rb', line 48

def process_report(m, mod)
  data = m.params['data']

  case m.params['type']
  when 'host'
    # Required
    host = {host: data['host']}

    # Optional
    host[:state] = data['state'] if data['state'] # TODO: validate -- one of the Msf::HostState constants (unknown, alive, dead)
    host[:os_name] = data['os_name'] if data['os_name']
    host[:os_flavor] = data['os_flavor'] if data['os_flavor']
    host[:os_sp] = data['os_sp'] if data['os_sp']
    host[:os_lang] = data['os_lang'] if data['os_lang']
    host[:arch] = data['arch'] if data['arch'] # TODO: validate -- one of the ARCH_* constants
    host[:mac] = data['mac'] if data['mac']
    host[:scope] = data['scope'] if data['scope']
    host[:virtual_host] = data['virtual_host'] if data['virtual_host']

    report_host(host)
  when 'service'
    # Required
    service = {host: data['host'], port: data['port'], proto: data['proto']}

    # Optional
    service[:name] = data['name'] || mod.meta['service_name'] if data['name'] || mod.meta['service_name']

    report_service(service)
  when 'vuln'
    # Required
    vuln = {host: data['host'], name: data['name']}

    # Optional
    vuln[:info] = data['info'] if data['info']
    vuln[:refs] = data['refs'] if data['refs']
    vuln[:port] = data['port'] if data['port']
    vuln[:proto] = data['port'] if data['port']

    # Metasploit magic
    vuln[:refs] = self.references

    report_vuln(vuln)
  when 'correct_password'
    # Required
    cred = {user: data['username'], private: data['password']}

    # Optional
    cred[:proof] = data['proof'] if data['proof']
    cred[:service_data] =
      {
        origin_type: :service,
        protocol: data['protocol'] || 'tcp',
        service_name: data['service_name'] || mod.meta['service_name'],
        address: data['host'] || datastore['rhost'] || rhost,
        port: data['port'] || datastore['rport'] || rport
      }

    cred[:private_type] = :password

    # Optional
    if data.has_key?('domain')
      cred[:service_data][:realm_value] = data['domain']
      cred[:service_data][:realm_key] = Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN
    end

    store_valid_credential(**cred)
  when 'wrong_password'
    # Required
    cred = {public: data['username'], private: data['password']}

    # Optional
    cred.merge!({
      address: data['host'] || datastore['rhost'] || rhost,
      port: data['port'] || datastore['rport'] || rport,
      protocol: data['protocol'] || 'tcp',
      status: Metasploit::Model::Login::Status::INCORRECT
    })

    (**cred)

  when 'credential_login'
    (data, mod)
  else
    print_warning "Skipping unrecognized report type #{m.params['type']}"
  end
end