First Commit

This commit is contained in:
cnrenil 2024-09-09 17:14:12 +08:00
commit 50df36f85b
4 changed files with 105 additions and 0 deletions

8
Dockerfile Normal file
View File

@ -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"]

51
_files/app.py Normal file
View File

@ -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"<h1>下面的密文有Flag哦PS单表替换</h1><p>{cipher_text}</p>"
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)

44
_files/cli.py Normal file
View File

@ -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)

2
_files/requirements.txt Normal file
View File

@ -0,0 +1,2 @@
fastapi
uvicorn