Compare commits

...

5 Commits

Author SHA1 Message Date
Daniel Sagi
f4c1e38c6f fixed merge problem in workflow file 2021-10-16 17:41:28 +03:00
Daniel Sagi
eebbc0e735 Merge branch 'main' into remove_cve_scanning 2021-10-16 17:32:48 +03:00
danielsagi
8d045fb1a8 Fix all of github action workflows (#481)
* fixed all of workflows
2021-10-16 17:23:41 +03:00
Daniel Sagi
9bff41a938 Made cve hunting optional, defaultly set to not run 2021-10-15 20:54:26 +03:00
Daniel Sagi
da560975b2 Removed registration of the k8s cve hunter. disabled cve hunting 2021-10-15 18:23:00 +03:00
11 changed files with 51 additions and 27 deletions

View File

@@ -77,9 +77,10 @@ jobs:
python-version: '3.9'
- name: Install dependencies
shell: bash
run: |
python -m pip install -U pip
python -m pip install -r requirements-dev.txt
pip install -U pip
make deps
- name: Build project
shell: bash

View File

@@ -10,7 +10,7 @@ name: Release
jobs:
build:
name: Upload Release Asset
runs-on: ubuntu-16.04
runs-on: ubuntu-18.04
steps:
- name: Checkout code
uses: actions/checkout@v2
@@ -18,12 +18,14 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.8'
- name: Install dependencies
shell: bash
run: |
python -m pip install -U pip
python -m pip install -r requirements-dev.txt
pip install -U pip
pip install pyinstaller
make deps
- name: Build project
shell: bash

View File

@@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04]
os: [ubuntu-20.04, ubuntu-18.04]
steps:
- uses: actions/checkout@v2
@@ -38,11 +38,11 @@ jobs:
${{ matrix.os }}-${{ matrix.python-version }}-
- name: Install dependencies
shell: bash
run: |
python -m pip install -U pip
python -m pip install -U wheel
python -m pip install -r requirements.txt
python -m pip install -r requirements-dev.txt
pip install -U pip
make dev-deps
make install
- name: Test
shell: bash

View File

@@ -31,7 +31,7 @@ lint-check:
.PHONY: test
test:
pytest
python -m pytest
.PHONY: build
build:

View File

@@ -28,6 +28,7 @@ config = Config(
k8s_auto_discover_nodes=args.k8s_auto_discover_nodes,
service_account_token=args.service_account_token,
kubeconfig=args.kubeconfig,
enable_cve_hunting=args.enable_cve_hunting,
)
setup_logger(args.log, args.log_file)
set_config(config)

View File

