본문 바로가기

old/Cyber Security

웹 해킹 예제: 인증과 인가 취약점_CTF: 달콤한 마이페이지 훔쳐보기

반응형

목표

admin 계정의 마이페이지를 확인하세요!

공격

공격순서

일단 마이페이지를 확인하고 내부 코드를 확인해본다

sfUser/sfUser1234로

로그인을 하고 마이페이지에 접근한후, 내부 코드를 살펴본다

요청코드

GET /auth8/mypage.php?user=sfUser HTTP/1.1
Host: ctf.segfaulthub.com:3481
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.134 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://ctf.segfaulthub.com:3481/auth8/index.php>
Accept-Encoding: gzip, deflate
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: user=sfUser; session=0c7573fe-ca9d-49aa-9e6e-1807a1a768d4.l3ljYnqyXXAPtH-5LPhkm-MZ6Xc; PHPSESSID=51ug79hj0eqojpmrpi5lijdn8b
Connection: close

응답코드

HTTP/1.1 200 OK
Date: Wed, 21 Jun 2023 21:48:52 GMT
Server: Apache/2.4.18 (Ubuntu)
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding
Content-Length: 1367
Connection: close
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="./css/style.css"  rel = "stylesheet"/>
    <title>Private Page</title>
</head>
<body>
    <div class = "wrapper">
        <div id = "login-form">
            <div class = "head">개인정보</div>
            <form method = "post" action = "mypage_update.php">
                <div class = "hori">
                    <i class="far fa-user fa-2x"></i>
                    <input name = "id" type = "text" placeholder="sfUser"/>
                </div>
                <div class = "hori">
                    <i class="fas fa-birthday-cake fa-2x"></i>
                    <input name = "info" type = "text" placeholder="Nothing Here..."/>
                </div>
                <div class = "hori">
                    <i class="fas fa-lock fa-2x"></i>
                    <input name = "pw" type = "password" placeholder="변경할 비밀번호"/>
                </div>
                <div class = "hori"><input type = "submit" value = "Update" id = "signup-btnl"/></div>
            </form>
        </div>
    </div>
    <script
        src="https://kit.fontawesome.com/6478f529f2.js"
        crossorigin="anonymous"
    ></script>
</body>
</html>

요청코드를 살펴본다면, 피라미터로 사용자의 아이디를 받아서 응답이 실행되는것을 확인할수 있습니다. 만약 서버에서 피라미터로 확인을 한다면, 피라미터 우회를 시도해볼수 있습니다.

리피터를 이용한 피라미터 변조

burp suite의 리피터를 사용해서 user피라미터를 admin으로 변경하여 실행하였으나, 여전히 응답페이지는 sfUser를 주는것을 확인할수 있습니다.

저 피라미터는 쓰지 않는다고 추측할수 있습니다. 이제 요청을 자세히 살펴보면, 쿠키에 세션과 유저가 셋팅이 됨을 확인할수 있습니다.

리피터를 이용한 쿠키 변조

burp suite의 리피터를 사용해서 쿠키의 user피라미터를 admin으로 변경하면 잘 실행되어 숨겨진 flag를 확인할수 있습니다.

쿠키가 세션까지 확인할경우

위의 경우는 쿠키의 user피라미터만 서버에서 확인하므로, 저 피라미터만 변조하면 원하는 flag를 얻을수 있습니다. 만약 세션과 세션 아이디까지 서버에서 인증을 할경우, XSS를 이용하여 사용자의 세션을 탈취해야 합니다.

정리

위의 피라미터는 사용되지 않고, 내부의 쿠키를 이용해서 인증하는 웹싸이트이기 때문에, 쿠키를 변조하여 문제를 해결할수 있습니다.

 

반응형