Performing Kubernetes Penetration Testing
Overview
Kubernetes penetration testing systematically evaluates cluster security by simulating attacker techniques against the API server, kubelet, etcd, pods, RBAC, network policies, and secrets. Using tools like kube-hunter, Kubescape, peirates, and manual kubectl exploitation, testers identify misconfigurations that could lead to cluster compromise.
When to Use
- When conducting security assessments that involve performing kubernetes penetration testing
- When following incident response procedures for related security events
- When performing scheduled security testing or auditing activities
- When validating security controls through hands-on testing
Prerequisites
- Authorized penetration testing engagement
- Kubernetes cluster access (various levels for different test scenarios)
- kube-hunter, kubescape, kube-bench installed
- kubectl configured
- Network access to cluster components
Core Concepts
Kubernetes Attack Surface
| Component |
Port |
Attack Vectors |
| API Server |
6443 |
Auth bypass, RBAC abuse, anonymous access |
| Kubelet |
10250/10255 |
Unauthenticated access, command execution |
| etcd |
2379/2380 |
Unauthenticated read, secret extraction |
| Dashboard |
8443 |
Default credentials, token theft |
| NodePort Services |
30000-32767 |
Service exposure, application exploits |
| CoreDNS |
53 |
DNS spoofing, zone transfer |
MITRE ATT&CK for Kubernetes
| Phase |
Techniques |
| Initial Access |
Exposed Dashboard, Kubeconfig theft, Application exploit |
| Execution |
exec into container, CronJob, deploy privileged pod |
| Persistence |
Backdoor container, mutating webhook, static pod |
| Privilege Escalation |
Privileged container, node access, RBAC abuse |
| Defense Evasion |
Pod name mimicry, namespace hiding, log deletion |
| Credential Access |
Secret extraction, service account token theft |
| Lateral Movement |
Container escape, cluster internal services |
Workflow
Step 1: External Reconnaissance
# Discover Kubernetes services
nmap -sV -p 443,6443,8443,2379,10250,10255,30000-32767 target-cluster.com
# Check for exposed API server
curl -k https://target-cluster.com:6443/api
curl -k https://target-cluster.com:6443/version
# Check anonymous authentication
curl -k https://target-cluster.com:6443/api/v1/namespaces
# Check for exposed kubelet
curl -k https://node-ip:10250/pods
curl http://node-ip:10255/pods # Read-only kubelet
Step 2: Automated Scanning with kube-hunter
# Install kube-hunter
pip install kube-hunter
# Remote scan
kube-hunter --remote target-cluster.com
# Internal network scan (from within cluster)
kube-hunter --internal
# Pod scan (from within a pod)
kube-hunter --pod
# Generate report
kube-hunter --remote target-cluster.com --report json --log output.json
Step 3: CIS Benchmark Assessment with kube-bench
# Run kube-bench on master node
kube-bench run --targets master
# Run on worker node
kube-bench run --targets node
# Check specific sections
kube-bench run --targets master --check 1.2.1,1.2.2,1.2.3
# JSON output
kube-bench run --json > kube-bench-results.json
# Run as Kubernetes job
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml
kubectl logs -l app=kube-bench
Step 4: Framework Compliance with Kubescape
# Install kubescape
curl -s https://raw.githubusercontent.com/kubescape/kubescape/master/install.sh | /bin/bash
# Scan against NSA/CISA hardening guide
kubescape scan framework nsa
> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.
1---2name: performing-kubernetes-penetration-testing3description: "Perform Kubernetes penetration testing. Signals: cloud privilege escalation, iam privilege escalation, container privilege escalation."4zh-signals: "Performing Kubernetes Penetration Testing 信号:云提权,iam提权,容器提权。"5when-to-use: >-6 Evaluates Kubernetes cluster security by actively simulating attacker techniques against the7 API server, kubelet, etcd, pods, RBAC, network policy, and secrets, using kube-hunter,8 Kubescape, peirates, and manual kubectl exploitation to find paths to cluster compromise.9 Use for an authorized penetration test or hands-on validation that controls actually stop an10 attacker. Keywords: kube-hunter, Kubescape, peirates, kubelet 10250, anonymous auth, token11 theft, lateral movement, cluster takeover. Do not use for a configuration-only compliance12 audit - use performing-kubernetes-cis-benchmark-with-kube-bench.13domain: cybersecurity14subdomain: container-security15tags:16- containers17- kubernetes18- security19- penetration-testing20- offensive-security21version: '1.0'22author: mahipal23license: Apache-2.024nist_csf:25- PR.PS-0126- PR.IR-0127- ID.AM-0828- DE.CM-0129mitre_attack:30- T161031- T161132- T160933- T152534metadata:35 source: https://skillmd.com/skills/dangeroussong/performing-kubernetes-penetration-testing36---3738# Performing Kubernetes Penetration Testing3940## Overview4142Kubernetes penetration testing systematically evaluates cluster security by simulating attacker techniques against the API server, kubelet, etcd, pods, RBAC, network policies, and secrets. Using tools like kube-hunter, Kubescape, peirates, and manual kubectl exploitation, testers identify misconfigurations that could lead to cluster compromise.434445## When to Use4647- When conducting security assessments that involve performing kubernetes penetration testing48- When following incident response procedures for related security events49- When performing scheduled security testing or auditing activities50- When validating security controls through hands-on testing5152## Prerequisites5354- Authorized penetration testing engagement55- Kubernetes cluster access (various levels for different test scenarios)56- kube-hunter, kubescape, kube-bench installed57- kubectl configured58- Network access to cluster components5960## Core Concepts6162### Kubernetes Attack Surface6364| Component | Port | Attack Vectors |65|-----------|------|---------------|66| API Server | 6443 | Auth bypass, RBAC abuse, anonymous access |67| Kubelet | 10250/10255 | Unauthenticated access, command execution |68| etcd | 2379/2380 | Unauthenticated read, secret extraction |69| Dashboard | 8443 | Default credentials, token theft |70| NodePort Services | 30000-32767 | Service exposure, application exploits |71| CoreDNS | 53 | DNS spoofing, zone transfer |7273### MITRE ATT&CK for Kubernetes7475| Phase | Techniques |76|-------|-----------|77| Initial Access | Exposed Dashboard, Kubeconfig theft, Application exploit |78| Execution | exec into container, CronJob, deploy privileged pod |79| Persistence | Backdoor container, mutating webhook, static pod |80| Privilege Escalation | Privileged container, node access, RBAC abuse |81| Defense Evasion | Pod name mimicry, namespace hiding, log deletion |82| Credential Access | Secret extraction, service account token theft |83| Lateral Movement | Container escape, cluster internal services |8485## Workflow8687### Step 1: External Reconnaissance8889```bash90# Discover Kubernetes services91nmap -sV -p 443,6443,8443,2379,10250,10255,30000-32767 target-cluster.com9293# Check for exposed API server94curl -k https://target-cluster.com:6443/api95curl -k https://target-cluster.com:6443/version9697# Check anonymous authentication98curl -k https://target-cluster.com:6443/api/v1/namespaces99100# Check for exposed kubelet101curl -k https://node-ip:10250/pods102curl http://node-ip:10255/pods # Read-only kubelet103```104105### Step 2: Automated Scanning with kube-hunter106107```bash108# Install kube-hunter109pip install kube-hunter110111# Remote scan112kube-hunter --remote target-cluster.com113114# Internal network scan (from within cluster)115kube-hunter --internal116117# Pod scan (from within a pod)118kube-hunter --pod119120# Generate report121kube-hunter --remote target-cluster.com --report json --log output.json122```123124### Step 3: CIS Benchmark Assessment with kube-bench125126```bash127# Run kube-bench on master node128kube-bench run --targets master129130# Run on worker node131kube-bench run --targets node132133# Check specific sections134kube-bench run --targets master --check 1.2.1,1.2.2,1.2.3135136# JSON output137kube-bench run --json > kube-bench-results.json138139# Run as Kubernetes job140kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml141kubectl logs -l app=kube-bench142```143144### Step 4: Framework Compliance with Kubescape145146```bash147# Install kubescape148curl -s https://raw.githubusercontent.com/kubescape/kubescape/master/install.sh | /bin/bash149150# Scan against NSA/CISA hardening guide151kubescape scan framework nsa152153> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.