[DreamHack] baby-Case Write-up
2025. 6. 9. 11:12ㆍ보안/웹
728x90
문제에 들어가면 hi guest라는 문구밖에 안나온다. 코드를 보자.
const express = require("express")
const words = require("./ag")
const app = express()
const PORT = 3000
app.use(express.urlencoded({ extended: true }))
function search(words, leg) {
return words.find(word => word.name === leg.toUpperCase())
}
app.get("/",(req, res)=>{
return res.send("hi guest")
})
app.post("/shop",(req, res)=>{
const leg = req.body.leg
if (leg == 'FLAG'){
return res.status(403).send("Access Denied")
}
const obj = search(words,leg)
if (obj){
return res.send(JSON.stringify(obj))
}
return res.status(404).send("Nothing")
})
app.listen(PORT,()=>{
console.log(`[+] Started on ${PORT}`)
})
코드를 보면 GET / 요청 시 hi guest 문구를 응답하고,
POST /shop 요청 시 req.body.leg값을 가져와 FLAG 이면 403에러를 응답한다.
그 외에는 words 배열에서 대소문자를 무시(search함수)하고 일치하는 name을 찾아 JSON 응답한다.
여기서 words 배열은 ./ag경로를 받고 있으므로 ag.js 코드를 보자.
module.exports = [
{
"id": 1,
"name": "FLAG",
"description": "DH{fake_flag}"
},
{
"id": 2,
"name": "DRAG",
"description": "To pull something along forcefully, often on the ground or another surface, causing friction or resistance. It also refers to the delay in performance or response time."
},
{
"id": 3,
"name": "SLAG",
"description": "The waste material produced by the smelting process, which involves separating metal from its ore. Slag is typically a mixture of metal oxides and silicon dioxide."
},
{
"id": 4,
"name": "SWAG",
"description": "Refers to stylish confidence in one's appearance or demeanor. It can also mean promotional goods or items given away for free as a form of advertising."
}
]
FLAG 제외하고는 각 단어의 의미가 설명되어 있다.
url 에 /shop을 추가해주면
flag도 입력 안했는데 403 forbidden이 나온다.
events {
worker_connections 1024;
}
http {
server {
listen 80;
listen [::]:80;
server_name _;
location = /shop {
deny all;
}
location = /shop/ {
deny all;
}
location / {
proxy_pass http://app:3000/;
}
}
}
nginx설정 파일을 보니 /shop 과 /shop/ 경로를 deny all로 모두 막고 있다.
하지만 /shop으로 접근을 해야 하므로 /shop을 우회해야 한다.
전에 프론트 개발 공부를 할 때 페이지 접근할 때 별다른 설정이 없으면 대소문자 구분을 안하고 경로를 쳐도 구분 없이 접근이 가능했던 기억이 나서 대문자로 접근해보았다.
GET 방식으로는 접근이 안된다. 코드에서도 POST라고 나와있었으니 burp suite를 이용해 POST 방식으로 보내주면
오류가 나왔다. 좀 찾아보니까 코드에
app.use(express.urlencoded({ extended: true }))
이런 코드가 있는데 url인코딩 방식으로 되어있다는 코드이다.
그러니까 HTTP 헤더에도 본문이 url 인코딩 방식이라는 것을 알려주는 헤더를 추가해줘야 한다.
Content-Type: application/x-www-form-urlencoded
해당 헤더를 추가해주면
728x90
'보안 > 웹' 카테고리의 다른 글
[DreamHack] Random Test Write-up (0) | 2025.06.16 |
---|---|
[DreamHack] My Best Friend Write-up (0) | 2025.06.08 |
[DreamHack] Test Your Luck Write-up (0) | 2025.06.08 |
[DreamHack] Replace Trick! Write-up (0) | 2025.01.06 |
[DreamHack] Find The Lost Flag Write-up (1) | 2025.01.06 |