Skip to content

Commit

Permalink
Feat(v0.17.0): Use PlatformProxy for private network accessing & traf…
Browse files Browse the repository at this point in the history
…fic capturing (#134)
  • Loading branch information
GZTimeWalker authored Aug 22, 2023
2 parents 57c1923 + 9b4b5b5 commit f661150
Show file tree
Hide file tree
Showing 110 changed files with 5,304 additions and 1,852 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

GZ::CTF 是一个基于 ASP.NET Core 的开源 CTF 平台。

**为了避免不必要的时间浪费,使用前请详细阅读使用文档:[https://docs.ctf.gzti.me/](https://docs.ctf.gzti.me/)**

## 特性 🛠️

- 创建高度可自定义的题目
Expand Down Expand Up @@ -86,7 +88,7 @@ _排名不分先后,欢迎提交 PR 进行补充。_

## 特别感谢 ❤️‍🔥

感谢 THUCTF 2022 的组织者 NanoApe 提供的赞助及阿里云公网并发压力测试,帮助验证了 GZCTF 单机实例在千级并发、三分钟 134w 请求压力下的服务稳定性。
感谢 THUCTF 2022 的组织者 NanoApe 提供的赞助及阿里云公网并发压力测试,帮助验证了 GZCTF 单机实例(16c90g)在千级并发、三分钟 134w 请求压力下的服务稳定性。

## Stars ✨

Expand Down
12 changes: 6 additions & 6 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
"build": "next build"
},
"dependencies": {
"@vercel/analytics": "^1.0.1",
"next": "^13.4.13",
"@vercel/analytics": "^1.0.2",
"next": "^13.4.16",
"next-themes": "^0.2.1",
"nextra": "^2.10.0",
"nextra-theme-docs": "^2.10.0",
"nextra": "^2.11.0",
"nextra-theme-docs": "^2.11.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^20.4.8",
"@types/react": "^18.2.18",
"@types/node": "^20.5.0",
"@types/react": "^18.2.20",
"typescript": "^5.1.6"
}
}
3 changes: 2 additions & 1 deletion docs/pages/_meta.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"deployment": "部署",
"guide": "使用指南",
"issue": "常见问题",
"thanks": "致谢"
"thanks": "致谢",
"changelog": "更新日志"
}
15 changes: 15 additions & 0 deletions docs/pages/changelog.zh.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Callout } from "nextra-theme-docs";

# 更新日志

## v0.17

**Break Changes**

- **将原有 `uploads` 目录移动至 `files/uploads`,移除了此目录的配置项,更改了日志存储位置**

更新步骤:将原有 `uploads` 目录移动至 `files/uploads`,并重新挂载相关目录,删除 `uploads` 目录的配置项和原有 `log` 目录

## v0.16-v0.1

