From 41e8de7673d9bed8749e9ba404d03893f6becbc2 Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 5 Oct 2026 15:44:26 +0000 Subject: [PATCH] Fix some unrequired-library warnings --- nselib/data/psexec/backdoor.lua | 30 +++-- nselib/data/psexec/drives.lua | 74 ++++++------ nselib/data/psexec/examples.lua | 107 +++++++++--------- nselib/data/psexec/network.lua | 192 ++++++++++++++++---------------- nselib/data/psexec/pwdump.lua | 68 ++++++----- nselib/dicom.lua | 4 +- nselib/packet.lua | 1 + scripts/dicom-cfind-ls.nse | 1 + scripts/dicom-get.nse | 1 + scripts/dicom-store-fuzzer.nse | 1 + 10 files changed, 237 insertions(+), 242 deletions(-) diff --git a/nselib/data/psexec/backdoor.lua b/nselib/data/psexec/backdoor.lua index 47f0d2318..70d61a9e0 100644 --- a/nselib/data/psexec/backdoor.lua +++ b/nselib/data/psexec/backdoor.lua @@ -9,19 +9,17 @@ overrides = {} --overrides.timeout = 40 -modules = {} -local mod - --- TODO: allow the user to specify parameters ---Note: password can't be longer than 14-characters, otherwise the program pauses for --- a response -mod = {} -mod.upload = false -mod.name = "Adding a user account: $username/$password" -mod.program = "net" -mod.args = "user $username $password /add" -mod.maxtime = 2 -mod.noblank = true -mod.req_args = {'username','password'} -table.insert(modules, mod) - +modules = { + { + -- TODO: allow the user to specify parameters + --Note: password can't be longer than 14-characters, otherwise the program pauses for + -- a response + upload = false, + name = "Adding a user account: $username/$password", + program = "net", + args = "user $username $password /add", + maxtime = 2, + noblank = true, + req_args = {'username','password'}, + }, +} diff --git a/nselib/data/psexec/drives.lua b/nselib/data/psexec/drives.lua index 22728215c..89df042fb 100644 --- a/nselib/data/psexec/drives.lua +++ b/nselib/data/psexec/drives.lua @@ -6,44 +6,42 @@ overrides = {} --overrides.timeout = 40 -modules = {} -local mod +modules = { + { + upload = false, + name = "Drive type", + program = "fsutil", + args = "fsinfo drivetype $drive", + req_args = {"drive"}, + maxtime = 1, + }, -mod = {} -mod.upload = false -mod.name = "Drive type" -mod.program = "fsutil" -mod.args = "fsinfo drivetype $drive" -mod.req_args = {"drive"} -mod.maxtime = 1 -table.insert(modules, mod) + { + upload = false, + name = "Drive info", + program = "fsutil", + args = "fsinfo ntfsinfo $drive", + req_args = {"drive"}, + replace = {{" :",":"}}, + maxtime = 1, + }, -mod = {} -mod.upload = false -mod.name = "Drive info" -mod.program = "fsutil" -mod.args = "fsinfo ntfsinfo $drive" -mod.req_args = {"drive"} -mod.replace = {{" :",":"}} -mod.maxtime = 1 -table.insert(modules, mod) - -mod = {} -mod.upload = false -mod.name = "Drive type" -mod.program = "fsutil" -mod.args = "fsinfo statistics $drive" -mod.req_args = {"drive"} -mod.replace = {{" :",":"}} -mod.maxtime = 1 -table.insert(modules, mod) - -mod = {} -mod.upload = false -mod.name = "Drive quota" -mod.program = "fsutil" -mod.args = "quota query $drive" -mod.req_args = {"drive"} -mod.maxtime = 1 -table.insert(modules, mod) + { + upload = false, + name = "Drive type", + program = "fsutil", + args = "fsinfo statistics $drive", + req_args = {"drive"}, + replace = {{" :",":"}}, + maxtime = 1, + }, + { + upload = false, + name = "Drive quota", + program = "fsutil", + args = "quota query $drive", + req_args = {"drive"}, + maxtime = 1, + }, +} diff --git a/nselib/data/psexec/examples.lua b/nselib/data/psexec/examples.lua index 8e15df4b9..6cfd4ec26 100644 --- a/nselib/data/psexec/examples.lua +++ b/nselib/data/psexec/examples.lua @@ -6,63 +6,62 @@ overrides = {} overrides.timeout = 40 -modules = {} -local mod +modules = { -mod = {} -mod.upload = false -mod.name = "Membership of 'administrators' from 'net localgroup administrators'" -mod.program = "net.exe" -mod.args = "localgroup administrators" -table.insert(modules, mod) + { + upload = false, + name = "Membership of 'administrators' from 'net localgroup administrators'", + program = "net.exe", + args = "localgroup administrators", + }, -mod = {} -mod.upload = false -mod.name = "Example 2: Membership of 'administrators', cleaned" -mod.program = "net.exe" -mod.args = "localgroup administrators" -mod.remove = {"The command completed", "%-%-%-%-%-%-%-%-%-%-%-", "Members", "Alias name", "Comment"} -mod.noblank = true -table.insert(modules, mod) + { + upload = false, + name = "Example 2: Membership of 'administrators', cleaned", + program = "net.exe", + args = "localgroup administrators", + remove = {"The command completed", "%-%-%-%-%-%-%-%-%-%-%-", "Members", "Alias name", "Comment"}, + noblank = true, + }, -mod = {} -mod.upload = false -mod.name = "Example 3: IP Address and MAC Address" -mod.program = "ipconfig.exe" -mod.args = "/all" -mod.maxtime = 1 -mod.find = {"IP Address", "Physical Address", "Ethernet adapter"} -mod.replace = {{"%. ", ""}, {"-", ":"}, {"Physical Address", "MAC Address"}} -table.insert(modules, mod) + { + upload = false, + name = "Example 3: IP Address and MAC Address", + program = "ipconfig.exe", + args = "/all", + maxtime = 1, + find = {"IP Address", "Physical Address", "Ethernet adapter"}, + replace = {{"%. ", ""}, {"-", ":"}, {"Physical Address", "MAC Address"}}, + }, -mod = {} -mod.upload = false -mod.name = "Example 4: Can the host ping our address?" -mod.program = "ping.exe" -mod.args = "$lhost" -mod.remove = {"statistics", "Packet", "Approximate", "Minimum"} -mod.noblank = true -mod.env = "SystemRoot=c:\\WINDOWS" -table.insert(modules, mod) + { + upload = false, + name = "Example 4: Can the host ping our address?", + program = "ping.exe", + args = "$lhost", + remove = {"statistics", "Packet", "Approximate", "Minimum"}, + noblank = true, + env = "SystemRoot=c:\\WINDOWS", + }, -mod = {} -mod.upload = false -mod.name = "Example 5: Can the host ping $host?" -mod.program = "ping.exe" -mod.args = "$host" -mod.remove = {"statistics", "Packet", "Approximate", "Minimum"} -mod.noblank = true -mod.env = "SystemRoot=c:\\WINDOWS" -mod.req_args = {'host'} -table.insert(modules, mod) - -mod = {} -mod.upload = true -mod.name = "Example 6: FgDump" -mod.program = "fgdump.exe" -mod.args = "-c -l fgdump.log" -mod.url = "http://www.foofus.net/fizzgig/fgdump/" -mod.tempfiles = {"fgdump.log"} -mod.outfile = "127.0.0.1.pwdump" -table.insert(modules, mod) + { + upload = false, + name = "Example 5: Can the host ping $host?", + program = "ping.exe", + args = "$host", + remove = {"statistics", "Packet", "Approximate", "Minimum"}, + noblank = true, + env = "SystemRoot=c:\\WINDOWS", + req_args = {'host'}, + }, + { + upload = true, + name = "Example 6: FgDump", + program = "fgdump.exe", + args = "-c -l fgdump.log", + url = "http://www.foofus.net/fizzgig/fgdump/", + tempfiles = {"fgdump.log"}, + outfile = "127.0.0.1.pwdump", + }, +} diff --git a/nselib/data/psexec/network.lua b/nselib/data/psexec/network.lua index 316cd3bc7..6632a35f3 100644 --- a/nselib/data/psexec/network.lua +++ b/nselib/data/psexec/network.lua @@ -6,108 +6,106 @@ overrides = {} --overrides.timeout = 40 -modules = {} -local mod +modules = { --- Grab the ip and mac address(es) from ipconfig. The output requires quite a bit of cleanup --- to end up being usable and pretty. -mod = {} -mod.upload = false -mod.name = "IP Address and MAC Address from 'ipconfig.exe'" -mod.program = "ipconfig.exe" -mod.args = "/all" -mod.maxtime = 1 -mod.find = {"IP Address", "Physical Address", "Ethernet adapter"} -mod.replace = {{"%. ", ""}, {"-", ":"}, {"Physical Address", "MAC Address"}} -table.insert(modules, mod) + -- Grab the ip and mac address(es) from ipconfig. The output requires quite a bit of cleanup + -- to end up being usable and pretty. + { + upload = false, + name = "IP Address and MAC Address from 'ipconfig.exe'", + program = "ipconfig.exe", + args = "/all", + maxtime = 1, + find = {"IP Address", "Physical Address", "Ethernet adapter"}, + replace = {{"%. ", ""}, {"-", ":"}, {"Physical Address", "MAC Address"}}, + }, --- Dump the arp cache of the system. -mod = {} -mod.name = "ARP Cache from arp.exe" -mod.program = 'arp.exe' -mod.upload = false -mod.args = '-a' -mod.remove = "Interface" -mod.noblank = true -table.insert(modules, mod) + -- Dump the arp cache of the system. + { + name = "ARP Cache from arp.exe", + program = 'arp.exe', + upload = false, + args = '-a', + remove = "Interface", + noblank = true, + }, --- Get the listening/connected ports -mod = {} -mod.upload = false -mod.name = "List of listening and established connections (netstat -an)" -mod.program = "netstat" -mod.args = "-anb" -mod.maxtime = 1 -mod.remove = {"Active"} -mod.noblank = true -mod.env = "SystemRoot=c:\\WINDOWS" -table.insert(modules, mod) + -- Get the listening/connected ports + { + upload = false, + name = "List of listening and established connections (netstat -an)", + program = "netstat", + args = "-anb", + maxtime = 1, + remove = {"Active"}, + noblank = true, + env = "SystemRoot=c:\\WINDOWS", + }, --- Get the routing table. --- --- Like 'ver', this has to be run through cmd.exe. This also requires the 'PATH' variable to be --- set properly, so it isn't going to work against systems with odd paths. -mod = {} -mod.upload = false -mod.name = "Full routing table from 'netstat -nr'" -mod.program = "cmd.exe" -mod.args = "/c \"netstat -nr\"" -mod.env = "PATH=C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINNT;C:\\WINNT\\system32" -mod.maxtime = 1 -mod.noblank = true -table.insert(modules, mod) + -- Get the routing table. + -- + -- Like 'ver', this has to be run through cmd.exe. This also requires the 'PATH' variable to be + -- set properly, so it isn't going to work against systems with odd paths. + { + upload = false, + name = "Full routing table from 'netstat -nr'", + program = "cmd.exe", + args = "/c \"netstat -nr\"", + env = "PATH=C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINNT;C:\\WINNT\\system32", + maxtime = 1, + noblank = true, + }, --- Try and ping back to our host. This helps check if there's a firewall in the way for connecting backwards. --- Interestingly, in my tests against Windows 2003, ping gives weird output (but still, more or less, worked) --- when the SystemRoot environmental variable wasn't set. -mod = {} -mod.upload = false -mod.name = "Can the host ping our address?" -mod.program = "ping" -mod.args = "-n 1 $lhost" -mod.maxtime = 5 -mod.remove = {"statistics", "Packet", "Approximate", "Minimum"} -mod.noblank = true -mod.env = "SystemRoot=c:\\WINDOWS" -table.insert(modules, mod) + -- Try and ping back to our host. This helps check if there's a firewall in the way for connecting backwards. + -- Interestingly, in my tests against Windows 2003, ping gives weird output (but still, more or less, worked) + -- when the SystemRoot environmental variable wasn't set. + { + upload = false, + name = "Can the host ping our address?", + program = "ping", + args = "-n 1 $lhost", + maxtime = 5, + remove = {"statistics", "Packet", "Approximate", "Minimum"}, + noblank = true, + env = "SystemRoot=c:\\WINDOWS", + }, --- Try a traceroute back to our host. I limited it to the first 5 hops in the interest of saving time. --- Like ping, if the SystemRoot variable isn't set, the output is a bit strange (but still works) -mod = {} -mod.upload = false -mod.name = "Traceroute back to the scanner" -mod.program = "tracert" -mod.args = "-d -h 5 $lhost" -mod.maxtime = 20 -mod.remove = {"Tracing route", "Trace complete"} -mod.noblank = true -mod.env = "SystemRoot=c:\\WINDOWS" -table.insert(modules, mod) - --- Ping an arbitrary address given by the user -mod = {} -mod.upload = false -mod.name = "Can the host ping $address?" -mod.program = "ping" -mod.args = "-n 1 $address" -mod.req_args = {'address'} -mod.maxtime = 5 -mod.remove = {"statistics", "Packet", "Approximate", "Minimum"} -mod.noblank = true -mod.env = "SystemRoot=c:\\WINDOWS" -table.insert(modules, mod) - --- Try a traceroute to an address given by the user -mod = {} -mod.upload = false -mod.name = "Traceroute to $address (5 hops or less)" -mod.program = "tracert" -mod.args = "-d -h 5 $address" -mod.req_args = {'address'} -mod.maxtime = 20 -mod.remove = {"Tracing route", "Trace complete"} -mod.noblank = true -mod.env = "SystemRoot=c:\\WINDOWS" -table.insert(modules, mod) + -- Try a traceroute back to our host. I limited it to the first 5 hops in the interest of saving time. + -- Like ping, if the SystemRoot variable isn't set, the output is a bit strange (but still works) + { + upload = false, + name = "Traceroute back to the scanner", + program = "tracert", + args = "-d -h 5 $lhost", + maxtime = 20, + remove = {"Tracing route", "Trace complete"}, + noblank = true, + env = "SystemRoot=c:\\WINDOWS", + }, + -- Ping an arbitrary address given by the user + { + upload = false, + name = "Can the host ping $address?", + program = "ping", + args = "-n 1 $address", + req_args = {'address'}, + maxtime = 5, + remove = {"statistics", "Packet", "Approximate", "Minimum"}, + noblank = true, + env = "SystemRoot=c:\\WINDOWS", + }, + -- Try a traceroute to an address given by the user + { + upload = false, + name = "Traceroute to $address (5 hops or less)", + program = "tracert", + args = "-d -h 5 $address", + req_args = {'address'}, + maxtime = 20, + remove = {"Tracing route", "Trace complete"}, + noblank = true, + env = "SystemRoot=c:\\WINDOWS", + }, +} diff --git a/nselib/data/psexec/pwdump.lua b/nselib/data/psexec/pwdump.lua index 3ec256d20..dcc81b830 100644 --- a/nselib/data/psexec/pwdump.lua +++ b/nselib/data/psexec/pwdump.lua @@ -9,44 +9,42 @@ overrides = {} --overrides.timeout = 40 -modules = {} -local mod +modules = { ---mod = {} ---mod.upload = true ---mod.name = "PwDump6 2.0.0" ---mod.program = "PwDump.exe" ---mod.args = "localhost" ---mod.maxtime = 10 ---mod.include_stderr = false ---mod.url = "http://www.foofus.net/fizzgig/pwdump/" ---table.insert(modules, mod) +--{ +--upload = true, +--name = "PwDump6 2.0.0", +--program = "PwDump.exe", +--args = "localhost", +--maxtime = 10, +--include_stderr = false, +--url = "http://www.foofus.net/fizzgig/pwdump/", +--}, ---Uncomment if you'd like to use PwDump6 1.7.2 (considered obsolete, but still works). -- Note that for some reason, this and 'fgdump' don't get along (fgdump only produces a blank -- file if these are run together) ---mod = {} ---mod.upload = true ---mod.name = "PwDump6 1.7.2" ---mod.program = "PwDump-1.7.2.exe" ---mod.args = "localhost" ---mod.maxtime = 10 ---mod.include_stderr = false ---mod.extrafiles = {"servpw.exe", "lsremora.dll"} ---mod.url = "http://www.foofus.net/fizzgig/pwdump/" ---table.insert(modules, mod) - --- Warning: the danger of using fgdump is that it always write the output to the harddrive unencrypted; --- this makes it more obvious that an attack has occurred. -mod = {} -mod.upload = true -mod.name = "FgDump" -mod.program = "fgdump.exe" -mod.args = "-c -l fgdump.log" -mod.maxtime = 10 -mod.url = "http://www.foofus.net/fizzgig/fgdump/" -mod.tempfiles = {"fgdump.log"} -mod.outfile = "127.0.0.1.pwdump" -table.insert(modules, mod) - +--{ +--upload = true, +--name = "PwDump6 1.7.2", +--program = "PwDump-1.7.2.exe", +--args = "localhost", +--maxtime = 10, +--include_stderr = false, +--extrafiles = {"servpw.exe", "lsremora.dll"}, +--url = "http://www.foofus.net/fizzgig/pwdump/", +--}, + -- Warning: the danger of using fgdump is that it always write the output to the harddrive unencrypted; + -- this makes it more obvious that an attack has occurred. + { + upload = true, + name = "FgDump", + program = "fgdump.exe", + args = "-c -l fgdump.log", + maxtime = 10, + url = "http://www.foofus.net/fizzgig/fgdump/", + tempfiles = {"fgdump.log"}, + outfile = "127.0.0.1.pwdump", + }, +} diff --git a/nselib/dicom.lua b/nselib/dicom.lua index e6e8e3d2d..25501ce9f 100644 --- a/nselib/dicom.lua +++ b/nselib/dicom.lua @@ -55,8 +55,8 @@ local stdnse = require "stdnse" local string = require "string" local table = require "table" local math = require "math" -local io = io -local os = os +local io = require "io" +local os = require "os" _ENV = stdnse.module("dicom", stdnse.seeall) diff --git a/nselib/packet.lua b/nselib/packet.lua index 6ef3bc601..3a0755d86 100644 --- a/nselib/packet.lua +++ b/nselib/packet.lua @@ -8,6 +8,7 @@ local ipOps = require "ipOps" local stdnse = require "stdnse" local string = require "string" local tableaux = require "tableaux" +local table = require "table" local unittest = require "unittest" _ENV = stdnse.module("packet", stdnse.seeall) diff --git a/scripts/dicom-cfind-ls.nse b/scripts/dicom-cfind-ls.nse index a54370176..0bfa767b2 100644 --- a/scripts/dicom-cfind-ls.nse +++ b/scripts/dicom-cfind-ls.nse @@ -98,6 +98,7 @@ local string = require "string" local table = require "table" local math = require "math" local dicom = require "dicom" +local os = require "os" -- Verify we have the enhanced library (not Nmap's built-in minimal version) assert(dicom.explicit_elem, diff --git a/scripts/dicom-get.nse b/scripts/dicom-get.nse index 2345af2fb..0e22105b7 100644 --- a/scripts/dicom-get.nse +++ b/scripts/dicom-get.nse @@ -97,6 +97,7 @@ local nmap = require "nmap" local string = require "string" local math = require "math" local dicom = require "dicom" +local os = require "os" portrule = shortport.port_or_service({104, 2762, 11112, 4242}, "dicom", "tcp", "open") diff --git a/scripts/dicom-store-fuzzer.nse b/scripts/dicom-store-fuzzer.nse index d9a81a063..12afa8473 100644 --- a/scripts/dicom-store-fuzzer.nse +++ b/scripts/dicom-store-fuzzer.nse @@ -119,6 +119,7 @@ local math = require "math" local io = require "io" local json = require "json" local dicom = require "dicom" +local os = require "os" portrule = shortport.port_or_service({104, 2762, 11112, 4242}, "dicom", "tcp", "open")