• Stars
    star
    216
  • Rank 176,645 (Top 4 %)
  • Language
    Shell
  • Created over 4 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Kubernetes Local Security Testing Lab

The goal of this project is to make use of Docker and specifically kind to create a lab environment for testing Kubernetes exploits and security tools entirely locally on a single machine without any requirement for remote resources or Virtual Machines being spun up.

To get the flexibility to set-up the various vulnerable clusters we're using Ansible playbooks.

If you want to get an idea of how this works and where to start, there's an episode of rawkode live where we go through it all. If you run into trouble while installing the Pre-Requisites, check out this installation guide which walks you though installing all the dependencies.

Pre-requisites

Before starting you'll need to install

  • Docker
  • Ansible
    • Also install the docker python module (e.g. pip install docker or pip3 install docker)
  • Kind 0.11.0 - Install guide here
    • Note: due to breaking changes in Kind v0.11.0+, currently only Kind v0.11.0 is supported
    • You can check your version with kind --version

If you're running Ubuntu 18.04, you can use the install_ansible_ubuntu.sh file to do the ansible setup. If you're running Ubuntu 20.04 then you can just get ansible from apt.

Getting Started

  1. Start up the vulnerable cluster you want to use, from the list below. At the end of the playbook you'll get an IP address for the cluster.
  2. Start the client machine container, and exec into a shell on it
  3. For the SSH clusters (the playbooks start ssh-to-*) SSH into a pod on the cluster with ssh -p 32001 sshuser@[Kubernetes Cluster IP] and a password of sshuser
  4. Attack away :)

More detailed explanations below .

Client Machine

There's a client machine with tools for Kubernetes security testing which can be brought up with the client-machine.yml playbook. It's best to use this client machine for all CLI tasks when running the scenarios, so you don't accidentally pick up creds from the host, but remember to start the kind cluster before the client machine, or the Docker network to connect to, may not be available.

  • ansible-playbook client-machine.yml

Once you've run the playbook, you can connect to the client machine with:-

docker exec -it client /bin/bash

The machine should be on the 172.18.0.0/24 network with the kind clusters (as well as being on the Docker default bridge)

Vulnerable Clusters

There's a number of playbooks which will bring up cluster's with a specific mis-configuration that can be exploited.

  • etcd-noauth.yml - ETCD Server available without authentication
  • insecure-port.yml - Kubernetes API Server Insecure Port available
  • rwkubelet-noauth.yml - Kubelet Read-Write Port available without authentication
  • ssh-to-cluster-admin.yml - Access to a running pod with a service account which has cluster-admin rights.
  • ssh-to-create-daemonsets-hard.yml
  • ssh-to-create-pods-easy.yml - Access to a running pod with a service account which has rights to manage pods.
  • ssh-to-create-pods-hard.yml - Access to a running pod with a service account which has rights to create pods.
  • ssh-to-create-pods-multi-node.yaml
  • ssh-to-get-secrets.yml - Access to a running pod with a service account which has cluster level rights to get secrets.
  • ssrf-to-insecure-port.yml - This cluster has a web application with an SSRF vulnerability in it, which can be exploited to target the insecure port.
  • tiller-noauth.yml - Tiller service configured without authentication.
  • unauth-api-server.yml - API Server with anonymous access possible to sensitive paths.
  • unauth-kubernetes-dashboard.yml - Cluster with the Kubernetes Dashboard installed and available without authentication.
  • rokubelet.yml - Exposed read only kubelet. This one doesn't have a compromise path ready (yet!)

If you would like to choose a random scenario to test your skills, run the get-random-scenario.sh script from your project folder!

Using the clusters

Each of these can be used to try out various techniques for attacking Kubernetes clusters. In general the goal of each exercise should be to get access to the /etc/kubernetes/pki/ca.key file as that's a "golden key" to persistent cluster access.

For each cluster the place to start is in the Scenario Setups which has details of how to get started.

If you want some information on one possible solution look in the Scenario Walkthroughs folder

