Include origin in remote requests and display it

GSoC/Meterpreter_Web_Console
James Barnett 2018-06-05 14:59:11 -05:00
parent ea6540358c
commit 64cb7dfb3c
No known key found for this signature in database
GPG Key ID: 647983861A4EC5EA
4 changed files with 32 additions and 19 deletions

View File

@ -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

View File

@ -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?
body = process_response(response_wrapper)
return JSON.parse(body).symbolize_keys
end
end
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))
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
end
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 }

View File

@ -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

View File

@ -429,7 +429,7 @@ class Creds
tbl << [
"", # host
"", # cred
origin, # origin
"", # service
public_val,
private_val,