From 50df36f85b74347213ca85bdcbf151cb29df3f10 Mon Sep 17 00:00:00 2001 From: cnrenil Date: Mon, 9 Sep 2024 17:14:12 +0800 Subject: [PATCH] First Commit --- Dockerfile | 8 +++++++ _files/app.py | 51 +++++++++++++++++++++++++++++++++++++++++ _files/cli.py | 44 +++++++++++++++++++++++++++++++++++ _files/requirements.txt | 2 ++ 4 files changed, 105 insertions(+) create mode 100644 Dockerfile create mode 100644 _files/app.py create mode 100644 _files/cli.py create mode 100644 _files/requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7196c2d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.10 + +WORKDIR /app +COPY _files /app + +RUN pip install -r requirements.txt --no-cache-dir + +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80"] diff --git a/_files/app.py b/_files/app.py new file mode 100644 index 0000000..3ebbae6 --- /dev/null +++ b/_files/app.py @@ -0,0 +1,51 @@ +import os +from fastapi import FastAPI +from fastapi.responses import HTMLResponse + +app = FastAPI() + +def generate_substitution_cipher(flag): + substitution_rules = [] + for i, char in enumerate(flag): + position = i + 1 # 1-based index + if char.isalpha(): + if char.isupper(): + substitution_rules.append(f"the {position}th flag is '{char}', upper.\n") + else: # char is lowercase + substitution_rules.append(f"the {position}th flag is '{char}', lower.\n") + else: + substitution_rules.append(f"the {position}th flag is '{char}', character.\n") + + substitution_dict = { + 'a': 'x', 'b': 'y', 'c': 'z', 'd': 'a', 'e': 'b', 'f': 'c', 'g': 'd', + 'h': 'e', 'i': 'f', 'j': 'g', 'k': 'h', 'l': 'i', 'm': 'j', 'n': 'k', + 'o': 'l', 'p': 'm', 'q': 'n', 'r': 'o', 's': 'p', 't': 'q', 'u': 'r', + 'v': 's', 'w': 't', 'x': 'u', 'y': 'v', 'z': 'w', + 'A': 'X', 'B': 'Y', 'C': 'Z', 'D': 'A', 'E': 'B', 'F': 'C', 'G': 'D', + 'H': 'E', 'I': 'F', 'J': 'G', 'K': 'H', 'L': 'I', 'M': 'J', 'N': 'K', + 'O': 'L', 'P': 'M', 'Q': 'N', 'R': 'O', 'S': 'P', 'T': 'Q', 'U': 'R', + 'V': 'S', 'W': 'T', 'X': 'U', 'Y': 'V', 'Z': 'W', + ' ': ' ' # 保持空格不变 + } + + substitution_rules.append("The quick brown fox jumps a lazy dog.") + encrypted_rules = [] + for rule in substitution_rules: + for char in rule: + if char in substitution_dict: + encrypted_rules.append(substitution_dict[char]) + else: + encrypted_rules.append(char) + + return ''.join(encrypted_rules) + +@app.get("/", response_class=HTMLResponse) +async def read_root(): + flag = os.getenv("GZCTF_FLAG", "Woodpecker{test-Flag_0}") + cipher_text = generate_substitution_cipher(flag) + return f"

下面的密文有Flag哦(PS:单表替换):

{cipher_text}

" + +if __name__ == "__main__": + import uvicorn + uvicorn.run(app, host="0.0.0.0", port=8000) + diff --git a/_files/cli.py b/_files/cli.py new file mode 100644 index 0000000..684e977 --- /dev/null +++ b/_files/cli.py @@ -0,0 +1,44 @@ +import os + +def generate_substitution_cipher(flag): + substitution_rules = [] + for i, char in enumerate(flag): + position = i + 1 # 1-based index + if char.isalpha(): + if char.isupper(): + substitution_rules.append(f"the {position}th flag is '{char}', upper.\n") + else: # char is lowercase + substitution_rules.append(f"the {position}th flag is '{char}', lower.\n") + else: + # 对于非字母字符,记录其位置和类型 + substitution_rules.append(f"the {position}th flag is '{char}', character.\n") + + # 生成替换字典 + substitution_dict = { + 'a': 'x', 'b': 'y', 'c': 'z', 'd': 'a', 'e': 'b', 'f': 'c', 'g': 'd', + 'h': 'e', 'i': 'f', 'j': 'g', 'k': 'h', 'l': 'i', 'm': 'j', 'n': 'k', + 'o': 'l', 'p': 'm', 'q': 'n', 'r': 'o', 's': 'p', 't': 'q', 'u': 'r', + 'v': 's', 'w': 't', 'x': 'u', 'y': 'v', 'z': 'w', + 'A': 'X', 'B': 'Y', 'C': 'Z', 'D': 'A', 'E': 'B', 'F': 'C', 'G': 'D', + 'H': 'E', 'I': 'F', 'J': 'G', 'K': 'H', 'L': 'I', 'M': 'J', 'N': 'K', + 'O': 'L', 'P': 'M', 'Q': 'N', 'R': 'O', 'S': 'P', 'T': 'Q', 'U': 'R', + 'V': 'S', 'W': 'T', 'X': 'U', 'Y': 'V', 'Z': 'W', + ' ': ' ' # 保持空格不变 + } + + substitution_rules.append("The quick brown fox jumps a lazy dog.") + encrypted_rules = [] + for rule in substitution_rules: + for char in rule: + if char in substitution_dict: + encrypted_rules.append(substitution_dict[char]) + else: + encrypted_rules.append(char) + # 应用替换字典 + return ''.join(encrypted_rules) + +# 示例Flag +flag = os.getenv("GZCTF_FLAG", "Woodpecker{test-Flag_0}") +cipher_text = generate_substitution_cipher(flag) +print(cipher_text) + diff --git a/_files/requirements.txt b/_files/requirements.txt new file mode 100644 index 0000000..97dc7cd --- /dev/null +++ b/_files/requirements.txt @@ -0,0 +1,2 @@ +fastapi +uvicorn