见 Release 记录:https://github.com/GZTimeWalker/GZCTF/releases
19 changes: 11 additions & 8 deletions docs/pages/config/appsettings.zh.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ import { Callout } from "nextra-theme-docs";
"XorKey": "<Random Key Str>",
"ContainerProvider": {
"Type": "Docker", // or "Kubernetes"
"PortMappingType": "Default",
"EnableTrafficCapture": false,
"PublicEntry": "ctf.example.com", // or "xxx.xxx.xxx.xxx"
"DockerConfig": {
// optional
"SwarmMode": false,
"ChallengeNetwork": "",
"Uri": "unix:///var/run/docker.sock"
},
"K8sConfig": {
Expand Down Expand Up @@ -80,12 +83,8 @@ import { Callout } from "nextra-theme-docs";
"ForwardLimit": 1,
"ForwardedForHeaderName": "X-Forwarded-For",
// use the following options to allow proxy
"TrustedNetworks": [
"10.0.0.0/8"
],
"TrustedProxies": [
"10.0.0.1"
]
"TrustedNetworks": ["10.0.0.0/8"],
"TrustedProxies": ["10.0.0.1"]
}
}
```
Expand Down Expand Up @@ -129,6 +128,8 @@ GZCTF 仅支持 PostgreSQL 作为数据库,不支持 MySQL 等其他数据库

- **Type:** 容器后端类型,可选 `Docker``Kubernetes`
- **PublicEntry:** 容器后端的公网地址,用于生成比赛的访问地址,展示给参赛队伍。
- **PortMappingType:** 端口映射类型,可选 `Default``PlatformProxy`
- **EnableTrafficCapture:** 是否开启流量捕获,仅在 `PortMappingType` 设置为 `PlatformProxy` 时可用。若开启,将会记录流量于 `/app/files/capture` 目录下。

#### Docker

Expand All @@ -145,12 +146,14 @@ GZCTF 仅支持 PostgreSQL 作为数据库,不支持 MySQL 等其他数据库
- 如需使用本地 docker,请将 Uri 置空,并将 `/var/run/docker.sock` 挂载入容器对应位置
- 如需使用外部 docker,请将 Uri 指向对应 docker API Server,**外部 API 鉴权尚未实现,不推荐此部署方式**

- **ChallengeNetwork:** 指定题目容器所在的网络,若不指定,将会使用默认网络。

#### Kubernetes

- **Namespace:** Kubernetes 命名空间,用于创建题目实例的命名空间,默认为 `gzctf-challenges`
- **ConfigPath:** Kubernetes 配置文件路径,用于连接集群,默认为 `k8sconfig.yaml`
- **AllowCIDR:** [实验功能] 允许访问 Pod 的 CIDR 白名单
- **DNS:** [实验功能] 避免使用集群 DNS 的自定义 DNS 服务器列表
- **AllowCIDR:** 允许访问 Pod 的 CIDR 白名单
- **DNS:** 避免使用集群 DNS 的自定义 DNS 服务器列表

默认行为请将集群连接配置放入 `k8sconfig.yaml` 文件中,并将其挂载到 `/app` 目录下。实验功能若非了解行为请勿更改。

Expand Down
3 changes: 1 addition & 2 deletions docs/pages/deployment/docker-k8s.zh.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ gzctf:
networks:
default:
volumes:
- "./data/files:/app/uploads"
- "./data/files:/app/files"
- "./appsettings.json:/app/appsettings.json:ro"
- "./logs:/app/log"
- "./k8sconfig.yaml:/app/k8sconfig.yaml:ro" # this is required for k8s deployment
# - "/var/run/docker.sock:/var/run/docker.sock" # this is required for docker deployment
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/deployment/k8s-only.zh.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ import { Callout } from "nextra-theme-docs";
name: http
volumeMounts:
- name: gzctf-files
mountPath: /app/uploads
mountPath: /app/files
- name: gzctf-config
mountPath: /app/appsettings.json
subPath: appsettings.json
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/guide/_meta.zh.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"challenge": "赛题配置",
"dynamic-flag": "动态 flag"
"dynamic-flag": "动态 flag",
"platform-proxy": "平台流量代理"
}
6 changes: 0 additions & 6 deletions docs/pages/guide/challenge/_meta.zh.json

This file was deleted.

3 changes: 0 additions & 3 deletions docs/pages/guide/challenge/dynamic-attachment.zh.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/pages/guide/challenge/dynamic-container.zh.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/pages/guide/challenge/static-attachment.zh.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/pages/guide/challenge/static-container.zh.mdx

This file was deleted.

48 changes: 48 additions & 0 deletions docs/pages/guide/platform-proxy.zh.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Callout } from "nextra-theme-docs";

# 平台代理

GZCTF 自带对于流量的 WebSocket-TCP 转发功能和对应的流量记录能力,可以通过相关配置项进行开启。

## 配置

`appsettings.json` 中,找到 `ContainerProvider` 节点,进行如下配置:

```json
{
"ContainerProvider": {
"PortMappingType": "PlatformProxy",
"EnableTrafficCapture": false
}
}
```

## 使用

在平台代理开启后,可以使用平台的 `/api/proxy/{guid}` 接口进行流量转发。

可用客户端:[WebSocketReflectorX](https://github.com/XDSEC/WebSocketReflectorX) 进行本地端口代理,从而进行无感交互。

## 注意事项

采用 `Docker` 单机作为后端且使用 `PlatformProxy` 端口映射类型时,为了使得 GZCTF 顺利访问题目容器,需要额外手动创建一个网络:

```bash
docker network create challenges -d bridge --subnet 192.168.133.0/24
```

设置配置项 **ChallengeNetwork** 为对应的网络名称,并需要在 docker-compose.yml 中桥接外部网络,例如:

```yaml
version: "3.7"
services:
gzctf:
...
networks:
- default
- challenges

