From 9849be68a9cef917c2ce53cca8c50251fed7a4ad Mon Sep 17 00:00:00 2001 From: djalal Date: Tue, 17 Aug 2010 01:58:47 +0000 Subject: [PATCH] Use the new get_script_args() function to parse script arguments and clean some whitespaces. --- scripts/nfs-ls.nse | 11 +++++++---- scripts/nfs-showmount.nse | 31 ++++++++++++++++--------------- scripts/nfs-statfs.nse | 29 +++++++++++++++-------------- scripts/rpcinfo.nse | 32 ++++++++++++++++---------------- 4 files changed, 54 insertions(+), 49 deletions(-) diff --git a/scripts/nfs-ls.nse b/scripts/nfs-ls.nse index d23705216..9b0cf129f 100644 --- a/scripts/nfs-ls.nse +++ b/scripts/nfs-ls.nse @@ -80,6 +80,7 @@ author = "Patrik Karlsson, Djalal Harouni" license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"discovery", "safe"} +require 'stdnse' require 'shortport' require 'rpc' require 'tab' @@ -239,13 +240,15 @@ action = function(host, port) { host = host, port = port, - version = nmap.registry.args['nfs.version'] or nil, - maxfiles = tonumber(nmap.registry.args['nfs-ls.maxfiles']) or 10, - time = nmap.registry.args['nfs-ls.time'] or "", - human = nmap.registry.args['nfs-ls.human'] or nil, --recurs = tonumber(nmap.registry.args['nfs-ls.recurs']) or 1, } + nfs_info.version, nfs_info.maxfiles, nfs_info.time, + nfs_info.human = stdnse.get_script_args('nfs.version', + 'nfs-ls.maxfiles','nfs-ls.time','nfs-ls.human') + + nfs_info.maxfiles = tonumber(nfs_info.maxfiles) or 10 + if nfs_info.time == "a" or nfs_info.time == "A" then nfs_info.time = "atime" elseif nfs_info.time == "c" or nfs_info.time == "C" then diff --git a/scripts/nfs-showmount.nse b/scripts/nfs-showmount.nse index 8f1956ef0..84ac84400 100644 --- a/scripts/nfs-showmount.nse +++ b/scripts/nfs-showmount.nse @@ -26,6 +26,7 @@ author = "Patrik Karlsson" license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"discovery", "safe"} +require("stdnse") require("shortport") require("rpc") @@ -33,21 +34,21 @@ portrule = shortport.port_or_service(111, "rpcbind", {"tcp", "udp"} ) action = function(host, port) - local status, mounts, proto - local result = {} - - status, mounts = rpc.Helper.ShowMounts( host, port ) + local status, mounts, proto + local result = {} + + status, mounts = rpc.Helper.ShowMounts( host, port ) - if not status or mounts == nil then - return stdnse.format_output(false, mounts) - end + if not status or mounts == nil then + return stdnse.format_output(false, mounts) + end - for _, v in ipairs( mounts ) do - local entry = v.name - entry = entry .. " " .. stdnse.strjoin(" ", v) - table.insert( result, entry ) - end - - return stdnse.format_output( true, result ) - + for _, v in ipairs( mounts ) do + local entry = v.name + entry = entry .. " " .. stdnse.strjoin(" ", v) + table.insert( result, entry ) + end + + return stdnse.format_output( true, result ) + end diff --git a/scripts/nfs-statfs.nse b/scripts/nfs-statfs.nse index 42c0e76f6..cc57835d0 100644 --- a/scripts/nfs-statfs.nse +++ b/scripts/nfs-statfs.nse @@ -31,6 +31,7 @@ author = "Patrik Karlsson, Djalal Harouni" license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"discovery", "safe"} +require("stdnse") require("shortport") require("rpc") require("tab") @@ -143,29 +144,29 @@ local function nfs_filesystem_info(nfs, mount, filesystem) status, res = table_fsstat(nfs, mount, res) if status then for k, v in pairs(res) do - results[k] = v + results[k] = v end end if nfs_comm.version == 3 then status, res = nfsobj:FsInfo(nfs_comm, fhandle) if status then - status, res = table_fsinfo(nfs, res) - if status then - for k, v in pairs(res) do - results[k] = v - end - end + status, res = table_fsinfo(nfs, res) + if status then + for k, v in pairs(res) do + results[k] = v + end + end end status, res = nfsobj:PathConf(nfs_comm, fhandle) if status then status, res = table_pathconf(nfs, res) - if status then - for k, v in pairs(res) do - results[k] = v - end - end + if status then + for k, v in pairs(res) do + results[k] = v + end + end end end @@ -187,8 +188,8 @@ action = function(host, port) { host = host, port = port, - human = nmap.registry.args['nfs-statfs.human'] or nil, } + nfs_info.human = stdnse.get_script_args('nfs-statfs.human') status, mounts = rpc.Helper.ShowMounts( host, port ) if (not(status)) then @@ -204,5 +205,5 @@ action = function(host, port) end table.insert(o, report(nfs_info, fs_info)) - return stdnse.format_output(true, o) + return stdnse.format_output(true, o) end diff --git a/scripts/rpcinfo.nse b/scripts/rpcinfo.nse index 7f1d11a5e..75e60a022 100644 --- a/scripts/rpcinfo.nse +++ b/scripts/rpcinfo.nse @@ -28,20 +28,20 @@ portrule = shortport.port_or_service(111, "rpcbind", {"tcp", "udp"} ) action = function(host, port) - local result = {} - local status, rpcinfo = rpc.Helper.RpcInfo( host, port ) - - if ( not(status) ) then - return stdnse.format_output(false, rpcinfo) - end - - for progid, v in pairs(rpcinfo) do - for proto, v2 in pairs(v) do - table.insert( result, ("%-7d %-10s %5d/%s %s"):format(progid, stdnse.strjoin(",", v2.version), v2.port, proto, rpc.Util.ProgNumberToName(progid) or "") ) - end - end - - table.sort(result) - return stdnse.format_output( true, result ) - + local result = {} + local status, rpcinfo = rpc.Helper.RpcInfo( host, port ) + + if ( not(status) ) then + return stdnse.format_output(false, rpcinfo) + end + + for progid, v in pairs(rpcinfo) do + for proto, v2 in pairs(v) do + table.insert( result, ("%-7d %-10s %5d/%s %s"):format(progid, stdnse.strjoin(",", v2.version), v2.port, proto, rpc.Util.ProgNumberToName(progid) or "") ) + end + end + + table.sort(result) + return stdnse.format_output( true, result ) + end