Nmap Development mailing list archives

Re: Current NSE script errors


From: Ron <ron () skullsecurity net>
Date: Sat, 23 Jan 2010 12:17:41 -0600

On 01/23/2010 11:53 AM, Patrik Karlsson wrote:
I've had a look at the error in afp-showmount and it occurs when the script fails to authenticate to the AFP server. 
This then triggers the catch that dumps the error message back from the script, which really was my intention. This brings 
me to my question.

Currently this is what I have in the afp-showmount script:

response = try( afp.fp_login( socket, "AFP3.1", "No User Authent") )

This means that if fp_login fails the catch method will be called and return the error back while aborting script execution. In 
this case the error was: FPLogin error: 1710030847, which could obviously have been a lot clearer/suitable like "Failed to 
authenticate as Guest".

The next sample piece of code will accomplish the same thing, but fail silently:

status, response = afp.fp_login( socket, "AFP3.1", "No User Authent")

if not status then
     socket:close()
     return
end

What's the preferred/better way of going about this?

//Patrik
--
Patrik Karlsson
http://www.cqure.net

I don't know what the standard/best way of doing this is, but I generally do

if(not(status)) then
    stdnse.print_debug(1, "script-name: error message")
    socket:close()
    return false, "error message"
end

And in main, I do

status, result = do_stuff()
if(not(status))
  if(nmap.debugging() > 0)
    return "ERROR: " .. result
  end
else
  print_result
end


That's sort of my own convention, but I find it works. I abstracted that a bit in format_output(), too.

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


Current thread: