Home page logo

nmap-dev logo Nmap Development mailing list archives

[NSE][patch]Structured XML output for scripts
From: Daniel Miller <bonsaiviking () gmail com>
Date: Sat, 25 Jun 2011 13:33:09 -0500


I'm so excited to finally submit this patch. It's a continuation of
the idea started in http://seclists.org/nmap-dev/2011/q2/130, of
providing structure for NSE script output so that it can be more
meaningfully parsed from Nmap's XML output. The first patch I
submitted was fatally flawed with memory corruption, as well as some
poor design choices, but I'm really happy about this new patch. I've
tested under valgrind while running every script I could, and I
haven't introduced any memory leaks, the XML output validates under
(my patched) nmap.dtd, and the plain output is identical (except for
possible minor whitespace) to what was being output before, all
without modifying the scripts themselves.

That's an important note for script writers: you don't have to change
anything to take advantage of this patch. My implementation modified
stdnse.format_output() to take the exact same input, but instead of
transforming it into a string (which is still valid to return from a
script), it just validates the structure of the table and returns it.
The NSE runtime takes any single value returned from a script (other
than nil) and interprets its structure to output well-formed XML.
There are a few table constructs that are not allowed, but anything
that stdnse.format() used to take will make sense. Some scripts could
be written to better take advantage of the new formatting, but I'll
submit a patch later that does a lot of that. In the meantime, a
script that, for instance, just returns a multiline string will have
the expected behavior in normal output, and have the whole chunk of
text shoved into a single <elem> in XML output.

One difference that I forgot to document (though I'll send in some
examples later), is that if you push a single-element dictionary-table
into your output tab
le, it will treat it as a key-value pair. So this:

table.insert( output, { Label="some information" } )

Turns into this in normal output:

| my-script:
|   Label: some information

... and into this in XML output:

<elem key="Label">some information</elem>

I'm really looking forward to hearing the feedback on this.


Attachment: nse_structured.patch

Sent through the nmap-dev mailing list
Archived at http://seclists.org/nmap-dev/

  By Date           By Thread  

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