반응형
문제설명
How are they aware of us even behind the wall?
Flag Location: /flag
Flag Format: DH{...}
코드분석
app.py
@app.route('/')
def flag():
user_ip = request.access_route[0] if request.access_route else request.remote_addr
try:
result = run(
["/bin/bash", "-c", f"echo {user_ip}"],
capture_output=True,
text=True,
timeout=3,
)
return render_template("ip.html", result=result.stdout)
except TimeoutExpired:
return render_template("ip.html", result="Timeout!")
- request.access_route가 비어있지 않으면 request.access_route[0] 사용 / 비어있으면 request.remote_addr 사용
- /bin/bash를 실행하고 -c(뒤의 문자열을 명령어로 해석해 실행) 한다
- user_ip가 1.2.3.4면 실행 명령은 echo 1.2.3.4
request.access_route
: 요청이 거쳐온 IP들의 목록이다. 보통 프록시/로드밸런스가 있으면 클라이언트 IP → 중간 프록시 순서로 들어옴
그 중 request.access_route[0]은 첫 번째 IP를 가져오는데 가장 앞의 클라이언트 IP로 취급
request.remote_addr
: 현재 TCP 연결 상대 IP(바로 앞단)이다
프록시/로드밸런서 뒤에 있으면 이 값은 보통 프록시/로드밸런서의 IP가 된다.
취약점 분석
- user_ip를 검증없이 그대로 명령어로 실행
익스플로잇
먼저 ip 우회를 위해 X-Forwarded-For 헤더를 이용한다.
X-Forwarded-For
: 프록시/로드밸런스가 원래 클라이언트 IP를 백엔드에 전달하려고 붙이는 IP 헤더
위 코드에서 프록시/로드밸런스가 있으면 request.access_route[0] (클라이언트 IP) 를 user_ip로 쓴다고 했으니 위 헤더를 입력해준다. 또한 이 user_id를 명령어로 실행한다고 했으니 cat /flag 까지 추가해주면 flag 획득
X-Forwarded-For: 1.2.3.4;cat /flag

반응형
'Dreamhack 워게임 > Lv.1' 카테고리의 다른 글
| Logical (0) | 2026.02.14 |
|---|---|
| baby-ai (0) | 2026.02.14 |
| Dream Badge (0) | 2026.02.09 |
| baby-Case (0) | 2026.02.09 |
| simple-phparse (0) | 2026.02.09 |