[00:00.720 --> 00:03.540] Woooo! Yeah, DEF CON! [00:06.600 --> 00:11.440] I'm Max. I go by Strikeout, as you can see by the backwards K on my hat. [00:11.660 --> 00:17.100] This is hacking the Zero NAS, or however you say that, from the perspective of a noob. [00:18.000 --> 00:23.100] Have you ever felt down? I mean, really down. [00:23.420 --> 00:26.900] Overwhelmed? Tired? Not enough? [00:28.660 --> 00:34.620] But, at realizing your defeat is a sense of calmness. [00:34.700 --> 00:39.300] I don't have to fake my greatness anymore. I can see myself for who I truly am. [00:39.580 --> 00:42.660] This is where growth happens. [00:43.120 --> 00:47.320] You see, my first DEF CON last year, I spent most of my time at IoT Village, [00:47.320 --> 00:51.300] and I was absolutely horrified of how much everyone knew compared to me. [00:51.660 --> 00:56.200] But, I saw a path that looked awesome. I saw directions I could go. [00:56.200 --> 01:01.080] I saw that IoT hacking didn't have to be some crazy hardware glitch kind of thing. [01:01.080 --> 01:03.840] This could just be a web interface, which is fairly common. [01:04.780 --> 01:07.620] I started watching the ISE live streams. [01:07.960 --> 01:12.460] And I went, huh, I can do this. This is something I could actually do. [01:12.540 --> 01:14.640] And that's why I named it from the perspective of a noob. [01:14.640 --> 01:17.840] I had virtually no idea what I was doing before I started this, [01:17.840 --> 01:20.360] besides some software dev background. [01:20.360 --> 01:23.760] But, I had virtually no experience hacking itself. [01:26.620 --> 01:28.700] I'm going to go into a lot of technical details, [01:28.700 --> 01:32.860] but one thing I really miss about most presentations is they talk about the exploit, [01:32.860 --> 01:35.440] but they don't talk about the methodology of how they found it. [01:35.520 --> 01:39.100] Finding the exploit is most of the time the hardest part. [01:39.100 --> 01:40.960] Exploiting tends to be the easier thing. [01:41.260 --> 01:45.440] To me, hacking is understanding and then manipulating. [01:45.740 --> 01:48.460] Take, for example, this classic SQL injection. [01:48.460 --> 01:49.600] Super common. [01:50.420 --> 01:54.400] Yeah, you can throw this into a login field, and it might work. [01:54.400 --> 01:57.700] But how does this actually work, is what we should actually be asking. [01:59.940 --> 02:03.800] I want to give an actual example of something I found on a site. [02:05.100 --> 02:08.260] I'm going to an interview. I am so excited. [02:08.260 --> 02:11.260] I'm blaring one of my favorite security podcasts, [02:11.260 --> 02:14.480] and all of a sudden, I rear-end a guy. [02:14.500 --> 02:17.960] And I am furious. My insurance rates go up. [02:17.960 --> 02:20.400] I have to pay for a bunch of stuff in the guy's car. [02:20.460 --> 02:26.140] I miss my interview. I then have to be taken home by a tow truck, [02:26.620 --> 02:28.620] which is another fee in itself. [02:28.620 --> 02:31.540] And then I get online, and I have to pay a freaking ticket. [02:33.080 --> 02:36.060] That really bothered me. Really did. [02:36.100 --> 02:38.080] So, what do you do when you're pissed off? [02:38.080 --> 02:41.520] As a hacker, you probably shouldn't do it, but you start looking at what you can find. [02:41.740 --> 02:47.020] On the site, there was a birthday field where you could find your ticket as well as your name. [02:47.020 --> 02:50.600] I just took out the birthday field and saw what happened. [02:50.600 --> 02:51.960] Nothing different happened. [02:51.960 --> 02:56.000] So then, I casually started taking more and more characters off my name. [02:56.000 --> 02:59.360] I went from Doolin, to Dooley, to Dool, all the way to Dee, [02:59.360 --> 03:03.240] until I had a full page of identifying information. [03:03.620 --> 03:07.140] And this is where the understanding really comes in here. [03:07.140 --> 03:11.280] Based upon the query, I thought it was going to be a like clause. [03:11.280 --> 03:18.240] For those who don't know, a like clause with a percent sign there will return X, [03:18.240 --> 03:22.120] like the letter X in this case, the input you give it, and then anything else. [03:22.120 --> 03:25.800] So this will return like xylophone, as far as anything else starts with X. [03:26.540 --> 03:29.820] So I said, well, what happens if I put another percent sign here? [03:29.820 --> 03:32.380] And boom! Well, nothing happened. [03:32.380 --> 03:34.800] Funny thing. You're supposed to laugh. [03:37.260 --> 03:39.700] I walked away, I came back a couple minutes later, [03:39.700 --> 03:44.640] and all of the ticket information for every digital ticket that had ever been given out by this county [03:44.640 --> 03:46.220] was now on the screen. [03:46.320 --> 03:51.100] The percent sign wasn't a very normal thing for this, [03:51.100 --> 03:53.240] but it was a classic SQL injection. [03:53.240 --> 03:58.280] By understanding how this worked, I was able to manipulate what I wanted to get out of it. [03:58.660 --> 04:00.740] And side note on the ticketing system, [04:02.720 --> 04:06.680] that information you could actually use to log in as someone, [04:06.680 --> 04:11.800] and then schedule court dates and send more documents towards you. [04:11.800 --> 04:14.280] It's a very subtle thing, but it worked out. [04:14.820 --> 04:17.640] So, going with my methodology, [04:17.640 --> 04:20.180] the first thing you have to do is understand how the device works. [04:20.180 --> 04:22.560] If you don't understand how something works, [04:22.560 --> 04:24.680] you can throw payloads at it, you may find stuff, [04:24.680 --> 04:26.340] but you're not going to find very cool things. [04:27.540 --> 04:32.080] The first thing I always do is, like, what the hell is a NAS in the first place? [04:32.320 --> 04:34.820] It stands for Network Attack Storage Device. [04:34.820 --> 04:38.920] I think of it as a USB drive that you can just connect to from the internet. [04:38.960 --> 04:40.920] That's all it really is. It helps you manage files. [04:41.020 --> 04:43.000] There's a bunch of other administrative features on it, [04:43.000 --> 04:45.900] but that's pretty much all there is to it. [04:46.720 --> 04:50.180] So, after you kind of research, like, what is the use case of this, [04:50.180 --> 04:51.720] I just start clicking around the site. [04:51.740 --> 04:54.020] What's on the site? What is the site meant to do? [04:54.180 --> 04:56.060] What kind of user privileges are there? [04:56.060 --> 04:58.000] I click through every link I can find. [04:58.000 --> 04:59.740] I start reading through user documentation. [04:59.980 --> 05:02.300] I start looking at firmware notes, [05:02.300 --> 05:04.740] because a lot of times they'll add new features or something. [05:07.180 --> 05:10.300] After that, I start looking at the tech stack. [05:10.620 --> 05:14.000] So, what kind of web server is this using? [05:14.000 --> 05:15.680] What kind of language are we using here? [05:15.680 --> 05:18.160] Just understanding how the device works. [05:18.720 --> 05:20.560] One thing I noticed that I thought was fairly interesting [05:20.560 --> 05:22.740] was there were two different APIs. [05:22.800 --> 05:27.480] One was for file upload, file download, and logging in, [05:27.480 --> 05:30.080] and then there was an entirely separate API for everything else. [05:30.080 --> 05:33.660] Understanding how they're accomplishing what they're doing is very important. [05:34.600 --> 05:38.880] At this point, I SSH onto the NAS, because you can do that, [05:38.880 --> 05:44.920] and I realized they were using Python, but they were in PYC files. [05:45.060 --> 05:49.340] So, I just grabbed all the PYC files, took them off the NAS, [05:49.340 --> 05:52.660] and, for those who don't know, it stands for Python Compiled, [05:52.660 --> 05:57.320] and there's actually a tool that will take PYC files back to Python files, [05:57.320 --> 05:59.780] and it includes comments and everything. [05:59.780 --> 06:00.720] It's incredible. [06:01.060 --> 06:03.260] Uncompile 6 is the name of that tool, if you're curious. [06:04.540 --> 06:06.660] So now, I have the source code. [06:06.660 --> 06:09.880] I'm looking through it, and I notice it's using Cherry PY, [06:09.880 --> 06:13.000] which is an older Python kind of thing. [06:13.900 --> 06:18.020] Now, well, there's information being stored on this. [06:18.160 --> 06:20.100] What can I see on here? [06:20.100 --> 06:24.320] So I start changing directories, want to know how the file system works, what's on it, [06:24.320 --> 06:25.800] and I see this file. [06:28.140 --> 06:29.920] Thank you for laughing this time. [06:31.940 --> 06:34.680] Clearly, there's going to be nothing secretive in here. [06:34.820 --> 06:39.000] So you look on it, and it's a base64 encoded admin password. [06:40.560 --> 06:42.680] Yeah, that's really bad. Don't do that at home. [06:42.700 --> 06:44.800] You shouldn't be doing that. It's kind of sad. [06:45.020 --> 06:47.200] But it was a nice find to find that. [06:49.660 --> 06:50.960] Next talk, yeah. [06:51.080 --> 06:54.540] So, to build on this, I was just... [06:54.540 --> 06:58.020] So, from our constants, I just started taking strings that I saw in URLs [06:58.020 --> 07:00.960] and started sticking it into Google. [07:00.960 --> 07:04.520] And I found that this thing actually can host a website. [07:04.720 --> 07:06.660] And that part wasn't done very well. [07:06.660 --> 07:11.840] And you could actually direct request this file on the person's server [07:12.540 --> 07:15.200] and just log in as admin if you wanted to. [07:15.240 --> 07:18.600] So, looking over everything that's on the device, how it works, [07:18.600 --> 07:22.600] is the most important thing before you start hacking on something. [07:24.540 --> 07:27.480] At this point, we've talked for a while, there's been no actual hacking involved. [07:27.480 --> 07:29.580] We've just looked at how something works. [07:29.820 --> 07:32.300] And that's... I mean, I probably spent a week just understanding [07:32.300 --> 07:33.640] what was going on in the device. [07:34.840 --> 07:37.500] Now I'm going to do some actual hacking, which is fun. [07:41.670 --> 07:43.930] So, the first thing I thought was kind of odd [07:43.930 --> 07:47.110] was I was looking over the normal API calls, [07:47.110 --> 07:50.710] I noticed that they were using a file name and a function name [07:50.710 --> 07:52.450] for all their API calls. [07:52.450 --> 07:54.630] And I learned that just by grepping. [07:54.630 --> 07:56.590] It's a common theme. I use grep a lot. [07:56.590 --> 07:59.410] Just in the file system. [07:59.450 --> 08:00.990] So, I was like, why is it doing that? [08:00.990 --> 08:04.510] So, I went to the spot where these APIs were actually being called [08:05.430 --> 08:06.970] and I found this. [08:09.410 --> 08:13.890] So, anytime you see an eval in anything that doesn't validate user input, [08:13.890 --> 08:15.650] it's a pretty good attack factor. [08:16.290 --> 08:17.630] I'm not that smart, though, [08:17.630 --> 08:20.430] so I initially tried doing some really crazy directory traversal shit [08:20.430 --> 08:21.910] to call whatever I wanted. [08:22.390 --> 08:23.870] And it took me a while to realize this, [08:23.870 --> 08:27.370] but this will actually execute Python native code. [08:27.470 --> 08:29.410] It's going controller, [08:29.410 --> 08:32.530] which we had an MVC or a model view controller set up. [08:32.970 --> 08:35.510] The first parameter is going to be the file name. [08:35.510 --> 08:38.230] The second parameter is going to be the function name. [08:39.630 --> 08:41.630] So, with this knowledge, I said, [08:41.630 --> 08:44.770] okay, I understand how this request works. [08:44.770 --> 08:48.010] Now, is there a way I can manipulate this to do whatever I wanted? [08:49.610 --> 08:51.950] I came to this little sketch of mine. [08:51.950 --> 08:54.970] So, the eval is essentially calling a file name. [08:54.970 --> 08:56.830] There's a file name, a function name, [08:56.830 --> 08:59.350] and then it passes in JSON as parameters. [08:59.690 --> 09:03.750] This was my understanding of how this request worked. [09:03.970 --> 09:06.570] And this took me some time to fully figure out. [09:07.430 --> 09:09.570] So now, what can I do with this? [09:09.810 --> 09:12.550] First thing I tried doing is I noticed that there was a file [09:12.550 --> 09:15.890] that had everything imported from OS, just import star. [09:15.910 --> 09:18.430] So, I was curious if I could call the OS package. [09:18.630 --> 09:20.370] So, I called this really simple function [09:20.370 --> 09:24.330] and I got int object not callable. [09:25.470 --> 09:26.950] What the hell does that mean? [09:27.070 --> 09:30.350] So, I did a similar function and got a string returned. [09:30.890 --> 09:33.390] Cool. I still don't know what that means. [09:33.550 --> 09:35.030] And then it hit me like a brick. [09:35.070 --> 09:38.170] This is returning whatever I'm calling from the OS function [09:38.170 --> 09:40.210] and then executing it. [09:40.710 --> 09:42.570] So, I knew I had some sort of RCA. [09:42.570 --> 09:44.930] I just had to figure out how to actually weaponize this. [09:45.230 --> 09:47.710] Next thing I wanted to understand, [09:47.710 --> 09:49.910] I wanted to completely validate it. [09:49.910 --> 09:52.790] So, when it returned, it gave you the type, [09:52.790 --> 09:54.730] but it didn't actually give you any sort of feedback [09:54.730 --> 09:56.170] on what it actually looked like. [09:56.170 --> 09:58.690] So, I wanted to get some sort of timing issue. [09:58.690 --> 10:00.170] So, I turned on the yes command. [10:00.170 --> 10:02.470] I did os.system with yes. [10:02.470 --> 10:05.210] And this will just go on forever. [10:05.210 --> 10:07.550] Yes just prints yes forever. [10:08.330 --> 10:12.630] So, I make the request and burp just freezes. [10:13.430 --> 10:15.210] It just doesn't do anything. [10:15.210 --> 10:16.190] I log on to the NAS [10:16.190 --> 10:20.390] and I run ps, which shows all processes, [10:20.390 --> 10:21.670] and I see the yes command. [10:21.890 --> 10:25.410] So, now I figured out that I had a remote code execution. [10:25.410 --> 10:26.650] I was very confident. [10:26.810 --> 10:29.910] Now, I wanted to create a backdoor, [10:29.910 --> 10:32.870] which is kind of like the quintessential thing you have to do. [10:32.910 --> 10:35.270] I own this. I ran whoami. [10:35.270 --> 10:36.570] Otherwise, it's not real. [10:37.850 --> 10:40.030] So, I was going to show the code for that [10:40.030 --> 10:41.370] and then show the exploit. [10:45.320 --> 10:47.720] So, for this API call here, [10:47.720 --> 10:51.060] this is the backup main, which is just the name of the file. [10:51.300 --> 10:53.640] I'm calling it os.package with system. [10:54.720 --> 10:58.420] And then, I threw in this backdoor I found online. [10:58.420 --> 10:59.720] Like, I didn't write this. [10:59.720 --> 11:02.000] Some really smart guy did that. I just found it. [11:02.000 --> 11:03.020] Put it in there. [11:04.100 --> 11:04.760] Yeah. [11:05.140 --> 11:07.720] Now, I will show this off. [11:07.720 --> 11:08.920] Hopefully, it works. [11:09.360 --> 11:11.940] I set up a Netcat listener on a server I control. [11:12.500 --> 11:15.200] And then, hope this works. [11:15.200 --> 11:15.900] Cool. [11:16.300 --> 11:17.180] Who am I? [11:17.980 --> 11:19.400] This is when you're supposed to clap. [11:19.400 --> 11:20.100] It's an RC. [11:20.100 --> 11:20.880] Come on. [11:20.900 --> 11:21.780] Thank you. [11:21.780 --> 11:22.660] Thank you. [11:24.820 --> 11:25.540] Cool. [11:26.740 --> 11:31.640] So, the simple bug in the routing led to a very bad thing. [11:31.720 --> 11:34.180] But now, the next question we should ask that... [11:39.950 --> 11:40.310] Okay. [11:41.570 --> 11:44.770] One thing we don't do very well as hackers is we tell people when they've effed up. [11:44.770 --> 11:46.150] We don't tell them how to fix it. [11:46.150 --> 11:47.910] We just kind of assume people know what they're doing. [11:48.210 --> 11:50.130] So, I want to talk about mitigations, too. [11:50.130 --> 11:53.850] In this situation, running the eval command is a terrible idea. [11:54.130 --> 11:55.410] That's sort of user input. [11:55.410 --> 11:58.090] There should be virtually no scenario where you want to do that. [11:59.270 --> 12:02.290] However, telling them not to use eval is just completely unrealistic [12:02.290 --> 12:05.110] because they'd have to rewrite their entire API from scratch. [12:05.110 --> 12:10.130] So, what I recommended was whitelisting all of their file names and all of their function names [12:10.130 --> 12:12.990] so that they wouldn't have an issue. [12:13.570 --> 12:17.290] They don't want to be able to call anything malicious because it would just be thrown out. [12:20.490 --> 12:26.290] So, the next bug was in the package installer, which for some reason lower privileged users can run. [12:26.290 --> 12:29.230] I don't know why that's the case, but that's how it worked. [12:31.330 --> 12:34.390] So, I'm not sure if you guys know, but ISE runs this place here [12:34.390 --> 12:37.530] and they have a bunch of really good live streams and a lot of good blog posts. [12:37.690 --> 12:39.930] And I just started to turn on the live streams. [12:39.930 --> 12:44.470] And one thing they kept showing in the NAS devices was a bunch of command injection issues [12:44.470 --> 12:47.050] with stuff directly interfacing with the OS. [12:47.530 --> 12:49.590] So, I went searching for that. [12:49.590 --> 12:52.490] And I did it in a very sophisticated way. [12:52.490 --> 12:54.010] I just started grepping again. [12:55.590 --> 12:59.730] I started grepping for exec, OS.system. [12:59.730 --> 13:02.850] And I found lots of matches, but they were all dead code. [13:02.850 --> 13:05.610] After like 20 or 30 times of finding dead ends, [13:05.610 --> 13:10.710] I found one function which was at the very end of my grep list called execute script. [13:12.550 --> 13:14.110] So, I like analogies. [13:14.110 --> 13:17.690] I'm going to explain why I think this came about with an analogy. [13:17.690 --> 13:19.010] Have you guys ever played telephone? [13:20.290 --> 13:22.270] It always goes really well, right? [13:22.690 --> 13:25.710] No. Telephone never goes well. [13:25.870 --> 13:29.190] The premise of telephone is you're trying to get, like you talk in a circle, [13:29.190 --> 13:33.710] you're trying to get the message from the first person to the last person. [13:34.150 --> 13:35.990] It never gets to the last person. [13:36.150 --> 13:37.450] And in the correct form. [13:37.450 --> 13:39.010] This was similar to this vulnerability. [13:39.270 --> 13:43.310] The execute script function was probably written a long time ago by a developer. [13:43.310 --> 13:47.730] And then it was six function calls below the API call that was being called. [13:47.970 --> 13:52.810] That sort of indirection can create a lot of issues. [13:52.810 --> 13:54.190] Because the original developer probably thought, [13:54.190 --> 13:57.070] we don't need to escape shell meta characters. [13:57.070 --> 13:59.310] Why do I need to do that? Someone else can do that for me. [13:59.370 --> 14:01.930] By the time it gets to the person who wrote the API, [14:01.930 --> 14:05.930] they just had no idea that was the assumption that they had made. [14:08.390 --> 14:10.630] So this was what the command looked like. [14:10.630 --> 14:12.210] I'll show the exploit in a second. [14:12.210 --> 14:15.490] It was a package installer binary. [14:15.890 --> 14:18.350] And there was a package name that had to be called. [14:18.870 --> 14:21.230] And then there was a command that had to be passed into it. [14:21.230 --> 14:24.130] The package name had to be an actual package. [14:24.130 --> 14:26.850] Otherwise, it was a whitelist thing, so it couldn't do anything else. [14:26.850 --> 14:31.510] But the command had no filtration whatsoever. [14:32.230 --> 14:35.190] And that's where I put the payload at. [14:35.710 --> 14:37.150] So I'll go back to the code. [14:43.480 --> 14:46.480] So again, we have the portal main file. [14:46.480 --> 14:48.720] We have the package init command. [14:48.820 --> 14:50.380] This is the function name. [14:50.380 --> 14:52.800] We throw in the package, which is a valid package. [14:52.800 --> 14:56.080] And then we have the actual command here. [14:56.080 --> 14:57.420] Sorry, this is the package name. [14:58.820 --> 15:01.680] I again just put a shell I found online. [15:01.680 --> 15:05.540] The one little trickier thing about this is I had to put ticks right here, [15:05.540 --> 15:08.180] so it would execute slightly out of band. [15:08.380 --> 15:11.960] I could have put a command and then a semicolon or something. [15:11.960 --> 15:13.840] This is just the way I chose to do it. [15:13.840 --> 15:16.460] And I put an ampersand so it would run in the background. [15:17.720 --> 15:20.540] So it didn't screw up what I was doing in my code. [15:22.020 --> 15:23.480] So now I'll show this off. [15:31.510 --> 15:33.890] I have all the functions at the bottom here. [15:46.550 --> 15:48.170] We have root again. [15:57.450 --> 15:59.830] Talking makes my mouth really dry, so... [15:59.830 --> 16:00.630] Give me a sec. [16:07.600 --> 16:10.180] So the next thing I started looking at... [16:10.180 --> 16:11.600] Oh, sorry, mitigations. [16:11.600 --> 16:13.720] In order to mitigate this, [16:13.720 --> 16:16.740] you really should just whitelist those commands for the package installer. [16:16.780 --> 16:19.660] There was only like four or five commands to do with this. [16:19.680 --> 16:22.880] Even if you couldn't whitelist the commands itself, [16:22.880 --> 16:24.620] you could whitelist characters. [16:24.620 --> 16:28.140] I doubt you're going to need backticks or semicolons and a command name. [16:28.320 --> 16:30.620] So that's something that was pretty easy to do. [16:34.990 --> 16:37.250] So this is probably my favorite of the vulnerabilities. [16:37.250 --> 16:39.110] Not because it has the most impact, [16:39.110 --> 16:40.690] but it was the most interesting, [16:40.690 --> 16:42.510] and it took me the longest time to figure out. [16:42.510 --> 16:44.490] So we see arbitrary file share. [16:44.490 --> 16:46.850] The first thing is, like, what the hell is a file share? [16:46.890 --> 16:48.610] In this sort of situation. [16:51.110 --> 16:52.190] Here we go. [16:52.270 --> 16:55.090] So you can view all of your files, [16:55.090 --> 16:59.150] and a file share essentially is a folder that is abstracted with privileges. [16:59.510 --> 17:03.650] So the music, photo, and video are shares, essentially. [17:03.650 --> 17:05.070] And you don't see this right now, [17:05.070 --> 17:07.750] but there's an admin user who has access to other things [17:07.750 --> 17:09.690] that you can't see here. [17:09.850 --> 17:10.890] So there's some sort of boundary [17:10.890 --> 17:13.410] between what you control compared to other users. [17:20.120 --> 17:20.760] Yeah. [17:20.940 --> 17:22.040] All right, so I was... [17:22.040 --> 17:23.620] I wanted to find a direct address [17:23.620 --> 17:26.580] or cross-site scripting in this page. [17:26.580 --> 17:29.260] So I was looking through, and they did a very good job, actually. [17:29.300 --> 17:30.460] While I was looking through the source code, [17:30.460 --> 17:31.980] they were checking for the absolute path [17:31.980 --> 17:33.760] and see if it was owned by the right person. [17:33.800 --> 17:36.100] I was very impressed with how good of a job [17:36.100 --> 17:37.660] they did locking this down. [17:38.880 --> 17:41.420] So when this gray box kind of approach failed, [17:41.420 --> 17:42.700] I decided to take a white box approach [17:42.700 --> 17:45.140] and see if I can find anything in this file. [17:46.260 --> 17:48.140] And I started looking around, [17:48.140 --> 17:50.660] and I started seeing functions I had never seen before. [17:50.660 --> 17:52.520] They were very odd to me. [17:52.800 --> 17:53.920] And what ended up happening was [17:53.920 --> 17:56.580] there was a file that had... [17:56.580 --> 17:58.280] or an API that had [17:58.280 --> 18:01.220] no usage in the entire UI. [18:02.500 --> 18:04.200] This is where my... [18:04.200 --> 18:05.520] another analogy comes in. [18:05.520 --> 18:07.520] I'm the king of analogies when I talk. [18:08.460 --> 18:09.760] So when you're on a diet, [18:09.760 --> 18:11.920] and you are really focusing on protein, [18:11.920 --> 18:14.280] you're going to get a lot of protein. [18:14.280 --> 18:17.500] But you may not get enough vitamin C or something. [18:17.920 --> 18:19.060] That's an issue. [18:19.140 --> 18:19.560] Because... [18:20.800 --> 18:23.380] in the actual code here, [18:23.380 --> 18:24.700] these people focus on securing [18:24.700 --> 18:26.960] the APIs they actually meant to be public, [18:26.960 --> 18:28.740] but not the ones they weren't looking at. [18:28.740 --> 18:30.140] So as soon as I saw this API [18:30.140 --> 18:33.560] that wasn't used at all, [18:33.560 --> 18:35.120] I kind of started drooling a little bit [18:35.120 --> 18:37.240] because I knew something was going to be wrong with this. [18:42.920 --> 18:44.980] The issue, though, is because this wasn't used, [18:44.980 --> 18:46.240] I had to reverse the API. [18:46.360 --> 18:49.100] This is the actual source code trimmed down a little bit. [18:50.540 --> 18:53.300] So the first thing is there's an action parameter that I saw. [18:53.300 --> 18:54.560] This action parameter dictates [18:54.560 --> 18:57.500] if you're going to create a folder or rename a file. [18:57.680 --> 19:00.080] The create folder didn't seem super interesting to me, [19:00.080 --> 19:02.600] so I went on the rename file path, [19:02.600 --> 19:04.620] and I followed this down, [19:04.620 --> 19:06.400] reversed the API, [19:06.400 --> 19:07.700] added all the proper parameters, [19:07.700 --> 19:10.960] and eventually I was able to rename files using this. [19:11.660 --> 19:14.180] I noticed there was no absolute path check, [19:14.180 --> 19:16.040] which meant this was likely going to be vulnerable [19:16.040 --> 19:18.140] to some sort of a directory traversal. [19:21.050 --> 19:23.270] So now I have a directory traversal. [19:23.270 --> 19:25.030] I can move file from any share. [19:25.030 --> 19:26.070] You're probably thinking, [19:26.730 --> 19:28.090] you're done, right? [19:29.150 --> 19:30.290] Nowhere near done. [19:30.290 --> 19:31.870] This is where I felt like Alice [19:31.870 --> 19:34.570] and I just went way down the rabbit hole. [19:37.450 --> 19:39.710] I want to make this a really deadly sort of thing. [19:39.710 --> 19:41.430] What if I can move the admin password [19:41.430 --> 19:44.890] I just found into one of my shares [19:44.890 --> 19:47.730] and so then I can just take over everything I want to. [19:47.890 --> 19:49.290] That was my thought. [19:49.290 --> 19:51.050] However, whenever I tried moving [19:51.050 --> 19:53.330] outside of the shares, it didn't work. [19:53.330 --> 19:54.830] And that was the most infuriating thing. [19:54.830 --> 19:56.470] I wanted to understand that. [19:56.470 --> 19:58.950] So I decided I was going to turn on logging. [19:58.990 --> 20:01.430] The issue was that it was a read-only [20:01.890 --> 20:03.410] partition on this part of the drive [20:03.410 --> 20:05.130] where the code was at. [20:05.470 --> 20:06.650] I want to bypass that. [20:06.950 --> 20:08.610] I couldn't figure it out. [20:08.610 --> 20:11.330] I tried remounting partitions. [20:11.330 --> 20:12.670] I tried altering the bash RC [20:15.090 --> 20:17.270] I tried altering the boot scripts. [20:17.270 --> 20:18.330] No matter what I did, [20:18.330 --> 20:19.730] I couldn't get any of it to work. [20:19.870 --> 20:21.750] If anyone has any ideas, I'd love to talk to. [20:21.750 --> 20:23.290] It would be something fun to know. [20:23.490 --> 20:24.810] The whole point, though, [20:25.450 --> 20:27.010] of this was just get the logging working [20:27.010 --> 20:28.670] and then after like four days [20:28.670 --> 20:30.530] of banging my head against this, [20:30.530 --> 20:32.110] I eventually decided I can just [20:33.170 --> 20:34.370] put a Python file [20:34.370 --> 20:35.890] in the root directory [20:36.570 --> 20:38.850] and just call the function I needed to call. [20:38.870 --> 20:39.970] Because I can write there. [20:39.970 --> 20:41.870] It was a really simple fix, [20:41.870 --> 20:44.010] but it just wasn't something I really thought of. [20:44.190 --> 20:45.810] So I did that, and I got [20:46.830 --> 20:47.230] erno18 [20:47.670 --> 20:49.270] invalid Christ device link. [20:50.110 --> 20:51.650] You guys know what that is, right? [20:52.590 --> 20:53.390] No. [20:53.550 --> 20:55.210] You're not really supposed to know what that is. [20:55.210 --> 20:56.610] I had no idea. I googled it. [20:56.610 --> 20:59.790] You can't rename files in Python 2.7 [20:59.790 --> 21:01.150] across partitions. [21:01.710 --> 21:03.250] It's just something that happened. [21:03.930 --> 21:05.870] I think you can actually do it in 3 for some reason, [21:05.870 --> 21:07.230] but not 2.7. [21:08.330 --> 21:09.330] So even though [21:09.330 --> 21:10.910] I didn't actually get [21:10.910 --> 21:13.130] all I wanted out of this vulnerability, [21:13.130 --> 21:14.110] I learned a lot. [21:14.390 --> 21:16.630] I actually encourage people to go down the rabbit hole [21:16.630 --> 21:18.090] if you're just trying to learn. [21:18.090 --> 21:20.930] Because now I understand how BusyBox works a lot more. [21:20.930 --> 21:21.930] I learned a lot about [21:23.150 --> 21:25.810] how BusyBox boots. [21:26.210 --> 21:27.190] A lot about how [21:27.190 --> 21:29.050] partitioning works. I had no idea how that worked. [21:29.050 --> 21:31.530] And that rabbit hole was really beneficial for me. [21:32.410 --> 21:33.050] So now [21:33.050 --> 21:35.810] I'll show off my vulnerability. [21:35.810 --> 21:38.470] I'll explain the parameters first. [21:39.890 --> 21:42.010] The first thing you see is the URL. [21:42.010 --> 21:42.710] And the URL [21:43.950 --> 21:45.830] is just the command [21:45.830 --> 21:47.690] you're calling. The JSON is where the interesting [21:48.630 --> 21:49.830] black magic starts [21:49.830 --> 21:50.690] to happen. [21:50.690 --> 21:53.730] The share in this situation is just [21:53.730 --> 21:54.930] photo. [21:55.450 --> 21:57.710] The photo share is something that [21:57.710 --> 21:59.630] the test user has access to. [22:00.930 --> 22:01.770] The action [22:01.770 --> 22:04.570] is the rename action, which is what we were talking about. [22:04.570 --> 22:06.190] The user is the test user, because that's [22:06.190 --> 22:08.610] the user we're logged in as in this account. [22:08.610 --> 22:10.350] The target path is the [22:11.470 --> 22:12.770] file location, [22:13.110 --> 22:14.650] but it's actually just the photo, [22:14.650 --> 22:15.990] like the share, with [22:16.490 --> 22:19.050] the file name. In the example I'm going to show, [22:19.050 --> 22:20.770] I use nonce.txt. [22:21.690 --> 22:22.810] And the interesting [22:22.810 --> 22:24.810] thing is the path. [22:24.810 --> 22:26.430] So it's a very classic [22:26.430 --> 22:28.190] directory traversal. I move [22:28.190 --> 22:30.270] outside of my photo share. [22:30.370 --> 22:32.510] I go into the admin share [22:32.510 --> 22:34.450] and I move the nonce.txt [22:34.450 --> 22:36.570] file into my share. [22:38.330 --> 22:38.690] I'll [22:38.690 --> 22:40.050] show that now. [22:40.330 --> 22:42.370] This one can be really finicky, so [22:42.370 --> 22:44.250] this is the one I've been worried about. [22:44.270 --> 22:46.370] Don't make fun of me too much if it doesn't work. [22:50.450 --> 22:51.050] All right, just got [22:51.050 --> 22:53.130] to comment this out. [22:54.030 --> 22:54.950] Turn that on. [22:59.110 --> 22:59.650] Cool. [22:59.650 --> 23:01.470] So I think that worked then, if it gave you the okay [23:01.470 --> 23:03.610] message. I guess I didn't really [23:03.610 --> 23:05.530] show you what was... So this is [23:05.530 --> 23:07.730] the admin one. If we reset this, [23:08.450 --> 23:09.490] we'll... assuming they're [23:09.490 --> 23:11.390] still logged in, then [23:11.390 --> 23:12.730] you should notice that [23:13.950 --> 23:15.570] the nonce.txt [23:15.570 --> 23:17.530] file is now gone. And if we go [23:17.530 --> 23:19.510] to the regular test user, which is what [23:19.510 --> 23:21.590] I've been using for everything else, we go to the photo [23:21.590 --> 23:23.450] share, the nonce.txt [23:23.450 --> 23:24.550] is now there. [23:24.870 --> 23:26.190] Thank you. [23:31.710 --> 23:34.070] Cool. So again, [23:34.070 --> 23:36.230] we should probably talk about mitigations [23:36.230 --> 23:37.870] because this is important. If you're [23:37.870 --> 23:39.870] at my job, that's [23:39.870 --> 23:41.770] mostly what I do, is I find something that's [23:41.770 --> 23:43.810] remotely considered vulnerability, I write it up, [23:43.810 --> 23:46.190] I tell them how to fix it. That's the important thing the client needs. [23:47.170 --> 23:48.110] So as far as mitigations [23:48.110 --> 23:50.010] go, if they were just doing an absolute path [23:50.010 --> 23:51.830] check, checking for privileges, like they were [23:51.830 --> 23:54.250] doing initially, that would have worked wonderfully. [23:54.630 --> 23:55.850] But they just forgot to [23:55.850 --> 23:57.750] add that on there. So that would have been a really [23:57.750 --> 23:58.730] easy fix for them. [24:00.450 --> 24:01.810] There were a couple other things I wanted [24:01.810 --> 24:03.110] to talk about that weren't really [24:04.710 --> 24:06.230] worthy of their own sections. [24:07.330 --> 24:07.990] So, [24:07.990 --> 24:10.070] the company won't fix this. [24:10.170 --> 24:12.230] I emailed them, and they got back pretty quickly [24:12.230 --> 24:14.850] but they're like, yeah, we don't really care, these are all authenticated. [24:15.370 --> 24:16.330] And I wanted to bring [24:16.330 --> 24:18.010] to light an actual attack scenario. [24:18.010 --> 24:20.430] So this site also had no Csurf protection. [24:20.850 --> 24:21.930] For those who don't know, [24:21.930 --> 24:24.230] it stands for cross-site request forgery. [24:25.110 --> 24:26.230] An example of this would be [24:26.230 --> 24:28.090] if you have facebook.com, [24:28.090 --> 24:30.230] your cookies, when you make some sort of [24:30.230 --> 24:31.830] action on Facebook, are automatically [24:31.830 --> 24:34.190] sent with the request. [24:34.190 --> 24:36.850] Which you assume, and it's really nice. [24:36.910 --> 24:37.350] But, [24:37.910 --> 24:40.170] if you make it from a malicious website, [24:40.170 --> 24:41.930] that's also in your browser that you visit, [24:41.930 --> 24:44.410] it will actually use those cookies [24:44.410 --> 24:45.630] even though it's [24:46.070 --> 24:47.990] not the same site you're running on. So an example [24:47.990 --> 24:50.250] would be on my bad website, [24:50.250 --> 24:52.730] I make a call to Facebook to delete your profile. [24:52.730 --> 24:54.530] If it's a git request or something. [24:54.770 --> 24:56.490] Which, this is bad. [24:56.490 --> 24:57.910] So in theory, someone [24:57.910 --> 25:00.030] in a targeted attack could [25:00.030 --> 25:02.310] have a Csurf-based [25:02.310 --> 25:04.330] website that would then call this [25:04.330 --> 25:06.330] API with any sort [25:06.330 --> 25:08.970] of user and it could completely take control over it. [25:11.090 --> 25:12.370] Another interesting note [25:12.370 --> 25:13.310] is that there was [25:14.410 --> 25:16.370] a cross-site scripting bug, but it was [25:16.370 --> 25:18.330] I didn't really feel like showing it off because I literally just [25:18.330 --> 25:19.770] put script alert script [25:20.190 --> 25:22.170] in a description and it worked. [25:23.270 --> 25:24.870] Wasn't really that cool. [25:25.630 --> 25:26.290] This was [25:26.290 --> 25:28.290] over HTTP for some reason. [25:28.670 --> 25:30.350] Don't know why, but the web server [25:30.350 --> 25:33.110] you could host it with was over HTTPS. [25:33.190 --> 25:33.910] I don't know why, [25:34.610 --> 25:35.970] they clearly knew how, [25:35.970 --> 25:38.390] they just chose not to make this over HTTPS. [25:38.830 --> 25:39.830] It's kind of odd. [25:39.990 --> 25:42.430] The other, also kind of fun thing, [25:42.430 --> 25:44.270] was when you turned it on, it had [25:44.270 --> 25:47.070] the default password, admin1234. [25:47.610 --> 25:48.630] And it forced you [25:48.630 --> 25:50.510] to reset it as soon as you got on there, [25:50.510 --> 25:52.450] but if you knew someone was going to set this up, [25:52.450 --> 25:54.150] you could potentially just log on there, [25:54.150 --> 25:56.250] reset the password for the person. [25:56.770 --> 25:58.410] It's kind of hypothetical, [25:58.410 --> 25:59.310] but at the same time, [25:59.310 --> 26:01.670] you could really screw with people doing this. [26:09.860 --> 26:11.000] Cybersecurity does not have [26:11.000 --> 26:12.140] to be horrifying. [26:12.940 --> 26:14.920] Everything I did here was with known tools. [26:14.920 --> 26:16.960] I even used Notepad++ people. [26:16.960 --> 26:17.760] Come on. [26:18.440 --> 26:20.700] I used Python, Burp, [26:20.700 --> 26:22.580] Grep, Google, [26:22.580 --> 26:23.760] and uncompile 6 tool [26:23.760 --> 26:27.320] to decompile the source code. [26:27.320 --> 26:28.220] Other than that though, [26:28.220 --> 26:30.480] I used everything that was super basic. [26:30.480 --> 26:32.080] Everything I found [26:32.080 --> 26:34.000] were very known vulnerabilities. [26:34.000 --> 26:35.740] A lot of them are in the OS top 10. [26:38.140 --> 26:40.100] This is not block magic. [26:40.200 --> 26:41.940] The key to all this stuff [26:41.940 --> 26:44.320] is understanding how stuff works [26:44.320 --> 26:46.520] and then manipulating it. [26:47.000 --> 26:49.440] That's hacking. Thank you. [26:56.080 --> 26:58.460] Also, I work at Security Innovation. [26:58.520 --> 26:59.840] We do web app [26:59.840 --> 27:02.400] pen testing. We do a fair amount of IoT stuff too. [27:02.420 --> 27:03.360] Amazing company. [27:03.360 --> 27:04.700] Just started working there pretty recently. [27:04.700 --> 27:06.080] I just graduated from college. [27:06.080 --> 27:08.760] If you're interested, come talk to me. [27:09.680 --> 27:11.480] Anybody have any questions? [27:11.960 --> 27:13.960] I'd love to talk about stuff. [27:18.900 --> 27:20.300] I could. [27:20.820 --> 27:23.280] All these exploits are on my github. [27:23.280 --> 27:24.480] It's mdoolin2. [27:24.480 --> 27:25.660] I didn't put it up there. [27:26.260 --> 27:28.100] All the exploits are on github. [27:29.080 --> 27:30.580] If you want to look at this, [27:30.580 --> 27:32.940] my github account is mdoolin2. [27:33.180 --> 27:34.680] Go crazy, folks. [27:39.750 --> 27:42.250] I listen to Dark Knight Diaries, [27:42.250 --> 27:44.110] Malicious Life, [27:44.110 --> 27:46.410] and I also listen to Security Now. [27:46.690 --> 27:47.930] I've really only been doing [27:47.930 --> 27:48.930] this security thing for [27:49.850 --> 27:52.350] a year and a half, maybe two years at the most. [27:52.350 --> 27:53.830] Security Now is how I learned [27:53.830 --> 27:55.110] to talk the game. [27:56.310 --> 27:57.790] It's like a two-hour podcast. [27:57.790 --> 27:59.770] I'd just listen to it walking from my house [27:59.770 --> 28:00.890] to school. [28:01.270 --> 28:04.030] That was really helpful for me for talking the lingo. [28:05.590 --> 28:07.050] Any other questions? [28:12.710 --> 28:14.290] If there's no other questions, [28:14.630 --> 28:16.250] I would love to talk afterwards. [28:16.470 --> 28:18.270] There's a lot of other things you can find on this device [28:18.270 --> 28:19.230] if you're interested. [28:19.470 --> 28:22.110] If you want to talk about how to get a job, [28:22.110 --> 28:24.070] or you're depressed or something, [28:24.070 --> 28:25.250] come talk to me. [28:25.390 --> 28:27.250] I'm a pretty happy and chill guy to talk to. [28:27.250 --> 28:29.430] If you have any other questions, feel free to come up and talk. [28:29.430 --> 28:30.150] Thank you.