# 취약: 경로 조작 / 디렉터리 탈출
@app.route("/read")
def read_file():
filename = request.args.get("path", "")
# 사용자 입력과 직접 join (정규화/화이트리스트 없음)
path = os.path.join(".", filename)
try:
with open(path, "r", encoding="utf-8", errors="ignore") as f:
return {"path": path, "content": f.read()}
except Exception as e:
return {"error": str(e)}, 400
# 취약: 명령 주입 (shell=True)
@app.route("/ping")
def ping():
host = request.args.get("host", "")
cmd = f"ping -c 1 {host}" # 입력값 검증 없음
out = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
return {"cmd": cmd, "output": out.decode("utf-8", errors="ignore")}