@@ -33,16 +33,31 @@ def report_exploit_attempt(host, opts)
3333 # @option (see #do_report_failure_or_success)
3434 # @return (see #do_report_failure_or_success)
3535 def report_exploit_failure ( opts )
36- return unless opts . has_key? ( :refs ) && !opts [ :refs ] . blank?
37- host = opts [ :host ] || return
36+ return unless opts [ :refs ] . present? && opts [ :host ] . present?
3837
38+ host = opts [ :host ]
3939 wspace = Msf ::Util ::DBManager . process_opts_workspace ( opts , framework )
40- port = opts [ :port ]
41- proto = opts [ :proto ] || Msf ::DBManager ::DEFAULT_SERVICE_PROTO
42- svc = opts [ :service ]
40+ opts = opts . clone ( )
41+ port = opts [ :port ]
42+ proto = opts [ :proto ] || Msf ::DBManager ::DEFAULT_SERVICE_PROTO
43+ svc = opts [ :service ]
44+ rids = opts . delete ( :ref_ids ) || [ ]
45+
46+ opts [ :refs ] . each do |ref |
47+ if ref . instance_of? ( Mdm ::Module ::Ref )
48+ str = ref . name
49+ elsif ( ref . respond_to? ( :ctx_id ) ) && ( ref . respond_to? ( :ctx_val ) )
50+ str = "#{ ref . ctx_id } -#{ ref . ctx_val } "
51+ elsif ( ref . is_a? ( Hash ) && ref [ :ctx_id ] && ref [ :ctx_val ] )
52+ str = "#{ ref [ :ctx_id ] } -#{ ref [ :ctx_val ] } "
53+ elsif ref . is_a? ( String )
54+ str = ref
55+ end
56+ rids << find_or_create_ref ( name : str ) unless str . nil?
57+ end
4358
4459 # Look up the service as appropriate
45- if port and svc . nil?
60+ if port && svc . nil?
4661 # only one result can be returned, as the +port+ field restricts potential results to a single service
4762 svc = services ( :workspace => wspace ,
4863 :hosts => { address : host } ,
@@ -52,19 +67,30 @@ def report_exploit_failure(opts)
5267
5368 # Look up the host as appropriate
5469 if !host || !host . kind_of? ( ::Mdm ::Host )
55- if svc . kind_of? ::Mdm ::Service
70+ if svc & .kind_of? ::Mdm ::Service
5671 host = svc . host
5772 else
5873 host = get_host ( workspace : wspace , address : host )
5974 end
6075 end
6176
6277 # Bail if we dont have a host object
63- return if not host
78+ return unless host
79+
80+ vuln = nil
81+ if rids . present?
82+ if svc
83+ # Try to find an existing vulnerability with the same service & references
84+ vuln = find_vuln_by_refs ( rids , host , svc , false )
85+ else
86+ # Try to find an existing vulnerability with the same host & references
87+ vuln = find_vuln_by_refs ( rids , host , nil , false )
88+ end
89+ end
6490
65- opts = opts . clone ( )
6691 opts [ :service ] = svc
6792 opts [ :host ] = host
93+ opts [ :vuln ] = vuln if vuln
6894
6995 do_report_failure_or_success ( opts )
7096 end
@@ -137,7 +163,7 @@ def do_report_failure_or_success(opts)
137163 ref_objs = ::Mdm ::Ref . where ( name : ref_names )
138164
139165 # Try find a matching vulnerability
140- vuln = find_vuln_by_refs ( ref_objs , host , svc )
166+ vuln = find_vuln_by_refs ( ref_objs , host , svc , false )
141167 end
142168
143169 attempt_info = {
0 commit comments