diff --git a/src/network-services-pentesting/pentesting-web/electron-desktop-apps/README.md b/src/network-services-pentesting/pentesting-web/electron-desktop-apps/README.md index 143481b97..54b510c8c 100644 --- a/src/network-services-pentesting/pentesting-web/electron-desktop-apps/README.md +++ b/src/network-services-pentesting/pentesting-web/electron-desktop-apps/README.md @@ -4,14 +4,14 @@ ## 소개 -Electron은 로컬 백엔드(**NodeJS**)와 프론트엔드(**Chromium**)를 결합한 구조지만, 최신 브라우저가 제공하는 일부 보안 메커니즘이 부족합니다. +Electron은 로컬 백엔드(**NodeJS**)와 프론트엔드(**Chromium**)를 결합하지만, 현대 브라우저의 일부 보안 메커니즘은 갖추고 있지 않습니다. -보통 Electron 앱 코드는 `.asar` 애플리케이션 내부에 들어 있어, 코드를 얻으려면 이를 추출해야 합니다: +일반적으로 Electron 앱 코드는 `.asar` 애플리케이션 내부에 존재합니다. 코드를 얻으려면 이를 추출해야 합니다: ```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", @@ -19,12 +19,12 @@ Electron 앱의 소스 코드에서 `packet.json` 안에 보안 설정이 정의 ``` Electron에는 2가지 프로세스 유형이 있습니다: -- 메인 프로세스 (NodeJS에 대한 완전한 접근 권한을 가짐) -- 렌더러 프로세스 (보안상 NodeJS 접근이 제한되어야 함) +- Main Process (NodeJS에 대한 완전한 접근 권한 보유) +- Renderer Process (보안상 NodeJS 접근 권한을 제한해야 함) ![](<../../../images/image (182).png>) -**렌더러 프로세스**는 파일을 로드하는 브라우저 창입니다: +**renderer process**는 파일을 로드하는 브라우저 창입니다: ```javascript const { BrowserWindow } = require("electron") let win = new BrowserWindow() @@ -32,18 +32,18 @@ let win = new BrowserWindow() //Open Renderer Process win.loadURL(`file://path/to/index.html`) ``` -main.js 파일 안의 **메인 프로세스**에서 **렌더러 프로세스**의 설정을 **구성**할 수 있습니다. 일부 설정을 올바르게 구성하면 **Electron** 애플리케이션이 **RCE** 또는 다른 취약점을 얻는 것을 **방지**할 수 있습니다. +Settings of the **렌더러 프로세스** can be **구성** in the **메인 프로세스** inside the main.js file. Some of the configurations will **Electron 애플리케이션이 RCE를 얻는 것을 방지**하거나 다른 취약점을 막을 수 있습니다 if the **설정이 올바르게 구성된 경우**. -Electron 애플리케이션은 Node apis를 통해 **디바이스에 접근할 수 있습니다**, 하지만 이를 방지하도록 구성할 수 있습니다: +The Electron 애플리케이션 **Node apis를 통해 기기에 접근할 수 있습니다** although it can be configure to prevent it: - **`nodeIntegration`** - 기본값은 `off`입니다. 활성화되면 렌더러 프로세스에서 Node 기능에 접근할 수 있습니다. -- **`contextIsolation`** - 기본값은 `on`입니다. `off`이면 메인 프로세스와 렌더러 프로세스가 격리되지 않습니다. +- **`contextIsolation`** - 기본값은 `on`입니다. 비활성화하면 메인 프로세스와 렌더러 프로세스가 분리되지 않습니다. - **`preload`** - 기본값은 비어 있습니다. -- [**`sandbox`**](https://docs.w3cub.com/electron/api/sandbox-option) - 기본값은 `off`입니다. NodeJS가 수행할 수 있는 작업을 제한합니다. +- [**`sandbox`**](https://docs.w3cub.com/electron/api/sandbox-option) - 기본적으로 `off`입니다. NodeJS가 수행할 수 있는 동작을 제한합니다. - Workers에서의 Node Integration -- **`nodeIntegrationInSubframes`**- 기본값은 `off`입니다. -- `nodeIntegration`이 활성화되어 있으면, Electron 애플리케이션 내의 iframe에 로드된 웹 페이지에서 **Node.js APIs**를 사용할 수 있습니다. -- `nodeIntegration`이 비활성화되어 있으면 preload가 iframe에서 로드됩니다. +- **`nodeIntegrationInSubframes`** - 기본값은 `off`입니다. +- If **`nodeIntegration`** is **enabled**, this would allow the use of **Node.js APIs** in web pages that are **loaded in iframes** within an Electron application. +- If **`nodeIntegration`** is **disabled**, then preloads will load in the iframe Example of configuration: ```javascript @@ -71,7 +71,7 @@ spellcheck: true, }, } ``` -다음은 [here](https://7as.es/electron/nodeIntegration_rce.txt)에 있는 몇 가지 **RCE payloads**: +다음은 [here](https://7as.es/electron/nodeIntegration_rce.txt)에서 가져온 몇 가지 **RCE payloads**: ```html Example Payloads (Windows): require("child_process").exec("calc") @@ -124,7 +124,7 @@ top.require("child_process").exec("open /System/Applications/Calculator.app") ## RCE: preload -이 설정에 지정된 스크립트는 renderer의 다른 스크립트보다 **먼저 로드되므로**, Node APIs에 **무제한 접근 권한을 가집니다**: +이 설정에 지정된 스크립트는 **renderer의 다른 스크립트들보다 먼저 로드**되므로, **Node APIs에 무제한 접근** 권한을 갖습니다: ```javascript new BrowserWindow{ webPreferences: { @@ -133,7 +133,7 @@ preload: _path2.default.join(__dirname, 'perload.js'), } }); ``` -따라서 이 스크립트는 node-features를 페이지로 내보낼 수 있습니다: +따라서, 이 스크립트는 node-features를 페이지로 내보낼 수 있습니다: ```javascript:preload.js typeof require === "function" window.runCalc = function () { @@ -149,21 +149,20 @@ runCalc() ``` -> [!NOTE] > **`contextIsolation`이 켜져 있으면, 이 방법은 작동하지 않습니다** +> [!NOTE] > **If `contextIsolation` is on, this won't work** ## RCE: XSS + contextIsolation -_**contextIsolation**_은 **웹 페이지 스크립트와 JavaScript Electron의 내부 코드 간의 분리된 컨텍스트**를 도입하여 각 코드의 JavaScript 실행이 서로 영향을 미치지 않도록 합니다. 이는 RCE 가능성을 제거하기 위한 필수 기능입니다. +The _**contextIsolation**_ introduces the **separated contexts between the web page scripts and the JavaScript Electron's internal code** so that the JavaScript execution of each code does not affect each. This is a necessary feature to eliminate the possibility of RCE. -컨텍스트가 분리되어 있지 않다면 공격자는 다음을 할 수 있습니다: +컨텍스트가 격리되어 있지 않다면 공격자는 다음을 수행할 수 있습니다: -1. renderer에서 **임의의 JavaScript를 실행** (XSS 또는 외부 사이트로의 이동) -2. preload 또는 Electron 내부 코드에서 사용되는 **내장 메서드를 덮어써서 제어권 획득** +1. **renderer에서 임의의 JavaScript 실행** (XSS 또는 외부 사이트로의 이동) +2. **preload 또는 Electron 내부 코드에서 사용되는 내장 메서드를 덮어쓰기** 3. **덮어쓴 함수의 사용을 트리거** 4. RCE? -내장 메서드를 덮어쓸 수 있는 위치는 2곳입니다: preload 코드 또는 Electron 내부 코드: - +내장 메서드를 덮어쓸 수 있는 곳은 2곳이 있습니다: preload 코드 또는 Electron 내부 코드 안: {{#ref}} electron-contextisolation-rce-via-preload-code.md @@ -181,34 +180,34 @@ electron-contextisolation-rce-via-ipc.md ### 클릭 이벤트 우회 -링크를 클릭할 때 제한이 있는 경우, 일반 왼쪽 클릭 대신 **middle click**을 사용해 이를 우회할 수 있습니다. +링크를 클릭할 때 제한이 적용되어 있다면 일반 왼쪽 클릭 대신 **중간 클릭을 사용**하여 우회할 수 있습니다 ```javascript window.addEventListener('click', (e) => { ``` ## shell.openExternal을 통한 RCE -이 예제들에 대한 자세한 정보는 [https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8](https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8) 및 [https://benjamin-altpeter.de/shell-openexternal-dangers/](https://benjamin-altpeter.de/shell-openexternal-dangers/)를 확인하세요 +이 예제들에 대한 자세한 내용은 [https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8](https://shabarkin.medium.com/1-click-rce-in-electron-applications-79b52e1fe8b8) 및 [https://benjamin-altpeter.de/shell-openexternal-dangers/](https://benjamin-altpeter.de/shell-openexternal-dangers/)을 확인하세요 -Electron 데스크톱 애플리케이션을 배포할 때 `nodeIntegration` 및 `contextIsolation` 설정을 올바르게 구성하는 것이 중요합니다. 이러한 설정이 적용되면 preload scripts 또는 메인 프로세스의 Electron native code를 대상으로 한 **client-side remote code execution (RCE)**가 사실상 차단되는 것으로 알려져 있습니다. +Electron 데스크톱 애플리케이션을 배포할 때 `nodeIntegration`과 `contextIsolation`을 올바르게 설정하는 것은 매우 중요합니다. 이러한 설정이 적용되면 preload 스크립트나 메인 프로세스에서 Electron의 네이티브 코드로 향하는 **client-side remote code execution (RCE)**는 효과적으로 차단된다고 알려져 있습니다. -사용자가 링크를 클릭하거나 새 창을 열면 애플리케이션의 보안과 기능에 중요한 특정 이벤트 리스너가 트리거됩니다: +사용자가 링크를 클릭하거나 새 창을 열 때 특정 이벤트 리스너가 트리거되며, 이는 애플리케이션의 보안과 기능에 중요합니다: ```javascript webContents.on("new-window", function (event, url, disposition, options) {} webContents.on("will-navigate", function (event, url) {} ``` -이러한 리스너들은 **데스크탑 애플리케이션에 의해 재정의(overridden)**되어 자체 **비즈니스 로직**을 구현합니다. 애플리케이션은 탐색된 링크를 내부에서 열지 외부 웹 브라우저에서 열지를 평가합니다. 이 결정은 일반적으로 `openInternally` 함수에서 이루어집니다. 이 함수가 `false`를 반환하면 해당 링크는 외부에서 열려야 함을 의미하며, `shell.openExternal` 함수를 사용합니다. +이들 리스너는 **데스크탑 애플리케이션에 의해 오버라이드되어** 자체적인 **비즈니스 로직**을 구현합니다. 애플리케이션은 이동한 링크를 내부에서 열지 외부 웹 브라우저에서 열지를 판단합니다. 이 결정은 일반적으로 `openInternally` 함수에서 이루어집니다. 해당 함수가 `false`를 반환하면 링크를 외부에서 열어야 함을 나타내며, 이때 `shell.openExternal` 함수를 사용합니다. -**Here is a simplified pseudocode:** +**다음은 단순화된 의사코드입니다:** ![https://miro.medium.com/max/1400/1*iqX26DMEr9RF7nMC1ANMAA.png](<../../../images/image (261).png>) ![https://miro.medium.com/max/1400/1*ZfgVwT3X1V_UfjcKaAccag.png](<../../../images/image (963).png>) -Electron JS 보안 권장사항은 `openExternal` 함수를 통해 신뢰할 수 없는 콘텐츠를 수락하지 않도록 권고합니다. 이는 다양한 프로토콜을 통해 RCE로 이어질 수 있기 때문입니다. 운영체제는 RCE를 유발할 수 있는 서로 다른 프로토콜들을 지원합니다. 이 주제에 대한 자세한 예시와 추가 설명은 [this resource](https://positive.security/blog/url-open-rce#windows-10-19042)를 참조할 수 있으며, 해당 문서에는 이 취약점을 악용할 수 있는 Windows 프로토콜 예시들이 포함되어 있습니다. +Electron JS의 보안 권장사항은 `openExternal` 함수를 통해 신뢰할 수 없는 콘텐츠를 받아들이지 않을 것을 권고합니다. 이는 다양한 프로토콜을 통해 RCE로 이어질 수 있기 때문입니다. 운영 체제는 RCE를 유발할 수 있는 서로 다른 프로토콜을 지원합니다. 이 주제에 대한 자세한 예시와 설명은 [this resource](https://positive.security/blog/url-open-rce#windows-10-19042)를 참고할 수 있으며, 해당 자료에는 이 취약점을 악용할 수 있는 Windows 프로토콜 예시가 포함되어 있습니다. -macos에서 `openExternal` 함수는 `shell.openExternal('file:///System/Applications/Calculator.app')`처럼 임의의 명령을 실행하도록 악용될 수 있습니다. +macos에서는 `openExternal` 함수를 악용하여 `shell.openExternal('file:///System/Applications/Calculator.app')`와 같이 임의의 명령을 실행할 수 있습니다. -**Windows 프로토콜 exploits 예시에는 다음이 포함됩니다:** +**Windows 프로토콜 exploits의 예시는 다음과 같습니다:** ```html