완료됨
포트 질문
8000포트로는 왜 flag.txt에 접근할 수 없나요? 따로 만들고 있는 랜덤포트랑 다른 점이 무엇일까요?
#web
작성자 정보
답변
1
as3617
워게임 고인물
app.run(host="0.0.0.0", port=8000, threaded=True)
8000번 포트는 flask에서 사용하는 포트입니다.
flask는 따로 설정해주지 않는다면 Serving static file을 지원하지 않습니다.
def index():
return render_template("index.html")
@app.route("/img_viewer", methods=["GET", "POST"])
def img_viewer():
if request.method == "GET":
return render_template("img_viewer.html")
elif request.method == "POST":
url = request.form.get("url", "")
urlp = urlparse(url)
if url[0] == "/":
url = "http://localhost:8000" + url
elif ("localhost" in urlp.netloc) or ("127.0.0.1" in urlp.netloc):
data = open("error.png", "rb").read()
img = base64.b64encode(data).decode("utf8")
return render_template("img_viewer.html", img=img)
try:
data = requests.get(url, timeout=3).content
img = base64.b64encode(data).decode("utf8")
except:
data = open("error.png", "rb").read()
img = base64.b64encode(data).decode("utf8")
return render_template("img_viewer.html", img=img)
그렇기 때문에 8000번 포트로 접근할 수 있는 것은 위와 같이 flask에 정의된 router에만 가능합니다.