Skip to content

Commit

Permalink
Merge pull request #1 from atluxity/patch-1
Browse files Browse the repository at this point in the history
gitmopp changed to Python3
gitmopp integrated patch from novaksam 0xn1k5#1
atluxity merging to master branch
  • Loading branch information
atluxity authored Dec 15, 2020
2 parents 6b2b1bc + dc0d9a1 commit cb816a7
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions nessus_report_downloader.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/python
#!/usr/bin/env python3

########################################################################################################
# Name: Nessus Report downloader
# Author: Nikhil Raj ( [email protected] )
#
# Version: 1.0
# Last Updated: 13 Aug 2017
# Version: 1.1
# Last Updated: 24 Nov 2020
#
# Description: A python script for automating the download of nessus reports in multiple formats.
#
Expand All @@ -28,7 +28,7 @@
try:
from prettytable import PrettyTable
except ImportError:
print "[-] Unable to load PrettyTable library, will print data in generic format"
print("[-] Unable to load PrettyTable library, will print data in generic format")
HAS_PRETTYTABLE = False
else:
HAS_PRETTYTABLE = True
Expand All @@ -42,9 +42,10 @@
def sendGetRequest(url, headers):
try:
r = requests.get(url, verify=False, headers=headers)
# print("Connecting to " + url + " " + str(headers) + " HTTP Code: " + str(r.status_code))
return r
except requests.exceptions.ConnectionError:
print "[-] Failed to establish connection"
print("[-] Failed to establish connection")
exit(-1)


Expand All @@ -54,7 +55,7 @@ def sendPostRequest(url, json_data={}, headers={}):
r = requests.post(url, verify=False, headers=headers, json=json_data)
return r
except requests.exceptions.ConnectionError:
print "[-] Failed to establish connection"
print("[-] Failed to establish connection")
exit(-1)

# Send HTTP DELETE request
Expand All @@ -63,19 +64,19 @@ def sendDeleteRequest(url, json_data={}, headers={}):
r = requests.delete(url, verify=False, headers=headers, json=json_data)
return r
except requests.exceptions.ConnectionError:
print "[-] Failed to establish connection"
print("[-] Failed to establish connection")
exit(-1)

# Print message on stdout
def printMessage(msg, flag=1):
if flag == 1:
print "[+] " + msg
print("[+] " + msg)
elif flag == 0:
print "[-] " + msg
print("[-] " + msg)
elif flag == 2:
print "[*] " + msg
print("[*] " + msg)
else:
print msg
print(msg)


# Check response code for an HTTP Response and print req message
Expand All @@ -100,7 +101,7 @@ def printTable(data, table_headers):
else:
l.append(str(row[header]))
tab.add_row(l)
print tab
print(tab)


def printScanData(scan_data):
Expand All @@ -113,13 +114,13 @@ def printScanData(scan_data):
printTable(scan_data["scans"], ["id", "name", "folder_id", "status", "creation_date", "last_modification_date"])
else:
# print scan header
print '\t %-10s %-20s %-20s %-40s %-20s %-20s' %("Scan Id", "Folder Name (id)", "Scan status","Scan Name","creation_date", "last_modification_date")
print '\t %-10s %-20s %-20s %-40s %-20s %-20s' %("-------", "---------------", "------------", "-----------------","-------------------", "--------------------")
print('\t %-10s %-20s %-20s %-40s %-20s %-20s' %("Scan Id", "Folder Name (id)", "Scan status","Scan Name","creation_date", "last_modification_date"))
print('\t %-10s %-20s %-20s %-40s %-20s %-20s' %("-------", "---------------", "------------", "-----------------","-------------------", "--------------------"))
for scan in scan_data["scans"]:
print '\t %-10s %-20s %-20s %-40s %-20s %-20s' %(str(scan["id"]),folder_info[scan["folder_id"]] + ' (' + str(
scan["folder_id"]) + ') ', scan["status"], scan["name"],datetime.fromtimestamp(int(scan["creation_date"])).strftime('%Y-%m-%d %H:%M:%S'),datetime.fromtimestamp(int(scan["last_modification_date"])).strftime('%Y-%m-%d %H:%M:%S'))
print('\t %-10s %-20s %-20s %-40s %-20s %-20s' %(str(scan["id"]),folder_info[scan["folder_id"]] + ' (' + str(
scan["folder_id"]) + ') ', scan["status"], scan["name"],datetime.fromtimestamp(int(scan["creation_date"])).strftime('%Y-%m-%d %H:%M:%S'),datetime.fromtimestamp(int(scan["last_modification_date"])).strftime('%Y-%m-%d %H:%M:%S')))

print '\n'
print('\n')

# Verify user specified folder Id
def verifyScanId(scan_data, ui_scan_id):
Expand Down Expand Up @@ -227,7 +228,7 @@ def downloadNessusReport(base_url, token, scan_id_list, json_user_data):
resp2 = sendGetRequest(url, headers=token_header)

# If nessus report is ready for download, then write the response in external file
url= base_url + "/scans/exports/{0}/download".format(str(file_token["token"]))
url= base_url + "/tokens/{0}/download".format(str(file_token["token"]))
if json.loads(resp2.text)["status"] == "ready":
printMessage("Download link is available now", 1)
resp3 = sendGetRequest(url,headers=token_header)
Expand Down Expand Up @@ -292,7 +293,7 @@ def main():
resp = sendPostRequest(base_url + "/session", creds)
if checkStatus(resp, "Login successful", "Invalid Login credentials"):
token = json.loads(resp.text)
# print token["token"]
# print(token["token"])

# Fetching nessus scan report list
resp = sendGetRequest(base_url + "/scans", headers={'X-Cookie': 'token=' + token['token']})
Expand Down Expand Up @@ -332,4 +333,4 @@ def main():
printMessage("Thanks, See you again!")

if __name__ == '__main__':
main()
main()

0 comments on commit cb816a7

Please sign in to comment.