From 563a11d3c8132dc3a5927ba7eddde021d9257d2d Mon Sep 17 00:00:00 2001 From: Johan Guldmyr Date: Fri, 3 Jun 2022 14:04:41 +0300 Subject: [PATCH 1/3] discovery: Make kubectl.py able to find kubectl The arguments in subprocess check_output in python 3.8.10 needs to be a list. Before the change the error in "--log debug" would look like: ``` 2022-06-03 13:54:56,497 DEBUG kube_hunter.modules.discovery.kubectl Could not find kubectl client ``` And if I add small code change to also print the exception error it prints: ``` 2022-06-03 13:54:56,497 DEBUG kube_hunter.modules.discovery.kubectl [Errno 2] No such file or directory: 'kubectl version --client' 2022-06-03 13:54:56,497 DEBUG kube_hunter.modules.discovery.kubectl Could not find kubectl client ``` --- kube_hunter/modules/discovery/kubectl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kube_hunter/modules/discovery/kubectl.py b/kube_hunter/modules/discovery/kubectl.py index 38e52e07..c0f3e6ac 100644 --- a/kube_hunter/modules/discovery/kubectl.py +++ b/kube_hunter/modules/discovery/kubectl.py @@ -32,7 +32,7 @@ def get_kubectl_binary_version(self): version = None try: # kubectl version --client does not make any connection to the cluster/internet whatsoever. - version_info = subprocess.check_output("kubectl version --client", stderr=subprocess.STDOUT) + version_info = subprocess.check_output(["kubectl", "version", "--client"], stderr=subprocess.STDOUT) if b"GitVersion" in version_info: # extracting version from kubectl output version_info = version_info.decode() From 2e50ae09b2e099046275d36762787db93cb13283 Mon Sep 17 00:00:00 2001 From: Johan Guldmyr Date: Wed, 24 Aug 2022 10:52:24 +0300 Subject: [PATCH 2/3] Use shlex.split in discovery/kubectl.py Co-authored-by: Md Safiyat Reza --- kube_hunter/modules/discovery/kubectl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kube_hunter/modules/discovery/kubectl.py b/kube_hunter/modules/discovery/kubectl.py index c0f3e6ac..82c1673e 100644 --- a/kube_hunter/modules/discovery/kubectl.py +++ b/kube_hunter/modules/discovery/kubectl.py @@ -32,7 +32,7 @@ def get_kubectl_binary_version(self): version = None try: # kubectl version --client does not make any connection to the cluster/internet whatsoever. - version_info = subprocess.check_output(["kubectl", "version", "--client"], stderr=subprocess.STDOUT) + version_info = subprocess.check_output(shlex.split("kubectl version --client"), stderr=subprocess.STDOUT) if b"GitVersion" in version_info: # extracting version from kubectl output version_info = version_info.decode() From fc9811b88ecaefffad781ed9a8e12c33f6bb51ab Mon Sep 17 00:00:00 2001 From: Johan Guldmyr Date: Mon, 29 Aug 2022 07:21:26 +0300 Subject: [PATCH 3/3] Import shlex for command parsing --- kube_hunter/modules/discovery/kubectl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kube_hunter/modules/discovery/kubectl.py b/kube_hunter/modules/discovery/kubectl.py index 82c1673e..3a93a6b8 100644 --- a/kube_hunter/modules/discovery/kubectl.py +++ b/kube_hunter/modules/discovery/kubectl.py @@ -1,5 +1,6 @@ import logging import subprocess +import shlex from kube_hunter.core.types import Discovery from kube_hunter.core.events.event_handler import handler