Osori Development Studio

sfw6 up 본문

전공쪽/동아리 관련

sfw6 up

OSOR2 2021. 1. 7. 13:47

 페이지의 소스코드이다. 

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Playlist</title>
    <link rel="stylesheet" href="index_css.css">
  </head>
  <body>
    <form action="check.php" method="post">
      <table class="sub_news" border ="1" cellspacing="0" summary="Playlist">
        <caption>Playlist</caption>
        <h1>Playlist</h1>
        <h2>"All the songs on my playlist were legally downloaded"</h2>
        <colgroup>
          <col width="400">
          <col width="200">
          <col width="80">
          <col width="80">
        </colgroup>
        <thead>
          <tr>
            <th scope="col">title</th>
            <th scope="col">name</th>
            <th scope="col">date</th>
            <th scope="col">time</th>
          </tr>
        </thead>
        <tbody>
          <tr>
          <tr><td>will not go home without you</td><td>maroon5</td><td>2008/02/26</td><td>351</td></tr><tr><td>i love you</td><td>taeyeon</td><td>2010/12/13</td><td>322</td></tr><tr><td>what makes you beautiful</td><td>one direction</td><td>2011/11/29</td><td>318</td></tr><tr><td>why so serious?</td><td>shinee</td><td>2013/04/29</td><td>340</td></tr><tr><td>you will never know</td><td>ariana grande</td><td>2014/09/02</td><td>334</td></tr><tr><td>text me merry christmas</td><td>straight no chaser</td><td>2014/11/17</td><td>241</td></tr><tr><td>when you hold me tight</td><td>yael mayer</td><td>2014/12/22</td><td>312</td></tr><tr><td>shame</td><td>melomance</td><td>2015/03/10</td><td>325</td></tr><tr><td>work from home</td><td>fifty harmony</td><td>2016/05/28</td><td>334</td></tr><tr><td>treat you better</td><td>shawn mendes</td><td>2017/04/21</td><td>308</td></tr><tr><td>wanne be</td><td>wanna one</td><td>2017/08/07</td><td>321</td></tr><tr><td>some things never change</td><td>anna</td><td>2019/11/15</td><td>329</td></tr><tr><td>Away</td><td>eunji</td><td>2020/07/16</td><td>320</td></tr>        </tr>
        </tbody>
      </table>
      <p>
        <h2>
          "what song do you want to play?"
          <input type="text" name="title" placeholder="title" value="">
          <input type="submit" value="PLAY"> </h2>
      </p>
      </form>
      <form action="check2.php" method="post">
      <p>
        <h4>
          <!--"If the song is not correct, please alert the link to the site. (site link is "title of song to report.kr" (without space))"-->
          <input type="text" name="link" value="">
          <input type="submit" value="send message">
        </h4>
      </p>
      </form>
  </body>
</html>

 

만약 노래가 이상하면 alert으로 곡제목report.kr 을 띄우라고 되어있다. 그래서 노래를 하나하나 다 살펴보았더니 some things never change 라는 노래만 X표 되있었다. 

 

그래서 alert을 띄워주려고 했는데 ', " , alert 등은 검증루틴이 존재하는 것 같았다. <script></script>에 대해서는 딱히 필터링이 되지 않는다. 

 

그런데 몇가지 실험을 해보니 <script> 태그는 필요가 없었다. 왜냐하면 

 

노란색 부분에 그냥 자바스크립트 코드를 넣어주면 동작하는 것을 알 수 있었기 때문이다. 

 

document.write(1);

따라서 alert을 그냥 넣어봤는데 아무일도 안일어나는 것을 보면 alert은 저기서도 필터링 되어있다. 그래서 alert 대체함수를 찾아보았는데, 그런건 없었고 ( 있을 필요가 없으니까..) 최근에 자바스크립트에 대한 공부(?) 라고 해야할까.. 뭐 딱히 한 것 같진 않은데 각종 자료들을 보면서 eval함수에 대한 것을 한번 본적이 있었고. 그 함수를 사용해 보기로 하였다. 

 

 

함수의 원형은 eval(string) 이기 때문에 string 을 아스키코드로 만들어준다면 따옴표에 대한 우회가 가능할 것이라고 생각했다. 그리고 자바스크립트의 String 클래스에는 fromCharCode 라는 static 메소드가 존재한다. 

String.fromCharCode(97,108,101,114,116,40,49,41,59);

이 코드를 eval 안에 넣어서 전달하니 제대로 alert이 되었다. 그래서 노래이름인 some things never change를 전달해주려고 했다. 

eval(String.fromCharCode(97,108,101,114,116,40,39,115,111,109,101,32,116,104,105,110,103,115,32,110,101,118,101,114,32,99,104,97,110,103,101,39,41,59));

그런데 not success가 떠서 다시 보니까 난 바보였다. somethingsneverchangereport.kr 을 해줘야한다.. 

찾아서 타이핑하는게 귀찮아서 C언어로 만들었다. 

........? 역시 바보였다. report는 왜들어가 있는건지 

이것도 근데 결국에는 실패했다.

 

삽질 

그래서 생각을 좀 해보았는데 이런 류의 문제들이 alert을 감지하는 방법은  alert을 재정의해서 사용하는 것 밖에 생각이 나지 않았다. 

eval에서 실행된 alert과 그냥 alert이 달라서 발생하는 문제일 수 도 있다는 생각이 들었다. 그래서 직접 테스트를 해보았다. 

 

먼저 alert의 부모는 Window 라는 클래스이다. 

 자바스크립트는 그냥 함수 재정의가 지원된다. 아래 코드를 보자. 

 

<!doctype html>
<meta charset="utf8">
<html>
	<head>
		<title>js test</title>
	</head>
	<body>
		<script>
			const originalAlert = window.alert;
    		window.alert = function(msg) {
         		originalAlert('success!\n'+ msg);
    		}
		    alert('1');
		    
		</script>
	</body>
</html>

 

이 코드의 결과는 success 1 이다. 이런 방법으로 alert이 재정의 되있으면 eval에서 실행하면 어떤 코드가 실행되는지를 테스트 했는데, eval('alert(1)'); 과 alert(1)은 완전하게 동일한 결과를 보였다. 

즉 완전 잘못 짚었다. eval의 문제는 아닌 것 같다. 

 

결론

 아무리 생각해도 이 문제의 푸는 방법이 이해가 가지 않아서 다른 친구의 라업을 보았다. 

각종 문자 필터링이 있어서 이를 우회하고 alert을 해줘야 한다는 것이 결론이다. 

 

er = e
' ' = NULL
some = NULL
never = NULL
".kr" = NULL
"change." = "change ." : 공백이 생김
ngs = h
thig=n

 

 

alerrt('sosomemethithiggsnevnevererrchan.krge.k.krr');

 

를 넣으면 success가 뜨는데.. 음... 

 

eval(alerrt('sosomemethithiggsnevnevererrchan.krge.k.krr')); 를 넣어도 success 가 뜨지 않는 것을 보면 

xss 문제가 아니라 필터링 우회 문제에 가까운 것 같다. 처음부터 방향을 잘못 잡았던 듯..

'전공쪽 > 동아리 관련' 카테고리의 다른 글

sfw5 write up  (0) 2021.01.10
xss challenges  (0) 2021.01.07
sfwebstudy 3,4 write up  (0) 2021.01.02
xss game level 1~6  (0) 2020.12.29
atoi 함수 우회 가능 문자  (0) 2020.11.30