scanning_k8s

Home

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

This 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

The kube-hunter GitHub repository contains example YAML files for running it as a Job.

  1. Clone the repository:

    git clone https://github.com/aquasecurity/kube-hunter.git
  2. Navigate 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

  1. Deploy the kube-hunter Job (Passive Mode): The default job.yaml usually runs kube-hunter in passive mode (often with the --pod argument to scan from within a pod).

  2. Check Job Status and Pod Logs:

  3. View Passive Scan Results:

2.3 Active Scan Mode

Active scanning attempts to exploit discovered vulnerabilities. Use with caution.

  1. Delete the Previous Job (if any):

    (Added --ignore-not-found=true)

  2. Modify job.yaml for Active Scanning: Edit the job.yaml file. You need to add the --active flag to the args section of the container spec.

    For example, change:

    to:

    (The exact structure of args in your job.yaml might vary. Ensure you add --active correctly to the list of arguments passed to the kube-hunter command within the YAML.)

    Note: The --active argument extends the tests to use findings to attempt further actions. This is more effective when run from within the cluster but carries more risk.

  3. Deploy the Active Scan Job:

  4. Check Job Status and Pod Logs (Active Scan):

  5. View Active Scan Results and Compare:

    Review the differences between myresultspassive.txt and myresultsactive.txt. The active scan may report more findings or details.

3. Running kube-hunter Remotely

You can also run kube-hunter from a machine outside the cluster, targeting the cluster's exposed endpoints.

  1. Install kube-hunter locally: On your scanning machine (e.g., the studentx-4.training.dockerhack.me placeholder from the original document, or your own machine), ensure you are in the cloned kube-hunter directory.

  2. Run Remote Scans:

    • Scan a specific remote host (e.g., a Kubernetes API server or node): Replace target-node.example.com with the actual IP or hostname.

    • Scan a CIDR range:

    (Generalized placeholders.)

Home

Last updated