1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 12:41:29 +00:00

Avoid infinite runtime in snmp-brute due to 'Invalid reuse of a socket' killing send thread.

This commit is contained in:
dmiller
2020-02-18 17:02:39 +00:00
parent 648a08eecf
commit 5d281d0e6e

View File

@@ -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