Archive - November, 2004

How do I use nmap XML?

Recently, in the nmap-dev mailing list, Fyodor asked:

In what ways do you use the Nmap XML output? Do you parse it from within a higher level program, transform it to HTML with XSLT, use it to populate a database, use XPath to parse the results from the command-line in a way that is as easy as awk/sec/cut/etc. on the normal output, or something else entirely?

I’ll share here my approach to nmap output parsing.

For my automated scans I use a combination of Python, Bash and AWK scripts. I always keep nmap scans in XML even if these will be used by some Bash/Awk scripts.

With Python I just parse the XML with libxml’s Python bindings.

With Bash and/or AWK I transform the XML output into PYX format with a custom made utility called xmltopyx.

For those not familiar with PYX, it is a way of converting XML documents into a more grep/AWK friendly format. More information about it can be found here and here.

An example of xmltopyx + AWK usage:

$ xmltopyx nmap-sample-tcpudp-portscan.xml | awk -f getports
tcp 21 open ftp
tcp 22 open ssh
tcp 53 open domain
udp 53 open|filtered domain
tcp 111 open rpcbind
udp 111 open|filtered rpcbind
udp 608 open|filtered sift-uft
tcp 611 open npmp-gui
udp 636 open|filtered
tcp 639 open
udp 664 open|filtered
udp 667 open|filtered
tcp 670 open
tcp 953 open rndc
tcp 2049 open nfs
udp 2049 open|filtered nfs
tcp 3128 open squid-http
udp 3130 open|filtered squid-ipc
udp 3401 open|filtered squid-snmp
udp 4827 open|filtered squid-htcp
udp 32768 open|filtered omad
udp 32771 open|filtered sometimes-rpc6

Then, using getports together with a while read proto port state service; do ... ; done loop in Bash is very simple.

Time oddity

I just read the presentation by Klein, D. V.; “Flying Linux” Keynote speech at the 2004 Copenhagen LinuxForum, and invited talk at the 2004 USENIX LISA Conference, Atlanta GA. And found there the following amusement:

$ cal 9 1752

September 1752
Su Mo Tu We Th Fr Sa
1  2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

So I googled for an explanation and came up with this and also this. I must say I find the second version more entertaining:

The guy that originally wrote the “cal” command on some old Version 7 machine had an off-by-one error in his code. This showed up as some erroneous output when a malloc’d variable overwrote 12 extra bytes with zeroes, thus leading to the strange calendar output seen above.

Guerrilla SMS projector

I wonder what the Billboard Liberation Front thinks about this device. It came via popcorn and Smart Mobs.

Rolling just to keep on rolling…

I just came back from the Mark Lanegan concert at Arena (Madrid). It was great although the sound could have been better. They played songs from their latest album Bubblegum as well as from previous albums which gave me the chance to listen to No easy action and some of their past hits.