Skip to content

Commit cfb98aa

Browse files
authored
Adding Setup, Access, Teardown powershell scripts
Adding these scripts so that people on windows can also use the kubernetes goat platform from their native OS.
1 parent e28d132 commit cfb98aa

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

access-kubernetes-goat.ps1

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Author: Madhu Akula
2+
# This program has been created as part of Kubernetes Goat
3+
# Kubernetes Goat Access vulnerable infrastructure
4+
5+
# Checking kubectl.exe setup
6+
try {
7+
kubectl.exe version > $null 2>&1
8+
Write-Host "kubectl.exe setup looks good."
9+
} catch {
10+
Write-Host "Please check kubectl.exe setup."
11+
exit
12+
}
13+
14+
15+
Write-Host 'Creating port forward for all the Kubernetes Goat resources to locally. We will be using 1230 to 1236 ports locally!'
16+
17+
# Exposing Sensitive keys in code bases Scenario
18+
$POD_NAME = kubectl.exe get pods --namespace default -l "app=build-code" -o jsonpath="{.items[0].metadata.name}"
19+
Start-Process -NoNewWindow -FilePath "C:\Program Files\Docker\Docker\resources\bin\kubectl.exe" -ArgumentList "port-forward $POD_NAME --address 0.0.0.0 1230:3000" -RedirectStandardError "C:\NUL" -RedirectStandardOutput ".\NUL"
20+
21+
# Exposing DIND (docker-in-docker) exploitation Scenario
22+
$POD_NAME = kubectl.exe get pods --namespace default -l "app=health-check" -o jsonpath="{.items[0].metadata.name}"
23+
Start-Process -NoNewWindow -FilePath "C:\Program Files\Docker\Docker\resources\bin\kubectl.exe" -ArgumentList "port-forward $POD_NAME --address 0.0.0.0 1231:80" -RedirectStandardError "C:\NUL" -RedirectStandardOutput ".\NUL"
24+
25+
# Exposing SSRF in K8S world Scenario
26+
$POD_NAME = kubectl.exe get pods --namespace default -l "app=internal-proxy" -o jsonpath="{.items[0].metadata.name}"
27+
Start-Process -NoNewWindow -FilePath "C:\Program Files\Docker\Docker\resources\bin\kubectl.exe" -ArgumentList "port-forward $POD_NAME --address 0.0.0.0 1232:3000" -RedirectStandardError "C:\NUL" -RedirectStandardOutput ".\NUL"
28+
29+
# Exposing Container escape to access host system Scenario
30+
$POD_NAME = kubectl.exe get pods --namespace default -l "app=system-monitor" -o jsonpath="{.items[0].metadata.name}"
31+
Start-Process -NoNewWindow -FilePath "C:\Program Files\Docker\Docker\resources\bin\kubectl.exe" -ArgumentList "port-forward $POD_NAME --address 0.0.0.0 1233:8080" -RedirectStandardError "C:\NUL" -RedirectStandardOutput ".\NUL"
32+
33+
# Exposing Kubernetes Goat Home
34+
$POD_NAME = kubectl.exe get pods --namespace default -l "app=kubernetes-goat-home" -o jsonpath="{.items[0].metadata.name}"
35+
Start-Process -NoNewWindow -FilePath "C:\Program Files\Docker\Docker\resources\bin\kubectl.exe" -ArgumentList "port-forward $POD_NAME --address 0.0.0.0 1234:80" -RedirectStandardError "C:\NUL" -RedirectStandardOutput ".\NUL"
36+
37+
# Exposing Attacking private registry Scenario
38+
$POD_NAME = kubectl.exe get pods --namespace default -l "app=poor-registry" -o jsonpath="{.items[0].metadata.name}"
39+
Start-Process -NoNewWindow -FilePath "C:\Program Files\Docker\Docker\resources\bin\kubectl.exe" -ArgumentList "port-forward $POD_NAME --address 0.0.0.0 1235:5000" -RedirectStandardError "C:\NUL" -RedirectStandardOutput ".\NUL"
40+
41+
# Exposing DoS resources Scenario
42+
$POD_NAME = kubectl.exe get pods --namespace big-monolith -l "app=hunger-check" -o jsonpath="{.items[0].metadata.name}"
43+
Start-Process -NoNewWindow -FilePath "C:\Program Files\Docker\Docker\resources\bin\kubectl.exe" -ArgumentList "--namespace big-monolith port-forward $POD_NAME --address 0.0.0.0 1236:8080" -RedirectStandardError "C:\NUL" -RedirectStandardOutput ".\NUL"
44+
45+
Write-Host "Visit http://127.0.0.1:1234 to get started with your Kubernetes Goat hacking!"

