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
This commit is contained in:
danielsagi
2019-08-28 12:18:58 +03:00
committed by GitHub
parent 0315af75cf
commit 427a295c8c
3 changed files with 30 additions and 15 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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: