@@ -127,6 +127,9 @@ def is_vulnerable?(ip)
127127 ::Rex ::Proto ::SMB ::Exceptions ::InvalidWordCount ,
128128 ::Rex ::Proto ::SMB ::Exceptions ::NoReply => e
129129 elog ( e )
130+ rescue ::Rex ::Proto ::DCERPC ::Exceptions ::Fault => e
131+ elog ( e )
132+ return false
130133 rescue ::Exception => e
131134 if e . to_s =~ /execution expired/i
132135 # So what happens here is that when you trigger the buggy code path, you hit this:
@@ -204,33 +207,34 @@ def maybe_vulnerable?(samba_version)
204207
205208 # Check command
206209 def check_host ( ip )
207- samba_info = ''
210+ @ samba_info = ''
208211 smb_ports = [ 445 , 139 ]
209212 smb_ports . each do |port |
213+ # Update line prefix, as port changes
214+ remove_instance_variable ( :@print_prefix ) if instance_variable_defined? ( :@print_prefix )
210215 @smb_port = port
211- samba_info = get_samba_info
212- vprint_status ( "Samba version: #{ samba_info } " )
216+ @ samba_info = get_samba_info
217+ vprint_status ( "Samba version: #{ @ samba_info} " )
213218
214- if samba_info !~ /^samba/i
219+ if @ samba_info !~ /^samba/i
215220 vprint_status ( "Target isn't Samba, no check will run." )
216221 return Exploit ::CheckCode ::Safe ( 'Target is not running Samba' )
217222 end
218223
219224 if datastore [ 'PASSIVE' ]
220- if maybe_vulnerable? ( samba_info )
221- flag_vuln_host ( ip , samba_info )
225+ if maybe_vulnerable? ( @ samba_info)
226+ flag_vuln_host ( ip , @ samba_info)
222227 return Exploit ::CheckCode ::Appears ( 'Samba version appears to be vulnerable based on version check' )
223228 end
224229 else
225230 # Explicit: Actually triggers the bug
226231 if is_vulnerable? ( ip )
227- flag_vuln_host ( ip , samba_info )
228- return Exploit ::CheckCode ::Vulnerable ( 'Samba uninitialized credential vulnerability confirmed' )
232+ flag_vuln_host ( ip , @samba_info )
229233 end
230234 end
231235 end
232236
233- return Exploit ::CheckCode ::Detected ( 'Samba detected but vulnerability could not be confirmed' ) if samba_info =~ /^samba/i
237+ return Exploit ::CheckCode ::Detected ( 'Samba detected but vulnerability could not be confirmed' ) if @ samba_info =~ /^samba/i
234238
235239 Exploit ::CheckCode ::Safe ( 'Target does not appear to be running Samba' )
236240 end
@@ -249,7 +253,8 @@ def flag_vuln_host(ip, samba_version)
249253
250254 def run_host ( ip )
251255 peer = "#{ ip } :#{ rport } "
252- case check_host ( ip )
256+ result = check_host ( ip )
257+ case result
253258 when Exploit ::CheckCode ::Vulnerable
254259 print_good ( "The target is vulnerable to CVE-2015-0240." )
255260 when Exploit ::CheckCode ::Appears
@@ -259,5 +264,14 @@ def run_host(ip)
259264 else
260265 print_status ( "The target appears to be safe" )
261266 end
267+
268+ report_service (
269+ :host => ip ,
270+ :port => rport ,
271+ :proto => 'tcp' ,
272+ :name => 'smb' ,
273+ :info => @samba_info . to_s
274+ ) if [ Exploit ::CheckCode ::Vulnerable , Exploit ::CheckCode ::Appears , Exploit ::CheckCode ::Detected ] . include? ( result )
262275 end
263276end
277+
0 commit comments