Archive
Advisory: Western Digital My Cloud Pro Series PR4100 RCE

Advisory: Western Digital My Cloud Pro Series PR4100 RCE

2024-11-28 A few months ago,we took part in Pwn2Own Austin 2021. Organized by the Zero Day Initiative,the event focuses on the exploitation of vulnerabilities in

Related articles

智能电视TV版VPN推荐 Best gaming laptops in 2024: our top picks tested & rated Лучший vpn США

A few months ago,we took part in

Pwn2Own Austin 2021.

Organized by the

Zero Day Initiative

,the event focuses on the exploitation of vulnerabilities in phones,printers,NAS,and more – a welcomed opportunity to put our skills to the test and compete with the brightest minds in the reversing and exploitation scene.

At the IoT Inspector Research Lab,we usually stop at identifying a vulnerability,as we then head on to create a short proof of concept,responsibly disclose the issue to the vendor and focus on automating the detection of this and other similar issues to improve the analysis capabilities of IoT Inspector. To successfully compete at Pwn2Own,participants are required to craft a working exploit,potentially bypassing mitigation controls such as ASLR,and chaining together different vulnerabilities to finally pop a root shell on the device. But why go into the lengths of crafting exploits,you may ask? Well,we can think of three good reasons:

  1. It keeps our skills sharp and our Spidey-senses tingling to attempt exploitation every now and then.
  2. It is helps help us to well assess severity and impact of vulnerability identify in an automate manner .
  3. It’s fun 😊

For Pwn2Own,we submitted three exploit(chain)s targeting

western Digital My Cloud Pro Series pr4100

,

netgear Nighthawk Smart Wi – Fi Router ( R6700 AC1750 )

,and our

old friend

,the

Cisco RV340

.

This post is the first one of a three-part series on vulnerabilities we exploited during Pwn2Own Mobile 2021. This entry for western Digital My Cloud Pro Series pr4100 takes advantage of a command injection vulnerability affecting a connectivity checking service running on the device by default. Spoiler: During Pwn2Own,this exploit actually failed – but a root cause analysis for this is included in this write-up too 🙂 During Pwn2Own,the same vulnerability was independently discovered by Martin Rakhmanov (

@mrakhmanov

) from

Spider Labs

.

Advisory: Western Digital My Cloud Pro Series PR4100 RCE

compromise pr4100 from the comfort of your office is easy.[/caption ]

Summary

On boot and then every 300 seconds,the

ConnectivityService

binary verifies a few things:

  • whether it can reach the local rest SDK server
  • whether it can ping the local gateway
  • whether it can reach the remote cloud service

The cloud service connectivity check looks similar to the C code below we rebuilt from Ghidra’s disassembly.

FILE* stream;
FILE* stream_00;
char content[0x100];
char cmd_buf[129];
char* cloud_api_url = "http://downloads.mycloud.com/healthcheck/index.html";

system("rm -rf /tmp/healthcheck ; mkdir /tmp/healthcheck");
system("cd /tmp/healthcheck ; wget -o /tmp / healthcheck / check.txt %s",cloud_api_url);

// check if the request could be sent out by wget
sprintf(cmd_buf,"cat %s/%s | grep \"%s\"","/tmp/healthcheck","check.txt","HTTP request sent,awaiting response... ");
stream = popen((char *)cmd_buf,"r");
if (stream != NULL) {
    success = fgets(content,0x100,stream);
    // the request could not be sent by wget
    if (success == NULL) {
        // we don't care because the output of wget is therefore non-controllable
    }
    else{
        // inlined string length checks
    // check if response is 200 ok
    is_200_ok = strstr(content,"200 ok");
    if (is_200_ok != (char *)0x0) {
            fclose(__stream);
            sprintf((char *)cmd_buf,"%s:HTTP-response:\"200 ok\"",
                  "analyticlog -l NOTICE -s ConnectivityService -m checkCloudConnect string");
            system((char *)cmd_buf);
            sprintf(&DAT_00105200,"%s:HTTP-response:\"200 ok\"",
                  "analyticlog -l NOTICE -s ConnectivityService -m checkCloudConnect string");
            return 1;
        }
    // call logging utility with the command 'analyticlog -l NOTICE -s ConnectivityService -m checkCloudConnect string:content:"first 0x100 bytes of file"
    // SHOULD BE VULNERABLE
        sprintf(cmd_buf,"%s:HTTP-response:\"%s\"",
          "analyticlog -l NOTICE -s ConnectivityService -m checkCloudConnect string",
          content);
        system(cmd_buf);
    }
}

This procedure executes the following:

1. It sends a GET request to a remote server using

wget

and saves the command output to

/tmp / healthcheck / check.txt

.
2. It greps the file for ‘

HTTP request sent,awaiting response...


3. If there is a match,it checks whether the matched content contains ‘

200 ok

