Nmap Development mailing list archives

[NSE][PATCH] make --script-updatedb skip scripts it cannot load instead of failing


From: Sven Klemm <sven () c3d2 de>
Date: Tue, 23 Sep 2008 11:05:44 +0200

Hi everyone,

currently nmap --script-updatedb fails if it cannot load all scripts. With the attached patch it skips scripts it cannot load.

Example output:

./nmap --script-updatedb

Starting Nmap 4.76 ( http://nmap.org ) at 2008-09-23 11:07 CEST
SCRIPT ENGINE: Skipping script './scripts//ssltest.nse' because it produced errors while loading. SCRIPT ENGINE: Skipping script './scripts//SSH-hostkey.nse' because it produced errors while loading.
NSE script database updated successfully.
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.13 seconds


./nmap --script-updatedb -v

Starting Nmap 4.76 ( http://nmap.org ) at 2008-09-23 11:07 CEST
SCRIPT ENGINE: Updating rule database.
SCRIPT ENGINE: Skipping script './scripts//ssltest.nse' because it produced errors while loading.
./scripts//ssltest.nse:2: module 'openssl' not found:
        no field package.preload['openssl']
        no file './nselib/openssl.lua'
        no file './openssl.lua'
        no file '/usr/local/share/lua/5.1/openssl.lua'
        no file '/usr/local/share/lua/5.1/openssl/init.lua'
        no file '/usr/local/lib/lua/5.1/openssl.lua'
        no file '/usr/local/lib/lua/5.1/openssl/init.lua'
        no file './openssl.so'
        no file '/usr/local/lib/lua/5.1/openssl.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
SCRIPT ENGINE: Skipping script './scripts//SSH-hostkey.nse' because it produced errors while loading.
./scripts//SSH-hostkey.nse:35: module 'openssl' not found:
        no field package.preload['openssl']
        no file './nselib/openssl.lua'
        no file './openssl.lua'
        no file '/usr/local/share/lua/5.1/openssl.lua'
        no file '/usr/local/share/lua/5.1/openssl/init.lua'
        no file '/usr/local/lib/lua/5.1/openssl.lua'
        no file '/usr/local/lib/lua/5.1/openssl/init.lua'
        no file './openssl.so'
        no file '/usr/local/lib/lua/5.1/openssl.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
NSE script database updated successfully.
Read data files from: .
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.11 seconds

Cheers,
Sven

--
Sven Klemm
http://cthulhu.c3d2.de/~sven/

Index: nse_init.cc
===================================================================
--- nse_init.cc (revision 10328)
+++ nse_init.cc (working copy)
@@ -410,7 +410,16 @@
         luaL_error(L, "file '%s' could not be loaded", file);
       lua_pushvalue(L, -2); // push environment
       lua_setfenv(L, -2); // set it
-      lua_call(L, 0, 0);
+      if ( lua_pcall(L, 0, 0, NULL) != 0 ) {
+        // skip scripts that produce errors
+        log_write(LOG_STDOUT, "%s: Skipping script '%s' because it produced errors while loading.\n", 
+          SCRIPT_ENGINE, file );
+        SCRIPT_ENGINE_VERBOSE(
+          error("%s", lua_tostring(L, -1));
+        )
+        lua_pop(L, 3);
+        continue;
+      }
 
       lua_getfield(L, -1, "categories");
       if (lua_isnil(L, -1))

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

Current thread: