@@ -4,6 +4,9 @@ module RPC
4
4
class RPC_Db < RPC_Base
5
5
6
6
private
7
+
8
+ include Metasploit ::Credential ::Creation
9
+
7
10
def db
8
11
self . framework . db . active
9
12
end
@@ -15,6 +18,21 @@ def find_workspace(wspace = nil)
15
18
self . framework . db . workspace
16
19
end
17
20
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
+
18
36
def fix_options ( opts )
19
37
newopts = { }
20
38
opts . each do |k , v |
@@ -88,6 +106,40 @@ def init_db_opts_workspace(xopts)
88
106
89
107
public
90
108
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
+
91
143
def rpc_hosts ( xopts )
92
144
::ActiveRecord ::Base . connection_pool . with_connection {
93
145
opts , wspace = init_db_opts_workspace ( xopts )
@@ -490,33 +542,6 @@ def rpc_notes(xopts)
490
542
}
491
543
end
492
544
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
-
520
545
def rpc_get_ref ( name )
521
546
::ActiveRecord ::Base . connection_pool . with_connection {
522
547
db_check
@@ -828,42 +853,6 @@ def rpc_loots(xopts)
828
853
}
829
854
end
830
855
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
867
856
868
857
def rpc_import_data ( xopts )
869
858
::ActiveRecord ::Base . connection_pool . with_connection {
0 commit comments