XSL Transform to .audit Conversion

This topic explains how to build and use custom XSL transforms and convert them into .audit files.

Several compliance check plugins rely on auditing XML content, such as Palo Alto, VMware, and Unix compliance checks. To take advantage of these capabilities, you should become familiar with creating XSL transforms. In some cases, building an XSL transform requires trial and error. Once you are familiar with that process, you can convert the transform into an .audit file.

Several audit checks (for example, AUDIT_XML, AUDIT_VCENTER, AUDIT_ESX) are separate and distinct, but use the same underlying logic. Understanding the fundamentals of working with XML allows you to translate them directly to other platforms that use XML.

By using the xsltproc utility, you can follow these steps to generate custom .audit files for XML content:

Install xsltproc

Verify xsltproc is installed on your system, or install it if needed. You can verify it is installed and works by entering the following command:

[tater@pearl ~]# xsltproc

Usage: xsltproc [options] stylesheet file [file ...]

Options:

--version or -V: show the version of libxml and libxslt used

--verbose or -v: show logs of what's happening

[..]

Identify the XML File to Use

Determine the XML file you are going to use. Verify the location of the file, and that it is XML content. For example:

[tater@pearl ~]# ls top-applications.xml

-rw-r--r-- 1 tater gpigs 3857 2011-09-08 21:20 top-applications.xml

[tater@pearl ~]# head top-applications.xml

<?xml version="1.0"?>

<report reportname="top-applications" logtype="appstat">

<result name="Top applications" logtype="appstat" start="2013/01/29 00:00:00" start-epoch="1359446400" end="2013/01/29 23:59:59" end-epoch="1359532799" generated-at="2013/01/30 02:02:09" generated-at-epoch="1359540129" range="Tuesday, January 29, 2013">

<entry>

[..]

Create the XSLT Transform

Note: This process requires a basic understanding of XSL Transforms and XPath concepts. For additional information:

The goal is to extract relevant data from an XML file using XSL transforms. Start by creating an XSL transform. For example, assume you need to extract the “name” element from an XML file. The following XSLT extracts the required information:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text"/>

 

<xsl:template match="result">

<xsl:for-each select="entry">

+ <xsl:value-of select="name"/>

</xsl:for-each>

 

</xsl:template>

</xsl:stylesheet>

Once the XSLT is created, save it in a convenient place for testing in the next step. This example can be saved as pa.xsl.

When using a custom XSLT in an .audit, ignore the first three lines and the last two lines. The Tenable Nessus plugin nbin adds those standard lines during processing. In this example, lines 5-8 are the lines to use in the AUDIT_XML or AUDIT_REPORTS item.

The testing process in step 5 can also be used while building the XSLT to validate assumptions or new techniques. This process is especially useful if you are new to XSLT or working on more complex transforms.

Test the XSLT Transform

Verify your XSL Transform works with xsltproc. The general format for testing is:

/usr/bin/xsltproc {XSLT file} {Source XML}

Plugging in the sample file names from the steps above returns the following output, which confirms that the XSL transform is correct and properly formatted and that the expected data is returned.

[tater@pearl ~]# xsltproc pa.xsl top-applications.xml

 

+ insufficient-data

+ ping

+ snmp

+ dns

+ lpd

+ ntp

+ time

+ icmp

+ netbios-ns

+ radius

+ source-engine

+ stun

+ rip

+ tftp

+ echo

+ portmapper

+ teredo

+ slp

+ ssdp

+ dhcp

+ mssql-mon

+ pcanywhere

+ apple-airport

+ ike

+ citrix

+ xdmcp

+ l2tp

Copy the XSLT to the .audit File

Once the XSL Transform works as intended, copy the XSLT lines of interest (lines 5-8 in this example) to the .audit check.

xsl_stmt: "<xsl:template match=\"result\">"

xsl_stmt: "<xsl:for-each select=\"entry\">"

xsl_stmt: "+ <xsl:value-of select=\"name\"/>"

xsl_stmt: "</xsl:for-each>"

Each line of the custom XSL transform must be placed into its own xsl_stmt element enclosed in double quotes. Because the xsl_stmt element uses double quotes to encapsulate the <xsl> statements, any double quotes within must be escaped.

Note: Escaping the double quotes is important and not doing so risks errors in check execution.

/usr/bin/xsltproc {XSLT file} {Source XML}

In the next step you can see several examples of properly escaped double quotes.

Perform the Audit

Once the first five steps are complete, you have everything required to construct an audit:

<custom_item>

type: AUDIT_REPORTS

description: "Palo Alto Reports - Top Applications"

request: "&reporttype=predefined&reportname=top-applications"

xsl_stmt: "<xsl:template match=\"result\">"

xsl_stmt: "<xsl:for-each select=\"entry\">"

xsl_stmt: "+ <xsl:value-of select=\"name\"/>"

xsl_stmt: "</xsl:for-each>"

</custom_item>