Created
November 26, 2018 11:19
-
-
Save frknozr/b09ed106f0ed006ba49ac9a07d1d29a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
from docx import Document | |
A_KEY = "" | |
S_KEY = "" | |
headers = {"X-ApiKeys": "accessKey=; secretKey="} | |
BASE_URL = "https://localhost:8834" | |
SCAN_ID = 13 | |
CHUNK_SIZE = 3 | |
def chunks(l, n): | |
for i in range(0, len(l), n): | |
yield l[i:i + n] | |
def get_plugin_detail(scan_id,plugin_id): | |
URL = BASE_URL + "/scans/" + str(scan_id) + "/plugins/" + str(plugin_id) | |
response = requests.get(url=URL,headers=headers,verify=False) | |
data = json.loads(response.content) | |
return data | |
def get_scan_vulnerabilities(scan_id): | |
URL = BASE_URL + "/scans/" + str(scan_id) | |
response = requests.get(url=URL,headers=headers,verify=False) | |
data = json.loads(response.content) | |
return data | |
inf = [] | |
vulnerabilities = get_scan_vulnerabilities(SCAN_ID)["vulnerabilities"] | |
for v in vulnerabilities: | |
see_also = [] | |
plugin_id = v["plugin_id"] | |
detail = get_plugin_detail(SCAN_ID,plugin_id) | |
plugin_name = detail["info"]["plugindescription"]["pluginname"] | |
severity = detail["info"]["plugindescription"]["severity"] | |
plugin_description = detail["info"]["plugindescription"]["pluginattributes"]["description"] | |
try: | |
see_also = detail["info"]["plugindescription"]["pluginattributes"]["see_also"] | |
except: | |
pass | |
solution = detail["info"]["plugindescription"]["pluginattributes"]["solution"] | |
outputs = detail["outputs"] | |
vulnerable_ports = {} | |
for o in outputs: | |
ports = o["ports"] | |
for key in ports: | |
hosts = [] | |
for h in ports[key]: | |
hosts.append(h["hostname"]) | |
vulnerable_ports[key.split("/")[0] + "/" + key.split("/")[1]]=hosts | |
ports = [] | |
for k in vulnerable_ports: | |
for h in vulnerable_ports[k]: | |
ports.append(h + " (" + k.split("/")[0].strip() + "/" + k.split("/")[1].strip() + ")") | |
info = {"plugin_name":plugin_name, | |
"severity":severity, | |
"plugin_description":plugin_description, | |
"solution":solution, | |
"see_also":see_also, | |
"ports":ports} | |
inf.append(info) | |
document = Document() | |
for i in inf: | |
if i["severity"] > 1: | |
index = 0 | |
table = document.add_table(rows=1,cols=1) | |
hdr_cells = table.rows[0].cells | |
hdr_cells[0].text = "Vulnerability: " + i["plugin_name"] | |
index += 1 | |
if i["solution"] is not None: | |
hdr_cells = table.add_row().cells | |
hdr_cells[0].text = "Solution: " + i["solution"] | |
index += 1 | |
if len(i["see_also"]) != 0: | |
hdr_cells = table.add_row().cells | |
hdr_cells[0].text = "References: " + "\n".join(i["see_also"]) | |
index += 1 | |
if len(i["ports"]) != 0: | |
ports = list(chunks(i["ports"],CHUNK_SIZE)) | |
table2 = document.add_table(rows=len(ports),cols=3) | |
for port in range(len(ports)): | |
cells = table2.rows[port].cells | |
hosts = ports[port] | |
for host in range(len(hosts)): | |
cells[host].text = hosts[host] | |
document.add_page_break() | |
document.save('report.docx') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment