|
| 1 | +import os |
| 2 | +import sqlite3 |
| 3 | +conn = sqlite3.connect('nessus.db') |
| 4 | +c = conn.cursor() |
| 5 | +os.mkdir('nessus_report_output') |
| 6 | + |
| 7 | +departments = [] |
| 8 | +c.execute('SELECT DISTINCT Department FROM dates ORDER BY Department') |
| 9 | +for row in c.fetchall(): |
| 10 | + departments.append(row[0]) |
| 11 | + |
| 12 | +vulnerabilities = ['MySQL Default Account Credentials','SNMP Agent Default Community Name (public)','Microsoft SQL Server sa Account Default Blank Password','Microsoft Windows SMB Registry : Autologon Enabled','Microsoft Windows Guest Account Belongs to a Group','Microsoft Windows SMB Shares Unprivileged Access','Microsoft Windows 2000 Unsupported Installation Detection','Microsoft Windows Administrator Default Password Detection (W32/Deloder Worm Susceptibility)','NFS Share User Mountable'] |
| 13 | +nonmsapplicationsall = ['%Adobe Reader%','%Flash Player%','%Adobe AIR%','%Shockwave Player%','%Oracle Java%','%Sun Java%','%iTunes%','%Adobe Acrobat%','%Google Chrome%','%Quicktime%','%Safari%','%RealPlayer%','%Opera%','%Firefox%','%Foxit Reader%','%VLC%','%Google Picasa%','%Adobe Photoshop%','%Netscape Browser%','%Winamp%','%HP System Management%','%Adobe Illustrator%','%IrfanView%','%PHP%','%Wireshark%','%VMware vCenter%','%AIX 6.1 TL%','%Oracle Database%','%Apache%','%SAP Sybase Adaptive Server Enterprise%','%DB2%','%IBM WebSphere Application%'] |
| 14 | + |
| 15 | +e = open('nessus_report_output/combined.txt', 'w') |
| 16 | +for department in departments: |
| 17 | + mspatchingpresent = 0 |
| 18 | + nonmspatchingpresent = 0 |
| 19 | + vulnerabilitypresent = 0 |
| 20 | + f = open('nessus_report_output/' + department + '.tex', 'w') |
| 21 | + f.write(r""" |
| 22 | +\documentclass[12pt]{article} |
| 23 | +\usepackage{longtable} |
| 24 | +\usepackage{rotating} |
| 25 | +\usepackage{color} |
| 26 | +\usepackage{lscape} |
| 27 | +""") |
| 28 | + f.write('\\title{Vulnerability Report for ' + department.replace("_"," ") + '}') |
| 29 | + f.write(r""" |
| 30 | +\author{Author} |
| 31 | +\date{\today} |
| 32 | +\begin{document} |
| 33 | +\maketitle |
| 34 | +\newpage |
| 35 | +\tableofcontents |
| 36 | +\newpage |
| 37 | +\section{Executive Summary} |
| 38 | +""") |
| 39 | + count = c.execute('SELECT COUNT(DISTINCT Host) FROM nessus WHERE (Department LIKE ?)', (department,)).fetchone()[0] |
| 40 | + f.write(r"""Number of hosts scanned: """ + str(count) + r"""\\""") |
| 41 | + date = c.execute('SELECT Date FROM dates WHERE (Department LIKE ?)', (department,)).fetchone()[0] |
| 42 | + f.write(r"""Scan date: """ + str(date) + r"""\\""") |
| 43 | + f.write(r""" |
| 44 | +\newpage |
| 45 | +\section{Microsoft Patching Report} |
| 46 | +\begin{center} |
| 47 | +\begin{longtable}{ | l | l | } |
| 48 | +\hline |
| 49 | +Host & Number of Missing Microsoft Patches \endhead \hline\hline |
| 50 | +""") |
| 51 | + microsoftTable = [] |
| 52 | + for row in c.execute('SELECT DISTINCT(Host), "Plugin Output" FROM nessus WHERE ("Plugin ID" LIKE "38153" and Department LIKE ?)', (department,)): |
| 53 | + count = row[1].count('\n')-2 |
| 54 | + microsoftTable.append([row[0],count]) |
| 55 | + mspatchingpresent = 1 |
| 56 | + for host, count in sorted(microsoftTable,key=lambda row: -row[1]): |
| 57 | + if (count > 25): f.write(host + ' & \\textcolor{red}{' + str(count) + '} \\\\ \\hline\n') |
| 58 | + else: f.write(host + ' & ' + str(count) + ' \\\\ \\hline\n') |
| 59 | + f.write(r"""\end{longtable}\end{center}""") |
| 60 | + if mspatchingpresent: f.write('All other hosts are up-to-date on Microsoft Patches.') |
| 61 | + else: f.write('All hosts up-to-date on Microsoft Patches, or no Microsoft Patching information in scan results.') |
| 62 | + f.write(r"""\newpage""") |
| 63 | + f.write(r"""\section{Non-Microsoft Patching Report}""") |
| 64 | + nonmsapplications = [] |
| 65 | + for application in nonmsapplicationsall: |
| 66 | + count = c.execute('SELECT COUNT(DISTINCT "Plugin ID") FROM nessus WHERE (Risk LIKE "High" OR Risk LIKE "Critical") and Name LIKE ? and Department LIKE ?', (application,department,)).fetchone()[0] |
| 67 | + if count: nonmsapplications.append(application) |
| 68 | + f.write(r""" |
| 69 | +The following table lists the number of missing patches for each application on each host: |
| 70 | +\begin{longtable}{ | l""") |
| 71 | + for application in nonmsapplications: f.write(' | l ') |
| 72 | + f.write(r""" | } |
| 73 | +\hline |
| 74 | +Host""") |
| 75 | + for application in nonmsapplications: |
| 76 | + f.write(' & \\begin{sideways}' + application[1:len(str(application))-1] + ' \\end{sideways} ') |
| 77 | + f.write('\\endhead \\hline\\hline\n') |
| 78 | + hosts = [] |
| 79 | + nonmsapplicationscollapsed = '" OR Name LIKE "'.join(nonmsapplicationsall) |
| 80 | + c.execute('SELECT DISTINCT Host FROM nessus WHERE (Risk LIKE "High" OR Risk LIKE "Critical") AND Department like ? AND (Name LIKE "' + nonmsapplicationscollapsed + '")',(department,)) |
| 81 | + for row in c.fetchall(): |
| 82 | + hosts.append(row[0]) |
| 83 | + for host in hosts: |
| 84 | + f.write(host[:20]) |
| 85 | + for application in nonmsapplications: |
| 86 | + count = c.execute('SELECT COUNT(DISTINCT "Plugin ID") FROM nessus WHERE (Risk LIKE "High" OR Risk LIKE "Critical") and Host LIKE ? and Name LIKE ? and Department LIKE ?', (host,application,department,)).fetchone()[0] |
| 87 | + if (count > 10): f.write(' & \\textcolor{red}{' + str(count) + '}') |
| 88 | + elif (count > 0): f.write(' & ' + str(count)) |
| 89 | + else: f.write(' & ') |
| 90 | + nonmspatchingpresent = 1 |
| 91 | + f.write('\\\\ \\hline\n') |
| 92 | + f.write(r""" |
| 93 | +\end{longtable} |
| 94 | +""") |
| 95 | + if nonmspatchingpresent: f.write('All other hosts are up-to-date on Non-Microsoft Patches.') |
| 96 | + else: f.write('All hosts up-to-date on Non-Microsoft Patches, or No Non-Microsoft Patching information in scan results.') |
| 97 | + f.write(r""" |
| 98 | +\newpage |
| 99 | +\section{Other Vulnerabilities} |
| 100 | +\begin{center} |
| 101 | +\begin{longtable}{ | l | l | } |
| 102 | +\hline |
| 103 | +Issue & Host \\ \hline |
| 104 | +""") |
| 105 | + for vulnerability in vulnerabilities: |
| 106 | + for row in c.execute('SELECT DISTINCT Host FROM nessus WHERE (Department LIKE ? and Name LIKE ?)', (department, vulnerability,)): |
| 107 | + f.write(vulnerability + ' & ' + row[0] + ' \\\\ \\hline\n') |
| 108 | + e.write(department + ',' + vulnerability + ',' + row[0] + '\n') |
| 109 | + vulnerabilitypresent = 1 |
| 110 | + f.write(r""" |
| 111 | +\end{longtable} |
| 112 | +\end{center} |
| 113 | +""") |
| 114 | + if not vulnerabilitypresent: f.write('No Other Vulnerabilities in scan results.') |
| 115 | + f.write(r""" |
| 116 | +\end{document} |
| 117 | +""") |
| 118 | + f.close() |
| 119 | + os.system('texi2pdf -q -o nessus_report_output/' + department + '.pdf nessus_report_output/' + department + '.tex') |
| 120 | +e.close() |
0 commit comments