Home page logo
/

nmap-dev logo Nmap Development mailing list archives

Re: Accessing Information Between Scripts
From: Patrick Donnelly <batrick () batbytes com>
Date: Wed, 26 Jan 2011 01:30:37 -0500

On Tue, Jan 25, 2011 at 4:16 AM, m k <mpmab1 () gmail com> wrote:
*FIRST.nse*
________________________________________________________________________________________
**-- Code not shown are things like description, categories etc

portrule = shortport.port_or_service(80, "http")

action = function(host, port)

    local status = http.get(host, port, "/").status             -- Assigns
the HTTP response status code sent to the server at "/" to "status"
    nmap.registry.status = nmap.registry.status or {}      -- Assigns the
status to the register
    table.insert(nmap.registry.status)                             -- Puts
it in a table

   if  status == 200 then                                              --
Check if HTTP response status code is 200, if yes print hello world
               return ("Hello World");
    end
end
________________________________________________________________________________________

*SECOND.nse
.....
*dependencies =
{"FIRST.nse"}                                                     --
Include the script that contains the required information
portrule = shortport.port_or_service(80, "http")

action = function(host, port)
   if   (nmap.registry.status == 200)
then                                       -- Attempt to access status code
from the first script
       return "You Passed status from FIRST script to SECOND"
    end
end

Ok, so first let me recommend you always run your scripts with -d
(double verbosity is also really good) so you can know if there was an
error either syntactically or at runtime. Right now you're blind to
those problems.

The general approach you are using is fine. However there are some
errors. First, conventionally, you should use a special string name
for your registry table. "status" is too general:

nmap.registry.status = nmap.registry.status or {}      -- Assigns the
status to the register

I'd call it something like nmap.registry.<myscripts>-status.

The other problem is SECOND.nse tests that nmap.registry.status is
equal to the number 200:

   if   (nmap.registry.status == 200)
then                                       -- Attempt to access status code
from the first script


This condition will never be true since nmap.registry.status is a
table (your SECOND.nse script will never do anything). You need to
access the table values (1-N). For example,

if nmap.registry.status[1] == 200 then



You may want to peruse Programming in Lua [1] to get a better feel for
the language.

[1] http://www.lua.org/pil/

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

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]
AlienVault