Home page logo
/

nmap-dev logo Nmap Development mailing list archives

Making Threads Wait for Other Thread's Results
From: "Patrick Donnelly" <batrick.donnelly () gmail com>
Date: Fri, 6 Jun 2008 04:12:42 -0600

Hey guys,

I've formed a solution for the problem discussed in this thread:
http://seclists.org/nmap-dev/2008/q1/0294.html

The problem is threads (coroutines) have no method of entering and
leaving the waiting thread queue except through the nsock library.
This introduces problems for scripts that query a service that may ban
your IP if many threads are making queries for different targets at
the same time.

I'm going to add a function to the nmap library that allows you to
yield the current thread so long as certain conditions are met
(discussed later). The function is passed the Script's ID
(http://nmap.org/book/nse-scripts.html#nse-format-id) in order to
generate a function that allows you to yield your thread. This
function is to be called with string "lock" in order to get a lock for
thread's of that script (similar to a mutex). It should be called
before any "competitive" work is done by each thread. Once this
function returns, you can continue as normal. When your thread is
finished, before returning from main (action), you must release your
lock by calling the function again with the argument "done". It's
functionality will work as follows:

<file>
author = "Patrick"
id = "My script's unique ID"

local my_mutex = nmap.mutex(id);

function action(host, port)
  my_mutex"lock";
  -- Do stuff
  my_mutex"done";
  return script_output;
end
</file>

If you have any comments or questions please ask.

Cheers,

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org


  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]
AlienVault