> For the complete documentation index, see [llms.txt](https://hacktricks.xsx.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacktricks.xsx.tw/pentesting-web/postmessage-vulnerabilities/blocking-main-page-to-steal-postmessage.md).

# Blocking main page to steal postmessage

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

* 您在**网络安全公司**工作吗？ 想要看到您的**公司在 HackTricks 中被宣传**吗？ 或者您想要访问**PEASS 的最新版本或下载 HackTricks 的 PDF**吗？ 请查看[**订阅计划**](https://github.com/sponsors/carlospolop)！
* 发现我们的独家[NFTs 集合](https://opensea.io/collection/the-peass-family) - [**The PEASS Family**](https://opensea.io/collection/the-peass-family)
* 获得[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* **加入** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 上关注我 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* **通过向** [**hacktricks 仓库**](https://github.com/carlospolop/hacktricks) **和** [**hacktricks-cloud 仓库**](https://github.com/carlospolop/hacktricks-cloud) **提交 PR 来分享您的黑客技巧**。

</details>

## 使用 iframe 赢得 RCs

根据这个[**Terjanq 的解说**](https://gist.github.com/terjanq/7c1a71b83db5e02253c218765f96a710)，从空源创建的 blob 文档出于安全考虑而被隔离，这意味着如果您让主页面保持繁忙状态，iframe 页面将被执行。

基本上，在这个挑战中，**一个隔离的 iframe 被执行**，并且**在**它**加载完成后**，**父页面将发送一个带有**标志的**post**消息。\
然而，该 postmessage 通信**容易受到 XSS 攻击**（**iframe** 可以执行 JS 代码）。

因此，攻击者的目标是**让父页面创建 iframe**，但在**让**父页面**发送敏感数据（标志）之前**让其保持繁忙状态，并将**有效负载发送到 iframe**。在**父页面忙碌**时，**iframe 执行有效负载**，这将是一些 JS 代码，将监听**父 postmessage 消息并泄漏标志**。\
最后，iframe 执行了有效负载，父页面停止忙碌，因此发送标志，有效负载泄漏了它。

但是，您如何让父页面在**生成 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]);
```

为了准确地在**iframe**创建后但在其准备好接收来自父级的数据之前**发送**该**postmessage**，您需要**通过`setTimeout`的毫秒数进行调整**。

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

* 您在**网络安全公司**工作吗？ 想要看到您的**公司在HackTricks中做广告**吗？ 或者您想要访问**PEASS的最新版本或下载HackTricks的PDF**吗？ 请查看[**订阅计划**](https://github.com/sponsors/carlospolop)！
* 发现我们的独家[NFT收藏品**The PEASS Family**](https://opensea.io/collection/the-peass-family)
* 获取[**官方PEASS和HackTricks周边产品**](https://peass.creator-spring.com)
* **加入** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在**Twitter**上关注我 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* **通过向**[**hacktricks repo**](https://github.com/carlospolop/hacktricks)**和**[**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud)**提交PR来分享您的黑客技巧**。

</details>
