# Blocking main page to steal postmessage
{% hint style="success" %}
Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** ๐ฌ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** ๐ฆ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}
## Winning RCs with Iframes
์ด [**Terjanq writeup**](https://gist.github.com/terjanq/7c1a71b83db5e02253c218765f96a710)์ ๋ฐ๋ฅด๋ฉด, null origin์์ ์์ฑ๋ blob ๋ฌธ์๋ ๋ณด์์์ ์ด์ ์ผ๋ก ๊ฒฉ๋ฆฌ๋์ด ์์ผ๋ฉฐ, ์ด๋ ๋ฉ์ธ ํ์ด์ง๊ฐ ๋ฐ์๋ฉด iframe ํ์ด์ง๊ฐ ์คํ๋๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก ์ด ๋์ ์์ **๊ฒฉ๋ฆฌ๋ iframe์ด ์คํ**๋๊ณ ๋ฐ๋ก **๋ก๋๋ ํ** **๋ถ๋ชจ** ํ์ด์ง๊ฐ **ํ๋๊ทธ**์ ํจ๊ป **post** ๋ฉ์์ง๋ฅผ **๋ณด๋
๋๋ค**.\
๊ทธ๋ฌ๋ ๊ทธ postmessage ํต์ ์ **XSS์ ์ทจ์ฝ**ํฉ๋๋ค( **iframe**์ด JS ์ฝ๋๋ฅผ ์คํํ ์ ์์ต๋๋ค).
๋ฐ๋ผ์ ๊ณต๊ฒฉ์์ ๋ชฉํ๋ **๋ถ๋ชจ๊ฐ iframe์ ์์ฑํ๊ฒ** ํ๋, **๋ถ๋ชจ** ํ์ด์ง๊ฐ **๋ฏผ๊ฐํ ๋ฐ์ดํฐ(ํ๋๊ทธ)**๋ฅผ **๋ณด๋ด๊ธฐ ์ ์** **๋ฐ์๊ฒ ์ ์ง**ํ๊ณ **payload๋ฅผ iframe์ผ๋ก ๋ณด๋ด๋** ๊ฒ์
๋๋ค. **๋ถ๋ชจ๊ฐ ๋ฐ์ ๋** **iframe์ payload๋ฅผ ์คํ**ํ๋ฉฐ, ์ด๋ **๋ถ๋ชจ postmessage ๋ฉ์์ง๋ฅผ ๋ฃ๊ณ ํ๋๊ทธ๋ฅผ ์ ์ถํ๋** JS๊ฐ ๋ ๊ฒ์
๋๋ค.\
๋ง์ง๋ง์ผ๋ก, iframe์ด payload๋ฅผ ์คํํ๊ณ ๋ถ๋ชจ ํ์ด์ง๊ฐ ๋ฐ์์ง ์๊ฒ ๋๋ฉด, ํ๋๊ทธ๋ฅผ ๋ณด๋ด๊ณ payload๊ฐ ์ด๋ฅผ ์ ์ถํฉ๋๋ค.
ํ์ง๋ง ๋ถ๋ชจ๊ฐ **iframe์ ์์ฑํ ์งํ์ ๋ฐ์๊ฒ ๋ง๋ค๊ณ , ๋ฏผ๊ฐํ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ด๊ธฐ ์ํด iframe์ด ์ค๋น๋๊ธฐ๋ฅผ ๊ธฐ๋ค๋ฆฌ๋ ๋์ ์ด๋ป๊ฒ ํ ์ ์์๊น์?** ๊ธฐ๋ณธ์ ์ผ๋ก ๋ถ๋ชจ๊ฐ **์คํํ ์ ์๋** **๋น๋๊ธฐ** **์์
**์ ์ฐพ์์ผ ํฉ๋๋ค. ์๋ฅผ ๋ค์ด, ์ด ๋์ ์์ ๋ถ๋ชจ๋ ๋ค์๊ณผ ๊ฐ์ด **postmessages**๋ฅผ **๋ฃ๊ณ ** ์์์ต๋๋ค:
```javascript
window.addEventListener('message', (e) => {
if (e.data == 'blob loaded') {
$("#previewModal").modal();
}
});
```
๊ทธ๋์ **postmessage**์์ **ํฐ ์ ์๋ฅผ ๋ณด๋ด๋** ๊ฒ์ด ๊ฐ๋ฅํ์ผ๋ฉฐ, ์ด๋ ๊ทธ ๋น๊ต์์ **๋ฌธ์์ด๋ก ๋ณํ๋ ** ๊ฒ์ด๊ณ , ์๊ฐ์ด ์ข ๊ฑธ๋ฆด ๊ฒ์
๋๋ค:
```bash
const buffer = new Uint8Array(1e7);
win?.postMessage(buffer, '*', [buffer.buffer]);
```
์ ํํ๊ฒ **postmessage**๋ฅผ **iframe**์ด ์์ฑ๋ **ํ**์, ๊ทธ๋ฌ๋ ๋ถ๋ชจ๋ก๋ถํฐ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ์ค๋น๊ฐ **๋๊ธฐ ์ ์** **setTimeout**์ ๋ฐ๋ฆฌ์ด๋ฅผ **์กฐ์ **ํด์ผ ํฉ๋๋ค.
{% hint style="success" %}
Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** ๐ฌ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** ๐ฆ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}