diff --git a/lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb b/lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb index b4e788218d..c1f0fc0c7b 100644 --- a/lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb +++ b/lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb @@ -12,8 +12,10 @@ module RemoteCredentialDataService rv = json_to_mdm_object(data, CREDENTIAL_MDM_CLASS, []) parsed_body = JSON.parse(data.response.body) parsed_body.each do |cred| - private_object = to_ar(cred['private_class'].constantize, cred['private']) + private_object = to_ar(cred['private']['type'].constantize, cred['private']) + origin_object = to_ar(cred['origin']['type'].constantize, cred['origin']) rv[parsed_body.index(cred)].private = private_object + rv[parsed_body.index(cred)].origin = origin_object end rv end diff --git a/lib/metasploit/framework/data_service/remote/http/response_data_helper.rb b/lib/metasploit/framework/data_service/remote/http/response_data_helper.rb index 6bb2506309..f39f046b28 100644 --- a/lib/metasploit/framework/data_service/remote/http/response_data_helper.rb +++ b/lib/metasploit/framework/data_service/remote/http/response_data_helper.rb @@ -5,6 +5,21 @@ require 'digest' # module ResponseDataHelper + + def process_response(response_wrapper) + begin + if response_wrapper.expected + body = response_wrapper.response.body + unless body.nil? && body.empty? + return body + end + end + rescue => e + elog "Error processing response: #{e.message}" + e.backtrace.each { |line| elog line } + end + end + # # Converts an HTTP response to a Hash # @@ -13,14 +28,10 @@ module ResponseDataHelper # def json_to_hash(response_wrapper) begin - if response_wrapper.expected - body = response_wrapper.response.body - unless body.nil? && body.empty? - return JSON.parse(body).symbolize_keys - end - end + body = process_response(response_wrapper) + return JSON.parse(body).symbolize_keys rescue => e - elog "Error parsing response: #{e.message}" + elog "Error parsing response as JSON: #{e.message}" e.backtrace.each { |line| elog line } end end @@ -36,15 +47,12 @@ module ResponseDataHelper def json_to_mdm_object(response_wrapper, mdm_class, returns_on_error = nil) if response_wrapper.expected begin - body = response_wrapper.response.body - if !body.nil? && !body.empty? - parsed_body = Array.wrap(JSON.parse(body)) - rv = [] - parsed_body.each do |json_object| - rv << to_ar(mdm_class.constantize, json_object) - end - return rv + parsed_body = Array.wrap(JSON.parse(process_response(response_wrapper))) + rv = [] + parsed_body.each do |json_object| + rv << to_ar(mdm_class.constantize, json_object) end + return rv rescue => e elog "Mdm Object conversion failed #{e.message}" e.backtrace.each { |line| elog "#{line}\n" } @@ -102,6 +110,8 @@ module ResponseDataHelper case association.macro when :belongs_to data.delete("#{k}_id") + # Polymorphic associations do not auto-create the 'build_model' method + next if association.options[:polymorphic] to_ar(association.klass, v, obj.send("build_#{k}")) obj.class_eval do define_method("#{k}_id") { obj.send(k).id } diff --git a/lib/msf/core/db_manager/http/servlet_helper.rb b/lib/msf/core/db_manager/http/servlet_helper.rb index 43c8ea6923..fee2cbabcf 100644 --- a/lib/msf/core/db_manager/http/servlet_helper.rb +++ b/lib/msf/core/db_manager/http/servlet_helper.rb @@ -71,11 +71,12 @@ module ServletHelper end def format_cred_json(data) - includes = [:logins, :public, :private, :realm] + includes = [:logins, :public, :private, :realm, :origin] response = [] Array.wrap(data).each do |cred| - json = cred.as_json(include: includes).merge('private_class' => cred.private.class.to_s) + json = cred.as_json(include: includes) + json['origin'] = json['origin'].merge('type' => cred.origin.class.to_s) json['public'] = json['public'].merge('type' => cred.public.type) json['private'] = json['private'].merge('type' => cred.private.type) response << json diff --git a/lib/msf/ui/console/command_dispatcher/creds.rb b/lib/msf/ui/console/command_dispatcher/creds.rb index f874365d19..b842c0bc92 100644 --- a/lib/msf/ui/console/command_dispatcher/creds.rb +++ b/lib/msf/ui/console/command_dispatcher/creds.rb @@ -429,7 +429,7 @@ class Creds tbl << [ "", # host - "", # cred + origin, # origin "", # service public_val, private_val,