Home page logo

nmap-dev logo Nmap Development mailing list archives

[NSE] Lua implementation merged into Nmap trunk
From: Patrick Donnelly <batrick () batbytes com>
Date: Sun, 5 Apr 2009 02:11:57 -0600

The change from C++ to Lua [1] has been merged (r12887) into the Nmap
trunk. The merge came from the nse-lua-merge [2] branch which is a
watered down version of nse-lua [3]. The features removed in the final
patch from nse-lua were developed with the intention of demonstrating
solutions to known (and some unknown) bugs or problems in NSE. These
features were not directly related to the main intent of the branch --
changing the C++ version of NSE to Lua -- and so will be discussed and
possibly merged separately.

To be specific, the parts of nse-lua which were not merged:

o Host Timeout Management -- Charging a host time for execution only
when threads are actively working on its behalf.
o Coroutine Yields Propagated up to NSE -- When NSE would yield a
thread, the yield would properly propagate back to NSE.
o NSE API -- A variety of functions in the 'nse' namespace which
manipulate NSE or the running threads.
o Host and Port Userdata - Lua userdata that would represent Targets
and individual Ports on the target.

Users should not expect this change to impact their scripts directly;
however, NSE does operate differently in a few significant ways:

o NSE loads immediately when Nmap starts. It first loads and runs
nse_main.lua which will:
  o Load script arguments.
  o Set package.path to include the nselib directory.
  o Load all invariant (across host group scans) chosen by the
categories, directories, or script files (--script). Any problems
loading scripts will cause NSE to immediately exit before any scanning

o NSE now uses the procedures open_nse and close_nse to initialize
NSE's state and destroy it.

o The procedure nse_restore(lua_State *L, int number) is used to
resume a thread that is waiting. It replaces the old
process_waiting2running function. L is the thread and number is the
amount of values on the stack to be resumed.

As noted above, these functional changes do not directly affect script
execution but do affect how NSE operates. Users can expect to see NSE
perform with less baffling errors and with more meaningful debug
output. Because the script engine is now written in Lua, users can
also inspect how the engine actually runs their code. Further, because
nse_main.lua is recompiled across Nmap invocations, a user can
actually change how NSE operates without recompiling Nmap. For
example, one could add more debug output when developing scripts among
other endless possibilities.

Please post here if you have any questions concerning this new
implementation in this thread.

[1] http://seclists.org/nmap-dev/2009/q1/0047.html
[2] svn://svn.insecure.org/nmap-exp/patrick/nse-lua-merge
[3] svn://svn.insecure.org/nmap-exp/patrick/nse-lua

-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
Archived at http://SecLists.Org

  By Date           By Thread  

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