‘ and call

analyticlog

There is a command injection vulnerability that can be triggered by injecting a malicious command in the HTTP status textual phrase. To reach the command injection,we must return an HTTP response with a status other than ‘

200 ok

‘ .

This is is is what the exploit chain look like : the

ConnectivityService

client sends a GET request with

wget

,we hijack the connection due to its plaintext nature and return the following response:

HTTP/1.0 200 `touch /tmp/pwn2own`
Server: BaseHTTP/0.6 Python/3.8.10
Date: Thu,02 Sep 2021 10:45:30 GMT

It will then execute the grep call and put the output in a buffer:

$ grep "HTTP request sent,awaiting response... " /tmp / healthcheck / check.txt 
HTTP request sent,awaiting response... 200 `touch /tmp/pwn2own`

This buffer is then used to execute the following command,leading to the execution of our injected command:

$ analyticlog -l NOTICE -s ConnectivityService -m checkCloudConnect \
string:HTTP-response:"HTTP request sent,awaiting response... 200 `touch /tmp/pwn2own`"

Exploitation Strategy

For the vulnerable code path to be taken,two conditions must be met:

  1. the gateway is answer must answer to ICMP echo – request packet send byConnectivityService
  2. the staging server (staging.mycloud.com) must be unreachable

We implemented our exploit as a man-in-the-middle attack targeting the vulnerable device only. To do so,we ARP spoof the device by sending gratuitous ARP responses to the device for the LAN gateway so that all outgoing traffic from that target device is headed our way.

We setup

scapy

sniffers for ICMP and DNS traffic in their own dedicated threads. Whenever we observe an ICMP echo-request for the gateway,we craft an ICMP echo-reply and send it back to the device. Whenever we see DNS requests for

staging.mycloud.com

,we do not answer. Whenever we see DNS requests for

downloads.mycloud.com

,we craft a DNS answer holding the attacker’s IP address.

This will force the

ConnectivityService

binary to contact our malicious HTTP server that answers with a command injection payload,leading it into establishing a reverse shell to us (and some fancy LCD/LED things,it’s pwn2own after all).

A PoC works on my machine,an exploit works on yours

Everything is great by the look of this advisory,so what went wrong with this entry at PWN2OWN? Well,let me warn you about hardcoding IP addresses in your exploit code:

def fake_dns(iface,target_ip):

    spoof_domains = {
        "downloads.mycloud.com": "192.168.100.140",
    }

For all of our other entries we had two separate devices and could cross-validate within the team that it indeed worked as expected. With this one,this mistake went unnoticed up until the first failed attempt. Wireshark was running in the background so I immediately knew what was wrong and I guided the ZDI engineer so we could fix it on the fly. Sadly the device did not send further DNS requests and we ultimately failed 🙂

Identifying High Value Targets

“How do you know where to look at?” is a question we get asked a lot,so we also want to take the opportunity to provide you with a glimpse inside the IoT Inspector Research Lab. Inspired by Zhijie Gui et. Al,“

FIRMCORN: Vulnerability-Oriented Fuzzing of IoT Firmware via Optimized Virtual Execution

”,one of the techniques we use to scour through large firmware images in search for vulnerable binaries and good candidates for further inspection is to classify them according to two indices:

  • a vulnerability index representing the amount of insecure function calls and ratio of memory instructions
  • a complexity index represent code complexity from average cyclomatic complexity .

Using this approach against the PR4100,

ConnectivityService

ranked in position 3:

python3 firmware_index.py --verbose /home/quentin/research/_WDMyCloudPR4100_5.16.105_prod.bin.extracted/squashfs-root
#   filename                            avg complexity avg vuln       avg composite  med composite
0   /python37/bin/python3.7             109.17         6.74           986.89         77.00
1   /wd/usr/sbin/hdVerify               60.30          4.88           654.07         74.00
2   /wd/usr/sbin/ConnectivityService    25.00          6.21           306.50         57.00

Key Takeaways

Breaking it down: two fundamental issues allowed us to exploit this vulnerability – supplying untrusted data with insufficient validation to

system()

is always a recipe for disaster. Another easy mitigation that could have made the exploit almost impossible is the consistent usage of encrypted communication. Man-in-the-middling a TLS encrypted connection would have likely resulted in us giving up on the exploitation attempt 😉 By applying basic security principles,this vulnerability could have easily been prevented or rendered useless.

One ray of light: The described attack vector is not the typical infection vector chosen by ransomware campaigns – so we likely won’t see this bug being abused my malware authors anytime soon. Nevertheless,updates provided by the vendor should be applied in a timely manner – but that’s a non-news to close part one of our Pwn2Own exploitation series.

timeline

2021-12-01 – Vulnerability reported to vendor
2022-01-17 – ZDI release advisory
2022-02-15 – Coordinated public release of IoT Inspector advisory