From 427a295c8c758d5777393a8a830ad13b2cfc3e65 Mon Sep 17 00:00:00 2001 From: danielsagi Date: Wed, 28 Aug 2019 12:18:58 +0300 Subject: [PATCH] Adding visibility for dispatching (#166) * minor addition to description * added documantation in readme * minor changes to logging levels and formatting * changed example in readme * fixed merge * added info logging to http dispatch method * changed description from environ to environment variables --- README.md | 17 ++++++++++++++--- kube-hunter.py | 2 +- src/modules/report/dispatchers.py | 26 +++++++++++++++----------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7b5e8b2..ad3f6fa 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,11 @@ You can see the list of tests with the `--list` option: Example: To see active hunting tests as well as passive: `./kube-hunter.py --list --active` +### Nodes Mapping +To see only a mapping of your nodes network, run with `--mapping` option. Example: +`./kube-hunter.py --cidr 192.168.0.0/24 --mapping` +This will output all the Kubernetes nodes kube-hunter has found. + ### Output To control logging, you can specify a log level, using the `--log` option. Example: `./kube-hunter.py --active --log WARNING` @@ -61,9 +66,15 @@ Available log levels are: * INFO (default) * WARNING -To see only a mapping of your nodes network, run with `--mapping` option. Example: -`./kube-hunter.py --cidr 192.168.0.0/24 --mapping` -This will output all the Kubernetes nodes kube-hunter has found. +### Dispatching +By default, the report will be dispatched to `stdout`, but you can specify different methods, by using the `--dispatch` option. Example: +`./kube-hunter.py --report json --dispatch http` +Available dispatch methods are: + +* stdout (default) +* http (to configure, set the following environment variables:) + * KUBEHUNTER_HTTP_DISPATCH_URL (defaults to: https://localhost) + * KUBEHUNTER_HTTP_DISPATCH_METHOD (defaults to: POST) ## Deployment There are three methods for deploying kube-hunter: diff --git a/kube-hunter.py b/kube-hunter.py index 7bb7328..ea5a582 100755 --- a/kube-hunter.py +++ b/kube-hunter.py @@ -15,7 +15,7 @@ parser.add_argument('--remote', nargs='+', metavar="HOST", default=list(), help= parser.add_argument('--active', action="store_true", help="enables active hunting") parser.add_argument('--log', type=str, metavar="LOGLEVEL", default='INFO', help="set log level, options are: debug, info, warn, none") parser.add_argument('--report', type=str, default='plain', help="set report type, options are: plain, yaml, json") -parser.add_argument('--dispatch', type=str, default='stdout', help="where to send the report to, options are: stdout, http (use KUBEHUNTER_HTTP_DISPATCH_URL and KUBEHUNTER_HTTP_DISPATCH_METHOD to configure)") +parser.add_argument('--dispatch', type=str, default='stdout', help="where to send the report to, options are: stdout, http (set KUBEHUNTER_HTTP_DISPATCH_URL and KUBEHUNTER_HTTP_DISPATCH_METHOD environment variables to configure)") parser.add_argument('--statistics', action="store_true", help="set hunting statistics") import plugins diff --git a/src/modules/report/dispatchers.py b/src/modules/report/dispatchers.py index 66af6ee..5f4b692 100644 --- a/src/modules/report/dispatchers.py +++ b/src/modules/report/dispatchers.py @@ -6,7 +6,7 @@ from __main__ import config class HTTPDispatcher(object): def dispatch(self, report): - logging.info('Dispatching report via http') + logging.debug('Dispatching report via http') dispatchMethod = os.environ.get( 'KUBEHUNTER_HTTP_DISPATCH_METHOD', 'POST' @@ -15,12 +15,6 @@ class HTTPDispatcher(object): 'KUBEHUNTER_HTTP_DISPATCH_URL', 'https://localhost/' ) - logging.info( - 'Dispatching report via {method} to {url}'.format( - method=dispatchMethod, - url=dispatchURL - ) - ) try: r = requests.request( dispatchMethod, @@ -29,23 +23,33 @@ class HTTPDispatcher(object): headers={'Content-Type': 'application/json'} ) r.raise_for_status() - logging.info( + logging.info('\nReport was dispatched to: {url}'.format(url=dispatchURL)) + logging.debug( "\tResponse Code: {status}\n\tResponse Data:\n{data}".format( status=r.status_code, data=r.text ) ) except requests.HTTPError as e: + # specific http exceptions logging.error( - "Dispatcher failed to deliver\n\tResponse Code: {status}\n\tResponse Data:\n{data}".format( + "\nCould not dispatch report using HTTP {method} to {url}\nResponse Code: {status}".format( status=r.status_code, - data=r.text + url=dispatchURL, + method=dispatchMethod ) ) + except Exception as e: + # default all exceptions + logging.error("\nCould not dispatch report using HTTP {method} to {url} - {error}".format( + method=dispatchMethod, + url=dispatchURL, + error=e + )) class STDOUTDispatcher(object): def dispatch(self, report): - logging.info('Dispatching report via stdout') + logging.debug('Dispatching report via stdout') if config.report == "plain": logging.info("\n{div}\n{report}".format(div="-" * 10, report=report)) else: