반응형
문제 설명
Topic: General
분야: Web
난이도: Easy
looks like the crawler's requests are weird
코드 분석

- process.env.FLAG가 있으면 FLAG사용
- 없다면 console.log("No flag") 실행
- undefined라면 process.exit(1); 실행

app.post("api/crawl-request", async (req, res) => {
- /api/crawl-request로 들어오는 POST요청을 처리하는 함수
- req는 요청 res는 응답
const url = req.body?.url;
- 요청 body의 url 값을 url에 저장 → req.body의 값이 없다면 undefiend 반환
if (typeof url !== "string" || (!url.startsWith("http://") && !url.startsWith("https://")))
return res.status(400).send("Invalid url");
- url이 string인지 검사 http://와 https://로 시작하는지 검사
- 아니면 400 에러와 Invalid url 반환
const r = await fetch(url, { headers: { FLAG }, signal: AbortSignal.timeout(5000) });
- 서버가 url로 HTTP 요청을 보냄
- 요청 헤더에 FLAG 넣음
- 시간제한 5초
if (!r.ok) return res.status(502).send("Fetch failed");
return res.sendStatus(200);
- 응답 상태가 200OK 아니면 502 반환?
- 성공이면 200보내고 끝
취약점분석
사용자가 지정한 URL로 서버가 직접 요청을 보내는데, 그 요청에 비밀값(FLAG)을 헤더로 붙여서 외부로 유출되는 SSRF 취약점
const r = await fetch(url, { headers: { FLAG }, signal: AbortSignal.timeout(5000) });
- 서버가 요청을 보내는데, 요청 헤더에 FLAG를 넣음
즉, 서버가 비밀 값을 스스로 요청에 붙여서 외부로 전송함
익스플로잇
웹 훅(Web hook)을 이용
https://webhook.site/#!/view/45c75d8b-7828-4a1b-b1d3-7d799ca993f9/e8260b65-0cd4-4de8-aa97-dcc08a6bfa8e/1


키워드
?? null 병합 연산자
a ?? b ?? c // a가 맞으면 a 아니면 b실행 b도 아니면 c실행
?. 옵셔널 체이닝 연산자
a?.b // a가 null이거나 undefined경우 undefined를 반환
SSRF(Server-Side-Request Forgery)
: 서버가 대신 HTTP요청을 보내게 만들 수 있는 취약점
반응형
'Alpacahack' 카테고리의 다른 글
| Alpacahack: Stateless Auth (0) | 2026.01.25 |
|---|---|
| Alpacahack: Animal Viewer (0) | 2026.01.22 |
| Alpacahack: dice roll (0) | 2026.01.21 |
| Alpacahack: secret-table (0) | 2026.01.20 |
| Alpacahack: I wanna be the Admin (0) | 2026.01.16 |