forked from USTC-Hackergame/hackergame2023-writeups
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: taoky <[email protected]> Co-authored-by: Elsa <[email protected]> Co-authored-by: liuly <[email protected]> Co-authored-by: Jiyan He <[email protected]> Co-authored-by: tl2cents <[email protected]> Co-authored-by: RTXUX <[email protected]> Co-authored-by: zzh1996 <[email protected]> Co-authored-by: Hypercube <[email protected]> Co-authored-by: Long Deng <[email protected]> Co-authored-by: Mingliang Zeng <[email protected]> Co-authored-by: Underworld511 <[email protected]> Co-authored-by: emc2314 <[email protected]> Co-authored-by: PRO-2684 <[email protected]> Co-authored-by: regymm <[email protected]> Co-authored-by: Yanbing Zhao <[email protected]> Co-authored-by: iBug <[email protected]>
- Loading branch information
Showing
360 changed files
with
62,039 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,2 @@ | ||
.DS_Store | ||
__pycache__/ |
Large diffs are not rendered by default.
Oops, something went wrong.
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,87 @@ | ||
# hackergame2023-writeups | ||
|
||
本文档收集整理了中国科学技术大学第十届信息安全大赛的官方与非官方题解。 | ||
|
||
该仓库仍在活跃更新中,欢迎各位选手以 Pull Request 的形式提交自己的 write-up(players 目录下以自己的昵称创建新文件夹,并在本文件的「来自选手」部分增加一行)。 | ||
|
||
若大家对本题解有任何疑问或改进建议,欢迎 [提 issue](https://github.com/USTC-Hackergame/hackergame2023-writeups/issues/new)。 | ||
|
||
比赛平台:[https://hack.lug.ustc.edu.cn/](https://hack.lug.ustc.edu.cn/) | ||
|
||
比赛时间:北京时间 2023 年 10 月 28 日 中午 12:00 ~ 11 月 04 日 中午 12:00(共七天) | ||
|
||
## 目录 | ||
|
||
### 官方题解 | ||
|
||
部分题目需要使用 token。Token 可以从比赛平台注册获取,也可以使用 `2:MEUCIQC40y4XGGJHH303roxcGXaDxmkE4GJ2yKBAgnkWdSwY+gIgP45PlTy+3eAQsjd1iwdHxPBJwC7sjzwzs3K3ZJ3Z4OY=` 作为测试 token。 | ||
|
||
| 题目描述与 write-up | 文件、源代码 | | ||
| ------------------------------------------------------------ | ------------------------------------------------------- | | ||
| [Hackergame 启动](official/Hackergame%20启动/README.md) | - | | ||
| [猫咪小测](official/猫咪小测/README.md) | - | | ||
| [更深更暗](official/更深更暗/README.md) | [文件、源代码](official/更深更暗/src) | | ||
| [旅行照片 3.0](official/旅行照片%203.0/README.md) | - | | ||
| [赛博井字棋](official/赛博井字棋/README.md) | [文件、源代码](official/赛博井字棋/src) | | ||
| [奶奶的睡前 flag 故事](official/奶奶的睡前%20flag%20故事/README.md) | [文件](official/奶奶的睡前%20flag%20故事/files/) | | ||
| [组委会模拟器](official/组委会模拟器/README.md) | [文件、源代码](official/组委会模拟器/src) | | ||
| [虫](official/虫/README.md) | [文件](official/虫/files/) | | ||
| [JSON ⊂ YAML?](official/JSON%20⊂%20YAML/README.md) | [文件](official/JSON%20⊂%20YAML/files/) | | ||
| [Git? Git!](official/Git%20Git!/README.md) | [文件](official/Git%20Git!/files/) | | ||
| [HTTP 集邮册](official/HTTP%20集邮册/README.md) | [文件、源代码](official/HTTP%20集邮册/src) | | ||
| [Docker for Everyone](official/Docker%20for%20Everyone/README.md) | [文件、源代码](official/Docker%20for%20Everyone/src) | | ||
| [惜字如金 2.0](official/惜字如金%202.0/README.md) | [文件、源代码](official/惜字如金%202.0/src) | | ||
| [🪐 高频率星球](official/🪐%20高频率星球/README.md) | [文件](official/🪐%20高频率星球/files/)、[源代码](official/🪐%20高频率星球/src/) | | ||
| [🪐 小型大语言模型星球](official/🪐%20小型大语言模型星球/README.md) | [文件、源代码](official/🪐%20小型大语言模型星球/src) | | ||
| [🪐 流式星球](official/🪐%20流式星球/README.md) | [文件、源代码](official/🪐%20流式星球/src) | | ||
| [🪐 低带宽星球](official/🪐%20低带宽星球/README.md) | [文件、源代码](official/🪐%20低带宽星球/src) | | ||
| [Komm, süsser Flagge](official/Komm,%20süsser%20Flagge/README.md) | [文件、源代码](official/Komm,%20süsser%20Flagge/src) | | ||
| [为什么要打开 /flag 😡](official/为什么要打开%20flag%20😡/README.md) | [文件、源代码](official/为什么要打开%20flag%20😡/src) | | ||
| [异星歧途](official/异星歧途/README.md) | [文件](official/异星歧途/files/) | | ||
| [微积分计算小练习 2.0](official/微积分计算小练习%202.0/README.md) | [文件、源代码](official/微积分计算小练习%202.0/src) | | ||
| [逆向工程不需要 F5](official/逆向工程不需要%20F5/README.md) | [文件](official/逆向工程不需要%20F5/files/) | | ||
| [O(1) 用户登录系统](official/O(1)%20用户登录系统/README.md) | [文件](official/O(1)%20用户登录系统/files/) | | ||
| [链上猎手](official/链上猎手/README.md) | [文件](official/链上猎手/files/) | | ||
| [It's MyCalculator!!!!!](official/It's%20MyCalculator!!!!!/README.md) | [文件、源代码](official/It's%20MyCalculator!!!!!/src) | | ||
| [小 Z 的谜题](official/小%20Z%20的谜题/README.md) | [文件](official/小%20Z%20的谜题/files/) | | ||
| [黑客马拉松(部分完成)](official/黑客马拉松/README.md) | [文件、源代码](official/黑客马拉松/src) | | ||
| [不可加密的异世界 2](official/不可加密的异世界%202/README.md) | [文件](official/不可加密的异世界%202/files/) | | ||
| [旧日之痕(部分完成)](official/旧日之痕/README.md) | [文件、源代码](official/旧日之痕/src) | | ||
|
||
### 来自选手 | ||
|
||
**注意:选手提交的 write-up 需要在本仓库存档,仅仅提供到自己博客的题解链接的 Pull requests 不会被合并。在自己的 write-up 中可以添加自己的博客链接,以及指定 License(如不指定,则默认与本仓库相同,见 [版权声明](#版权声明) 一节)。** | ||
|
||
| write-up | 备注 | 包含题目 | | ||
| - | - | - | | ||
| [mcfx](players/mcfx/wp.md)(TODO) | 总排名第 1 名 | 全部题目 | | ||
|
||
## 其他资源 | ||
|
||
[Hackergame 2023 幕后工作人员](https://hack.lug.ustc.edu.cn/credits/) | ||
|
||
[搞笑 Flag & 花絮(暂缺)](./behind-the-scenes/README.md) | ||
|
||
### 历年题解 | ||
|
||
- [中国科学技术大学第九届信息安全大赛(Hackergame 2022)题解](https://github.com/USTC-Hackergame/hackergame2022-writeups) | ||
- [中国科学技术大学第八届信息安全大赛(Hackergame 2021)题解](https://github.com/USTC-Hackergame/hackergame2021-writeups) | ||
- [中国科学技术大学第七届信息安全大赛(Hackergame 2020)题解](https://github.com/USTC-Hackergame/hackergame2020-writeups) | ||
- [中国科学技术大学第六届信息安全大赛(Hackergame 2019)题解](https://github.com/ustclug/hackergame2019-writeups) | ||
- [中国科学技术大学第五届信息安全大赛(Hackergame 2018)题解](https://github.com/ustclug/hackergame2018-writeups) | ||
- [中国科学技术大学第四届信息安全大赛(Hackergame 2017)题解](https://volltin.gitbooks.io/hackergame2017-writeup/) | ||
|
||
### 知乎问题 | ||
|
||
- [知乎:参加中国科学技术大学第九届信息安全大赛(Hackergame 2022)是怎样一种体验?](https://www.zhihu.com/question/561919414) | ||
- [知乎:参加中国科学技术大学第八届信息安全大赛(Hackergame 2021)是怎样一种体验?](https://www.zhihu.com/question/492960717) | ||
- [知乎:参加中国科学技术大学第七届信息安全大赛(Hackergame 2020)是怎样一种体验?](https://www.zhihu.com/question/428140079) | ||
- [知乎:参加中国科学技术大学第六届信息安全大赛(Hackergame 2019)是怎样一种体验?](https://www.zhihu.com/question/351947330) | ||
- [知乎:参加中国科学技术大学第五届信息安全大赛(Hackergame 2018)是怎样一种体验?](https://www.zhihu.com/question/297850153) | ||
- [知乎:参加中科大第四届信息安全大赛是一种怎样的体验?](https://www.zhihu.com/question/67050288) | ||
|
||
## 版权声明 | ||
|
||
Copyright (c) USTC Hackergame 2023(中国科学技术大学第十届信息安全大赛组委会). All rights reserved. | ||
|
||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />本作品题解部分与未特别标注的源代码部分采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议</a>进行许可,特别标注的部分以标注的许可协议进行许可。 |
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,60 @@ | ||
# Docker for Everyone | ||
|
||
题解作者:[taoky](https://github.com/taoky) | ||
|
||
出题人、验题人、文案设计等:见 [Hackergame 2023 幕后工作人员](https://hack.lug.ustc.edu.cn/credits/)。 | ||
|
||
## 题目描述 | ||
|
||
- 题目分类:general | ||
|
||
- 题目分值:150 | ||
|
||
X 是实验室机器的管理员,为了在保证安全的同时让同学们都用上 docker,他把同学的账号加入了 docker 用户组,这样就不需要给同学 sudo 权限了! | ||
|
||
但果真如此吗? | ||
|
||
--- | ||
|
||
提供的环境会自动登录低权限的 `hg` 用户。登录后的提示信息显示了如何在该环境中使用 docker。读取 `/flag`(注意其为软链接)获取 flag。 | ||
|
||
题目环境运行 15 分钟后会自动关闭。 | ||
|
||
你可以在下面列出的两种方法中任选其一来连接题目: | ||
|
||
- 点击下面的「打开/下载题目」按钮通过网页终端与远程交互。如果采用这种方法,在正常情况下,你不需要手动输入 token。 | ||
- 在 Linux、macOS、WSL 或 Git Bash 等本地终端中使用 `stty raw -echo; nc 202.38.93.111 10338; stty sane` 命令来连接题目。如果采用这种方法,你必须手动输入 token(复制粘贴也可)。**注意,输入的 token 不会被显示,输入结束后按 Ctrl-J 即可开始题目。** | ||
|
||
无论采用哪种方法连接题目,启动题目均需要数秒时间,出现黑屏是正常现象,请耐心等待。 | ||
|
||
> 如果你不知道 `nc` 是什么,或者在使用上面的命令时遇到了困难,可以参考我们编写的 [萌新入门手册:如何使用 nc/ncat?](https://lug.ustc.edu.cn/planet/2019/09/how-to-use-nc/) | ||
## 题解 | ||
|
||
这题是 @zzh1996 的 idea,我负责实现。Docker 在配置的时候,很多人为了方便,会把自己加到 docker 的用户组里面,这么做在单人的环境下问题倒也不太大,但是在多人使用的服务器的场景下,这样做就有很大的问题,因为 docker 用户组和 root 事实上是等价的,本题也在尝试证明这一点。 | ||
|
||
解法很简单,在打开之后等待 alpine 开机,然后把 rootfs 挂(bind mount)进要运行的容器里即可: | ||
|
||
``` | ||
docker run -it --rm -v /:/outside alpine | ||
``` | ||
|
||
那么实际的 rootfs 就在 `/outside` 目录,注意 `/flag` 是个软链接,所以实际上 flag 位于 `/outside/dev/shm/flag`。如果希望能直接读根目录的软链接的话,得设置一下 IPC 模式为 `host`,这样的话主机和容器的 `/dev/shm` 就共享了: | ||
|
||
``` | ||
docker run -it --rm --ipc=host -v /:/outside alpine | ||
``` | ||
|
||
于是 flag 就在 `/dev/shm/flag`,可以直接读 `/outside/flag` 获取。 | ||
|
||
那么如果希望在保证安全的前提下让服务器的各个用户都能用上容器该怎么办?近年来流行的办法是启用 user namespace,然后配置 [rootless container](https://rootlesscontaine.rs/)。虽然 user namespace 这个内核特性是否安全还是个[颇具争议的话题](https://security.stackexchange.com/questions/209529/what-does-enabling-kernel-unprivileged-userns-clone-do)。 | ||
|
||
如果不希望开启 user namespace 的话,[PRoot](https://github.com/proot-me/PRoot/) 通过 `ptrace()` 来对程序假装自己的文件目录树、权限等信息,是一种可行的方案,但是 `ptrace` 带来的性能损失是远大于 user namespace 的;另一种方案是使用一个 root SUID 程序来做这个事情,例如 [bubblewrap](https://github.com/containers/bubblewrap) 就支持在 user namespace 关闭的时候通过 SUID 以 root 的身份提供服务,但是 SUID binary 本身的安全性也就成了很大的问题。 | ||
|
||
## 其他 | ||
|
||
在做这题的镜像的时候,我一开始用的方案是 buildroot,甚至内核编译参数都花了不少时间调,最后发现 docker 开不出来,`pivot_root` 会报错——然后发现 `pivot_root` 的限制使得我没有办法在 initramfs 里面跑 Docker 容器。 | ||
|
||
最后用了 Alpine,其实也还不错,改起来可能还比 buildroot 舒服点,虽然 OpenRC 开机好像确实不如 busybox 快就是(没有 KVM 加速的情况下)…… | ||
|
||
另外验题的时候发现有个「非预期解」:可以改 doas(sudo 的类似物)的配置让自己获得 root 权限,然后我就把 doas 的 binary 和配置删了,虽然都能改 doas 配置了,拿到 flag 应该是小菜一碟。 |
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 @@ | ||
port=10338 | ||
web_port=10339 | ||
nc_host=front | ||
nc_port=2333 | ||
nc_raw=1 | ||
conn_interval=10 | ||
token_timeout=30 | ||
challenge_timeout=900 | ||
pids_limit=128 | ||
mem_limit=1024m | ||
flag_path=/flag | ||
flag_rule=f"flag{{u5e_r00t1ess_conta1ner_{sha256('d0cker'+token)[:10]}_plz!}}" | ||
challenge_docker_name=docker_group_challenge | ||
read_only=1 |
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 @@ | ||
FROM ustclug/debian:bookworm | ||
|
||
RUN apt update && apt -y upgrade && \ | ||
apt install --no-install-recommends -y qemu-system wget p7zip-full ca-certificates | ||
|
||
ADD src /src | ||
WORKDIR /src | ||
|
||
RUN wget https://ftp.lug.ustc.edu.cn/~taoky/2023-004.7z && \ | ||
7z x -p5sIwZaW6q0XFHuHyyG0Ocw 2023-004.7z && \ | ||
echo "8cfd1662fb9408337cd902ec7044d0007422aed9fdceedb46ead74695b873e41 alpine.qcow2" | sha256sum -c && \ | ||
rm 2023-004.7z | ||
|
||
CMD ["/src/run.sh"] |
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,16 @@ | ||
version: '2.4' | ||
|
||
services: | ||
challenge: | ||
build: ./ | ||
entrypoint: ["/bin/true"] | ||
front: | ||
extends: | ||
file: ../dynamic_flag/docker-compose.yml | ||
service: front | ||
depends_on: | ||
- challenge | ||
web: | ||
extends: | ||
file: ../web_netcat/docker-compose.yml | ||
service: web |
Binary file not shown.
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,12 @@ | ||
#!/bin/sh -e | ||
|
||
cp /flag /dev/shm/flag | ||
|
||
qemu-system-x86_64 \ | ||
-device virtio-blk,drive=alpine \ | ||
-blockdev driver=qcow2,file.filename=./alpine.qcow2,file.driver=file,node-name=alpine,read-only=true,auto-read-only=true \ | ||
-m 256m -kernel ./vmlinuz-virt -initrd ./initramfs-virt \ | ||
-append "root=UUID=0eb3588b-da48-4c5e-a050-209c913fa8ea modules=ext4 quiet rootfstype=ext4 console=ttyS0 quiet oops=panic panic=1" \ | ||
-device virtio-blk,drive=flag \ | ||
-blockdev driver=raw,file.filename=/dev/shm/flag,file.driver=file,node-name=flag,read-only=false,auto-read-only=false \ | ||
-nographic -no-reboot -monitor /dev/null -nic none |
Binary file not shown.
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,55 @@ | ||
# Git? Git! | ||
|
||
题解作者:[PRO-2684](https://github.com/PRO-2684) | ||
|
||
出题人、验题人、文案设计等:见 [Hackergame 2023 幕后工作人员](https://hack.lug.ustc.edu.cn/credits/)。 | ||
|
||
## 题目描述 | ||
|
||
- 题目分类:general | ||
|
||
- 题目分值:150 | ||
|
||
> 图片使用 AI 技术生成,与真实人物无关。 | ||
![](files/copy.jpg) | ||
|
||
「幸亏我发现了……」马老师长吁了一口气。 | ||
|
||
「马老师,发生甚么事了?」马老师的一位英国研究生问。 | ||
|
||
「刚刚一不小心,把 flag 提交到本地仓库里了。」马老师回答,「还好我发现了,撤销了这次提交,不然就惨了……」 | ||
|
||
「这样啊,那太好了。」研究生说。 | ||
|
||
马老师没想到的是,这位年轻人不讲武德,偷偷把他的本地仓库拷贝到了自己的电脑上,然后带出了实验室,想要一探究竟…… | ||
|
||
**[打开/下载题目](files/ML-Course-Notes.zip)** | ||
|
||
## 题解 | ||
|
||
下载并解压附件,然后进入 `ML-Course-Notes` 目录。根据题目描述,首先使用 `git reflog` 查看完整的操作历史: | ||
|
||
```bash | ||
ubuntu@some-linux:/home/ubuntu/ML-Course-Notes$ git reflog | ||
ea49f0c (HEAD -> main) HEAD@{0}: commit: Trim trailing spaces | ||
15fd0a1 (origin/main, origin/HEAD) HEAD@{1}: reset: moving to HEAD~ | ||
505e1a3 HEAD@{2}: commit: Trim trailing spaces | ||
15fd0a1 (origin/main, origin/HEAD) HEAD@{3}: clone: from https://github.com/dair-ai/ML-Course-Notes.git | ||
``` | ||
|
||
可以看到,`clone` 后最近的一次提交 hash 是 `505e1a3`,猜测这就是马老师~~故意~~不小心提交 flag 的 commit。使用 `git reset` 回退到这次提交: | ||
|
||
```bash | ||
ubuntu@some-linux:/home/ubuntu/ML-Course-Notes$ git reset --hard 505e1a3 | ||
HEAD is now at 505e1a3 Trim trailing spaces | ||
``` | ||
|
||
查看 `README.md` 文件,发现 flag: | ||
|
||
```bash | ||
ubuntu@some-linux:/home/ubuntu/ML-Course-Notes$ cat .\README.md | ||
... | ||
<!-- flag{TheRe5_@lwAy5_a_R3GreT_pi1l_1n_G1t} --> | ||
... | ||
``` |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.