Module: Msf::OptionalSession

Includes:
SessionCompatibility
Included in:
LDAP, MSSQL, MySQL, PostgreSQL, SMB
Defined in:
lib/msf/core/optional_session.rb,
lib/msf/core/optional_session/smb.rb,
lib/msf/core/optional_session/ldap.rb,
lib/msf/core/optional_session/mssql.rb,
lib/msf/core/optional_session/mysql.rb,
lib/msf/core/optional_session/postgresql.rb

Defined Under Namespace

Modules: LDAP, MSSQL, MySQL, PostgreSQL, SMB

Instance Attribute Summary

Attributes included from SessionCompatibility

#passive, #session_types

Attributes included from Module::HasActions

#actions, #default_action, #passive, #passive_actions

Instance Method Summary collapse

Methods included from SessionCompatibility

#check_for_session_readiness, #cleanup, #command_names_for, #compatible_sessions, #initialize, #meterpreter_session_incompatibility_reasons, #passive?, #post_commands, #session_changed?, #session_compatible?, #session_display_info, #session_incompatibility_reasons, #setup, #sysinfo

Methods included from Post::Common

#clear_screen, #cmd_exec, #cmd_exec_get_pid, #cmd_exec_with_result, #command_exists?, #create_process, #get_env, #get_envs, #initialize, #peer, #report_virtualization, #rhost, #rport

Methods included from Module::HasActions

#action, #find_action, #initialize, #passive?, #passive_action?

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

#sessionObject



26
27
28
29
30
# File 'lib/msf/core/optional_session.rb', line 26

def session
  return nil unless optional_session_enabled?

  super
end

#validateObject

Validates options depending on whether we are using SESSION or an RHOST for our connection



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/msf/core/optional_session.rb', line 12

def validate
  super
  return unless optional_session_enabled?

  # If the session is set use that by default regardless of rhost being (un)set
  if session
    validate_session
  elsif rhost
    validate_rhost
  else
    raise Msf::OptionValidateError.new(message: 'A SESSION or RHOST must be provided')
  end
end

#validate_group(group_name) ⇒ Object (protected)

Validates the options within an option group

Parameters:

  • group_name (String)

    Name of the option group



53
54
55
56
# File 'lib/msf/core/optional_session.rb', line 53

def validate_group(group_name)
  option_group = options.groups[group_name]
  option_group.validate(options, datastore) if option_group
end

#validate_rhostObject (protected)

Used to validate options when RHOST has been set



35
36
37
# File 'lib/msf/core/optional_session.rb', line 35

def validate_rhost
  validate_group('RHOST')
end

#validate_sessionObject (protected)

Used to validate options when SESSION has been set



40
41
42
43
44
45
46
47
48
# File 'lib/msf/core/optional_session.rb', line 40

def validate_session
  issues = {}
  if session_types && !session_types.include?(session.type)
    issues['SESSION'] = "Incompatible session type: #{session.type}. This module works with: #{session_types.join(', ')}."
  end
  raise Msf::OptionValidateError.new(issues.keys.to_a, reasons: issues) unless issues.empty?

  validate_group('SESSION')
end