description = [[ ]] --- -- @usage -- nmap --script pipe -p 80 -- -- @output -- PORT STATE SERVICE REASON -- 80/tcp open http syn-ack -- -- author = "Piotr Olma" license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"discovery", "intrusive"} local shortport = require 'shortport' local http = require 'http' local stdnse = require 'stdnse' local string = require 'string' local table = require 'table' local nmap = require 'nmap' portrule = shortport.port_or_service( {80, 8000, 443}, {"http", "https"}, "tcp", "open") local responses = {} local function add_thread_to_pool(host, port, url) return stdnse.new_thread( (function () local r = http.get(host, port, url, nil) local cvar = nmap.condvar(("%s:%s"):format(stdnse.get_hostname(host),SCRIPT_NAME)) if r.status then responses[url] = r else responses[url] = false end cvar "signal" end) ) end function action(host, port) local reqs = {} for i = 1,320,1 do table.insert(reqs, "/pipe/"..tostring(i)) end local threads = {} for _,r in ipairs(reqs) do threads[#threads+1] = add_thread_to_pool(host, port, r) end local rcount = #reqs local finished = 0 local cvar = nmap.condvar(("%s:%s"):format(stdnse.get_hostname(host),SCRIPT_NAME)) while finished < rcount do cvar "wait" finished = 0 for _, t in ipairs(threads) do if coroutine.status(t) == "dead" then finished = finished + 1 end end stdnse.print_debug("Waiting for %d threads to finish.", rcount - finished) end local i = 0 for u,r in pairs(responses) do stdnse.print_debug("%s --> %s",u, r.body) i=i+1 end stdnse.print_debug("All responses received: %d.",i) return nil end