Skip to content

Commit d863ff9

Browse files
committed
Merge pull request rapid7#3576 from dmaloney-r7/feature/MSP-9641/cred-rpc-calls
Feature/msp 9641/cred roc calls MSP-9641 #land
2 parents 0876302 + 3870b59 commit d863ff9

File tree

1 file changed

+52
-63
lines changed

1 file changed

+52
-63
lines changed

lib/msf/core/rpc/v10/rpc_db.rb

Lines changed: 52 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ module RPC
44
class RPC_Db < RPC_Base
55

66
private
7+
8+
include Metasploit::Credential::Creation
9+
710
def db
811
self.framework.db.active
912
end
@@ -15,6 +18,21 @@ def find_workspace(wspace = nil)
1518
self.framework.db.workspace
1619
end
1720

21+
def fix_cred_options(opts)
22+
new_opts = fix_options(opts)
23+
24+
# Convert some of are data back to symbols
25+
if new_opts[:origin_type]
26+
new_opts[:origin_type] = new_opts[:origin_type].to_sym
27+
end
28+
29+
if new_opts[:private_type]
30+
new_opts[:private_type] = new_opts[:private_type].to_sym
31+
end
32+
33+
new_opts
34+
end
35+
1836
def fix_options(opts)
1937
newopts = {}
2038
opts.each do |k,v|
@@ -88,6 +106,40 @@ def init_db_opts_workspace(xopts)
88106

89107
public
90108

109+
def rpc_create_cracked_credential(xopts)
110+
opts = fix_cred_options(xopts)
111+
create_credential(opts)
112+
end
113+
114+
def rpc_create_credential(xopts)
115+
opts = fix_cred_options(xopts)
116+
core = create_credential(opts)
117+
118+
ret = {
119+
username: core.public.try(:username),
120+
private: core.private.try(:data),
121+
private_type: core.private.try(:type),
122+
realm_value: core.realm.try(:value),
123+
realm_key: core.realm.try(:key)
124+
}
125+
126+
if opts[:last_attempted_at] && opts[:status]
127+
opts[:core] = core
128+
opts[:last_attempted_at] = opts[:last_attempted_at].to_datetime
129+
login = create_credential_login(opts)
130+
131+
ret[:host] = login.service.host.address,
132+
ret[:sname] = login.service.name
133+
ret[:status] = login.status
134+
end
135+
ret
136+
end
137+
138+
def rpc_invalidate_login(xopts)
139+
opts = fix_cred_options(xopts)
140+
invalidate_login(opts)
141+
end
142+
91143
def rpc_hosts(xopts)
92144
::ActiveRecord::Base.connection_pool.with_connection {
93145
opts, wspace = init_db_opts_workspace(xopts)
@@ -490,33 +542,6 @@ def rpc_notes(xopts)
490542
}
491543
end
492544

493-
def rpc_report_auth_info(xopts)
494-
::ActiveRecord::Base.connection_pool.with_connection {
495-
opts, wspace = init_db_opts_workspace(xopts)
496-
res = self.framework.db.report_auth_info(opts)
497-
return { :result => 'success' } if(res)
498-
{ :result => 'failed' }
499-
}
500-
end
501-
502-
def rpc_get_auth_info(xopts)
503-
::ActiveRecord::Base.connection_pool.with_connection {
504-
opts, wspace = init_db_opts_workspace(xopts)
505-
ret = {}
506-
ret[:auth_info] = []
507-
# XXX: This method doesn't exist...
508-
ai = self.framework.db.get_auth_info(opts)
509-
ai.each do |i|
510-
info = {}
511-
i.each do |k,v|
512-
info[k.to_sym] = v
513-
end
514-
ret[:auth_info] << info
515-
end
516-
ret
517-
}
518-
end
519-
520545
def rpc_get_ref(name)
521546
::ActiveRecord::Base.connection_pool.with_connection {
522547
db_check
@@ -828,42 +853,6 @@ def rpc_loots(xopts)
828853
}
829854
end
830855

831-
# requires host, port, user, pass, ptype, and active
832-
def rpc_report_cred(xopts)
833-
::ActiveRecord::Base.connection_pool.with_connection {
834-
opts, wspace = init_db_opts_workspace(xopts)
835-
res = framework.db.find_or_create_cred(opts)
836-
return { :result => 'success' } if res
837-
{ :result => 'failed' }
838-
}
839-
end
840-
841-
#right now workspace is the only option supported
842-
def rpc_creds(xopts)
843-
::ActiveRecord::Base.connection_pool.with_connection {
844-
opts, wspace = init_db_opts_workspace(xopts)
845-
limit = opts.delete(:limit) || 100
846-
offset = opts.delete(:offset) || 0
847-
848-
ret = {}
849-
ret[:creds] = []
850-
::Mdm::Cred.find(:all, :include => {:service => :host}, :conditions => ["hosts.workspace_id = ?",
851-
framework.db.workspace.id ], :limit => limit, :offset => offset).each do |c|
852-
cred = {}
853-
cred[:host] = c.service.host.address if(c.service.host)
854-
cred[:updated_at] = c.updated_at.to_i
855-
cred[:port] = c.service.port
856-
cred[:proto] = c.service.proto
857-
cred[:sname] = c.service.name
858-
cred[:type] = c.ptype
859-
cred[:user] = c.user
860-
cred[:pass] = c.pass
861-
cred[:active] = c.active
862-
ret[:creds] << cred
863-
end
864-
ret
865-
}
866-
end
867856

868857
def rpc_import_data(xopts)
869858
::ActiveRecord::Base.connection_pool.with_connection {

0 commit comments

Comments
 (0)