1 00:00:00,720 --> 00:00:01,840 Woooo! 2 00:00:01,860 --> 00:00:03,540 Yeah, DEF CON! 3 00:00:06,600 --> 00:00:07,760 I'm Max. 4 00:00:07,760 --> 00:00:11,440 I go by Strikeout, as you can see by the backwards K on my hat. 5 00:00:11,660 --> 00:00:17,100 This is hacking the Zero NAS, or however you say that, from the perspective of a noob. 6 00:00:18,000 --> 00:00:20,660 Have you ever felt down? 7 00:00:20,720 --> 00:00:23,100 I mean, really down. 8 00:00:23,420 --> 00:00:24,540 Overwhelmed? 9 00:00:24,560 --> 00:00:25,440 Tired? 10 00:00:25,540 --> 00:00:26,900 Not enough? 11 00:00:28,660 --> 00:00:34,620 But, at realizing your defeat is a sense of calmness. 12 00:00:34,700 --> 00:00:36,780 I don't have to fake my greatness anymore. 13 00:00:36,820 --> 00:00:39,300 I can see myself for who I truly am. 14 00:00:39,580 --> 00:00:42,660 This is where growth happens. 15 00:00:43,120 --> 00:00:51,300 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. 16 00:00:51,660 --> 00:00:54,520 But, I saw a path that looked awesome. 17 00:00:54,520 --> 00:00:56,200 I saw directions I could go. 18 00:00:56,200 --> 00:01:01,080 I saw that IoT hacking didn't have to be some crazy hardware glitch kind of thing. 19 00:01:01,080 --> 00:01:03,840 This could just be a web interface, which is fairly common. 20 00:01:04,780 --> 00:01:07,620 I started watching the ISE live streams. 21 00:01:07,960 --> 00:01:10,420 And I went, huh, I can do this. 22 00:01:10,420 --> 00:01:12,460 This is something I could actually do. 23 00:01:12,540 --> 00:01:14,640 And that's why I named it from the perspective of a noob. 24 00:01:14,640 --> 00:01:20,360 I had virtually no idea what I was doing before I started this, besides some software dev background. 25 00:01:20,360 --> 00:01:23,760 But, I had virtually no experience hacking itself. 26 00:01:26,620 --> 00:01:35,440 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. 27 00:01:35,520 --> 00:01:39,100 Finding the exploit is most of the time the hardest part. 28 00:01:39,100 --> 00:01:40,960 Exploiting tends to be the easier thing. 29 00:01:41,260 --> 00:01:45,440 To me, hacking is understanding and then manipulating. 30 00:01:45,740 --> 00:01:48,460 Take, for example, this classic SQL injection. 31 00:01:48,460 --> 00:01:49,600 Super common. 32 00:01:50,420 --> 00:01:54,400 Yeah, you can throw this into a login field, and it might work. 33 00:01:54,400 --> 00:01:57,700 But how does this actually work, is what we should actually be asking. 34 00:01:59,940 --> 00:02:03,800 I want to give an actual example of something I found on a site. 35 00:02:05,100 --> 00:02:06,700 I'm going to an interview. 36 00:02:06,700 --> 00:02:08,260 I am so excited. 37 00:02:08,260 --> 00:02:14,480 I'm blaring one of my favorite security podcasts, and all of a sudden, I rear-end a guy. 38 00:02:14,500 --> 00:02:16,140 And I am furious. 39 00:02:16,300 --> 00:02:17,960 My insurance rates go up. 40 00:02:17,960 --> 00:02:20,400 I have to pay for a bunch of stuff in the guy's car. 41 00:02:20,460 --> 00:02:21,740 I miss my interview. 42 00:02:21,980 --> 00:02:28,620 I then have to be taken home by a tow truck, which is another fee in itself. 43 00:02:28,620 --> 00:02:31,540 And then I get online, and I have to pay a freaking ticket. 44 00:02:33,080 --> 00:02:34,880 That really bothered me. 45 00:02:34,940 --> 00:02:36,060 Really did. 46 00:02:36,100 --> 00:02:38,080 So, what do you do when you're pissed off? 47 00:02:38,080 --> 00:02:41,520 As a hacker, you probably shouldn't do it, but you start looking at what you can find. 48 00:02:41,740 --> 00:02:47,020 On the site, there was a birthday field where you could find your ticket as well as your name. 49 00:02:47,020 --> 00:02:50,600 I just took out the birthday field and saw what happened. 50 00:02:50,600 --> 00:02:51,960 Nothing different happened. 51 00:02:51,960 --> 00:02:56,000 So then, I casually started taking more and more characters off my name. 52 00:02:56,000 --> 00:03:03,240 I went from Doolin, to Dooley, to Dool, all the way to Dee, until I had a full page of identifying information. 53 00:03:03,620 --> 00:03:07,140 And this is where the understanding really comes in here. 54 00:03:07,140 --> 00:03:11,280 Based upon the query, I thought it was going to be a like clause. 55 00:03:11,280 --> 00:03:22,120 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. 56 00:03:22,120 --> 00:03:25,800 So this will return like xylophone, as far as anything else starts with X. 57 00:03:26,540 --> 00:03:29,820 So I said, well, what happens if I put another percent sign here? 58 00:03:29,820 --> 00:03:30,860 And boom! 59 00:03:31,120 --> 00:03:32,380 Well, nothing happened. 60 00:03:32,380 --> 00:03:33,500 Funny thing. 61 00:03:33,540 --> 00:03:34,800 You're supposed to laugh. 62 00:03:37,260 --> 00:03:46,220 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. 63 00:03:46,320 --> 00:03:53,240 The percent sign wasn't a very normal thing for this, but it was a classic SQL injection. 64 00:03:53,240 --> 00:03:58,280 By understanding how this worked, I was able to manipulate what I wanted to get out of it. 65 00:03:58,660 --> 00:04:11,800 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. 66 00:04:11,800 --> 00:04:14,280 It's a very subtle thing, but it worked out. 67 00:04:14,820 --> 00:04:20,180 So, going with my methodology, the first thing you have to do is understand how the device works. 68 00:04:20,180 --> 00:04:26,340 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. 69 00:04:27,540 --> 00:04:32,080 The first thing I always do is, like, what the hell is a NAS in the first place? 70 00:04:32,320 --> 00:04:34,820 It stands for Network Attack Storage Device. 71 00:04:34,820 --> 00:04:38,920 I think of it as a USB drive that you can just connect to from the internet. 72 00:04:38,960 --> 00:04:39,600 That's all it really is. 73 00:04:39,600 --> 00:04:40,920 It helps you manage files. 74 00:04:41,020 --> 00:04:45,900 There's a bunch of other administrative features on it, but that's pretty much all there is to it. 75 00:04:46,720 --> 00:04:51,720 So, after you kind of research, like, what is the use case of this, I just start clicking around the site. 76 00:04:51,740 --> 00:04:52,640 What's on the site? 77 00:04:52,640 --> 00:04:54,020 What is the site meant to do? 78 00:04:54,180 --> 00:04:56,060 What kind of user privileges are there? 79 00:04:56,060 --> 00:04:58,000 I click through every link I can find. 80 00:04:58,000 --> 00:04:59,740 I start reading through user documentation. 81 00:04:59,980 --> 00:05:04,740 I start looking at firmware notes, because a lot of times they'll add new features or something. 82 00:05:07,180 --> 00:05:10,300 After that, I start looking at the tech stack. 83 00:05:10,620 --> 00:05:14,000 So, what kind of web server is this using? 84 00:05:14,000 --> 00:05:15,680 What kind of language are we using here? 85 00:05:15,680 --> 00:05:18,160 Just understanding how the device works. 86 00:05:18,720 --> 00:05:22,740 One thing I noticed that I thought was fairly interesting was there were two different APIs. 87 00:05:22,800 --> 00:05:30,080 One was for file upload, file download, and logging in, and then there was an entirely separate API for everything else. 88 00:05:30,080 --> 00:05:33,660 Understanding how they're accomplishing what they're doing is very important. 89 00:05:34,600 --> 00:05:44,920 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. 90 00:05:45,060 --> 00:05:59,780 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. 91 00:05:59,780 --> 00:06:00,720 It's incredible. 92 00:06:01,060 --> 00:06:03,260 Uncompile 6 is the name of that tool, if you're curious. 93 00:06:04,540 --> 00:06:06,660 So now, I have the source code. 94 00:06:06,660 --> 00:06:13,000 I'm looking through it, and I notice it's using Cherry PY, which is an older Python kind of thing. 95 00:06:13,900 --> 00:06:18,020 Now, well, there's information being stored on this. 96 00:06:18,160 --> 00:06:20,100 What can I see on here? 97 00:06:20,100 --> 00:06:25,800 So I start changing directories, want to know how the file system works, what's on it, and I see this file. 98 00:06:28,140 --> 00:06:29,920 Thank you for laughing this time. 99 00:06:31,940 --> 00:06:34,680 Clearly, there's going to be nothing secretive in here. 100 00:06:34,820 --> 00:06:39,000 So you look on it, and it's a base64 encoded admin password. 101 00:06:40,560 --> 00:06:41,660 Yeah, that's really bad. 102 00:06:41,660 --> 00:06:42,680 Don't do that at home. 103 00:06:42,700 --> 00:06:43,780 You shouldn't be doing that. 104 00:06:43,780 --> 00:06:44,800 It's kind of sad. 105 00:06:45,020 --> 00:06:47,200 But it was a nice find to find that. 106 00:06:49,660 --> 00:06:50,960 Next talk, yeah. 107 00:06:51,080 --> 00:06:54,540 So, to build on this, I was just... 108 00:06:54,540 --> 00:07:00,960 So , from our constants, I just started taking strings that I saw in URLs and started sticking it into Google. 109 00:07:00,960 --> 00:07:04,520 And I found that this thing actually can host a website. 110 00:07:04,720 --> 00:07:06,660 And that part wasn't done very well. 111 00:07:06,660 --> 00:07:15,200 And you could actually direct request this file on the person's server and just log in as admin if you wanted to. 112 00:07:15,240 --> 00:07:22,600 So, looking over everything that's on the device, how it works, is the most important thing before you start hacking on something. 113 00:07:24,540 --> 00:07:27,480 At this point, we've talked for a while, there's been no actual hacking involved. 114 00:07:27,480 --> 00:07:29,580 We've just looked at how something works. 115 00:07:29,820 --> 00:07:33,640 And that's... I mean, I probably spent a week just understanding what was going on in the device. 116 00:07:34,840 --> 00:07:37,500 Now I'm going to do some actual hacking, which is fun. 117 00:07:41,670 --> 00:07:52,450 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. 118 00:07:52,450 --> 00:07:54,630 And I learned that just by grepping. 119 00:07:54,630 --> 00:07:55,450 It's a common theme. 120 00:07:55,450 --> 00:07:56,590 I use grep a lot. 121 00:07:56,590 --> 00:07:59,410 Just in the file system. 122 00:07:59,450 --> 00:08:00,990 So, I was like, why is it doing that? 123 00:08:00,990 --> 00:08:06,970 So, I went to the spot where these APIs were actually being called and I found this. 124 00:08:09,410 --> 00:08:15,650 So, anytime you see an eval in anything that doesn't validate user input, it's a pretty good attack factor. 125 00:08:16,290 --> 00:08:21,910 I'm not that smart, though, so I initially tried doing some really crazy directory traversal shit to call whatever I wanted. 126 00:08:22,390 --> 00:08:27,370 And it took me a while to realize this, but this will actually execute Python native code. 127 00:08:27,470 --> 00:08:32,530 It's going controller, which we had an MVC or a model view controller set up. 128 00:08:32,970 --> 00:08:35,510 The first parameter is going to be the file name. 129 00:08:35,510 --> 00:08:38,230 The second parameter is going to be the function name. 130 00:08:39,630 --> 00:08:44,770 So, with this knowledge, I said, okay, I understand how this request works. 131 00:08:44,770 --> 00:08:48,010 Now, is there a way I can manipulate this to do whatever I wanted? 132 00:08:49,610 --> 00:08:51,950 I came to this little sketch of mine. 133 00:08:51,950 --> 00:08:54,970 So, the eval is essentially calling a file name. 134 00:08:54,970 --> 00:08:59,350 There's a file name, a function name, and then it passes in JSON as parameters. 135 00:08:59,690 --> 00:09:03,750 This was my understanding of how this request worked. 136 00:09:03,970 --> 00:09:06,570 And this took me some time to fully figure out. 137 00:09:07,430 --> 00:09:09,570 So now, what can I do with this? 138 00:09:09,810 --> 00:09:15,890 First thing I tried doing is I noticed that there was a file that had everything imported from OS, just import star. 139 00:09:15,910 --> 00:09:18,430 So, I was curious if I could call the OS package. 140 00:09:18,630 --> 00:09:24,330 So, I called this really simple function and I got int object not callable. 141 00:09:25,470 --> 00:09:26,950 What the hell does that mean? 142 00:09:27,070 --> 00:09:30,350 So, I did a similar function and got a string returned. 143 00:09:30,890 --> 00:09:31,770 Cool. 144 00:09:31,770 --> 00:09:33,390 I still don't know what that means. 145 00:09:33,550 --> 00:09:35,030 And then it hit me like a brick. 146 00:09:35,070 --> 00:09:40,210 This is returning whatever I'm calling from the OS function and then executing it. 147 00:09:40,710 --> 00:09:42,570 So, I knew I had some sort of RCA. 148 00:09:42,570 --> 00:09:44,930 I just had to figure out how to actually weaponize this. 149 00:09:45,230 --> 00:09:49,910 Next thing I wanted to understand, I wanted to completely validate it. 150 00:09:49,910 --> 00:09:56,170 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. 151 00:09:56,170 --> 00:09:58,690 So, I wanted to get some sort of timing issue. 152 00:09:58,690 --> 00:10:00,170 So, I turned on the yes command. 153 00:10:00,170 --> 00:10:02,470 I did os.system with yes. 154 00:10:02,470 --> 00:10:05,210 And this will just go on forever. 155 00:10:05,210 --> 00:10:07,550 Yes just prints yes forever. 156 00:10:08,330 --> 00:10:12,630 So, I make the request and burp just freezes. 157 00:10:13,430 --> 00:10:15,210 It just doesn't do anything. 158 00:10:15,210 --> 00:10:21,670 I log on to the NAS and I run ps, which shows all processes, and I see the yes command. 159 00:10:21,890 --> 00:10:25,410 So, now I figured out that I had a remote code execution. 160 00:10:25,410 --> 00:10:26,650 I was very confident. 161 00:10:26,810 --> 00:10:32,870 Now, I wanted to create a backdoor, which is kind of like the quintessential thing you have to do. 162 00:10:32,910 --> 00:10:34,110 I own this. 163 00:10:34,110 --> 00:10:35,270 I ran whoami. 164 00:10:35,270 --> 00:10:36,570 Otherwise, it's not real. 165 00:10:37,850 --> 00:10:41,370 So, I was going to show the code for that and then show the exploit. 166 00:10:45,320 --> 00:10:51,060 So, for this API call here, this is the backup main, which is just the name of the file. 167 00:10:51,300 --> 00:10:53,640 I'm calling it os.package with system. 168 00:10:54,720 --> 00:10:58,420 And then, I threw in this backdoor I found online. 169 00:10:58,420 --> 00:10:59,720 Like, I didn't write this. 170 00:10:59,720 --> 00:11:00,900 Some really smart guy did that. 171 00:11:00,900 --> 00:11:02,000 I just found it. 172 00:11:02,000 --> 00:11:03,020 Put it in there. 173 00:11:04,100 --> 00:11:04,760 Yeah. 174 00:11:05,140 --> 00:11:07,720 Now, I will show this off. 175 00:11:07,720 --> 00:11:08,920 Hopefully, it works. 176 00:11:09,360 --> 00:11:11,940 I set up a Netcat listener on a server I control. 177 00:11:12,500 --> 00:11:15,200 And then, hope this works. 178 00:11:15,200 --> 00:11:15,900 Cool. 179 00:11:16,300 --> 00:11:17,180 Who am I? 180 00:11:17,980 --> 00:11:19,400 This is when you're supposed to clap. 181 00:11:19,400 --> 00:11:20,100 It's an RC. 182 00:11:20,100 --> 00:11:20,880 Come on. 183 00:11:20,900 --> 00:11:21,780 Thank you. 184 00:11:21,780 --> 00:11:22,660 Thank you. 185 00:11:24,820 --> 00:11:25,540 Cool. 186 00:11:26,740 --> 00:11:31,640 So, the simple bug in the routing led to a very bad thing. 187 00:11:31,720 --> 00:11:34,180 But now, the next question we should ask that... 188 00:11:39,950 --> 00:11:40,310 Okay . 189 00:11:41,570 --> 00:11:44,770 One thing we don't do very well as hackers is we tell people when they've effed up. 190 00:11:44,770 --> 00:11:46,150 We don't tell them how to fix it. 191 00:11:46,150 --> 00:11:47,910 We just kind of assume people know what they're doing. 192 00:11:48,210 --> 00:11:50,130 So, I want to talk about mitigations, too. 193 00:11:50,130 --> 00:11:53,850 In this situation, running the eval command is a terrible idea. 194 00:11:54,130 --> 00:11:55,410 That's sort of user input. 195 00:11:55,410 --> 00:11:58,090 There should be virtually no scenario where you want to do that. 196 00:11:59,270 --> 00:12:05,110 However, telling them not to use eval is just completely unrealistic because they'd have to rewrite their entire API from scratch. 197 00:12:05,110 --> 00:12:12,990 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. 198 00:12:13,570 --> 00:12:17,290 They don't want to be able to call anything malicious because it would just be thrown out. 199 00:12:20,490 --> 00:12:26,290 So, the next bug was in the package installer, which for some reason lower privileged users can run. 200 00:12:26,290 --> 00:12:29,230 I don't know why that's the case, but that's how it worked. 201 00:12:31,330 --> 00:12:37,530 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. 202 00:12:37,690 --> 00:12:39,930 And I just started to turn on the live streams. 203 00:12:39,930 --> 00:12:47,050 And one thing they kept showing in the NAS devices was a bunch of command injection issues with stuff directly interfacing with the OS. 204 00:12:47,530 --> 00:12:49,590 So, I went searching for that. 205 00:12:49,590 --> 00:12:52,490 And I did it in a very sophisticated way. 206 00:12:52,490 --> 00:12:54,010 I just started grepping again. 207 00:12:55,590 --> 00:12:59,730 I started grepping for exec, OS.system. 208 00:12:59,730 --> 00:13:02,850 And I found lots of matches, but they were all dead code. 209 00:13:02,850 --> 00:13:10,710 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. 210 00:13:12,550 --> 00:13:14,110 So, I like analogies. 211 00:13:14,110 --> 00:13:17,690 I'm going to explain why I think this came about with an analogy. 212 00:13:17,690 --> 00:13:19,010 Have you guys ever played telephone? 213 00:13:20,290 --> 00:13:22,270 It always goes really well, right? 214 00:13:22,690 --> 00:13:23,550 No. 215 00:13:23,670 --> 00:13:25,710 Telephone never goes well. 216 00:13:25,870 --> 00:13:33,710 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. 217 00:13:34,150 --> 00:13:35,990 It never gets to the last person. 218 00:13:36,150 --> 00:13:37,450 And in the correct form. 219 00:13:37,450 --> 00:13:39,010 This was similar to this vulnerability. 220 00:13:39,270 --> 00:13:43,310 The execute script function was probably written a long time ago by a developer. 221 00:13:43,310 --> 00:13:47,730 And then it was six function calls below the API call that was being called. 222 00:13:47,970 --> 00:13:52,810 That sort of indirection can create a lot of issues. 223 00:13:52,810 --> 00:13:57,070 Because the original developer probably thought, we don't need to escape shell meta characters. 224 00:13:57,070 --> 00:13:58,010 Why do I need to do that? 225 00:13:58,010 --> 00:13:59,310 Someone else can do that for me. 226 00:13:59,370 --> 00:14:05,930 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. 227 00:14:08,390 --> 00:14:10,630 So this was what the command looked like. 228 00:14:10,630 --> 00:14:12,210 I'll show the exploit in a second. 229 00:14:12,210 --> 00:14:15,490 It was a package installer binary. 230 00:14:15,890 --> 00:14:18,350 And there was a package name that had to be called. 231 00:14:18,870 --> 00:14:21,230 And then there was a command that had to be passed into it. 232 00:14:21,230 --> 00:14:24,130 The package name had to be an actual package. 233 00:14:24,130 --> 00:14:26,850 Otherwise, it was a whitelist thing, so it couldn't do anything else. 234 00:14:26,850 --> 00:14:31,510 But the command had no filtration whatsoever. 235 00:14:32,230 --> 00:14:35,190 And that's where I put the payload at. 236 00:14:35,710 --> 00:14:37,150 So I'll go back to the code. 237 00:14:43,480 --> 00:14:46,480 So again, we have the portal main file. 238 00:14:46,480 --> 00:14:48,720 We have the package init command. 239 00:14:48,820 --> 00:14:50,380 This is the function name. 240 00:14:50,380 --> 00:14:52,800 We throw in the package, which is a valid package. 241 00:14:52,800 --> 00:14:56,080 And then we have the actual command here. 242 00:14:56,080 --> 00:14:57,420 Sorry, this is the package name. 243 00:14:58,820 --> 00:15:01,680 I again just put a shell I found online. 244 00:15:01,680 --> 00:15:08,180 The one little trickier thing about this is I had to put ticks right here, so it would execute slightly out of band. 245 00:15:08,380 --> 00:15:11,960 I could have put a command and then a semicolon or something. 246 00:15:11,960 --> 00:15:13,840 This is just the way I chose to do it. 247 00:15:13,840 --> 00:15:16,460 And I put an ampersand so it would run in the background. 248 00:15:17,720 --> 00:15:20,540 So it didn't screw up what I was doing in my code. 249 00:15:22,020 --> 00:15:23,480 So now I'll show this off. 250 00:15:31,510 --> 00:15:33,890 I have all the functions at the bottom here. 251 00:15:46,550 --> 00:15:48,170 We have root again. 252 00:15:57,450 --> 00:15:59,830 Talking makes my mouth really dry, so... 253 00:15:59,830 --> 00:16:00,630 Give me a sec. 254 00:16:07,600 --> 00:16:10,180 So the next thing I started looking at... 255 00:16:10,180 --> 00:16:11,600 Oh, sorry, mitigations. 256 00:16:11,600 --> 00:16:16,740 In order to mitigate this, you really should just whitelist those commands for the package installer. 257 00:16:16,780 --> 00:16:19,660 There was only like four or five commands to do with this. 258 00:16:19,680 --> 00:16:24,620 Even if you couldn't whitelist the commands itself, you could whitelist characters. 259 00:16:24,620 --> 00:16:28,140 I doubt you're going to need backticks or semicolons and a command name. 260 00:16:28,320 --> 00:16:30,620 So that's something that was pretty easy to do. 261 00:16:34,990 --> 00:16:37,250 So this is probably my favorite of the vulnerabilities. 262 00:16:37,250 --> 00:16:42,510 Not because it has the most impact, but it was the most interesting, and it took me the longest time to figure out. 263 00:16:42,510 --> 00:16:44,490 So we see arbitrary file share. 264 00:16:44,490 --> 00:16:46,850 The first thing is, like, what the hell is a file share? 265 00:16:46,890 --> 00:16:48,610 In this sort of situation. 266 00:16:51,110 --> 00:16:52,190 Here we go. 267 00:16:52,270 --> 00:16:59,150 So you can view all of your files, and a file share essentially is a folder that is abstracted with privileges. 268 00:16:59,510 --> 00:17:03,650 So the music, photo, and video are shares, essentially. 269 00:17:03,650 --> 00:17:09,690 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. 270 00:17:09,850 --> 00:17:13,410 So there's some sort of boundary between what you control compared to other users. 271 00:17:20,120 --> 00:17:20,760 Yeah. 272 00:17:20,940 --> 00:17:22,040 All right, so I was... 273 00:17:22,040 --> 00:17:26,580 I wanted to find a direct address or cross-site scripting in this page. 274 00:17:26,580 --> 00:17:29,260 So I was looking through, and they did a very good job, actually. 275 00:17:29,300 --> 00:17:33,760 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. 276 00:17:33,800 --> 00:17:37,660 I was very impressed with how good of a job they did locking this down. 277 00:17:38,880 --> 00:17:45,140 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. 278 00:17:46,260 --> 00:17:50,660 And I started looking around, and I started seeing functions I had never seen before. 279 00:17:50,660 --> 00:17:52,520 They were very odd to me. 280 00:17:52,800 --> 00:17:56,580 And what ended up happening was there was a file that had... 281 00:17:56,580 --> 00:18:01,220 or an API that had no usage in the entire UI. 282 00:18:02,500 --> 00:18:04,200 This is where my... 283 00:18:04,200 --> 00:18:05,520 another analogy comes in. 284 00:18:05,520 --> 00:18:07,520 I'm the king of analogies when I talk. 285 00:18:08,460 --> 00:18:14,280 So when you're on a diet, and you are really focusing on protein, you're going to get a lot of protein. 286 00:18:14,280 --> 00:18:17,500 But you may not get enough vitamin C or something. 287 00:18:17,920 --> 00:18:19,060 That's an issue. 288 00:18:19,140 --> 00:18:19,560 Because... 289 00:18:20,800 --> 00:18:28,740 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. 290 00:18:28,740 --> 00:18:37,240 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. 291 00:18:42,920 --> 00:18:46,240 The issue, though, is because this wasn't used, I had to reverse the API. 292 00:18:46,360 --> 00:18:49,100 This is the actual source code trimmed down a little bit. 293 00:18:50,540 --> 00:18:53,300 So the first thing is there's an action parameter that I saw. 294 00:18:53,300 --> 00:18:57,500 This action parameter dictates if you're going to create a folder or rename a file. 295 00:18:57,680 --> 00:19:10,960 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. 296 00:19:11,660 --> 00:19:18,140 I noticed there was no absolute path check, which meant this was likely going to be vulnerable to some sort of a directory traversal. 297 00:19:21,050 --> 00:19:23,270 So now I have a directory traversal. 298 00:19:23,270 --> 00:19:25,030 I can move file from any share. 299 00:19:25,030 --> 00:19:28,090 You're probably thinking, you're done, right? 300 00:19:29,150 --> 00:19:30,290 Nowhere near done. 301 00:19:30,290 --> 00:19:34,570 This is where I felt like Alice and I just went way down the rabbit hole. 302 00:19:37,450 --> 00:19:39,710 I want to make this a really deadly sort of thing. 303 00:19:39,710 --> 00:19:47,730 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. 304 00:19:47,890 --> 00:19:49,290 That was my thought. 305 00:19:49,290 --> 00:19:53,330 However, whenever I tried moving outside of the shares, it didn't work. 306 00:19:53,330 --> 00:19:54,830 And that was the most infuriating thing. 307 00:19:54,830 --> 00:19:56,470 I wanted to understand that. 308 00:19:56,470 --> 00:19:58,950 So I decided I was going to turn on logging. 309 00:19:58,990 --> 00:20:05,130 The issue was that it was a read-only partition on this part of the drive where the code was at. 310 00:20:05,470 --> 00:20:06,650 I want to bypass that. 311 00:20:06,950 --> 00:20:08,610 I couldn't figure it out. 312 00:20:08,610 --> 00:20:11,330 I tried remounting partitions. 313 00:20:11,330 --> 00:20:17,270 I tried altering the bash RC I tried altering the boot scripts. 314 00:20:17,270 --> 00:20:19,730 No matter what I did, I couldn't get any of it to work. 315 00:20:19,870 --> 00:20:21,750 If anyone has any ideas, I'd love to talk to. 316 00:20:21,750 --> 00:20:23,290 It would be something fun to know. 317 00:20:23,490 --> 00:20:38,850 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. 318 00:20:38,870 --> 00:20:39,970 Because I can write there. 319 00:20:39,970 --> 00:20:44,010 It was a really simple fix, but it just wasn't something I really thought of. 320 00:20:44,190 --> 00:20:49,270 So I did that, and I got erno18 invalid Christ device link. 321 00:20:50,110 --> 00:20:51,650 You guys know what that is, right? 322 00:20:52,590 --> 00:20:53,390 No. 323 00:20:53,550 --> 00:20:55,210 You're not really supposed to know what that is. 324 00:20:55,210 --> 00:20:55,770 I had no idea. 325 00:20:55,770 --> 00:20:56,610 I googled it. 326 00:20:56,610 --> 00:21:01,150 You can't rename files in Python 2.7 across partitions. 327 00:21:01,710 --> 00:21:03,250 It's just something that happened. 328 00:21:03,930 --> 00:21:07,230 I think you can actually do it in 3 for some reason, but not 2.7. 329 00:21:08,330 --> 00:21:14,110 So even though I didn't actually get all I wanted out of this vulnerability, I learned a lot. 330 00:21:14,390 --> 00:21:18,090 I actually encourage people to go down the rabbit hole if you're just trying to learn. 331 00:21:18,090 --> 00:21:20,930 Because now I understand how BusyBox works a lot more. 332 00:21:20,930 --> 00:21:25,810 I learned a lot about how BusyBox boots. 333 00:21:26,210 --> 00:21:28,090 A lot about how partitioning works. 334 00:21:28,090 --> 00:21:29,050 I had no idea how that worked. 335 00:21:29,050 --> 00:21:31,530 And that rabbit hole was really beneficial for me. 336 00:21:32,410 --> 00:21:35,810 So now I'll show off my vulnerability. 337 00:21:35,810 --> 00:21:38,470 I'll explain the parameters first. 338 00:21:39,890 --> 00:21:42,010 The first thing you see is the URL. 339 00:21:42,010 --> 00:21:46,550 And the URL is just the command you're calling. 340 00:21:46,550 --> 00:21:50,690 The JSON is where the interesting black magic starts to happen. 341 00:21:50,690 --> 00:21:54,930 The share in this situation is just photo. 342 00:21:55,450 --> 00:21:59,630 The photo share is something that the test user has access to. 343 00:22:00,930 --> 00:22:04,570 The action is the rename action, which is what we were talking about. 344 00:22:04,570 --> 00:22:08,610 The user is the test user, because that's the user we're logged in as in this account. 345 00:22:08,610 --> 00:22:17,510 The target path is the file location, but it's actually just the photo, like the share, with the file name. 346 00:22:17,510 --> 00:22:20,770 In the example I'm going to show, I use nonce.txt. 347 00:22:21,690 --> 00:22:24,810 And the interesting thing is the path. 348 00:22:24,810 --> 00:22:27,610 So it's a very classic directory traversal. 349 00:22:27,610 --> 00:22:30,270 I move outside of my photo share. 350 00:22:30,370 --> 00:22:36,570 I go into the admin share and I move the nonce.txt file into my share. 351 00:22:38,330 --> 00:22:40,050 I'll show that now. 352 00:22:40,330 --> 00:22:44,250 This one can be really finicky, so this is the one I've been worried about. 353 00:22:44,270 --> 00:22:46,370 Don't make fun of me too much if it doesn't work. 354 00:22:50,450 --> 00:22:53,130 All right, just got to comment this out. 355 00:22:54,030 --> 00:22:54,950 Turn that on. 356 00:22:59,110 --> 00:22:59,650 Cool. 357 00:22:59,650 --> 00:23:02,130 So I think that worked then, if it gave you the okay message. 358 00:23:02,770 --> 00:23:06,450 I guess I didn't really show you what was... So this is the admin one. 359 00:23:06,450 --> 00:23:17,090 If we reset this, we'll... assuming they're still logged in, then you should notice that the nonce.txt file is now gone. 360 00:23:17,170 --> 00:23:24,550 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. 361 00:23:24,870 --> 00:23:26,190 Thank you. 362 00:23:31,710 --> 00:23:32,750 Cool. 363 00:23:33,370 --> 00:23:37,610 So again, we should probably talk about mitigations because this is important. 364 00:23:37,610 --> 00:23:44,570 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. 365 00:23:44,570 --> 00:23:46,190 That's the important thing the client needs. 366 00:23:47,170 --> 00:23:54,250 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. 367 00:23:54,630 --> 00:23:56,510 But they just forgot to add that on there. 368 00:23:56,510 --> 00:23:58,730 So that would have been a really easy fix for them. 369 00:24:00,450 --> 00:24:06,230 There were a couple other things I wanted to talk about that weren't really worthy of their own sections. 370 00:24:07,330 --> 00:24:10,070 So, the company won't fix this. 371 00:24:10,170 --> 00:24:14,850 I emailed them, and they got back pretty quickly but they're like, yeah, we don't really care, these are all authenticated. 372 00:24:15,370 --> 00:24:18,010 And I wanted to bring to light an actual attack scenario. 373 00:24:18,010 --> 00:24:20,430 So this site also had no Csurf protection. 374 00:24:20,850 --> 00:24:24,230 For those who don't know, it stands for cross-site request forgery. 375 00:24:25,110 --> 00:24:34,190 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. 376 00:24:34,190 --> 00:24:36,850 Which you assume, and it's really nice. 377 00:24:36,910 --> 00:24:47,530 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. 378 00:24:47,530 --> 00:24:52,730 So an example would be on my bad website, I make a call to Facebook to delete your profile. 379 00:24:52,730 --> 00:24:54,530 If it's a git request or something. 380 00:24:54,770 --> 00:24:56,490 Which, this is bad. 381 00:24:56,490 --> 00:25:08,970 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. 382 00:25:11,090 --> 00:25:22,170 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. 383 00:25:23,270 --> 00:25:24,870 Wasn't really that cool. 384 00:25:25,630 --> 00:25:28,290 This was over HTTP for some reason. 385 00:25:28,670 --> 00:25:33,110 Don't know why, but the web server you could host it with was over HTTPS. 386 00:25:33,190 --> 00:25:38,390 I don't know why, they clearly knew how, they just chose not to make this over HTTPS. 387 00:25:38,830 --> 00:25:39,830 It's kind of odd. 388 00:25:39,990 --> 00:25:47,070 The other, also kind of fun thing, was when you turned it on, it had the default password, admin1234. 389 00:25:47,610 --> 00:25:56,250 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. 390 00:25:56,770 --> 00:26:01,670 It's kind of hypothetical, but at the same time, you could really screw with people doing this. 391 00:26:09,860 --> 00:26:12,140 Cybersecurity does not have to be horrifying. 392 00:26:12,940 --> 00:26:14,920 Everything I did here was with known tools. 393 00:26:14,920 --> 00:26:16,960 I even used Notepad++ people. 394 00:26:16,960 --> 00:26:17,760 Come on. 395 00:26:18,440 --> 00:26:27,320 I used Python, Burp, Grep, Google, and uncompile 6 tool to decompile the source code. 396 00:26:27,320 --> 00:26:30,480 Other than that though, I used everything that was super basic. 397 00:26:30,480 --> 00:26:34,000 Everything I found were very known vulnerabilities. 398 00:26:34,000 --> 00:26:35,740 A lot of them are in the OS top 10. 399 00:26:38,140 --> 00:26:40,100 This is not block magic. 400 00:26:40,200 --> 00:26:46,520 The key to all this stuff is understanding how stuff works and then manipulating it. 401 00:26:47,000 --> 00:26:47,920 That's hacking. 402 00:26:47,920 --> 00:26:49,440 Thank you. 403 00:26:56,080 --> 00:26:58,460 Also, I work at Security Innovation. 404 00:26:58,520 --> 00:27:00,540 We do web app pen testing. 405 00:27:00,540 --> 00:27:02,400 We do a fair amount of IoT stuff too. 406 00:27:02,420 --> 00:27:03,360 Amazing company. 407 00:27:03,360 --> 00:27:04,700 Just started working there pretty recently. 408 00:27:04,700 --> 00:27:06,080 I just graduated from college. 409 00:27:06,080 --> 00:27:08,760 If you're interested, come talk to me. 410 00:27:09,680 --> 00:27:11,480 Anybody have any questions? 411 00:27:11,960 --> 00:27:13,960 I'd love to talk about stuff. 412 00:27:18,900 --> 00:27:20,300 I could. 413 00:27:20,820 --> 00:27:23,280 All these exploits are on my github. 414 00:27:23,280 --> 00:27:24,480 It's mdoolin2. 415 00:27:24,480 --> 00:27:25,660 I didn't put it up there. 416 00:27:26,260 --> 00:27:28,100 All the exploits are on github. 417 00:27:29,080 --> 00:27:32,940 If you want to look at this, my github account is mdoolin2. 418 00:27:33,180 --> 00:27:34,680 Go crazy, folks. 419 00:27:39,750 --> 00:27:46,410 I listen to Dark Knight Diaries, Malicious Life, and I also listen to Security Now. 420 00:27:46,690 --> 00:27:52,350 I've really only been doing this security thing for a year and a half, maybe two years at the most. 421 00:27:52,350 --> 00:27:55,110 Security Now is how I learned to talk the game. 422 00:27:56,310 --> 00:27:57,790 It's like a two-hour podcast. 423 00:27:57,790 --> 00:28:00,890 I'd just listen to it walking from my house to school. 424 00:28:01,270 --> 00:28:04,030 That was really helpful for me for talking the lingo. 425 00:28:05,590 --> 00:28:07,050 Any other questions? 426 00:28:12,710 --> 00:28:16,250 If there's no other questions, I would love to talk afterwards. 427 00:28:16,470 --> 00:28:19,230 There's a lot of other things you can find on this device if you're interested. 428 00:28:19,470 --> 00:28:25,250 If you want to talk about how to get a job, or you're depressed or something, come talk to me. 429 00:28:25,390 --> 00:28:27,250 I'm a pretty happy and chill guy to talk to. 430 00:28:27,250 --> 00:28:29,430 If you have any other questions, feel free to come up and talk. 431 00:28:29,430 --> 00:28:30,150 Thank you.