scanning_k8s
Scanning Kubernetes with kube-hunter
kube-hunter is a tool by Aqua Security that hunts for security weaknesses in Kubernetes clusters. It can be run as a Job within the cluster or remotely against a cluster.
Project Repository: https://github.com/aquasecurity/kube-hunter
1. Overview
kube-hunter performs a series of tests based on known vulnerabilities and misconfigurations.
Passive mode: Runs tests that do not interfere with cluster operations (e.g., checking for exposed dashboards, open ports).
Active mode: Extends passive tests by attempting to use discovered vulnerabilities to simulate attacks. This mode is more intrusive and should be used with caution, especially on production systems.
2. Running kube-hunter as a Job in-Cluster
kube-hunter as a Job in-ClusterThis method runs kube-hunter from within a pod in your cluster, allowing it to discover and test internal services.
2.1 Cloning kube-hunter for Job Manifests
kube-hunter for Job ManifestsThe kube-hunter GitHub repository contains example YAML files for running it as a Job.
Clone the repository:
git clone https://github.com/aquasecurity/kube-hunter.gitNavigate to the cloned directory:
cd kube-hunter # The job.yaml file is typically in this directory or a subdirectory like 'job'.
2.2 Passive Scan Mode
Deploy the
kube-hunterJob (Passive Mode): The defaultjob.yamlusually runskube-hunterin passive mode (often with the--podargument to scan from within a pod).Check Job Status and Pod Logs:
View Passive Scan Results:
2.3 Active Scan Mode
Active scanning attempts to exploit discovered vulnerabilities. Use with caution.
Delete the Previous Job (if any):
(Added
--ignore-not-found=true)Modify
job.yamlfor Active Scanning: Edit thejob.yamlfile. You need to add the--activeflag to theargssection of the container spec.For example, change:
to:
(The exact structure of
argsin yourjob.yamlmight vary. Ensure you add--activecorrectly to the list of arguments passed to thekube-huntercommand within the YAML.)Note: The
--activeargument extends the tests to use findings to attempt further actions. This is more effective when run from within the cluster but carries more risk.Deploy the Active Scan Job:
Check Job Status and Pod Logs (Active Scan):
View Active Scan Results and Compare:
Review the differences between
myresultspassive.txtandmyresultsactive.txt. The active scan may report more findings or details.
3. Running kube-hunter Remotely
kube-hunter RemotelyYou can also run kube-hunter from a machine outside the cluster, targeting the cluster's exposed endpoints.
Install
kube-hunterlocally: On your scanning machine (e.g., thestudentx-4.training.dockerhack.meplaceholder from the original document, or your own machine), ensure you are in the clonedkube-hunterdirectory.Run Remote Scans:
Scan a specific remote host (e.g., a Kubernetes API server or node): Replace
target-node.example.comwith the actual IP or hostname.Scan a CIDR range:
(Generalized placeholders.)
Last updated