From fdca963b6192b95fb089b4d536cb6160e16a0168 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Fri, 30 Dec 2016 14:59:31 -0600 Subject: [PATCH] check if the socket exists before closing --- modules/auxiliary/scanner/portscan/tcp.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/auxiliary/scanner/portscan/tcp.rb b/modules/auxiliary/scanner/portscan/tcp.rb index bfe24b14b4..e521c053fd 100644 --- a/modules/auxiliary/scanner/portscan/tcp.rb +++ b/modules/auxiliary/scanner/portscan/tcp.rb @@ -80,8 +80,10 @@ class MetasploitModule < Msf::Auxiliary 'ConnectTimeout' => (timeout / 1000.0) } ) - print_status("#{ip}:#{port} - TCP OPEN") - r << [ip,port,"open"] + if s + print_status("#{ip}:#{port} - TCP OPEN") + r << [ip,port,"open"] + end rescue ::Rex::ConnectionRefused vprint_status("#{ip}:#{port} - TCP closed") r << [ip,port,"closed"] @@ -92,7 +94,9 @@ class MetasploitModule < Msf::Auxiliary rescue ::Exception => e print_error("#{ip}:#{port} exception #{e.class} #{e} #{e.backtrace}") ensure - disconnect(s) rescue nil + if s + disconnect(s) rescue nil + end end end end