mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 05:01:29 +00:00
Avoid infinite runtime in snmp-brute due to 'Invalid reuse of a socket' killing send thread.
This commit is contained in:
@@ -180,6 +180,11 @@ local sniff_snmp_responses = function(host, port, lport, result)
|
|||||||
|
|
||||||
-- receive even when status=false until all the probes are sent
|
-- receive even when status=false until all the probes are sent
|
||||||
while true do
|
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()
|
local status, plen, l2, l3, _ = pcap:pcap_receive()
|
||||||
|
|
||||||
if status then
|
if status then
|
||||||
@@ -204,7 +209,7 @@ local sniff_snmp_responses = function(host, port, lport, result)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if last_run then
|
if last_run or not result.status then
|
||||||
condvar "signal"
|
condvar "signal"
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
@@ -236,6 +241,7 @@ action = function(host, port)
|
|||||||
result.sent = false --whether the probes are sent
|
result.sent = false --whether the probes are sent
|
||||||
result.msg = "" -- Error/Status msg
|
result.msg = "" -- Error/Status msg
|
||||||
result.status = true -- Status (is everything ok)
|
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")
|
local socket = nmap.new_socket("udp")
|
||||||
status = socket:connect(host, port)
|
status = socket:connect(host, port)
|
||||||
@@ -257,6 +263,7 @@ action = function(host, port)
|
|||||||
condvar "wait"
|
condvar "wait"
|
||||||
recv_dead = (coroutine.status(recv_co) == "dead")
|
recv_dead = (coroutine.status(recv_co) == "dead")
|
||||||
send_dead = (coroutine.status(send_co) == "dead")
|
send_dead = (coroutine.status(send_co) == "dead")
|
||||||
|
if send_dead then result.sent = true end
|
||||||
if recv_dead then break end
|
if recv_dead then break end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user