Woooo! Yeah, DEF CON! I'm Max. I go by Strikeout, as you can see by the backwards K on my hat. This is hacking the Zero NAS, or however you say that, from the perspective of a noob. Have you ever felt down? I mean, really down. Overwhelmed? Tired? Not enough? But, at realizing your defeat is a sense of calmness. I don't have to fake my greatness anymore. I can see myself for who I truly am. This is where growth happens. You see, my first DEF CON last year, I spent most of my time at IoT Village, and I was absolutely horrified of how much everyone knew compared to me. But, I saw a path that looked awesome. I saw directions I could go. I saw that IoT hacking didn't have to be some crazy hardware glitch kind of thing. This could just be a web interface, which is fairly common. I started watching the ISE live streams. And I went, huh, I can do this. This is something I could actually do. And that's why I named it from the perspective of a noob. I had virtually no idea what I was doing before I started this, besides some software dev background. But, I had virtually no experience hacking itself. I'm going to go into a lot of technical details, but one thing I really miss about most presentations is they talk about the exploit, but they don't talk about the methodology of how they found it. Finding the exploit is most of the time the hardest part. Exploiting tends to be the easier thing. To me, hacking is understanding and then manipulating. Take, for example, this classic SQL injection. Super common. Yeah, you can throw this into a login field, and it might work. But how does this actually work, is what we should actually be asking. I want to give an actual example of something I found on a site. I'm going to an interview. I am so excited. I'm blaring one of my favorite security podcasts, and all of a sudden, I rear-end a guy. And I am furious. My insurance rates go up. I have to pay for a bunch of stuff in the guy's car. I miss my interview. I then have to be taken home by a tow truck, which is another fee in itself. And then I get online, and I have to pay a freaking ticket. That really bothered me. Really did. So, what do you do when you're pissed off? As a hacker, you probably shouldn't do it, but you start looking at what you can find. On the site, there was a birthday field where you could find your ticket as well as your name. I just took out the birthday field and saw what happened. Nothing different happened. So then, I casually started taking more and more characters off my name. I went from Doolin, to Dooley, to Dool, all the way to Dee, until I had a full page of identifying information. And this is where the understanding really comes in here. Based upon the query, I thought it was going to be a like clause. For those who don't know, a like clause with a percent sign there will return X, like the letter X in this case, the input you give it, and then anything else. So this will return like xylophone, as far as anything else starts with X. So I said, well, what happens if I put another percent sign here? And boom! Well, nothing happened. Funny thing. You're supposed to laugh. I walked away, I came back a couple minutes later, and all of the ticket information for every digital ticket that had ever been given out by this county was now on the screen. The percent sign wasn't a very normal thing for this, but it was a classic SQL injection. By understanding how this worked, I was able to manipulate what I wanted to get out of it. And side note on the ticketing system, that information you could actually use to log in as someone, and then schedule court dates and send more documents towards you. It's a very subtle thing, but it worked out. So, going with my methodology, the first thing you have to do is understand how the device works. If you don't understand how something works, you can throw payloads at it, you may find stuff, but you're not going to find very cool things. The first thing I always do is, like, what the hell is a NAS in the first place? It stands for Network Attack Storage Device. I think of it as a USB drive that you can just connect to from the internet. That's all it really is. It helps you manage files. There's a bunch of other administrative features on it, but that's pretty much all there is to it. So, after you kind of research, like, what is the use case of this, I just start clicking around the site. What's on the site? What is the site meant to do? What kind of user privileges are there? I click through every link I can find. I start reading through user documentation. I start looking at firmware notes, because a lot of times they'll add new features or something. After that, I start looking at the tech stack. So, what kind of web server is this using? What kind of language are we using here? Just understanding how the device works. One thing I noticed that I thought was fairly interesting was there were two different APIs. One was for file upload, file download, and logging in, and then there was an entirely separate API for everything else. Understanding how they're accomplishing what they're doing is very important. At this point, I SSH onto the NAS, because you can do that, and I realized they were using Python, but they were in PYC files. So, I just grabbed all the PYC files, took them off the NAS, and, for those who don't know, it stands for Python Compiled, and there's actually a tool that will take PYC files back to Python files, and it includes comments and everything. It's incredible. Uncompile 6 is the name of that tool, if you're curious. So now, I have the source code. I'm looking through it, and I notice it's using Cherry PY, which is an older Python kind of thing. Now, well, there's information being stored on this. What can I see on here? So I start changing directories, want to know how the file system works, what's on it, and I see this file. Thank you for laughing this time. Clearly, there's going to be nothing secretive in here. So you look on it, and it's a base64 encoded admin password. Yeah, that's really bad. Don't do that at home. You shouldn't be doing that. It's kind of sad. But it was a nice find to find that. Next talk, yeah. So, to build on this, I was just... So, from our constants, I just started taking strings that I saw in URLs and started sticking it into Google. And I found that this thing actually can host a website. And that part wasn't done very well. And you could actually direct request this file on the person's server and just log in as admin if you wanted to. So, looking over everything that's on the device, how it works, is the most important thing before you start hacking on something. At this point, we've talked for a while, there's been no actual hacking involved. We've just looked at how something works. And that's... I mean, I probably spent a week just understanding what was going on in the device. Now I'm going to do some actual hacking, which is fun. So, the first thing I thought was kind of odd was I was looking over the normal API calls, I noticed that they were using a file name and a function name for all their API calls. And I learned that just by grepping. It's a common theme. I use grep a lot. Just in the file system. So, I was like, why is it doing that? So, I went to the spot where these APIs were actually being called and I found this. So, anytime you see an eval in anything that doesn't validate user input, it's a pretty good attack factor. I'm not that smart, though, so I initially tried doing some really crazy directory traversal shit to call whatever I wanted. And it took me a while to realize this, but this will actually execute Python native code. It's going controller, which we had an MVC or a model view controller set up. The first parameter is going to be the file name. The second parameter is going to be the function name. So, with this knowledge, I said, okay, I understand how this request works. Now, is there a way I can manipulate this to do whatever I wanted? I came to this little sketch of mine. So, the eval is essentially calling a file name. There's a file name, a function name, and then it passes in JSON as parameters. This was my understanding of how this request worked. And this took me some time to fully figure out. So now, what can I do with this? First thing I tried doing is I noticed that there was a file that had everything imported from OS, just import star. So, I was curious if I could call the OS package. So, I called this really simple function and I got int object not callable. What the hell does that mean? So, I did a similar function and got a string returned. Cool. I still don't know what that means. And then it hit me like a brick. This is returning whatever I'm calling from the OS function and then executing it. So, I knew I had some sort of RCA. I just had to figure out how to actually weaponize this. Next thing I wanted to understand, I wanted to completely validate it. So, when it returned, it gave you the type, but it didn't actually give you any sort of feedback on what it actually looked like. So, I wanted to get some sort of timing issue. So, I turned on the yes command. I did os.system with yes. And this will just go on forever. Yes just prints yes forever. So, I make the request and burp just freezes. It just doesn't do anything. I log on to the NAS and I run ps, which shows all processes, and I see the yes command. So, now I figured out that I had a remote code execution. I was very confident. Now, I wanted to create a backdoor, which is kind of like the quintessential thing you have to do. I own this. I ran whoami. Otherwise, it's not real. So, I was going to show the code for that and then show the exploit. So, for this API call here, this is the backup main, which is just the name of the file. I'm calling it os.package with system. And then, I threw in this backdoor I found online. Like, I didn't write this. Some really smart guy did that. I just found it. Put it in there. Yeah. Now, I will show this off. Hopefully, it works. I set up a Netcat listener on a server I control. And then, hope this works. Cool. Who am I? This is when you're supposed to clap. It's an RC. Come on. Thank you. Thank you. Cool. So, the simple bug in the routing led to a very bad thing. But now, the next question we should ask that... Okay. One thing we don't do very well as hackers is we tell people when they've effed up. We don't tell them how to fix it. We just kind of assume people know what they're doing. So, I want to talk about mitigations, too. In this situation, running the eval command is a terrible idea. That's sort of user input. There should be virtually no scenario where you want to do that. However, telling them not to use eval is just completely unrealistic because they'd have to rewrite their entire API from scratch. So, what I recommended was whitelisting all of their file names and all of their function names so that they wouldn't have an issue. They don't want to be able to call anything malicious because it would just be thrown out. So, the next bug was in the package installer, which for some reason lower privileged users can run. I don't know why that's the case, but that's how it worked. So, I'm not sure if you guys know, but ISE runs this place here and they have a bunch of really good live streams and a lot of good blog posts. And I just started to turn on the live streams. And one thing they kept showing in the NAS devices was a bunch of command injection issues with stuff directly interfacing with the OS. So, I went searching for that. And I did it in a very sophisticated way. I just started grepping again. I started grepping for exec, OS.system. And I found lots of matches, but they were all dead code. After like 20 or 30 times of finding dead ends, I found one function which was at the very end of my grep list called execute script. So, I like analogies. I'm going to explain why I think this came about with an analogy. Have you guys ever played telephone? It always goes really well, right? No. Telephone never goes well. The premise of telephone is you're trying to get, like you talk in a circle, you're trying to get the message from the first person to the last person. It never gets to the last person. And in the correct form. This was similar to this vulnerability. The execute script function was probably written a long time ago by a developer. And then it was six function calls below the API call that was being called. That sort of indirection can create a lot of issues. Because the original developer probably thought, we don't need to escape shell meta characters. Why do I need to do that? Someone else can do that for me. By the time it gets to the person who wrote the API, they just had no idea that was the assumption that they had made. So this was what the command looked like. I'll show the exploit in a second. It was a package installer binary. And there was a package name that had to be called. And then there was a command that had to be passed into it. The package name had to be an actual package. Otherwise, it was a whitelist thing, so it couldn't do anything else. But the command had no filtration whatsoever. And that's where I put the payload at. So I'll go back to the code. So again, we have the portal main file. We have the package init command. This is the function name. We throw in the package, which is a valid package. And then we have the actual command here. Sorry, this is the package name. I again just put a shell I found online. The one little trickier thing about this is I had to put ticks right here, so it would execute slightly out of band. I could have put a command and then a semicolon or something. This is just the way I chose to do it. And I put an ampersand so it would run in the background. So it didn't screw up what I was doing in my code. So now I'll show this off. I have all the functions at the bottom here. We have root again. Talking makes my mouth really dry, so... Give me a sec. So the next thing I started looking at... Oh, sorry, mitigations. In order to mitigate this, you really should just whitelist those commands for the package installer. There was only like four or five commands to do with this. Even if you couldn't whitelist the commands itself, you could whitelist characters. I doubt you're going to need backticks or semicolons and a command name. So that's something that was pretty easy to do. So this is probably my favorite of the vulnerabilities. Not because it has the most impact, but it was the most interesting, and it took me the longest time to figure out. So we see arbitrary file share. The first thing is, like, what the hell is a file share? In this sort of situation. Here we go. So you can view all of your files, and a file share essentially is a folder that is abstracted with privileges. So the music, photo, and video are shares, essentially. And you don't see this right now, but there's an admin user who has access to other things that you can't see here. So there's some sort of boundary between what you control compared to other users. Yeah. All right, so I was... I wanted to find a direct address or cross-site scripting in this page. So I was looking through, and they did a very good job, actually. While I was looking through the source code, they were checking for the absolute path and see if it was owned by the right person. I was very impressed with how good of a job they did locking this down. So when this gray box kind of approach failed, I decided to take a white box approach and see if I can find anything in this file. And I started looking around, and I started seeing functions I had never seen before. They were very odd to me. And what ended up happening was there was a file that had... or an API that had no usage in the entire UI. This is where my... another analogy comes in. I'm the king of analogies when I talk. So when you're on a diet, and you are really focusing on protein, you're going to get a lot of protein. But you may not get enough vitamin C or something. That's an issue. Because... in the actual code here, these people focus on securing the APIs they actually meant to be public, but not the ones they weren't looking at. So as soon as I saw this API that wasn't used at all, I kind of started drooling a little bit because I knew something was going to be wrong with this. The issue, though, is because this wasn't used, I had to reverse the API. This is the actual source code trimmed down a little bit. So the first thing is there's an action parameter that I saw. This action parameter dictates if you're going to create a folder or rename a file. The create folder didn't seem super interesting to me, so I went on the rename file path, and I followed this down, reversed the API, added all the proper parameters, and eventually I was able to rename files using this. I noticed there was no absolute path check, which meant this was likely going to be vulnerable to some sort of a directory traversal. So now I have a directory traversal. I can move file from any share. You're probably thinking, you're done, right? Nowhere near done. This is where I felt like Alice and I just went way down the rabbit hole. I want to make this a really deadly sort of thing. What if I can move the admin password I just found into one of my shares and so then I can just take over everything I want to. That was my thought. However, whenever I tried moving outside of the shares, it didn't work. And that was the most infuriating thing. I wanted to understand that. So I decided I was going to turn on logging. The issue was that it was a read-only partition on this part of the drive where the code was at. I want to bypass that. I couldn't figure it out. I tried remounting partitions. I tried altering the bash RC I tried altering the boot scripts. No matter what I did, I couldn't get any of it to work. If anyone has any ideas, I'd love to talk to. It would be something fun to know. The whole point, though, of this was just get the logging working and then after like four days of banging my head against this, I eventually decided I can just put a Python file in the root directory and just call the function I needed to call. Because I can write there. It was a really simple fix, but it just wasn't something I really thought of. So I did that, and I got erno18 invalid Christ device link. You guys know what that is, right? No. You're not really supposed to know what that is. I had no idea. I googled it. You can't rename files in Python 2.7 across partitions. It's just something that happened. I think you can actually do it in 3 for some reason, but not 2.7. So even though I didn't actually get all I wanted out of this vulnerability, I learned a lot. I actually encourage people to go down the rabbit hole if you're just trying to learn. Because now I understand how BusyBox works a lot more. I learned a lot about how BusyBox boots. A lot about how partitioning works. I had no idea how that worked. And that rabbit hole was really beneficial for me. So now I'll show off my vulnerability. I'll explain the parameters first. The first thing you see is the URL. And the URL is just the command you're calling. The JSON is where the interesting black magic starts to happen. The share in this situation is just photo. The photo share is something that the test user has access to. The action is the rename action, which is what we were talking about. The user is the test user, because that's the user we're logged in as in this account. The target path is the file location, but it's actually just the photo, like the share, with the file name. In the example I'm going to show, I use nonce.txt. And the interesting thing is the path. So it's a very classic directory traversal. I move outside of my photo share. I go into the admin share and I move the nonce.txt file into my share. I'll show that now. This one can be really finicky, so this is the one I've been worried about. Don't make fun of me too much if it doesn't work. All right, just got to comment this out. Turn that on. Cool. So I think that worked then, if it gave you the okay message. I guess I didn't really show you what was... So this is the admin one. If we reset this, we'll... assuming they're still logged in, then you should notice that the nonce.txt file is now gone. And if we go to the regular test user, which is what I've been using for everything else, we go to the photo share, the nonce.txt is now there. Thank you. Cool. So again, we should probably talk about mitigations because this is important. If you're at my job, that's mostly what I do, is I find something that's remotely considered vulnerability, I write it up, I tell them how to fix it. That's the important thing the client needs. So as far as mitigations go, if they were just doing an absolute path check, checking for privileges, like they were doing initially, that would have worked wonderfully. But they just forgot to add that on there. So that would have been a really easy fix for them. There were a couple other things I wanted to talk about that weren't really worthy of their own sections. So, the company won't fix this. I emailed them, and they got back pretty quickly but they're like, yeah, we don't really care, these are all authenticated. And I wanted to bring to light an actual attack scenario. So this site also had no Csurf protection. For those who don't know, it stands for cross-site request forgery. An example of this would be if you have facebook.com, your cookies, when you make some sort of action on Facebook, are automatically sent with the request. Which you assume, and it's really nice. But, if you make it from a malicious website, that's also in your browser that you visit, it will actually use those cookies even though it's not the same site you're running on. So an example would be on my bad website, I make a call to Facebook to delete your profile. If it's a git request or something. Which, this is bad. So in theory, someone in a targeted attack could have a Csurf-based website that would then call this API with any sort of user and it could completely take control over it. Another interesting note is that there was a cross-site scripting bug, but it was I didn't really feel like showing it off because I literally just put script alert script in a description and it worked. Wasn't really that cool. This was over HTTP for some reason. Don't know why, but the web server you could host it with was over HTTPS. I don't know why, they clearly knew how, they just chose not to make this over HTTPS. It's kind of odd. The other, also kind of fun thing, was when you turned it on, it had the default password, admin1234. And it forced you to reset it as soon as you got on there, but if you knew someone was going to set this up, you could potentially just log on there, reset the password for the person. It's kind of hypothetical, but at the same time, you could really screw with people doing this. Cybersecurity does not have to be horrifying. Everything I did here was with known tools. I even used Notepad++ people. Come on. I used Python, Burp, Grep, Google, and uncompile 6 tool to decompile the source code. Other than that though, I used everything that was super basic. Everything I found were very known vulnerabilities. A lot of them are in the OS top 10. This is not block magic. The key to all this stuff is understanding how stuff works and then manipulating it. That's hacking. Thank you. Also, I work at Security Innovation. We do web app pen testing. We do a fair amount of IoT stuff too. Amazing company. Just started working there pretty recently. I just graduated from college. If you're interested, come talk to me. Anybody have any questions? I'd love to talk about stuff. I could. All these exploits are on my github. It's mdoolin2. I didn't put it up there. All the exploits are on github. If you want to look at this, my github account is mdoolin2. Go crazy, folks. I listen to Dark Knight Diaries, Malicious Life, and I also listen to Security Now. I've really only been doing this security thing for a year and a half, maybe two years at the most. Security Now is how I learned to talk the game. It's like a two-hour podcast. I'd just listen to it walking from my house to school. That was really helpful for me for talking the lingo. Any other questions? If there's no other questions, I would love to talk afterwards. There's a lot of other things you can find on this device if you're interested. If you want to talk about how to get a job, or you're depressed or something, come talk to me. I'm a pretty happy and chill guy to talk to. If you have any other questions, feel free to come up and talk. Thank you.