D-Link: A Firmware Vulnerability – Part 1

by | Jul 29, 2019

Have you ever wanted to be like the super l33t hax0rs that you see in the movies? Sitting in a dark room pounding away randomly on a keyboard with the only light coming from the screen in front of you? The silence only broken by you saying “I’m in.”?

Then this is the blog for you.

It will take you through the initial firmware analysis to finding vulnerabilities (if there are any), what to do when you find one, and writing that juicy proof of concept to impress your friends. We might even throw in a few failures along the way because not every device you look at will be a win.

Finding a Vulnerability?

Finding a vulnerability in an IOT firmware is more of an art than a science. Most of the time it feels like running your head against a brick wall and coming back for more until the wall breaks or you break. Hence, persistence is a good quality to have when looking for vulnerabilities.

Normally this is a very tedious and time consuming processes, but luckily I have a subscription to a pretty sweet tool that makes everything a little bit simpler. The tool in question is the Centrifuge Platform provided by Refirm Labs.

Shamelessly pulled directly from the website, Centrifuge allows for vetting, validating, and monitoring firmware security. I use it to break security and it does a really good job of helping me with that.

Step 1 of….there are a lot of steps

First step is to select the target because you can’t look at firmware from a device if you don’t have a device. The device in question for this post is the D-Link DCS–5020L, a pan and tilt day/night network camera.

D-Link DCS-5020LD-Link DCS–5020L

D-Link is pretty good about providing different versions of the firmware. And if your Google powers are strong, you can find all versions of the firmware for most of their devices.

I will normally search for the most recent version of the firmware so if I find a vulnerability it has the best chance of being a 0-day.

For this camera, the most recent version of the firmware is version 1.15.12 released July 25, 2018. A quick 7.3MB download later and we are well on our way to running our head into the proverbial brick wall mentioned earlier.

Centrifuge Submission

We have a downloaded ZIP file of unknown contents that is supposedly a firmware.

Now what?

My next step is to submit the downloaded firmware to Centrifuge for analysis. This process, depending on the size and nature of the firmware, usually takes about 30 minutes at which point I am greeted with a page full of analysis.

Centrifuge Analysis ViewCentrifuge Analysis View

From here I have a lot of options for starting my analysis.

Starting with the top left box with a folder, I can view the contents of the unpacked firmware in a nice tree view to see what binaries come with it, does it have config files, what server does it use for administration, etc. The platform updates the view as analysis completes so I’ll normally peruse through the tree view to see what the firmware holds while the rest of the analysis completes.

The next box, with the key, displays all public and private crypto keys that are discovered baked into the firmware. This is useful for seeing if the manufacture left a private key in there that they should not have.

If any password hashes are found in the firmware, /etc/shadow or /etc/passwd, they will be displayed in the top right box.

Bottom left is my favorite view: the high risk executables section, which we will talk about soon.

Next is the software bill of materials which identifies software components present in the firmware such as busybox or openssl. A nice general purpose, here’s what I found.

The Security Checklist performs a little proprietary analysis to let you know if it found known vulnerabilities in the firmware you uploaded. Things like backdoor checks, UPnP command injection vulnerabilities, Mirai botnet, among other checks are performed on the firmware and reported. These security checks are constantly being updated and added to identify more problems.

Centfrifuge Guardian piggy backs off the bill of materials to identify current CVEs against software that is present in the firmware.

Oh this firmware has libcurl 7.29.0 and their’s an open CVE for it? Well, luckily for us Centrifuge tells exactly which file is affected and provides recommendations for remediation.

There are a few other other boxes that give us useful metadata about the firmware, but that’s the bulk of it.

On to the high risk executables!

High Risk Executables

High Risk Executables is the portion of Centrifuge where I spend most of my time because it is directly applicable to finding vulnerabilities within the code.

To populate this information Centrifuge identifies all potentially vulnerable calls within the binaries present in the firmware. A potentially vulnerable call, for example, could be an sprintf call with a destination buffer on the stack or a strcpy directly to the stack. Even though the function is listed in this view doesn’t automatically make it an exploit, you still need to view the call in full context to see if it’s exploitable.

High Risk ExecutablesHigh Risk Executables

Centrifuge will even try to emulate the functionality of the binaries to see if the parameters are user controllable. These function calls are listed as Critical and should be looked at a little more closely.

Clicking on the individual binaries will provide specific information and is where all the (potential) vulnerabilities are displayed. Information such as the offset of the call, type of flaw, function call, and named offset are displayed in this view.

High Risk ExecutablesHigh Risk Executables

Conclusion

You don’t need Centrifuge to perform vulnerability analysis, you just may end up looking at 100 sprintf calls where I only need to look at 10.

That’s the convenience and time saving power that Centrifuge provides.

Next time we get a lot more technical and dive into finding out which, if any, of the “flaws” listed in Centrifuge are, in fact, flaws.

###

Evan Walls is a vulnerability analyst and developer at Tactical Network Solutions, focusing on embedded system exploitation. When he isn’t searching for new exploits, he teaches training courses developed by TNS, including IoT Firmware Exploitation. Prior to working at TNS he was a Windows developer for the Department of Defense. Now that he’s seen the glory and freedom that is Linux he vowed never to use another windows development machine again.

You can follow him on LinkedIn or GitHub.

Recent Posts
Russians, Fancy Bears, and IoT Security

Russians, Fancy Bears, and IoT Security

During the 2019 Black Hat conference in Las Vegas, Nevada there was a massive announcement from Microsoft generating a lot of buzz. Their discovery? A malicious Russian hacker group has been targeting common IoT devices. Their goal? Widespread attacks on corporate...

Do We Need to Watch the Eyes Watching Us?

Do We Need to Watch the Eyes Watching Us?

On May 21, 2019 the New York Times reported that the Trump Administration is considering a limit on Hikvision’s ability to buy American technology. Hikvision is one of the world’s largest surveillance camera manufacturers and is 42% owned by the Chinese...

Deep Dive into Binary Firmware Analysis

Deep Dive into Binary Firmware Analysis

The Centrifuge Platform is capable of analyzing binary firmware for previously unknown vulnerabilities and providing detailed reports of great use to developers and vulnerability researchers alike. This document details the interpretation of these code analysis...