changed a bit of report uploading process

This commit is contained in:
daniel_sagi
2018-07-04 11:36:16 +03:00
parent 23c03afc02
commit 16537e1ff6
2 changed files with 18 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ import logging
import sys
import time
parser = argparse.ArgumentParser(description='Kube-Hunter, Hunter for weak Kubernetes clusters. By default, with no special arguments, Kube Hunter will scan all network interfaces for existing Kubernetes clusters. At the end of the hunt, a report will be printed to your screen.')
parser = argparse.ArgumentParser(description='Kube-Hunter, Hunter for weak Kubernetes clusters. At the end of the hunt, a report will be printed to your screen.')
parser.add_argument('--pod', action="store_true", help="set hunter as an insider pod in cluster")
parser.add_argument('--internal', action="store_true", help="set hunting of all internal network interfaces")
parser.add_argument('--cidr', type=str, help="set manual cidr to scan, example: 192.168.0.0/16")

View File

@@ -1,5 +1,6 @@
import json
import logging
import time
from collections import defaultdict
import requests
@@ -53,6 +54,9 @@ class Reporter(object):
desc=self.event.explain(),
))
if config.token:
self.send_report(token=config.token)
def print_tables(self):
"""generates report tables and outputs to stdout"""
if len(services):
@@ -106,7 +110,6 @@ class Reporter(object):
return current_list
def send_report(self, token):
logging.debug("generating report")
def generate_report():
"""function generates a report corresponding to specifications of the frontend of kubehunter"""
for service in services:
@@ -127,22 +130,31 @@ class Reporter(object):
}
report["services"].append(service_report)
return report
finished = (not handler.unfinished_tasks)
logging.debug("generating report")
report = {
'results': generate_report(),
'metadata': {}
}
'metadata': {
'finished': finished
}
}
logging.debug("uploading report")
r = requests.put(AQUA_PUSH_URL.format(token=token), json=report)
if r.status_code == 201: # created status
print "\nYour report: \n{}".format(AQUA_RESULTS_URL.format(token=token))
logging.debug("report was uploaded successfully")
if finished:
print "\nYour report: \n{}".format(AQUA_RESULTS_URL.format(token=token))
else:
logging.debug("Failed sending report with:{}, {}".format(r.status_code, r.text))
print "\nSomething went wrong.\nPlease try hunting again."
if finished:
print "\nCould not send report.\n{}".format(json.loads(r.text).get("status", ""))
reporter = Reporter()
""" Tables Generation """
def print_nodes():
nodes_table = PrettyTable(["Type", "Location"], hrules=ALL)
nodes_table.align="l"