Skip to content

Commit 9361827

Browse files
committed
πŸ—οΈ Reorganize files
1 parent bc1f507 commit 9361827

File tree

404 files changed

+232
-60652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

404 files changed

+232
-60652
lines changed

β€Ž.github/workflows/build-infra.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
id: build-and-push
7474
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
7575
with:
76-
context: ./infrastructure/paradigmctf.py
76+
context: ./paradigmctf.py
7777
push: ${{ github.event_name != 'pull_request' }}
7878
tags: ${{ steps.meta.outputs.tags }}
7979
labels: ${{ steps.meta.outputs.labels }}

β€Ž.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# venv
2+
/venv
3+
/include
4+
**/__pycache__
5+
.DS_Store

β€ŽREADME.md

+115-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,120 @@
1-
# OpenZeppelin CTF 2023
1+
# OpenZeppelin CTF Infra
22

3-
This repo contains the infrastructure & challenges for the OpenZeppelin CTF in 2023. The infrasturcture is built on top of [kCTF](https://github.com/google/kctf) and forked from [blazctf-2023](https://github.com/fuzzland/blazctf-2023).
3+
This repository contains all the infrastructure to host the OpenZeppelin CTF, based on [Paradigm CTF](https://ctf.paradigm.xyz).
44

5-
Directory:
6-
* `infrastructure`: Contains the infrastructure code forked from [paradigm-ctf-infrastructure](https://github.com/paradigmxyz/paradigm-ctf-infrastructure) with some modifications.
7-
* `challenges`: Challenges code and environment setup.
8-
* `solutions`: Solutions for the challenges.
5+
## Usage Local
96

10-
### How launch the challenge locally?
11-
1. cd into `infrastucture/paradigmctf.py` and run `docker-compose up -d` to start the infra servers.
12-
2. cd into `challenges/<challenge_name>/challenge` and run `docker-compose up -d` to start the challenge server.
13-
3. nc localhost 1337 to manage instance.
7+
To run the CTF infrastructure locally, simply run the following commands:
148

15-
Remember to delete existing instance before you switch to another challenge.
9+
```bash
10+
cd paradigmctf.py
11+
docker compose up
12+
```
1613

17-
# Challenges
18-
WIP
14+
To run the CTF infrastructure in kCTF, you'll need to do the following:
15+
16+
```bash
17+
# create the cluster if it doesn't exist
18+
kctf cluster create --type kind local-cluster --start
19+
20+
# build the image
21+
(cd paradigmctf.py; docker build us-docker.pkg.dev/idyllic-adviser-409615/openzeppelin/ctf-2023-server:latest)
22+
23+
# push the image to kind
24+
kind load docker-image --name "${CLUSTER_NAME}" "us-docker.pkg.dev/idyllic-adviser-409615/openzeppelin/ctf-2023-server:latest"
25+
26+
# create all the resources
27+
kubectl apply kubernetes/ctf-server.yaml
28+
29+
# port forward the anvil proxy for local access
30+
kubectl port-forward service/anvil-proxy 8545:8545 &
31+
```
32+
33+
Now you'll be able to build and test challenges in kCTF:
34+
```bash
35+
# start the challenge
36+
kctf chal start
37+
38+
# port forward the challenge
39+
kctf chal debug port-forward --port 1337 --local-port 1337 &
40+
41+
# connect to the challenge
42+
nc 127.0.0.1 1337
43+
```
44+
45+
## Usage Server
46+
47+
To run the CTF infrastructure in kCTF, you'll need to do the following:
48+
49+
```bash
50+
# get the challenges
51+
git clone ssh://[email protected]/openzeppelin/ctf-2023.git & cd ctf-2023
52+
53+
# pull the infrastructure
54+
docker pull us-docker.pkg.dev/idyllic-adviser-409615/openzeppelin/ctf-2023-server:latest
55+
56+
# umask allow copying executable files
57+
umask 0022
58+
59+
# enable docker integration with Google Container Registry
60+
gcloud auth configure-docker
61+
62+
# get and activate kctf
63+
curl -sSL https://kctf.dev/sdk | tar xz
64+
source kctf/activate
65+
66+
# create and start gke cluster
67+
kctf cluster create --project idyllic-adviser-409615 --domain openzeppelin.kctf.cloud --start remote-cluster
68+
69+
# create all the resources
70+
kubectl apply -f infrastructure/kubernetes/ctf-server.yaml
71+
72+
# port forward the anvil proxy for local access
73+
kubectl port-forward service/anvil-proxy 8545:8545 &
74+
```
75+
76+
Now you'll be able to build and test challenges in kCTF:
77+
```bash
78+
# start the challenge
79+
kctf chal start
80+
81+
# port forward the challenge
82+
kctf chal debug port-forward --port 1337 --local-port 1337 &
83+
84+
# connect to the challenge
85+
nc 127.0.0.1 1337
86+
```
87+
88+
## Images
89+
90+
Paradigm CTF is hosted using [kCTF](https://google.github.io/kctf/), a Kubernetes-based CTF platform. Follow the kCTF setup instructions to get a local cluster running on your computer.
91+
92+
### kctf-challenge
93+
The [kctf-challenge](/kctf-challenge/) image acts as a standard image on top of the kCTF base image. It's optional, not required, but provides the following features:
94+
- Adds the `/bin/kctf_persist_env` and `/bin/kctf_restore_env` scripts for use with `kctf_drop_privs`, which resets all environment variables (this might be removed if a better way of passing configuration variables is identified)
95+
- Adds a common `nsjail.cfg` for use with Anvil. The usefulness of running the Anvil server inside nsjail is debatable, as a lot of security features need to be disabled (timeouts, resource limits, etc). The file is also poorly-named, and may be changed in the future
96+
97+
### paradigmctf.py
98+
The [paradigmctf.py](/paradigmctf.py/) image acts as the base image for all challenges. It provides the following features:
99+
- Installs the `ctf_launchers`, `ctf_solvers`, and `ctf_server` libraries. These can be used to orchestrate CTF challenge instances.
100+
101+
## Libraries
102+
103+
### forge-ctf
104+
The [forge-ctf](/forge-ctf/) library provides two Forge scripts which can be used to deploy and solve challenges. They are intended to be used with the `eth_launchers` package.
105+
106+
The `CTFDeployment` script can be overridden to implement the `deploy(address system, address player) internal returns (address challenge)` function. It defaults to using the `test [...] test junk` mnemonic, but will read from the `MNEMONIC` environment variable. It writes the address that the challenge was deployed at to `/tmp/deploy.txt`, or the value of `OUTPUT_FILE`.
107+
108+
The `CTFSolver` script can be overriden to implement the `solve(address challenge, address player)` function. The challenge address must be specified as the `CHALLENGE` environment variable. The player private key defaults to the first key generated from the `test [...] junk` mnemonic, but can be overridden with `PLAYER`.
109+
110+
## Templates
111+
112+
Templates are provided for you to quickly get started with creating challenges of your own. To use them, copy the [templates](/templates/) into `kctf/challenge-templates`. Then, you will be able to use `kctf chal create --template eth-pwn`.
113+
114+
## TODO
115+
Huff support is pretty bad, needs the following changes upstream:
116+
- https://github.com/huff-language/foundry-huff/issues/47
117+
- Needs to support broadcasting from specific address
118+
- Needs to stop using hexdump to generate some random bytes
119+
120+
Kubernetes support is not complete yet

β€Žchallenges/.gitignore

-2
This file was deleted.

β€Žchallenges/eazy-nft/.challengeignore

-7
This file was deleted.

β€Žchallenges/eazy-nft/README.md

-50
This file was deleted.

β€Žchallenges/eazy-nft/challenge.yaml

-18
This file was deleted.

β€Žchallenges/eazy-nft/challenge/Dockerfile

-27
This file was deleted.

β€Žchallenges/eazy-nft/challenge/Dockerfile.local

-14
This file was deleted.

β€Žchallenges/eazy-nft/challenge/challenge.py

-12
This file was deleted.

β€Žchallenges/eazy-nft/challenge/docker-compose.yml

-19
This file was deleted.

β€Žchallenges/eazy-nft/challenge/project/.gitignore

-3
This file was deleted.

β€Žchallenges/eazy-nft/challenge/project/foundry.toml

-8
This file was deleted.

β€Žchallenges/eazy-nft/challenge/project/lib/forge-ctf/src/CTFSolver.sol

-20
This file was deleted.

0 commit comments

Comments
Β (0)