Nmap Development mailing list archives

Re: Bugfixes for smb-psexec


From: Patrick Donnelly <batrick () batbytes com>
Date: Mon, 5 Jul 2010 18:18:41 -0400

Hi Ron,

On Mon, Jul 5, 2010 at 2:41 PM, Ron <ron () skullsecurity net> wrote:
On Mon, 21 Jun 2010 16:12:48 -0600 David Fifield
<david () bamsoftware com> wrote:
It's not particularly clean to grep the first line for the word
"module". Could you redefine the module function to a do-nothing
function, or a function that prints the error message?
I was looking at how to do that, but I don't know how. Batrick, here's the code I'm using, can you tell me what's 
going wrong? I'm out of my Lua element here.

   -- Load the config file
   stdnse.print_debug(1, "smb-psexec: Attempting to load config file: %s", filename)
   local file = loadfile(filename)
   if(not(file)) then
       return false, "Couldn't load module file:\n" .. filename
   end

   -- Run the config file
   local real_module = module

   -- Re-define the module() function temporarily
   module = function()
       io.write("TESTING!\n\n")
   end

   -- Run the code
   file()

   -- Restore the original module() function
   module = real_module

Each function can have its own environment, so you don't need to
change the module function in the global environment. Instead you can
assign an environment that has a custom module function:

local f = loadfile(...)
setfenv(f, setmetatable({module = function() end}, {__index = _G}))
f()

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

Current thread: