From a1feb06ec7084a7700354edba9993edb96c47efe Mon Sep 17 00:00:00 2001 From: Yehuda Chikvashvili Date: Thu, 19 Sep 2019 21:57:39 +0300 Subject: [PATCH] Ignore downstream version flag (#181) * Ignore downstream version flag This commit adds `--ignore-downstream` flag to kube-hunter. Enabling the flag will make kube-hunter considering patched versions as not vulnerable. Resolves #179 * Add test cases and refine argument description --- kube-hunter.py | 1 + runtest.py | 1 + src/modules/hunting/cves.py | 15 +++++++++--- tests/hunting/test_cvehunting.py | 41 ++++++++++++++++++++++++++++++-- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/kube-hunter.py b/kube-hunter.py index ea5a582..a855554 100755 --- a/kube-hunter.py +++ b/kube-hunter.py @@ -9,6 +9,7 @@ parser.add_argument('--list', action="store_true", help="displays all tests in k parser.add_argument('--interface', action="store_true", help="set hunting of all network interfaces") parser.add_argument('--pod', action="store_true", help="set hunter as an insider pod") parser.add_argument('--quick', action="store_true", help="Prefer quick scan (subnet 24)") +parser.add_argument('--ignore-downstream', action="store_true", help="Ignore patched kubernetes versions") parser.add_argument('--cidr', type=str, help="set an ip range to scan, example: 192.168.0.0/16") parser.add_argument('--mapping', action="store_true", help="outputs only a mapping of the cluster's nodes") parser.add_argument('--remote', nargs='+', metavar="HOST", default=list(), help="one or more remote ip/dns to hunt") diff --git a/runtest.py b/runtest.py index f5ad18a..fe7619d 100644 --- a/runtest.py +++ b/runtest.py @@ -6,6 +6,7 @@ parser.add_argument('--list', action="store_true", help="displays all tests in k parser.add_argument('--interface', action="store_true", help="set hunting of all interface network interfaces") parser.add_argument('--pod', action="store_true", help="set hunter as an insider pod") parser.add_argument('--quick', action="store_true", help="Prefer quick scan (subnet 24)") +parser.add_argument('--ignore-downstream', action="store_true", help="Ignore patched kubernetes versions") parser.add_argument('--cidr', type=str, help="set an ip range to scan, example: 192.168.0.0/16") parser.add_argument('--mapping', action="store_true", help="outputs only a mapping of the cluster's nodes") parser.add_argument('--remote', nargs='+', metavar="HOST", default=list(), help="one or more remote ip/dns to hunt") diff --git a/src/modules/hunting/cves.py b/src/modules/hunting/cves.py index 582d598..46a220d 100644 --- a/src/modules/hunting/cves.py +++ b/src/modules/hunting/cves.py @@ -2,6 +2,8 @@ import logging import json import requests +from __main__ import config + from ...core.events import handler from ...core.events.types import Vulnerability, Event, K8sVersionDisclosure from ...core.types import Hunter, ActiveHunter, KubernetesCluster, RemoteCodeExec, AccessRisk, InformationDisclosure, \ @@ -95,8 +97,15 @@ class CveUtils: return (v1>v2)-(v1