Ye Lin Kyaw Random Thoughts

Nmap Script Updatedb

After adding a custom NSE script and updating nmap database, the following error was shown. My nmap was installed from Mac OS X Binary from

$ nmap --script-updatedb
Starting Nmap 6.25 ( ) at 2013-03-29 00:40 SGT
NSE: Updating rule database.
NSE: Failed to load /usr/local/bin/../share/nmap/scripts//sql-injection.nse:
/usr/local/bin/../share/nmap/scripts//sql-injection.nse:44: variable 'shortport' is not declared
stack traceback:
    [C]: in function 'error'
    /usr/local/bin/../share/nmap/nselib/strict.lua:80: in function '__index'
    /usr/local/bin/../share/nmap/scripts//sql-injection.nse:44: in function 
NSE: failed to initialize the script engine:
/usr/local/bin/../share/nmap/nse_main.lua:523: could not load script
stack traceback:
    [C]: in function 'error'
    /usr/local/bin/../share/nmap/nse_main.lua:523: in function 'new'
    /usr/local/bin/../share/nmap/nse_main.lua:1223: in main chunk
    [C]: in ?

I tried to examine the sql-injection.nse and shortport.lua. In sql-injection.nse, the variable shortport is properly import with require(‘shortport’) and I could not find any issues in shortport.lua.

portrule = shortport.port_or_service({80, 443}, {"http","https"})

Normally Lua assumes the name from require statement as the variable. The only way I could try is explicitly declaring the variable for each require statements and giving the same name as the required module. Then I could update properly my nmap scripts database.

local url = require('url')
local shortport = require('shortport')
local stdnse = require('stdnse')
local strbuf = require('strbuf')
local comm = require('comm')
local http = require('http')
local nsedebug = require('nsedebug')
local httpspider = require('httpspider')
comments powered by Disqus