Skip to content

Commit 0654979

Browse files
committed
Remove separate code path for openstruct for creds.
Also fix RemoteCredentialDataService to work with json_to_mdm
1 parent bab9b66 commit 0654979

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

lib/metasploit/framework/data_service/remote/http/remote_credential_data_service.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ module RemoteCredentialDataService
88
CREDENTIAL_MDM_CLASS = 'Metasploit::Credential::Core'
99

1010
def creds(opts = {})
11-
json_to_mdm_object(self.get_data(CREDENTIAL_API_PATH, opts), CREDENTIAL_MDM_CLASS, [])
11+
data = self.get_data(CREDENTIAL_API_PATH, opts)
12+
rv = json_to_mdm_object(data, CREDENTIAL_MDM_CLASS, [])
13+
parsed_body = JSON.parse(data.response.body)
14+
parsed_body.each do |cred|
15+
private_object = to_ar(cred['private_class'].constantize, cred['private'])
16+
rv[parsed_body.index(cred)].private = private_object
17+
end
18+
rv
1219
end
1320

1421
def create_credential(opts)

lib/msf/core/db_manager/http/servlet/credential_servlet.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def self.get_credentials
2323
# This is normally pulled from a class method from the MetasploitCredential class
2424
response = []
2525
data.each do |cred|
26-
json = cred.as_json(include: includes).merge('human' => cred.private.class.model_name.human)
26+
json = cred.as_json(include: includes).merge('private_class' => cred.private.class.to_s)
2727
response << json
2828
end
2929
set_json_response(response)

lib/msf/ui/console/command_dispatcher/creds.rb

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,7 @@ def creds_search(*args)
424424
public_val = core.public ? core.public.username : ""
425425
private_val = core.private ? core.private.data : ""
426426
realm_val = core.realm ? core.realm.value : ""
427-
human_val = ""
428-
# TODO: We shouldn't have separate code paths depending on the model we're working with
429-
# This should always expect an OpenStruct.
430-
if core.private
431-
if core.private.is_a?(OpenStruct)
432-
human_val = core.human
433-
else
434-
human_val = core.private.class.model_name.human
435-
end
436-
end
427+
human_val = core.private ? core.private.class.model_name.human : ""
437428

438429
tbl << [
439430
"", # host
@@ -442,7 +433,7 @@ def creds_search(*args)
442433
public_val,
443434
private_val,
444435
realm_val,
445-
human_val,
436+
human_val
446437
]
447438
else
448439
core.logins.each do |login|
@@ -466,22 +457,13 @@ def creds_search(*args)
466457
public_val = core.public ? core.public.username : ""
467458
private_val = core.private ? core.private.data : ""
468459
realm_val = core.realm ? core.realm.value : ""
469-
human_val = ""
470-
# TODO: We shouldn't have separate code paths depending on the model we're working with
471-
# This should always expect an OpenStruct.
472-
if core.private
473-
if core.private.is_a?(OpenStruct)
474-
human_val = core.human
475-
else
476-
human_val = core.private.class.model_name.human
477-
end
478-
end
460+
human_val = core.private ? core.private.class.model_name.human : ""
479461

480462
row += [
481463
public_val,
482464
private_val,
483465
realm_val,
484-
human_val,
466+
human_val
485467
]
486468
tbl << row
487469
end

0 commit comments

Comments
 (0)