setup-kubernetes-goat.ps1

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Author: Madhu Akula
2+
# This program has been created as part of Kubernetes Goat
3+
# Kubernetes Goat setup and manage vulnerable infrastructure
4+
5+
# Checking kubectl setup
6+
try {
7+
kubectl.exe version > $null 2>&1
8+
Write-Host "kubectl.exe setup looks good."
9+
} catch {
10+
Write-Host "Error: Could not find kubectl.exe or another error happened, please check kubectl.exe setup."
11+
exit
12+
}
13+
14+
# Deprecated helm2 scenario
15+
# Checking helm2 setup
16+
#try {
17+
# helm2 --help > $null 2>&1
18+
# Write-Host "helm2 setup looks good."
19+
#} catch {
20+
# Write-Host "Error: Could not find helm2, please check helm2 setup."
21+
# exit
22+
#}
23+
#
24+
## helm2 setup
25+
#Write-Host "setting up helm2 rbac account and initialise tiller"
26+
#kubectl apply -f scenarios/helm2-rbac/setup.yaml
27+
#helm2 init --service-account tiller
28+
#
29+
## wait for tiller service to ready
30+
#Write-Host "waiting for helm2 tiller service to be active."
31+
#Start-Sleep -Seconds 50
32+
33+
# deploying insecure-rbac scenario
34+
Write-Host "deploying insecure super admin scenario"
35+
kubectl.exe apply -f scenarios/insecure-rbac/setup.yaml
36+
37+
# deploying helm chart to verify the setup
38+
Write-Host "deploying helm chart metadata-db scenario"
39+
helm install metadata-db scenarios/metadata-db/
40+
41+
# setup the scenarios/configurations
42+
Write-Host 'deploying the vulnerable scenarios manifests'
43+
kubectl.exe apply -f scenarios/batch-check/job.yaml
44+
kubectl.exe apply -f scenarios/build-code/deployment.yaml
45+
kubectl.exe apply -f scenarios/cache-store/deployment.yaml
46+
kubectl.exe apply -f scenarios/health-check/deployment.yaml
47+
kubectl.exe apply -f scenarios/hunger-check/deployment.yaml
48+
kubectl.exe apply -f scenarios/internal-proxy/deployment.yaml
49+
kubectl.exe apply -f scenarios/kubernetes-goat-home/deployment.yaml
50+
kubectl.exe apply -f scenarios/poor-registry/deployment.yaml
51+
kubectl.exe apply -f scenarios/system-monitor/deployment.yaml
52+
kubectl.exe apply -f scenarios/hidden-in-layers/deployment.yaml
53+
54+
Write-Host 'Successfully deployed Kubernetes Goat. Have fun learning Kubernetes Security!'
55+
Write-Host 'Ensure pods are in running status before running access-kubernetes-goat.sh script'
56+
Write-Host 'Now run the bash access-kubernetes-goat.sh to access the Kubernetes Goat environment.'

teardown-kubernetes-goat.ps1

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Author: Madhu Akula
2+
# This program has been created as part of Kubernetes Goat
3+
# Teardown Kubernetes Goat setup
4+
5+
# Removing the superadmin cluster role/binding
6+
kubectl.exe delete clusterrolebindings superadmin
7+
kubectl.exe delete serviceaccount -n kube-system superadmin
8+
9+
# Removing the helm-tiller cluster role/binding
10+
kubectl.exe delete clusterrole all-your-base
11+
kubectl.exe delete clusterrolebindings belong-to-us
12+
13+
# Removing metadata db chart
14+
helm delete metadata-db --no-hooks
15+
# helm2 delete pwnchart --purge
16+
17+
# Remove tiller deployment
18+
kubectl.exe delete deployments -n kube-system tiller-deploy
19+
20+
# Delete the scenarios
21+
kubectl.exe delete -f scenarios/batch-check/job.yaml
22+
kubectl.exe delete -f scenarios/build-code/deployment.yaml
23+
kubectl.exe delete -f scenarios/cache-store/deployment.yaml
24+
kubectl.exe delete -f scenarios/health-check/deployment.yaml
25+
kubectl.exe delete -f scenarios/hunger-check/deployment.yaml
26+
kubectl.exe delete -f scenarios/internal-proxy/deployment.yaml
27+
kubectl.exe delete -f scenarios/kubernetes-goat-home/deployment.yaml
28+
kubectl.exe delete -f scenarios/poor-registry/deployment.yaml
29+
kubectl.exe delete -f scenarios/system-monitor/deployment.yaml
30+
kubectl.exe delete -f scenarios/hidden-in-layers/deployment.yaml
31+
32+
Write-Host "The Kubernetes Goat scenarios have been removed. Ensure to clean up what you installed and used. It's better to delete the cluster."

0 commit comments

Comments
 (0)