diff --git a/kube-hunter.py b/kube-hunter.py index 28ed1f8..bcb1d64 100644 --- a/kube-hunter.py +++ b/kube-hunter.py @@ -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") diff --git a/report/reporter.py b/report/reporter.py index 1f43aab..27fb748 100644 --- a/report/reporter.py +++ b/report/reporter.py @@ -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"