networks:
challenges:
external: true
```
16 changes: 11 additions & 5 deletions docs/pages/quick-start.zh.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ GZCTF 的安全性和前端功能(如操作剪贴板)依赖于 HTTPS,此
"XorKey": "<Your XOR_KEY>",
"ContainerProvider": {
"Type": "Docker", // or "Kubernetes"
"PortMappingType": "Default", // or "PlatformProxy"
"EnableTrafficCapture": false,
"PublicEntry": "<Your PUBLIC_ENTRY>", // or "xxx.xxx.xxx.xxx"
"DockerConfig": {
// optional
Expand All @@ -66,6 +68,11 @@ GZCTF 的安全性和前端功能(如操作剪贴板)依赖于 HTTPS,此
"Sitekey": "",
"Secretkey": "",
"RecaptchaThreshold": "0.5"
},
"ForwardedOptions": {
"ForwardedHeaders": 5,
"ForwardLimit": 1,
"TrustedNetworks": ["192.168.12.0/8"]
}
}
```
Expand All @@ -83,9 +90,8 @@ GZCTF 的安全性和前端功能(如操作剪贴板)依赖于 HTTPS,此
ports:
- "80:80"
volumes:
- "./data/files:/app/uploads"
- "./data/files:/app/files"
- "./appsettings.json:/app/appsettings.json:ro"
- "./logs:/app/log"
# - "./k8sconfig.yaml:/app/k8sconfig.yaml:ro" # this is required for k8s deployment
- "/var/run/docker.sock:/var/run/docker.sock" # this is required for docker deployment
depends_on:
Expand Down Expand Up @@ -116,7 +122,7 @@ GZCTF 的安全性和前端功能(如操作剪贴板)依赖于 HTTPS,此

</Callout>

4. 运行 `docker-compose up -d` 来启动 GZCTF,之后你可以通过浏览器访问 GZCTF 了。
4. 运行 `docker compose up -d` 来启动 GZCTF,之后你可以通过浏览器访问 GZCTF 了。

## 初始管理员

Expand All @@ -131,7 +137,7 @@ UPDATE "AspNetUsers" SET "Role"=3 WHERE "UserName"='your_admin_user_name';
你可能会用到如下的命令:

```bash
docker-compose exec db psql -U postgres
docker compose exec db psql -U postgres
```

```bash
Expand Down Expand Up @@ -179,7 +185,7 @@ ctf=# #do your sql query
}
```

之后重新使用 `docker-compose up -d` 启动 GZCTF 即可。
之后重新使用 `docker compose up -d` 启动 GZCTF 即可。

## 容器镜像

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/thanks.zh.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _排名不分先后,欢迎提交 PR 进行补充。_

## 特别感谢 ❤️‍🔥

感谢 THUCTF 2022 的组织者 NanoApe 提供的赞助及阿里云公网并发压力测试,帮助验证了 GZCTF 单机实例在千级并发、三分钟 134w 请求压力下的服务稳定性。
感谢 THUCTF 2022 的组织者 NanoApe 提供的赞助及阿里云公网并发压力测试,帮助验证了 GZCTF 单机实例(16c90g)在千级并发、三分钟 134w 请求压力下的服务稳定性。

## 贡献者 👋

Expand Down
Loading

0 comments on commit f661150

Please sign in to comment.