26 Nov 2008

Simple conversion of nmap output in XML to CSV using XSLT

Here's a simple nmap.xsl file to include in the same directory as the nmap XML output file (replace all curly braces with the greater/smaller than signs):
{?xml version="1.0" encoding="UTF-8"?}
{xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"}
{xsl:output method="html" indent="yes" encoding="UTF-8"/}
{xsl:template match="/nmaprun"}host,protocol,port,service,state,
{xsl:apply-templates select="host"} {/xsl:apply-templates}
{/xsl:template}
{xsl:template match="host"}
{xsl:for-each select="ports/port"}
{xsl:value-of select="../../hostnames/hostname/@name"/},{xsl:value-of select="@protocol"/},{xsl:value-of select="@portid"/},{xsl:value-of select="service/@name"/},{xsl:value-of select="state/@state"/},
{/xsl:for-each}
{xsl:apply-templates/}
{/xsl:template}
{/xsl:stylesheet}


On Windows
1. Run nmap. For example: nmap.exe -T3 -sS -sV -p1-9000 -oX nmap-out.xml 10.10.1.1-254
2. Convert the file by using: msxsl nmap-out.xml nmap.xsl -o nmap-out.csv

I'm about to test the same thing on Linux...

To download the msxsl utility, go here

No comments:

Post a Comment