Recreating CVE-2015-1187 in the DIR-820L

Adding Cat gifs to the DIR-820L using CVE-2015-1187 with the firmware emulator

We'll be recreating CVE-2015-1187 using the firmware posted on D-Link's website here a direct link to the firmware here. This exploit takes advantage of the DIR-820L at version 1.05.

$ wget https://ftp.dlink.ca/ftp/PRODUCTS/DIR-820L/DIR-820L_REVA_FIRMWARE_1.05B03.BIN

Setup

We'll be using the Firmware Emulator (help me find a better name please) to emulate this firmware. And so we'll need to clone and install it first.

$ git clone https://github.com/ChrisTheCoolHut/firmware_emulator.git
$ cd firmware_emulator
$ ./install.sh
$ sudo apt-get install qemu-system-arm qemu-system-mips qemu-system-x86 qemu-utils kpartx uml-utilities bridge-utils

With that, it should be installed, and we pop into the interactive emulator.

$ python fw_emulator.py 

______ _                                      
|  ___(_)                                     
| |_   _ _ __ _ __ _____      ____ _ _ __ ___ 
|  _| | | '__| '_ ` _ \ \ /\ / / _` | '__/ _ \
| |   | | |  | | | | | \ V  V / (_| | | |  __/
\_|   |_|_|  |_| |_| |_|\_/\_/ \__,_|_|  \___|
                                              
                                              
 _____                _       _               
|  ___|              | |     | |              
| |__ _ __ ___  _   _| | __ _| |_ ___  _ __   
|  __| '_ ` _ \| | | | |/ _` | __/ _ \| '__|  
| |__| | | | | | |_| | | (_| | || (_) | |     
\____/_| |_| |_|\__,_|_|\__,_|\__\___/|_|     


emu:~$
emu:~$ 
add_file            export              info                remove_root_passwd  unmount             
add_network         force_network       make_image          run                 
del_file            force_tty_login     mount               setup_network 

Pressing tab reveals it's list of commands, which are explained here. But we'll just need a couple to emulate this image. The general flow of emulating an image will be using the make_image command followed by a setup_network command. If that flow doesn't work, we'll use the other commands to do some debugging.

We'll need to note down that ip and host_ip information. When we run our emulator next, we'll be able to ping it at it's specified ip. The next step is confirming that we can run it and interact with it, so we'll issue the run command.

These emulators tend to get pretty spammy and you'll see lots of messages like the picture below. This is normal and actually means it's running correctly!

Connecting to the device

We noted down the IP earlier being 192.168.0.1 , so our first step is make sure that it's network reachable:

At this point you can actually browse to the site at that address too!

Exporting an exploitable image

To stop the emulation you'll need to enter Ctrl+a,x. This will drop you back into the firmware emulator shell. A quick info command shows what information we've got currently captured from this image:

We're going to add an extra binary to the device next. If we were debugging a memory corruption bug, we could add gdbserver, but in this case we'll be adding the binary I want the command injection to run.

With our payload added, and networking information known, we can export the router image and use just that for finishing the exploit. I'm exporting my image to the folder DIR_820L_105_emulator and am closing out the firmware emulator.

Next is going into the directory and starting the emulator!

The description provided by the initial disclosure led me to write the following PoC:

Running the exploit with the cat payload starts a new service listening on port 12345 providing anyone with access to the router with free cat gifs!

Last updated

Was this helpful?