diff --git a/nselib/dnsbl.lua b/nselib/dnsbl.lua index 5f403c5d2..7b3b33b03 100644 --- a/nselib/dnsbl.lua +++ b/nselib/dnsbl.lua @@ -694,10 +694,12 @@ Helper = { end repeat - condvar "wait" for t in pairs(threads) do if ( coroutine.status(t) == "dead" ) then threads[t] = nil end end + if ( next(threads) ) then + condvar "wait" + end until( next(threads) == nil ) for name, answer in pairs(answers) do diff --git a/scripts/broadcast-dhcp-discover.nse b/scripts/broadcast-dhcp-discover.nse index 7b45f8461..234de1bf4 100644 --- a/scripts/broadcast-dhcp-discover.nse +++ b/scripts/broadcast-dhcp-discover.nse @@ -192,10 +192,12 @@ action = function() -- wait until all threads are done repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil local response = {} diff --git a/scripts/broadcast-dhcp6-discover.nse b/scripts/broadcast-dhcp6-discover.nse index 09f0a2c11..71eaf5fc4 100644 --- a/scripts/broadcast-dhcp6-discover.nse +++ b/scripts/broadcast-dhcp6-discover.nse @@ -104,12 +104,14 @@ action = function(host, port) -- wait until the probes are all done repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil return stdnse.format_output(true, result) diff --git a/scripts/broadcast-eigrp-discovery.nse b/scripts/broadcast-eigrp-discovery.nse index 30130f375..9d6f78732 100644 --- a/scripts/broadcast-eigrp-discovery.nse +++ b/scripts/broadcast-eigrp-discovery.nse @@ -251,10 +251,12 @@ action = function() local condvar = nmap.condvar(astab) -- Wait for the listening threads to finish repeat - condvar("wait") - for thread in pairs(lthreads) do - if coroutine.status(thread) == "dead" then lthreads[thread] = nil end - end + for thread in pairs(lthreads) do + if coroutine.status(thread) == "dead" then lthreads[thread] = nil end + end + if ( next(lthreads) ) then + condvar("wait") + end until next(lthreads) == nil; if #astab > 0 then diff --git a/scripts/broadcast-igmp-discovery.nse b/scripts/broadcast-igmp-discovery.nse index cf8b3be07..8d4d13712 100644 --- a/scripts/broadcast-igmp-discovery.nse +++ b/scripts/broadcast-igmp-discovery.nse @@ -309,10 +309,12 @@ action = function(host, port) local condvar = nmap.condvar(responses) -- Wait for the listening threads to finish repeat - condvar("wait") for thread in pairs(lthreads) do if coroutine.status(thread) == "dead" then lthreads[thread] = nil end end + if ( next(lthreads) ) then + condvar("wait") + end until next(lthreads) == nil; -- Output useful info from the responses diff --git a/scripts/broadcast-listener.nse b/scripts/broadcast-listener.nse index 3f5d68fe2..303bcf660 100644 --- a/scripts/broadcast-listener.nse +++ b/scripts/broadcast-listener.nse @@ -265,12 +265,14 @@ action = function() -- wait for all threads to finish sniffing repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil local out_outer = {} diff --git a/scripts/broadcast-pc-duo.nse b/scripts/broadcast-pc-duo.nse index 00017d6b5..c1cd61c64 100644 --- a/scripts/broadcast-pc-duo.nse +++ b/scripts/broadcast-pc-duo.nse @@ -113,12 +113,14 @@ action = function() -- wait until the probes are all done repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil table.sort(responses, function(a,b) return a.name < b.name end) diff --git a/scripts/broadcast-ping.nse b/scripts/broadcast-ping.nse index decf8d134..d43072a10 100644 --- a/scripts/broadcast-ping.nse +++ b/scripts/broadcast-ping.nse @@ -255,10 +255,12 @@ action = function() end repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil -- generate output diff --git a/scripts/broadcast-wsdd-discover.nse b/scripts/broadcast-wsdd-discover.nse index 112cc5944..e2f153592 100644 --- a/scripts/broadcast-wsdd-discover.nse +++ b/scripts/broadcast-wsdd-discover.nse @@ -86,11 +86,13 @@ action = function() local done -- wait for all threads to finish while( not(done) ) do - condvar("wait") done = true for thread in pairs(threads) do if (coroutine.status(thread) ~= "dead") then done = false end end + if ( not(done) ) then + condvar("wait") + end end if ( results ) then diff --git a/scripts/dns-brute.nse b/scripts/dns-brute.nse index 767098be2..fff11ceed 100644 --- a/scripts/dns-brute.nse +++ b/scripts/dns-brute.nse @@ -235,11 +235,13 @@ action = function(host) local done -- wait for all threads to finish while( not(done) ) do - condvar("wait") done = true for thread in pairs(threads) do if (coroutine.status(thread) ~= "dead") then done = false end end + if ( not(done) ) then + condvar("wait") + end end if(dosrv) then @@ -257,11 +259,13 @@ action = function(host) local done -- wait for all threads to finish while( not(done) ) do - condvar("wait") done = true for thread in pairs(threads) do if (coroutine.status(thread) ~= "dead") then done = false end end + if ( not(done) ) then + condvar("wait") + end end end diff --git a/scripts/dns-ip6-arpa-scan.nse b/scripts/dns-ip6-arpa-scan.nse index 2f757b899..580c5541a 100644 --- a/scripts/dns-ip6-arpa-scan.nse +++ b/scripts/dns-ip6-arpa-scan.nse @@ -80,10 +80,12 @@ action = function() local condvar = nmap.condvar(result) repeat - condvar "wait" for t in pairs(threads) do if ( coroutine.status(t) == "dead" ) then threads[t] = nil end end + if ( next(threads) ) then + condvar "wait" + end until( next(threads) == nil ) if ( 0 == #result ) then diff --git a/scripts/dns-srv-enum.nse b/scripts/dns-srv-enum.nse index e4eaa8282..a1fc7631c 100644 --- a/scripts/dns-srv-enum.nse +++ b/scripts/dns-srv-enum.nse @@ -167,10 +167,12 @@ action = function(host) local condvar = nmap.condvar(result) repeat - condvar "wait" for t in pairs(threads) do if ( coroutine.status(t) == "dead" ) then threads[t] = nil end end + if ( next(threads) ) then + condvar "wait" + end until( next(threads) == nil ) table.sort(result, function(a,b) return a.name < b.name end) diff --git a/scripts/http-slowloris.nse b/scripts/http-slowloris.nse index 9d1adaa8e..19ddfb5fb 100644 --- a/scripts/http-slowloris.nse +++ b/scripts/http-slowloris.nse @@ -239,7 +239,6 @@ local function worker_scheduler(host, port) while not DOSed and not StopAll do -- keep creating new threads, in case we want to run the attack indefinitely repeat - condvar("wait") if StopAll then return end @@ -252,6 +251,9 @@ local function worker_scheduler(host, port) stdnse.print_debug(SCRIPT_NAME .. " [SCHEDULER]: starting new thread") local co = stdnse.new_thread(do_half_http, host, port, obj) Threads[co] = true + if ( next(Threads) ) then + condvar("wait") + end until next(Threads) == nil; end end diff --git a/scripts/krb5-enum-users.nse b/scripts/krb5-enum-users.nse index 252f1637e..a44a0f558 100644 --- a/scripts/krb5-enum-users.nse +++ b/scripts/krb5-enum-users.nse @@ -389,10 +389,12 @@ action = function( host, port ) -- wait for all threads to finish up repeat - condvar "wait" for t in pairs(threads) do if ( coroutine.status(t) == "dead" ) then threads[t] = nil end end + if ( next(threads) ) then + condvar "wait" + end until( next(threads) == nil ) if ( #result > 0 ) then diff --git a/scripts/lltd-discovery.nse b/scripts/lltd-discovery.nse index ad91e6d22..8086d7b6b 100644 --- a/scripts/lltd-discovery.nse +++ b/scripts/lltd-discovery.nse @@ -308,10 +308,12 @@ action = function() end repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil -- generate output diff --git a/scripts/rpc-grind.nse b/scripts/rpc-grind.nse index 28f7e04e9..38506879f 100644 --- a/scripts/rpc-grind.nse +++ b/scripts/rpc-grind.nse @@ -237,12 +237,14 @@ action = function(host, port) local condvar = nmap.condvar(result) repeat - condvar "wait"; for thread in pairs(lthreads) do if coroutine.status(thread) == "dead" then lthreads[thread] = nil end end + if ( next(lthreads) ) then + condvar "wait"; + end until next(lthreads) == nil; -- Check the result and set the port version. diff --git a/scripts/rtsp-url-brute.nse b/scripts/rtsp-url-brute.nse index b8683e70d..876b7d3c9 100644 --- a/scripts/rtsp-url-brute.nse +++ b/scripts/rtsp-url-brute.nse @@ -125,10 +125,12 @@ action = function(host, port) end repeat - condvar "wait" for t in pairs(threads) do if ( coroutine.status(t) == "dead" ) then threads[t] = nil end end + if ( next(threads) ) then + condvar "wait" + end until( next(threads) == nil ) -- urls that could not be retrieved due to low level errors, such as diff --git a/scripts/targets-ipv6-multicast-echo.nse b/scripts/targets-ipv6-multicast-echo.nse index 35e3c244e..e19000641 100644 --- a/scripts/targets-ipv6-multicast-echo.nse +++ b/scripts/targets-ipv6-multicast-echo.nse @@ -169,10 +169,12 @@ action = function() end repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil return format_output(results) diff --git a/scripts/targets-ipv6-multicast-invalid-dst.nse b/scripts/targets-ipv6-multicast-invalid-dst.nse index d59de7e49..03af23fb6 100644 --- a/scripts/targets-ipv6-multicast-invalid-dst.nse +++ b/scripts/targets-ipv6-multicast-invalid-dst.nse @@ -201,10 +201,12 @@ action = function() end repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil return format_output(results) diff --git a/scripts/targets-ipv6-multicast-mld.nse b/scripts/targets-ipv6-multicast-mld.nse index 2fde34a23..a5d25de9b 100644 --- a/scripts/targets-ipv6-multicast-mld.nse +++ b/scripts/targets-ipv6-multicast-mld.nse @@ -166,10 +166,12 @@ action = function() end repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil return format_output(results) diff --git a/scripts/targets-ipv6-multicast-slaac.nse b/scripts/targets-ipv6-multicast-slaac.nse index 0b0a660ed..a1ea20fb7 100644 --- a/scripts/targets-ipv6-multicast-slaac.nse +++ b/scripts/targets-ipv6-multicast-slaac.nse @@ -251,10 +251,12 @@ action = function() end repeat - condvar "wait" for thread in pairs(threads) do if coroutine.status(thread) == "dead" then threads[thread] = nil end end + if ( next(threads) ) then + condvar "wait" + end until next(threads) == nil return format_output(results) diff --git a/scripts/wsdd-discover.nse b/scripts/wsdd-discover.nse index d749106dd..c656d9314 100644 --- a/scripts/wsdd-discover.nse +++ b/scripts/wsdd-discover.nse @@ -75,11 +75,13 @@ action = function(host, port) local done -- wait for all threads to finish while( not(done) ) do - condvar("wait") done = true for thread in pairs(threads) do if (coroutine.status(thread) ~= "dead") then done = false end end + if ( not(done) ) then + condvar("wait") + end end if ( results ) then