Cleanup

When you're finished with your cluster(s) just use:

kind get clusters

To get a list of running clusters, then:

kind delete cluster --name=[CLUSTERNAME]

to remove the kind clusters, and:

docker stop client

to remove the client container

Demo Setup

There's a specific pair of playbooks which can be useful for demonstrating Kubernetes vulnerabilities. the demo-cluster.yml brings up a kind cluster with multiple vulnerabilities and the demo-client-machine.yml brings up a client container with the Kubernetes Kubeconfig for the demo cluster already installed. For this pair, it's important to bring up the cluster before the client machine, so that the kubeconfig file is available to be installed.

More Repositories

1

bWAPP

PHP
125
star
2

container-security-site

HTML
86
star
3

TestingScripts

A More or less Random Collection of Scripts for security Testing.
Ruby
64
star
4

alpine-containertools

docker image with useful network and container tools and SSH
Shell
58
star
5

dockerized-security-tools

Dockerfiles for security tools
Dockerfile
48
star
6

CVE-2022-23648-POC

POC for CVE-2022-23648
Dockerfile
37
star
7

k8s_ssrf_portscanner

Go
31
star
8

container_sec_workstation

Shell
26
star
9

OWASP_Web_App_Testing_Cheatsheet_Converter

OWASP Web Application Testing Cheat Sheet converted to tool formats
Ruby
25
star
10

eathar

Go
22
star
11

Cloud-Native-Security-Talks

HTML
18
star
12

rorascanner

Ruby Oracle Security Scanner
Ruby
16
star
13

sectest

Docker Automated Build for Security Testing Tools
Dockerfile
14
star
14

kind-of-insecure

Deliberately insecure Kubernetes test clusters built using kind
10
star
15

sycamore

Sycamore - An app. for managing Deciduous Attack Trees
HTML
9
star
16

teisteanas

Go
9
star
17

public-k8s-censys

Ruby
9
star
18

alpine-noroot-containertools

Dockerfile
7
star
19

kubeconeu-presentation

Presentation on Kubernetes Security for KubeconEU 2018
JavaScript
6
star
20

burp-free

6
star
21

raesene.github.io

GH Pages Blog
HTML
6
star
22

alpine-nettools

A Docker container with SSH running with a randomly generated password and some common networking tools
Shell
5
star
23

tocan

Go
5
star
24

container_image_obfuscator

Go
4
star
25

k8s_audit

4
star
26

insecure_ssh_container

it's an insecure SSH container...
Shell
3
star
27

pentest_helm_charts

Some charts that can be used for CTFs or when pentesting helm installs.
Smarty
3
star
28

kubelet_dumper

Go
3
star
29

burp_sample_plugins

Some Sample JRuby Plugins for Burp Suite
Ruby
3
star
30

cosign_test

Just a test repository to see how cosigning an image works.
Dockerfile
3
star
31

Laptop_Setup_Script

Sprinkle scripts for setting up a testing laptop
Ruby
3
star
32

dockerized-old-tools

Various old pieces of software in Docker containers, in case you need something a bit older and unsupported.
2
star
33

vulnsrctwit

Testing App
JavaScript
2
star
34

docker-glasgow-presentation

JavaScript
2
star
35

nmap_auto_analyzer

Ruby
2
star
36

container-runtime-presentation

A Presentation for Cloud Native Glasgow on Container Runtime Security
JavaScript
2
star
37

railsgoat

A Docker Automated Build for the OWASP RailsGoat project.
1
star
38

ssrftester

Basic SSRF Testing App.
Ruby
1
star
39

Dradis_docker

Dockerfile for dradis
1
star
40

admission_controllers

1
star
41

www.mccune.org.uk

Personal Portfolio Site
SCSS
1
star
42

containerlister

Go
1
star
43

gitrob-docker

A Dockerized gitrob
Shell
1
star
44

testssl

1
star
45

kubernetes-presentation

JavaScript
1
star
46

debian-autochrome

1
star
47

container_utilities

Go
1
star