Nmap Development mailing list archives

Re: Problem using ~/.nmap/nselib/


From: David Fifield <david () bamsoftware com>
Date: Mon, 19 Sep 2011 17:04:21 -0700

On Mon, Sep 19, 2011 at 07:23:27PM -0400, Patrick Donnelly wrote:
On Mon, Sep 19, 2011 at 6:37 PM, Daniel Miller <bonsaiviking () gmail com> wrote:
Hey list,

I was trying to use the per-user Nmap directory ~/.nmap to test a library,
and I found that, unlike with scripts, Nmap only supports one nselib
directory. It will happily use ~/.nmap/nselib, or $NMAPDIR/nselib, but will
complain that every other NSE library cannot be found. Here is the error as
I see it:

Starting Nmap 5.59BETA3 ( http://nmap.org ) at 2011-09-19 17:24 CDT
Warning: File ./nselib/ exists, but Nmap is using
/home/miller/.nmap/nselib/ for security and consistency reasons.  set
NMAPDIR=. to give priority to files in your local directory (may affect the
other data files too).
NSE: failed to initialize the script engine:
/usr/local/bin/../share/nmap/nse_main.lua:131: module 'stdnse' not found:
   no field package.preload['stdnse']
   no file '/home/miller/.nmap/nselib/stdnse.lua'
   no file './stdnse.lua'
   no file '/usr/local/share/lua/5.1/stdnse.lua'
   no file '/usr/local/share/lua/5.1/stdnse/init.lua'
   no file '/usr/local/lib/lua/5.1/stdnse.lua'
   no file '/usr/local/lib/lua/5.1/stdnse/init.lua'
   no file '/usr/share/lua/5.1/stdnse.lua'
   no file '/usr/share/lua/5.1/stdnse/init.lua'
   no file './stdnse.so'
   no file '/usr/local/lib/lua/5.1/stdnse.so'
   no file '/usr/lib/lua/5.1/stdnse.so'
   no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
   [C]: in function 'require'
   /usr/local/bin/../share/nmap/nse_main.lua:131: in main chunk
   [C]: ?

QUITTING!

Is there a good reason for doing it this way, or should I spend the time to
hunt this down and add the proper locations to the package.path? Or has
someone already looked at this?

Try this patch:

---->8----
Index: nse_main.lua
===================================================================
--- nse_main.lua        (revision 26640)
+++ nse_main.lua        (working copy)
@@ -118,9 +118,16 @@
 local cnse, rules = ...; -- The NSE C library and Script Rules

 do -- Append the nselib directory to the Lua search path
-  local t, path = assert(cnse.fetchfile_absolute("nselib/"));
-  assert(t == "directory", "could not locate nselib directory!");
-  package.path = path.."?.lua;"..package.path;
+  local function loader (lib)
+    local name = "nselib/"..lib..".lua";
+    local type, path = cnse.fetchfile_absolute(name);
+    if type == "file" then
+      return loadfile(path);
+    else
+      return "\n\tNSE failed to find "..name.." in search paths.";
+    end
+  end
+  insert(package.loaders, loader);
 end

 local script_database_type, script_database_path =
----8<----

You can just modify your system nse_main.lua and put it in ~/.nmap.

We should probably commit this to the /trunk though.

Fine with me, if it works.

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

Current thread: