Saturday, August 14, 2010

Keeping Smaller Nessus Files

I've been playing a lot with Nessus XML lately and doing authenticated scans and assigning out result responsibility. One issue I've run into with the nessus gui, is each time you save your .nessus file, it constantly grows in size.

Here's a realy simple tool to chop out the most recent nessus scans. I use the lxml variant of ElementTree but there's no lxml exclusive functionality used. lxml is just much faster and supports xpath which I've used in my result importer.


import sys,os
import unittest
from lxml.etree import ElementTree

if __name__=='__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-f', action='store_true', help='force output overwrite', dest='force')
parser.add_argument('input', help='input filename to extract from', nargs=1)
parser.add_argument('output', help='output filename to extract from', nargs=1)
opts = parser.parse_args(sys.argv[1:])


et = ElementTree()
et.parse(opts.input[0])

# Get the root and remove all but the last report
root = et.getroot()
for rpt in root.findall("Report")[:-1]:
root.remove(rpt)

if not opts.force and os.path.exists(opts.output[0]):
print >>sys.stderr, "File Exists!, exiting"
sys.exit(1)

et.write(opts.output[0])

No comments:

Post a Comment