Module: SessionDataProxy

Included in:
DataProxyAutoLoader
Defined in:
lib/metasploit/framework/data_service/proxy/session_data_proxy.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert_msf_session_to_hash(msf_session) ⇒ Object

TODO: handle task info



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/metasploit/framework/data_service/proxy/session_data_proxy.rb', line 59

def self.convert_msf_session_to_hash(msf_session)
  hash = Hash.new()
  hash[:host_data] = parse_host_opts(msf_session)
  hash[:session_data] = parse_session_data(msf_session)

  if (msf_session.via_exploit)
    hash[:vuln_info] = parse_vuln_info(msf_session)
  end

  return hash
end

Instance Method Details

#report_session(opts) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/metasploit/framework/data_service/proxy/session_data_proxy.rb', line 13

def report_session(opts)
  begin
    self.data_service_operation do |data_service|
      add_opts_workspace(opts)
      data_service.report_session(opts)
    end
  rescue => e
    self.log_error(e, "Problem reporting session")
  end
end

#sessions(opts = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/metasploit/framework/data_service/proxy/session_data_proxy.rb', line 2

def sessions(opts={})
  begin
    self.data_service_operation do |data_service|
      add_opts_workspace(opts)
      data_service.sessions(opts)
    end
  rescue => e
    self.log_error(e, "Problem retrieving sessions")
  end
end

#update_session(opts) ⇒ Mdm::Session

Update the attributes of a session entry using opts. If opts is a Hash, the values should match the attributes to update and must contain :id. If opts is a Msf::Session object, it is converted to a Hash and used for the update. The db_record attribute of the Msf::Session object is updated using the returned Mdm::Session.

Parameters:

  • opts (Hash|Msf::Session)

    Hash containing the updated values. Key should match the attribute to update. Must contain :id of record to update. Otherwise, a Msf::Session object is used to update all attributes.

Returns:

  • (Mdm::Session)

    The updated Mdm::Session object.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/metasploit/framework/data_service/proxy/session_data_proxy.rb', line 32

def update_session(opts)
  begin
    self.data_service_operation do |data_service|
      is_msf_session = false
      if !opts.nil? && opts.kind_of?(Msf::Session)
        msf_session = opts
        is_msf_session = true
        tmp_opts = SessionDataProxy.convert_msf_session_to_hash(msf_session)
        # only updating session data
        opts = tmp_opts[:session_data]
        # add back session ID
        opts[:id] = msf_session.db_record.id
      end

      mdm_session = data_service.update_session(opts)

      # reassign returned Mdm::Session to the Msf::Session's db_record
      msf_session.db_record = mdm_session if is_msf_session

      mdm_session
    end
  rescue => e
    self.log_error(e, "Problem updating session")
  end
end