August 19, 2018
To start with, I want to give a huge shout out to the ISE(Independent Security Evaluators) for running the IoT village and the SOHOpelessly Broken challenge at DEFCON 26. I really enjoyed the village, contest, people and the talks! Please keep up what you're doing!
Today, I wanted to discuss the analysis and description of CVE-2018–12313 that was analyzed in this video by ISE researcher Shaun Mirani. An article describing the CVE can also be found here. I would like to thank the researchers at ISE for posting a exploitation video about this CVE. Not only that, but having a progression of how the device was actually tested. I personally find the hardest part of penetration testing to be actually finding the exploitable section, rather than exploiting it. Once the vulnerability is known, I believe it's typically trivial to do. This video gave me so great insight into how applications are actually tested, which is really appreciated! But, this could be an even better video.
I would even ask to take this a step further; to show a live stream of the entire penetration test on the device itself. Even though it would be quite boring and uneventful to do this, I believe this would provide so much benefit to the up-and-coming people in the IoT penetration testing area. Most of the time, I don't even know where to start with a penetration test! In the video, it directly goes into dealing with authentication; but, I'm not sure why they did that. So, by streaming the entire process the community could get a better understanding of the practices of good penetration testing. Even without this, the video was extremely insightful and awesome! I would like to see more videos like this in the future from ISE.
The exploit itself is actually amazingly simple! Use a setting edit request to the SNMP configuration file, run the command (which is easy because everything in the SNMP is unauthenticated), start telnet then connect to telnet. However, even if the exploit itself is simple to execute, there's a lot more that goes into discovering this.
Understanding the technology and system is the most important thing when trying to find an exploit. So, I'm positive that the ISE researchers knew all the protocols on the device, the access points and everything about the device quite well before even thinking about pen testing it. This is clearly shown by how much the researcher knows about the device while giving the demonstration.
The goal of the team was to get an easy to use remote code execution on the server, which they certainly achieved. A good place to start searching for an RCE is to get access into the system where we're not supposed to have access to. Most people do not create security in layers. So, once the initial layer is broken, it's much more likely to find vulnerabilities. I believe this was a good starting point and I appreciated their reasoning for why they went after the authentication first. To test for the authentication issues, ISE researchers removed all of the cookies and parameters associated with the auth process. This was easily editable and repeatable using Burp suite. I did not realize how amazing Burp suite was until this video. So, to all those hackers out there, download the free version of Burp to get ahead!
The researchers then wrote a quick bash script, and viewed the output to see if the authentication was being done correctly. What they found out was that the SNMP protocol was not doing authentication properly! So, this looked like a good target to pursue.
The methodologies for diving further into the weeds were interesting to me. To start with, he wanted to keep escalating his privileges further until he found a good attack point. The researcher found this with the unauthenticated attack. After this, he kept diving deeper and deeper until he thought it was a viable vector for attack.
Once he chose the SNMP protocol, he decided to see what else he could find on the system. Because there is direct access to the CGI's, or application protocols being ran, Shaun Mirani SSH'ed into the box directly to view the files. Because they ended up being x86_64 binaries, he obviously couldn't read it. So, now what? He did two unique things: used the strings command on it and then took it off the system to use IDA on the binary. The strings command displays all the continuous chain of alphabetic characters in the file. This is used to see all functions, host names, passwords, parameter or anything interesting. The information is very valuable to anyone trying to understand the executable. Secondly, he sent the file to his local machine to do static analysis on it. This gave him the ability to use any of his tools on the file.
Until going to DEFCON, I did not realize how important it was understand assembly! Most, if not all, of the exploits discovered in the IoT village talks relied on dumping the firmware onto their local machine then analyzing the functionality of it. Clearly, understanding assembly is extremely important for exploitation. So, I plan on digging into several books, that were recommended to me by Shaggy, the lead penetration tester of Playstation. Just in case your curious, he recommended Introduction to 64 Bit Assembly Programming for Linux and OS X for learning assembly then Hacking: The Art of Exploitation and The Shellcoder's Handbook: Discovering and Exploiting Security Holes for understanding how to use the knowledge of assembly to exploit flaws. Shaggy believed in buying books to gain the knowledge needed for exploitation. So, I will follow in his footsteps!
Now, it was time to use IDA in order to disassemble the binary. IDA opens up the assembly in a very nice manner, giving the user an easy view to trace the assembly code. Once in the assembly I was surprised where Shaun Mirani started from: the main file. I figured he'd search for interesting functions or keywords. But, he wanted to understand the CGI's flow from the beginning access point. His first walk through was really rough, just going through the workflow of a single set parameter in the URL. But, if he saw anything else interesting then he'd briefly glance at what was going on, then return to the workflow he'd started on.
Another important asset of the research was understanding what he controlled, as the hacker. By understanding which parameters and inputs were controllable, Shaun Mirani was able to evaluate what the proper attack vectors were.
Takeaway: Understanding what is controlled by the hacker in the application is extremely important for exploitation. These are the areas that a user can manipulate for their own purposes.
One peculiar thing that I would like to mention were his memory of names being used. He remembered configuration files, parameters, function names and more. This makes sense because the analysis of the names led him to the SNMP protocol config file.
Takeaway: Remembering names from around the applications are important; if the name appears often then it is likely important. But, remembering parameters and other things often give the pen tester a better understanding how the application is using each individual component.
Exploiting vulnerabilities in a system is quite tedious and difficult to do. Conceptually, we're trying to make the machine act in a way that it was not designed to do! So, this makes complete sense. Shaun is quite tedious checking his work; to positively clarify each parameter, variable, function and call is done perfectly. Otherwise, the exploit will not work. It should also be noted that items set previously, by the system, should just be left alone. For instance, when I was trying to bypass filtering of evil HTML tags. that was being done on the client side, I decided to run post requests in curl. The issue is that the request would just get rejected, no matter how many times I tried to alter it. But, then I realized that I had forgotten a header to set the request header to have an XML request. Then, magically it worked!
Takeaway: Be very cautious, intentional and tedious when making changes to important features of the system. Otherwise, you'll be playing with too many variables and are probably not actually testing the application to way you think.
Exploit time! Shaun added a telnetd call to the config, ran the command using the built in SNMPwalk then connected to telnet using netcat.Then, boom! bin/sh achieved. In order to automate this process, the researchers wrote a quick bash script to make this work. I highly recommend watching the video of the ISE reseacher walking through the entire process. These are just my personal takeaways, which should not take precedent over the researchers in detail explanation.
Hope you learned something from this! I really enjoyed listening to a professional pen tester go through his mindset when testing something. I look forward to becoming a better pen tester and finding exploits myself!
Cheers from Maxwell Dulin (ꓘ).