-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e681bae
commit 9f3732b
Showing
8 changed files
with
163 additions
and
57 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
.vscode/ | ||
env/ |
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,34 @@ | ||
FROM python:3.10.12-slim-bullseye | ||
|
||
# 制作者信息 | ||
LABEL auther_template="CTF-Archives" | ||
|
||
# apt更换镜像源,并更新软件包列表信息 | ||
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && \ | ||
sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list | ||
RUN apt-get update | ||
|
||
# 通过apt,安装xinetd用于服务转发 | ||
RUN apt-get install -y socat | ||
|
||
# 通过tuna源,安装必要的python依赖库 | ||
# 镜像中并没有更换源,只是在pip语句中每次制定了镜像源 | ||
RUN python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple \ | ||
pycryptodome pillow | ||
|
||
# 复制容器启动脚本 | ||
COPY ./service/docker-entrypoint.sh / | ||
RUN chmod +x /docker-entrypoint.sh | ||
|
||
# 新建用户,并进行账户改变 | ||
RUN useradd -m ctf | ||
WORKDIR /home/ctf | ||
|
||
# 部署程序 | ||
COPY ./src /app | ||
|
||
# [可选]指定对外暴露端口,对于GZCTF等平台,强制EXPOSE可能会造成非预期端口泄露,请酌情启用 | ||
# EXPOSE 9999 | ||
|
||
# 指定容器入口点 | ||
ENTRYPOINT ["/bin/sh","/docker-entrypoint.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,24 @@ | ||
# misc-lsb-dynamic | ||
|
||
## 环境说明 | ||
|
||
实现了基础的 Misc LSB 隐写脚本,并通过 `http.server.SimpleHTTPRequestHandler` 实现了一个简单的 HTTP 服务器 | ||
|
||
## 如何使用 | ||
|
||
本模板仅为示例,如果需要修改隐写的基础图像,或者更改隐写逻辑的话,请自行修改 `src/server.py` | ||
|
||
执行 | ||
|
||
```shell | ||
docker build . | ||
``` | ||
|
||
即可开始编译镜像 | ||
|
||
也可以在安放好程序文件之后,直接使用 `./docker/docker-compose.yml` 内的 `docker-compose` 文件实现一键启动测试容器 | ||
|
||
```shell | ||
cd ./docker | ||
docker-compose up -d | ||
``` |
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,11 @@ | ||
version: '3' | ||
services: | ||
test: | ||
build: ../ | ||
environment: | ||
# 仅为测试用flag | ||
FLAG: "flag{a63b4d37-7681-4850-b6a7-0d7109febb19}" | ||
ports: | ||
# 设置了暴露端口 | ||
- 8080:8080 | ||
restart: unless-stopped |
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,25 @@ | ||
#!/bin/sh | ||
|
||
# Get the user | ||
user=$(ls /home) | ||
|
||
# Check the environment variables for the flag and assign to INSERT_FLAG | ||
if [ "$DASFLAG" ]; then | ||
INSERT_FLAG="$DASFLAG" | ||
export DASFLAG=no_FLAG | ||
DASFLAG=no_FLAG | ||
elif [ "$FLAG" ]; then | ||
INSERT_FLAG="$FLAG" | ||
export FLAG=no_FLAG | ||
FLAG=no_FLAG | ||
elif [ "$GZCTF_FLAG" ]; then | ||
INSERT_FLAG="$GZCTF_FLAG" | ||
export GZCTF_FLAG=no_FLAG | ||
GZCTF_FLAG=no_FLAG | ||
else | ||
INSERT_FLAG="flag{TEST_Dynamic_FLAG}" | ||
fi | ||
|
||
cd /app | ||
|
||
python3 /app/server.py $INSERT_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,58 @@ | ||
from PIL import Image | ||
import http.server | ||
import socketserver | ||
import os | ||
import sys | ||
|
||
|
||
def string_to_binary(string: str): | ||
return [bin(ord(i))[2:].rjust(8, "0") for i in string] | ||
|
||
|
||
img_src = Image.open("./src.png").convert("RGB") | ||
|
||
flag = sys.argv[1] | ||
print("Flag: {}".format(flag)) | ||
flag = "".join([i for i in string_to_binary(sys.argv[1])]) | ||
flag = [i for i in flag] | ||
print("FLag binary: {}".format(flag)) | ||
|
||
W, H = img_src.size | ||
|
||
img_dst = Image.new(img_src.mode, (W, H)) | ||
|
||
for y in range(H): | ||
for x in range(W): | ||
if flag: | ||
pixel = img_src.getpixel((x, y)) | ||
pixel = (int(bin(pixel[0])[2:][:-1] + flag.pop(0), 2), pixel[1], pixel[2]) | ||
img_dst.putpixel((x, y), pixel) | ||
else: | ||
img_dst.putpixel((x, y), img_src.getpixel((x, y))) | ||
|
||
os.mkdir("./http") | ||
img_dst.save("./http/dst.png") | ||
|
||
|
||
class Handler(http.server.SimpleHTTPRequestHandler): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, directory="./http", **kwargs) | ||
|
||
def do_GET(self): | ||
if self.path == "/": | ||
self.send_response(200) | ||
self.send_header("Content-Disposition", 'attachment; filename="dst.png"') | ||
self.send_header("Content-type", "application/octet-stream") | ||
self.end_headers() | ||
|
||
# 读取文件内容并发送给客户端 | ||
with open("./http/dst.png", "rb") as file: | ||
self.wfile.write(file.read()) | ||
else: | ||
# 调用父类的默认处理方法 | ||
super().do_GET() | ||
|
||
|
||
with socketserver.TCPServer(("0.0.0.0", 8080), Handler) as httpd: | ||
print("Server is running\nhttp://0.0.0.0:8080/") | ||
httpd.serve_forever() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.