@@ -21,6 +21,7 @@ class Config:
- remote: Hosts to scan
- report: Output format
- statistics: Include hunters statistics
- enable_cve_hunting: enables cve hunting, shows cve results
"""
active: bool = False
@@ -39,6 +40,7 @@ class Config:
k8s_auto_discover_nodes: bool = False
service_account_token: Optional[str] = None
kubeconfig: Optional[str] = None
enable_cve_hunting: bool = False
_config: Optional[Config] = None

View File

@@ -76,6 +76,12 @@ def parser_add_arguments(parser):
parser.add_argument("--active", action="store_true", help="Enables active hunting")
parser.add_argument(
"--enable-cve-hunting",
action="store_true",
help="Show cluster CVEs based on discovered version (Depending on different vendors, may result in False Positives)",
)
parser.add_argument(
"--log",
type=str,

View File

@@ -62,7 +62,7 @@ class EventQueue(Queue):
######################################################
"""
def subscribe(self, event, hook=None, predicate=None):
def subscribe(self, event, hook=None, predicate=None, is_register=True):
"""
The Subscribe Decorator - For Regular Registration
Use this to register for one event only. Your hunter will execute each time this event is published
@@ -74,12 +74,12 @@ class EventQueue(Queue):
"""
def wrapper(hook):
self.subscribe_event(event, hook=hook, predicate=predicate)
self.subscribe_event(event, hook=hook, predicate=predicate, is_register=is_register)
return hook
return wrapper
def subscribe_many(self, events, hook=None, predicates=None):
def subscribe_many(self, events, hook=None, predicates=None, is_register=True):
"""
The Subscribe Many Decorator - For Multiple Registration,
When your attack needs several prerequisites to exist in the cluster, You need to register for multiple events.
@@ -99,12 +99,12 @@ class EventQueue(Queue):
"""
def wrapper(hook):
self.subscribe_events(events, hook=hook, predicates=predicates)
self.subscribe_events(events, hook=hook, predicates=predicates, is_register=is_register)
return hook
return wrapper
def subscribe_once(self, event, hook=None, predicate=None):
def subscribe_once(self, event, hook=None, predicate=None, is_register=True):
"""
The Subscribe Once Decorator - For Single Trigger Registration,
Use this when you want your hunter to execute only in your entire program run
@@ -125,7 +125,8 @@ class EventQueue(Queue):
hook.__new__ = __new__unsubscribe_self
self.subscribe_event(event, hook=hook, predicate=predicate)
self.subscribe_event(event, hook=hook, predicate=predicate, is_register=is_register)
return hook
return wrapper
@@ -256,7 +257,9 @@ class EventQueue(Queue):
self.hooks[event].append((hook, predicate))
logging.debug("{} subscribed to {}".format(hook, event))
def subscribe_event(self, event, hook=None, predicate=None):
def subscribe_event(self, event, hook=None, predicate=None, is_register=True):
if not is_register:
return
if not self._register_hunters(hook):
return
@@ -267,7 +270,9 @@ class EventQueue(Queue):
else:
self._register_hook(event, hook, predicate)
def subscribe_events(self, events, hook=None, predicates=None):
def subscribe_events(self, events, hook=None, predicates=None, is_register=True):
if not is_register:
return False
if not self._register_hunters(hook):
return False

View File

@@ -3,7 +3,8 @@ from packaging import version
from kube_hunter.conf import get_config
from kube_hunter.core.events import handler
from kube_hunter.core.events.types import Vulnerability, Event, K8sVersionDisclosure
from kube_hunter.core.events.types import K8sVersionDisclosure, Vulnerability, Event
from kube_hunter.core.types import (
Hunter,
KubectlClient,
@@ -15,6 +16,7 @@ from kube_hunter.core.types import (
from kube_hunter.modules.discovery.kubectl import KubectlClientEvent
logger = logging.getLogger(__name__)
config = get_config()
class ServerApiVersionEndPointAccessPE(Vulnerability, Event):
@@ -199,7 +201,7 @@ class CveUtils:
return vulnerable
@handler.subscribe_once(K8sVersionDisclosure)
@handler.subscribe_once(K8sVersionDisclosure, is_register=config.enable_cve_hunting)
class K8sClusterCveHunter(Hunter):
"""K8s CVE Hunter
Checks if Node is running a Kubernetes version vulnerable to
@@ -224,6 +226,7 @@ class K8sClusterCveHunter(Hunter):
self.publish_event(vulnerability(self.event.version))
# Removed due to incomplete implementation for multiple vendors revisions of kubernetes
@handler.subscribe(KubectlClientEvent)
class KubectlCVEHunter(Hunter):
"""Kubectl CVE Hunter

View File

@@ -1,5 +1,3 @@
-r requirements.txt
flake8
pytest >= 2.9.1
requests-mock >= 1.8

View File

@@ -1,6 +1,6 @@
# flake8: noqa: E402
from kube_hunter.conf import Config, set_config
from kube_hunter.conf import Config, set_config, get_config
set_config(Config(active=True))
@@ -23,7 +23,9 @@ from kube_hunter.modules.hunting.apiserver import (
from kube_hunter.modules.hunting.arp import ArpSpoofHunter
from kube_hunter.modules.hunting.capabilities import PodCapabilitiesHunter
from kube_hunter.modules.hunting.certificates import CertificateDiscovery
from kube_hunter.modules.hunting.cves import K8sClusterCveHunter, KubectlCVEHunter
from kube_hunter.modules.hunting.cves import K8sClusterCveHunter
from kube_hunter.modules.hunting.cves import KubectlCVEHunter
from kube_hunter.modules.hunting.dashboard import KubeDashboard
from kube_hunter.modules.hunting.dns import DnsSpoofHunter
from kube_hunter.modules.hunting.etcd import EtcdRemoteAccess, EtcdRemoteAccessActive
@@ -40,6 +42,8 @@ from kube_hunter.modules.hunting.mounts import VarLogMountHunter, ProveVarLogMou
from kube_hunter.modules.hunting.proxy import KubeProxy, ProveProxyExposed, K8sVersionDisclosureProve
from kube_hunter.modules.hunting.secrets import AccessSecrets
config = get_config()
PASSIVE_HUNTERS = {
ApiServiceDiscovery,
KubeDashboardDiscovery,
@@ -56,7 +60,6 @@ PASSIVE_HUNTERS = {
ApiVersionHunter,
PodCapabilitiesHunter,
CertificateDiscovery,
K8sClusterCveHunter,
KubectlCVEHunter,
KubeDashboard,
EtcdRemoteAccess,
@@ -67,6 +70,9 @@ PASSIVE_HUNTERS = {
AccessSecrets,
}
# if config.enable_cve_hunting:
# PASSIVE_HUNTERS.append(K8sClusterCveHunter)
ACTIVE_HUNTERS = {
ProveAzureSpnExposure,
AccessApiServerActive,