Module: RemoteCredentialDataService

Includes:
ResponseDataHelper
Included in:
DataServiceAutoLoader
Defined in:
lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb

Constant Summary collapse

CREDENTIAL_API_PATH =
'/api/v1/credentials'
CREDENTIAL_MDM_CLASS =

“MDM_CLASS” is a little misleading since it is not in that repo but trying to keep naming consistent across DataServices

'Metasploit::Credential::Core'

Instance Method Summary collapse

Methods included from ResponseDataHelper

#json_to_hash, #json_to_mdm_object, #process_file, #to_ar

Instance Method Details

#create_credential(opts) ⇒ Object



33
34
35
# File 'lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb', line 33

def create_credential(opts)
  json_to_mdm_object(self.post_data(CREDENTIAL_API_PATH, opts), CREDENTIAL_MDM_CLASS).first
end

#creds(opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb', line 10

def creds(opts = {})
  path = get_path_select(opts, CREDENTIAL_API_PATH)
  data = self.get_data(path, nil, opts)
  rv = json_to_mdm_object(data, CREDENTIAL_MDM_CLASS)
  parsed_body = JSON.parse(data.response.body, symbolize_names: true)
  data = parsed_body[:data]
  data.each do |cred|
    if cred[:public]
      public_object = to_ar(cred[:public][:type].constantize, cred[:public])
      rv[data.index(cred)].public = public_object
    end
    if cred[:private]
      private_object = to_ar(cred[:private][:type].constantize, cred[:private])
      rv[data.index(cred)].private = private_object
    end
    if cred[:origin]
      origin_object = to_ar(cred[:origin][:type].constantize, cred[:origin])
      rv[data.index(cred)].origin = origin_object
    end
  end
  rv
end

#delete_credentials(opts) ⇒ Object



41
42
43
# File 'lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb', line 41

def delete_credentials(opts)
  json_to_mdm_object(self.delete_data(CREDENTIAL_API_PATH, opts), CREDENTIAL_MDM_CLASS)
end

#update_credential(opts) ⇒ Object



37
38
39
# File 'lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb', line 37

def update_credential(opts)
  json_to_mdm_object(self.put_data(CREDENTIAL_API_PATH, opts), CREDENTIAL_MDM_CLASS).first
end