Nessus automation

来源:互联网 发布:网络刻章在线制作 编辑:程序博客网 时间:2024/06/08 05:17

First,download the API client, nessus_enterprise_rest_client-master.zip;https://github.com/jfalken/nessus_enterprise_rest_client


After install,write the python code to scan.

from NessusClient import *#import credentialsimport requestsimport sysimport timerequests.packages.urllib3.disable_warnings()nrc = NessusRestClient('https://nessusIP','admin','password','8834',False)policy = nrc.get_scan_policy_by_name(sys.argv[1])uuid=policy['template_uuid']targets=[sys.argv[2]]emails=['alei@websense.com']settings=nrc.get_settings_dict(uuid,sys.argv[3],'description',emails,targets)scan=nrc.create_scan(settings)scan_id=scan['id']print scan_idresp=nrc.launch_scan(scan_id)while True:    details=nrc.get_scan_details(scan_id)    rflag=details['info']['status']    if rflag=='completed':      break    else:      print rflag      time.sleep(300)      continuereport=nrc.download_report(scan_id,'html')sys.stdout=open("/jenkins/workspace/"+sys.argv[4]+"/report"+sys.argv[4]+".html",'w')print report#nrc.delete_scan(scan_id)



get the summary of the report

#!/bin/bash cat report$1.html | grep '<td width="15%" valign="top" class="classcell"><span class="classtext" style="color:' | head -12 > result.txt cat result.txt | awk -F '>' '{ print $3 }' | awk -F '<' '{print $1}' > result1.txt cat result1.txt | grep -v [a-z] > result2.txt



generate a XML file for Monkit to display the trend chart.

#!/bin/bashecho '<categories>    <category name="Summary" scale="mb">        <observations>            <observation name="Critical">'$1'</observation>            <observation name="High">'$2'</observation>             <observation name="Medium">'$3'</observation>             <observation name="Low">'$4'</observation>            <observation name="Info">'$5'</observation>            <observation name="Total">'$6'</observation>        </observations>    </category></categories>' > NessusMonkit.xml



the last ,compare this build result with the previous build,and highlight the new:


#!/bin/bashif [ -f /jenkins/oldreport$1.html ];thencat /jenkins/oldreport$1.html  | grep '<a href="http://www.nessus.org/plugins/index.php?view=single&' | awk -F 'id=' '{print $2}' | awk -F '"' '{print $1}' > oldid.txtcat report$1.html  | grep '<a href="http://www.nessus.org/plugins/index.php?view=single&' | awk -F 'id=' '{print $2}' | awk -F '"' '{print $1}' > newid.txtawk 'NR==FNR{a[$0]}NR>FNR{if ($0 in a) delete a[$0] ;else print $0 }' oldid.txt newid.txt >compareresult.txtvar=$(cat compareresult.txt)for i in $vardocat report$1.html | grep $i | head -1 >> new.htmlecho '<tr>' >> new.htmlsed -i '0,/>'$i' / s#>'$i' # style="background:red;font-weight:bold;">'$i' #' report$1.htmldonesed -i 's#href="#href="http://jenkinsIP:8080/job/'$1'/HTML_Report/report'$1'.html#' new.htmlfi



0 0