From 5d281d0e6ebc9fd8bcc233985641d31f023b7ddd Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 18 Feb 2020 17:02:39 +0000 Subject: [PATCH] Avoid infinite runtime in snmp-brute due to 'Invalid reuse of a socket' killing send thread. --- scripts/snmp-brute.nse | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/snmp-brute.nse b/scripts/snmp-brute.nse index 904cc88f2..450b3ca4a 100644 --- a/scripts/snmp-brute.nse +++ b/scripts/snmp-brute.nse @@ -180,6 +180,11 @@ local sniff_snmp_responses = function(host, port, lport, result) -- receive even when status=false until all the probes are sent while true do + if coroutine.status(result.main_thread) == "dead" then + -- Oops, main thread quit. Time to bail. + return + end + local status, plen, l2, l3, _ = pcap:pcap_receive() if status then @@ -204,7 +209,7 @@ local sniff_snmp_responses = function(host, port, lport, result) return end else - if last_run then + if last_run or not result.status then condvar "signal" return else @@ -236,6 +241,7 @@ action = function(host, port) result.sent = false --whether the probes are sent result.msg = "" -- Error/Status msg result.status = true -- Status (is everything ok) + result.main_thread = coroutine.running() -- to check if the main thread is dead. local socket = nmap.new_socket("udp") status = socket:connect(host, port) @@ -257,6 +263,7 @@ action = function(host, port) condvar "wait" recv_dead = (coroutine.status(recv_co) == "dead") send_dead = (coroutine.status(send_co) == "dead") + if send_dead then result.sent = true end if recv_dead then break end end