Here’s a short Python snippet that generates a list of IP addresses based on IP range. Nothing fancy, but could come in handy if you ever need it somewhere in your code. Enjoy!
If you for any reason have the need to merge / combine a few Nessus scans into a single *.nessus file, you can do so using this simple Python script. Since *.nessus files are basically just XML files with a different extension, what this script does is it finds all the *.nessus files in the current folder, finds all the “ReportHost” XML nodes accumulating them into a single report.nessus file which is then exported to nss_report folder.
Note that scans must be of the same type (same plugins must be used), but they can be from different subnets or different parts of the same subnet.
How to use it? – Put the script and all your *.nessus files into a same folder, run the script, import nss_report/report.nessus into Nessus – and there you have it, all the hosts are in one place..1
25#! /usr/bin/env python3.2
import xml.etree.ElementTree as etree
first = 1
for fileName in os.listdir("."):
if ".nessus" in fileName:
print(":: Parsing", fileName)
mainTree = etree.parse(fileName)
report = mainTree.find('Report')
first = 0
tree = etree.parse(fileName)
for element in tree.findall('.//ReportHost'):
print(":: => done.")
if "nss_report" in os.listdir("."):
mainTree.write("nss_report/report.nessus", encoding="utf-8", xml_declaration=True)
If you have any questions, just drop a comment bellow..
Let’s say you need to filter a Python list and remove all elements that match a given criteria. If you wanted to remove a single element, you could just use ‘del list[i]’ (example). But if you wanted to remove multiple elements this might be a problem since you would be modifying and iterating over the list at the same time (keeping track of list indexes can become very confusing, very fast).
A simple solution to this problem would be to keep record of all list elements (indexes) that need to be removed, and to remove tham afterwards. Also, one other thing to be wary about is that the removal process should be done in reverse because otherwise you would shift all the elements to the ‘left’ every time you removed an element from a list and you would (again) have to keep track of list indexes.
A simple function example:1
19matchingFilter = ['criteria1', 'criteria2']
def criteriaFiltering(aList, matchingFilter):
deletionIndexes = 
i = 0
for listLine in aList:
for match in matchingFilter:
if match in str(listLine):
i += 1
for number in reversed(deletionIndexes):
This might not be the fastest ‘algorithm’ to do the job, but it works well enough for me..