mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/network-services-pentesting/pentesting-web/electron-des
This commit is contained in:
parent
6046556206
commit
14d621535a
@ -6,12 +6,12 @@
|
||||
|
||||
Electron结合了本地后端(使用**NodeJS**)和前端(**Chromium**),尽管它缺乏现代浏览器的一些安全机制。
|
||||
|
||||
通常,您可能会在`.asar`应用程序中找到electron应用代码,获取代码需要提取它:
|
||||
通常,您可能会在`.asar`应用程序中找到electron应用程序代码,获取代码需要提取它:
|
||||
```bash
|
||||
npx asar extract app.asar destfolder #Extract everything
|
||||
npx asar extract-file app.asar main.js #Extract just a file
|
||||
```
|
||||
在Electron应用的源代码中,在`packet.json`文件内,可以找到指定的`main.js`文件,其中设置了安全配置。
|
||||
在 Electron 应用的源代码中,在 `packet.json` 文件内,可以找到指定的 `main.js` 文件,其中设置了安全配置。
|
||||
```json
|
||||
{
|
||||
"name": "standard-notes",
|
||||
@ -32,17 +32,17 @@ let win = new BrowserWindow()
|
||||
//Open Renderer Process
|
||||
win.loadURL(`file://path/to/index.html`)
|
||||
```
|
||||
设置 **renderer process** 可以在 **main process** 的 main.js 文件中 **配置**。一些配置将 **防止 Electron 应用程序获取 RCE** 或其他漏洞,如果 **设置正确配置**。
|
||||
**renderer process** 的设置可以在 **main process** 中的 main.js 文件中进行 **配置**。一些配置将 **防止 Electron 应用程序获取 RCE** 或其他漏洞,如果 **设置正确配置**。
|
||||
|
||||
Electron 应用程序 **可以通过 Node API 访问设备**,尽管可以配置以防止它:
|
||||
Electron 应用程序 **可以通过 Node apis 访问设备**,尽管可以配置以防止它:
|
||||
|
||||
- **`nodeIntegration`** - 默认情况下为 `off`。如果开启,允许从 renderer process 访问 Node 特性。
|
||||
- **`contextIsolation`** - 默认情况下为 `on`。如果关闭,主进程和渲染进程不被隔离。
|
||||
- **`nodeIntegration`** - 默认情况下为 `off`。如果开启,允许从 renderer process 访问 node 特性。
|
||||
- **`contextIsolation`** - 默认情况下为 `on`。如果关闭,主进程和渲染进程不会隔离。
|
||||
- **`preload`** - 默认情况下为空。
|
||||
- [**`sandbox`**](https://docs.w3cub.com/electron/api/sandbox-option) - 默认情况下为 off。它将限制 NodeJS 可以执行的操作。
|
||||
- Node Integration in Workers
|
||||
- **`nodeIntegrationInSubframes`** - 默认情况下为 `off`。
|
||||
- 如果 **`nodeIntegration`** 被 **启用**,这将允许在 Electron 应用程序中 **加载在 iframe 中的网页** 使用 **Node.js APIs**。
|
||||
- 如果 **`nodeIntegration`** 被 **启用**,这将允许在 Electron 应用程序中 **加载在 iframes 中的网页** 使用 **Node.js APIs**。
|
||||
- 如果 **`nodeIntegration`** 被 **禁用**,则预加载将在 iframe 中加载。
|
||||
|
||||
配置示例:
|
||||
@ -148,7 +148,7 @@ runCalc()
|
||||
</script>
|
||||
</body>
|
||||
```
|
||||
> [!NOTE] > **如果 `contextIsolation` 开启,这将无法工作**
|
||||
> [!NOTE] > **如果 `contextIsolation` 开启,这将不起作用**
|
||||
|
||||
## RCE: XSS + contextIsolation
|
||||
|
||||
@ -157,11 +157,11 @@ _**contextIsolation**_ 引入了 **网页脚本与 JavaScript Electron 内部代
|
||||
如果上下文没有被隔离,攻击者可以:
|
||||
|
||||
1. 在渲染器中执行 **任意 JavaScript**(XSS 或导航到外部网站)
|
||||
2. **覆盖内置方法**,该方法用于预加载或 Electron 内部代码,替换为自己的函数
|
||||
2. **覆盖内置方法**,该方法用于预加载或 Electron 内部代码,变为自己的函数
|
||||
3. **触发** 使用 **被覆盖的函数**
|
||||
4. RCE?
|
||||
|
||||
有两个地方可以覆盖内置方法:在预加载代码中或在 Electron 内部代码中:
|
||||
内置方法可以在两个地方被覆盖:在预加载代码中或在 Electron 内部代码中:
|
||||
|
||||
{{#ref}}
|
||||
electron-contextisolation-rce-via-preload-code.md
|
||||
@ -187,7 +187,7 @@ window.addEventListener('click', (e) => {
|
||||
|
||||
在部署 Electron 桌面应用程序时,确保 `nodeIntegration` 和 `contextIsolation` 的正确设置至关重要。已确定,**客户端远程代码执行 (RCE)** 针对预加载脚本或 Electron 的主进程本地代码在这些设置到位时有效防止。
|
||||
|
||||
当用户与链接交互或打开新窗口时,会触发特定的事件监听器,这些监听器对应用程序的安全性和功能至关重要:
|
||||
当用户与链接交互或打开新窗口时,会触发特定的事件监听器,这对应用程序的安全性和功能至关重要:
|
||||
```javascript
|
||||
webContents.on("new-window", function (event, url, disposition, options) {}
|
||||
webContents.on("will-navigate", function (event, url) {}
|
||||
@ -251,7 +251,7 @@ frames[0].document.body.innerText
|
||||
如果应用程序使用的 **chromium** 是 **旧版** 并且存在 **已知的** **漏洞**,那么可能可以通过 **XSS 利用它并获得 RCE**。\
|
||||
您可以在这个 **writeup** 中看到一个例子: [https://blog.electrovolt.io/posts/discord-rce/](https://blog.electrovolt.io/posts/discord-rce/)
|
||||
|
||||
## **通过内部 URL 正则表达式绕过进行 XSS 钓鱼**
|
||||
## **通过内部 URL 正则绕过进行 XSS 钓鱼**
|
||||
|
||||
假设您发现了一个 XSS,但您 **无法触发 RCE 或窃取内部文件**,您可以尝试利用它来 **通过钓鱼窃取凭据**。
|
||||
|
||||
@ -262,7 +262,7 @@ webContents.on("will-navigate", function (event, url) {} // o
|
||||
```
|
||||
对**`openInternally`**的调用将决定**链接**是作为平台的链接在**桌面窗口**中**打开**,还是作为**第三方资源**在**浏览器**中打开。
|
||||
|
||||
如果该函数使用的**regex**对绕过**漏洞**(例如**未转义子域的点**)是**脆弱的**,攻击者可以利用XSS**打开一个新窗口**,该窗口位于攻击者的基础设施中,**要求用户提供凭据**:
|
||||
如果该函数使用的**正则表达式****易受绕过攻击**(例如**未对子域的点进行转义**),攻击者可能会利用XSS**打开一个新窗口**,该窗口位于攻击者的基础设施中,**向用户请求凭据**:
|
||||
```html
|
||||
<script>
|
||||
window.open("<http://subdomainagoogleq.com/index.html>")
|
||||
@ -270,7 +270,7 @@ window.open("<http://subdomainagoogleq.com/index.html>")
|
||||
```
|
||||
## Remote module
|
||||
|
||||
Electron Remote模块允许**渲染进程访问主进程API**,促进Electron应用程序内的通信。然而,启用此模块会引入显著的安全风险。它扩大了应用程序的攻击面,使其更容易受到跨站脚本(XSS)攻击等漏洞的影响。
|
||||
Electron Remote模块允许**渲染进程访问主进程API**,促进Electron应用程序内的通信。然而,启用此模块会引入重大安全风险。它扩大了应用程序的攻击面,使其更容易受到跨站脚本(XSS)攻击等漏洞的影响。
|
||||
|
||||
> [!TIP]
|
||||
> 尽管**remote**模块将一些API从主进程暴露给渲染进程,但仅仅通过滥用组件并不容易获得RCE。然而,这些组件可能会暴露敏感信息。
|
||||
@ -278,7 +278,7 @@ Electron Remote模块允许**渲染进程访问主进程API**,促进Electron
|
||||
> [!WARNING]
|
||||
> 许多仍然使用remote模块的应用程序以**需要在渲染进程中启用NodeIntegration**的方式进行,这是一种**巨大的安全风险**。
|
||||
|
||||
自Electron 14以来,由于安全和性能原因,Electron的`remote`模块可能在多个步骤中启用,因此**建议不要使用它**。
|
||||
自Electron 14以来,由于安全和性能原因,Electron的`remote`模块可能在多个步骤中启用,**建议不要使用它**。
|
||||
|
||||
要启用它,首先需要**在主进程中启用它**:
|
||||
```javascript
|
||||
@ -319,7 +319,7 @@ Native.app.exit()
|
||||
```
|
||||
## systemPreferences 模块
|
||||
|
||||
在 Electron 中访问系统偏好设置和发出系统事件的 **主要 API**。像 **subscribeNotification**、**subscribeWorkspaceNotification**、**getUserDefault** 和 **setUserDefault** 这样的函数都是该模块的 **一部分**。
|
||||
在 Electron 中访问系统偏好设置和发出系统事件的 **主要 API**。像 **subscribeNotification**、**subscribeWorkspaceNotification**、**getUserDefault** 和 **setUserDefault** 这样的函数都是这个模块的 **一部分**。
|
||||
|
||||
**示例用法:**
|
||||
```javascript
|
||||
@ -348,7 +348,7 @@ console.log('Recent Places:', recentPlaces);
|
||||
|
||||
* **setUserDefault** 可以 **修改** 这些偏好设置,可能会影响应用的 **配置**。
|
||||
|
||||
* 在 **较旧的 Electron 版本**(v8.3.0 之前),只有 **标准套件** 的 NSUserDefaults 是 **可访问的**。
|
||||
* 在 **旧版 Electron**(v8.3.0 之前),只有 **标准套件** 的 NSUserDefaults 是 **可访问的**。
|
||||
|
||||
## Shell.showItemInFolder
|
||||
|
||||
@ -365,9 +365,9 @@ console.log('Recent Places:', recentPlaces);
|
||||
|
||||
## 实验室
|
||||
|
||||
在 [https://www.youtube.com/watch?v=xILfQGkLXQo\&t=22s](https://www.youtube.com/watch?v=xILfQGkLXQo&t=22s) 中,您可以找到一个实验来利用易受攻击的 Electron 应用程序。
|
||||
在 [https://www.youtube.com/watch?v=xILfQGkLXQo\&t=22s](https://www.youtube.com/watch?v=xILfQGkLXQo&t=22s) 中,您可以找到一个实验室来利用易受攻击的 Electron 应用程序。
|
||||
|
||||
一些将帮助您完成实验的命令:
|
||||
一些将帮助您完成实验室的命令:
|
||||
```bash
|
||||
# Download apps from these URls
|
||||
# Vuln to nodeIntegration
|
||||
|
Loading…
x
Reference in New Issue
Block a user