1 00:00:02,400 --> 00:00:09,000 Thank you. Thanks for coming. I know it's an early start. Good morning and welcome to 2 00:00:09,000 --> 00:00:15,680 Smashing the State Machine, the true potential of web race conditions. Have you ever seen a 3 00:00:15,680 --> 00:00:21,800 vulnerability that made absolutely no sense? Something that didn't just leave you wondering 4 00:00:21,800 --> 00:00:29,800 why would anyone code that, but asking how is it even possible to write code that has that effect? 5 00:00:31,060 --> 00:00:37,320 Maybe you even got hold of the code and stared at it for hours and it still made no sense. And 6 00:00:37,320 --> 00:00:43,560 perhaps if you showed it to somebody else, they'd say something like, oh, it must be a race 7 00:00:43,560 --> 00:00:49,440 condition. In this session, I'm going to share with you tools and techniques to discover and 8 00:00:49,440 --> 00:00:56,280 exploit that kind of race condition. Let's start by surveying what we do understand. What race 9 00:00:56,280 --> 00:00:59,980 conditions have you seen or exploited in the wild? Maybe things that you've never seen before. 10 00:01:00,000 --> 00:01:07,100 Things like reusing a single use voucher multiple times. Or bypassing some kind of rate limit. 11 00:01:07,380 --> 00:01:14,540 Or reviewing a single product multiple times. One of my favorite ones that I've found is I noticed 12 00:01:14,540 --> 00:01:21,420 that you can reuse a valid single reCAPTCHA solution multiple times within a short time window. 13 00:01:22,200 --> 00:01:27,400 And when I reported that to Google, they were like, oh, yeah, that's not good. But, well, 14 00:01:30,000 --> 00:01:34,900 we've contributed that we can't patch this. So that technique still works on a bunch of websites 15 00:01:34,900 --> 00:01:43,780 today. But all of these examples could be classed as limit overruns, right? They're all about doing 16 00:01:43,780 --> 00:01:51,380 something more times than you're supposed to. But if you go digging through every post that you can 17 00:01:51,380 --> 00:01:58,640 find on the topic, you'll land on one called Race Conditions on the Web by Josip Franković. And in 18 00:01:58,640 --> 00:01:59,980 this post, he describes race conditions on the web. And in this post, he describes race conditions on 19 00:01:59,980 --> 00:02:00,400 the web. And in this post, he describes race conditions on the web. And in this post, he describes 20 00:02:00,400 --> 00:02:07,060 four vulnerabilities. And three of them are regular limit overruns. And one of them is different. 21 00:02:08,080 --> 00:02:15,040 The vulnerability that he found took two months just for him and Facebook's security team to figure 22 00:02:15,040 --> 00:02:21,400 out how to replicate it. And the issue was that sometimes when changing your email, Facebook would 23 00:02:21,400 --> 00:02:27,740 put two confirmation codes for two different addresses using two different parameter names in a 24 00:02:27,740 --> 00:02:28,780 single email. 25 00:02:30,140 --> 00:02:35,400 Now, I had no idea what was happening here. And I don't think they did either. But one thing was clear. 26 00:02:35,540 --> 00:02:44,060 This wasn't a limit overrun vulnerability. And so last September, six years after I first read that 27 00:02:44,060 --> 00:02:50,540 blog post, I decided to try and figure out what happened. And gradually came to realize that the 28 00:02:50,540 --> 00:02:55,580 race condition attacks that we all know and love already are just toy vulnerabilities compared with 29 00:02:55,580 --> 00:02:57,000 what else is out there. 30 00:02:58,780 --> 00:03:05,980 So, in this session, I'm going to show you the true potential of this attack class, tools and techniques to achieve this 31 00:03:05,980 --> 00:03:12,020 potential, and case studies and a live demo to show some of the insanity that's out there waiting for you to 32 00:03:12,020 --> 00:03:18,780 discover it. After that, I'll share where things can be taken further, how to prevent these attacks, and the key 33 00:03:18,780 --> 00:03:26,460 takeaways, leaving five minutes for questions. On certain slides, you'll see there's a mortarboard icon. And that 34 00:03:26,460 --> 00:03:28,760 just means I've designed a framework. 35 00:03:28,780 --> 00:03:35,800 I've created a free online replica of this vulnerability and published it in the web security academy. So you can 36 00:03:35,800 --> 00:03:40,480 practice exploiting that vulnerability on a live system for yourself. 37 00:03:42,780 --> 00:03:50,840 Now, to communicate the true potential of this attack class, I'm going to use a multi-step vulnerability that I 38 00:03:50,840 --> 00:03:58,520 discovered by accident a while back. I noticed that when I logged into this website, it asked me to select a role before 39 00:03:58,520 --> 00:04:06,440 proceeding to the application. So I thought, okay, if I visualize the state machine for the user's role, it will look 40 00:04:06,440 --> 00:04:12,660 something like this. And, well, maybe we can just jump from the role selection page to the back end without choosing a 41 00:04:12,660 --> 00:04:19,280 role and get some kind of privilege escalation going. And I tried that, and it didn't work. And I thought, well, I guess it's 42 00:04:19,280 --> 00:04:28,040 secure then. I mean, look at that diagram. It looks pretty secure, right? But the diagram was actually wrong. It's 43 00:04:28,520 --> 00:04:36,060 not going to change the state because it's not zoomed in enough, because it's assuming that the get request to the role 44 00:04:36,060 --> 00:04:45,140 selection page doesn't change the application state. And as it so happened, for reasons that I don't entirely 45 00:04:45,140 --> 00:04:52,320 understand, the applications was creating every session with administrative privileges, and then the get request was 46 00:04:52,320 --> 00:04:58,500 revoking those privileges. So by failing to zoom in, I almost missed quite a bit of time. So I'm going to show you a 47 00:04:58,500 --> 00:04:58,860 video like this, and then I'll show you a video that I'm going to show you how to do this because it's quite a serious 48 00:04:58,860 --> 00:05:07,760 vulnerability. But, you know, that's just my bad, right? Because everyone knows that multi-step sequences are a wonderful 49 00:05:07,760 --> 00:05:16,020 source for all kinds of series vulnerabilities. And so it's essential to always zoom in as much as possible and test every 50 00:05:16,020 --> 00:05:25,320 possible permutation of a process like this. But researching race conditions, I found myself looking back at this 51 00:05:25,320 --> 00:05:28,480 finding and thinking, well, is that the furthest transition? And, well, there was a bit of a turning point, but it's not 52 00:05:28,500 --> 00:05:30,720 that we can zoom in, or can we go further still? 53 00:05:31,900 --> 00:05:34,460 What if the application had dropped our privileges 54 00:05:35,040 --> 00:05:37,780 immediately using a second database statement? 55 00:05:38,300 --> 00:05:42,120 There would still be maybe one millisecond time window 56 00:05:42,120 --> 00:05:45,200 where every session had administrator privileges, 57 00:05:46,320 --> 00:05:47,840 but I would never have discovered it. 58 00:05:49,200 --> 00:05:51,420 And that's a little bit of a scary thought, 59 00:05:52,040 --> 00:05:55,000 because any login form could have that vulnerability. 60 00:05:55,340 --> 00:05:57,100 It doesn't need to be a multi-step login, 61 00:05:57,100 --> 00:05:59,840 and actually, worse than that, 62 00:05:59,960 --> 00:06:02,780 it shows any HTTP request, 63 00:06:03,540 --> 00:06:06,100 might be transitioning the application 64 00:06:06,100 --> 00:06:09,460 through invisible vulnerable substates like that one, 65 00:06:09,840 --> 00:06:12,640 and these could potentially lead to some serious attacks. 66 00:06:13,620 --> 00:06:16,420 In other words, we all know 67 00:06:16,420 --> 00:06:19,540 that multi-step sequences are really dangerous, 68 00:06:19,800 --> 00:06:21,060 and with race conditions, 69 00:06:21,960 --> 00:06:24,620 everything is potentially multi-step. 70 00:06:24,620 --> 00:06:28,880 That is the true potential of web race conditions, 71 00:06:29,140 --> 00:06:31,540 and now it's time to start hacking some stuff. 72 00:06:36,300 --> 00:06:39,920 To discover a substate, we need a collision. 73 00:06:40,140 --> 00:06:42,020 That means we need two requests, 74 00:06:42,320 --> 00:06:45,000 one to trigger the substate or the race window, 75 00:06:45,540 --> 00:06:47,520 and another that accesses the same resource 76 00:06:47,520 --> 00:06:48,640 at the same time. 77 00:06:49,100 --> 00:06:50,700 So in the example we just saw, 78 00:06:50,760 --> 00:06:52,040 that might mean trying to log in 79 00:06:52,040 --> 00:06:54,600 and access the admin panel simultaneously. 80 00:06:54,620 --> 00:06:59,700 However, there's a major barrier to making this happen, 81 00:06:59,840 --> 00:07:01,700 which has plagued this attack class 82 00:07:02,040 --> 00:07:03,800 ever since it was invented pretty much, 83 00:07:03,940 --> 00:07:05,040 which is network jitter, 84 00:07:05,160 --> 00:07:08,580 which randomly delays our requests inconsistently, 85 00:07:09,300 --> 00:07:11,740 meaning that the race windows don't line up, 86 00:07:11,800 --> 00:07:14,220 and the vulnerabilities don't get discovered. 87 00:07:15,040 --> 00:07:16,460 To solve this problem, 88 00:07:16,600 --> 00:07:18,720 I've developed the single packet attack, 89 00:07:18,920 --> 00:07:24,200 which lets you make 20 to 30 HTTP requests arrive 90 00:07:24,620 --> 00:07:26,260 at the server simultaneously, 91 00:07:27,460 --> 00:07:30,920 regardless of how bad the network jitter is 92 00:07:31,240 --> 00:07:31,940 on your connection. 93 00:07:33,800 --> 00:07:37,220 Under the hood, this technique is all about TCP and HTTP. 94 00:07:37,720 --> 00:07:39,380 The previously best-known technique 95 00:07:39,640 --> 00:07:41,420 was called last byte synchronization, 96 00:07:42,200 --> 00:07:44,080 and it takes advantage of the fact 97 00:07:44,800 --> 00:07:48,240 that web servers generally won't start to process a request 98 00:07:48,240 --> 00:07:51,200 until the whole request has arrived. 99 00:07:51,640 --> 00:07:54,600 So with last byte sync, you withhold the final byte, 100 00:07:54,600 --> 00:07:56,200 of each request, 101 00:07:56,420 --> 00:07:59,280 and that makes the final packet of each request nice and small, 102 00:07:59,360 --> 00:08:01,260 and it makes the jitter not quite so bad, 103 00:08:01,960 --> 00:08:03,920 but it only goes so far. 104 00:08:04,700 --> 00:08:06,240 But a couple years back, 105 00:08:06,380 --> 00:08:08,380 I read a academic white paper 106 00:08:08,380 --> 00:08:10,400 called Timeless Timing Attacks, 107 00:08:10,500 --> 00:08:12,960 and there, they noticed that with HTTP2, 108 00:08:13,560 --> 00:08:16,920 you can actually stuff two entire requests 109 00:08:17,600 --> 00:08:19,720 into a single TCP packet. 110 00:08:20,680 --> 00:08:22,920 And they used that for timing attacks, 111 00:08:23,160 --> 00:08:23,960 which was pretty cool, 112 00:08:23,960 --> 00:08:24,760 but I was wondering, well, 113 00:08:24,840 --> 00:08:28,620 can we adapt this and use it for base conditions? 114 00:08:29,060 --> 00:08:31,760 There's only one barrier here, really, 115 00:08:31,840 --> 00:08:34,800 which is to find a base condition reliably, 116 00:08:34,980 --> 00:08:37,260 thanks to factors like server-side jitter, 117 00:08:37,360 --> 00:08:39,360 we need more than two requests. 118 00:08:40,360 --> 00:08:43,440 So what I did was, I took these two techniques 119 00:08:43,440 --> 00:08:47,840 and smushed them together to create a single packet attack, 120 00:08:48,360 --> 00:08:52,320 which completes 20 to 30 requests in a single packet, 121 00:08:52,420 --> 00:08:53,840 eliminating networks. 122 00:08:53,960 --> 00:08:57,420 And I've just released this in an update 123 00:08:57,420 --> 00:09:00,440 to the open-source tool, Turbo Intruder. 124 00:09:01,600 --> 00:09:05,160 Now, this technique, frankly, is pretty obvious. 125 00:09:06,300 --> 00:09:09,120 And actually, I was like, this is so obvious, 126 00:09:09,400 --> 00:09:10,120 and then I was like, well, 127 00:09:10,220 --> 00:09:12,420 I wonder if anyone else has already done it? 128 00:09:12,980 --> 00:09:15,320 And I Googled, and it turns out someone else 129 00:09:15,820 --> 00:09:17,360 implemented something quite similar 130 00:09:17,360 --> 00:09:19,400 for a master's project back in 2020, 131 00:09:19,720 --> 00:09:21,060 but nobody noticed. 132 00:09:21,740 --> 00:09:22,300 So, 133 00:09:23,960 --> 00:09:27,220 why is this, why am I so excited about this technique? 134 00:09:28,200 --> 00:09:30,920 Well, it's because this isn't just 135 00:09:30,920 --> 00:09:32,900 some cool implementation trick. 136 00:09:33,400 --> 00:09:36,600 After refining this technique over months of research, 137 00:09:36,880 --> 00:09:39,360 it now works on all major web servers, 138 00:09:39,560 --> 00:09:42,980 I can still fit the entire algorithm on a single slide, 139 00:09:43,720 --> 00:09:46,360 and ultimately, it brings insane performance 140 00:09:46,360 --> 00:09:49,040 in a parcel that's so easy to implement, 141 00:09:49,280 --> 00:09:52,520 I think it will end up in all major web testing tools. 142 00:09:53,960 --> 00:09:55,240 The reason it's so easy to implement 143 00:09:55,710 --> 00:09:59,280 is that thanks to some creative abuse of Nagel's algorithm, 144 00:09:59,500 --> 00:10:01,940 which is in all operating system network stacks, 145 00:10:02,660 --> 00:10:06,500 you don't need to code a custom TCP or TLS stack. 146 00:10:06,740 --> 00:10:08,860 You can just take a HB2 library 147 00:10:09,270 --> 00:10:11,520 and bolt this feature onto the site. 148 00:10:12,260 --> 00:10:14,800 If you're tempted to make your own version, 149 00:10:15,080 --> 00:10:17,940 I'd say go for it, and I think Golang's HB2 stack 150 00:10:17,940 --> 00:10:21,000 is probably one of the easiest to extend in that manner. 151 00:10:21,800 --> 00:10:23,800 And I'm really looking forward to seeing 152 00:10:23,800 --> 00:10:26,420 where other people take this technique in the future, 153 00:10:26,500 --> 00:10:27,980 because it can definitely be developed further. 154 00:10:28,620 --> 00:10:31,000 But of course, the thing I'm most excited about 155 00:10:31,480 --> 00:10:32,320 is the performance. 156 00:10:33,560 --> 00:10:35,500 So to benchmark this technique, 157 00:10:35,740 --> 00:10:39,120 I repeatedly sent a batch of 20 requests 158 00:10:39,120 --> 00:10:41,100 from Melbourne to Dublin, 159 00:10:41,200 --> 00:10:45,080 and I measured the gap in the execution timestamp 160 00:10:45,080 --> 00:10:46,860 of the first and last requests 161 00:10:47,420 --> 00:10:49,640 to reach the server in each batch. 162 00:10:49,840 --> 00:10:52,400 In other words, how close together the whole batch landed. 163 00:10:53,800 --> 00:10:58,420 And using GlassBySync, I saw a median spread 164 00:10:58,420 --> 00:11:01,380 of four milliseconds and a standard deviation of three, 165 00:11:01,880 --> 00:11:04,180 which is, to be honest, not that bad. 166 00:11:04,240 --> 00:11:05,280 It's better than I expected. 167 00:11:05,500 --> 00:11:07,780 I think that's because I had data centers 168 00:11:07,780 --> 00:11:09,500 at both ends of this benchmark, 169 00:11:09,640 --> 00:11:12,260 and if you were using Australian consumer broadband, 170 00:11:12,420 --> 00:11:13,780 you might have a different experience. 171 00:11:15,500 --> 00:11:18,140 And then I retried it with a single packet attack 172 00:11:18,140 --> 00:11:21,620 and saw a median spread of one millisecond 173 00:11:21,620 --> 00:11:23,140 and a standard deviation 174 00:11:23,140 --> 00:11:24,400 of 0.3. 175 00:11:24,520 --> 00:11:28,440 In other words, the majority of these 20 requests 176 00:11:28,440 --> 00:11:31,340 traveling 17,000 kilometers were getting executed 177 00:11:31,340 --> 00:11:34,320 in the same millisecond on the target server. 178 00:11:35,160 --> 00:11:37,620 In terms of what that means in practice, 179 00:11:37,800 --> 00:11:39,700 well, you could say, okay, it makes this technique 180 00:11:39,700 --> 00:11:43,900 four to 10 times more effective than GlassBySync. 181 00:11:44,740 --> 00:11:47,500 Or on one real vulnerability that I found, 182 00:11:47,700 --> 00:11:51,220 I was able to replicate the issue within 30 seconds 183 00:11:51,220 --> 00:11:52,740 using single packet attack, 184 00:11:52,740 --> 00:11:56,200 and it took over two hours of automated attempts 185 00:11:56,700 --> 00:12:00,120 to replicate the same issue using GlassBySync. 186 00:12:01,900 --> 00:12:04,520 In other words, if you want to kind of summarize this up 187 00:12:04,520 --> 00:12:06,040 in a little sound bite, I would say, 188 00:12:06,520 --> 00:12:08,220 by eliminating network jitter, 189 00:12:08,360 --> 00:12:12,580 the single packet attack makes remote race conditions local. 190 00:12:14,680 --> 00:12:16,660 Now that we've solved network jitter, 191 00:12:17,180 --> 00:12:18,660 it's time to go hunting for some bugs. 192 00:12:18,960 --> 00:12:21,560 Now, limit overrun vulnerabilities are easy to find. 193 00:12:21,680 --> 00:12:22,540 You look for a limit. 194 00:12:22,540 --> 00:12:23,820 You try and overrun it. 195 00:12:24,480 --> 00:12:28,200 But going beyond that, things get a bit trickier. 196 00:12:28,900 --> 00:12:31,040 And after months of manual testing 197 00:12:31,040 --> 00:12:33,420 and discovering every possible pitfall, 198 00:12:33,820 --> 00:12:36,100 I've developed the following three-step methodology 199 00:12:36,100 --> 00:12:38,500 to find these bugs reasonably efficiently. 200 00:12:39,800 --> 00:12:42,980 First, you predict where you might have potential collisions. 201 00:12:43,800 --> 00:12:46,020 Then you probe those places to identify clues 202 00:12:46,020 --> 00:12:47,320 that there's a sub-state there. 203 00:12:47,780 --> 00:12:49,600 And finally, you prove the concept 204 00:12:49,600 --> 00:12:52,360 by figuring out what happened and using that knowledge, 205 00:12:52,360 --> 00:12:53,540 to build an exploit. 206 00:12:57,080 --> 00:13:00,780 Prediction is just about efficiency. 207 00:13:01,850 --> 00:13:04,620 In theory, because everything is multi-step, 208 00:13:04,680 --> 00:13:06,660 every single request is an arbitrary, 209 00:13:06,760 --> 00:13:07,960 complex multi-step process, 210 00:13:08,200 --> 00:13:11,580 we ought to test every possible combination of endpoints 211 00:13:11,580 --> 00:13:14,300 on the entire website and any other websites 212 00:13:14,550 --> 00:13:15,640 that have the same backend. 213 00:13:16,570 --> 00:13:18,520 But that's not very practical. 214 00:13:18,680 --> 00:13:22,340 So instead, we're going to home in on places likely to have 215 00:13:22,360 --> 00:13:24,180 collisions that have serious consequences. 216 00:13:26,200 --> 00:13:29,200 After doing that, we can furthermore rule out endpoints 217 00:13:29,200 --> 00:13:32,140 that don't have as much collision potential. 218 00:13:32,580 --> 00:13:35,300 So for example, two threads that are editing 219 00:13:35,300 --> 00:13:37,540 a single piece of data at the same time, 220 00:13:37,620 --> 00:13:38,880 that could be quite interesting. 221 00:13:39,000 --> 00:13:40,540 Whereas if the two threads are just depending 222 00:13:40,540 --> 00:13:42,280 to the same piece of data, 223 00:13:43,020 --> 00:13:46,440 that's less likely to have an interesting outcome. 224 00:13:47,720 --> 00:13:49,820 Similarly, you can ask, well, are these requests 225 00:13:49,820 --> 00:13:52,340 going to be editing the same record in time? 226 00:13:52,340 --> 00:13:53,220 Are they going to be in the database? 227 00:13:53,820 --> 00:13:57,360 If the password reset system is storing tokens 228 00:13:57,720 --> 00:14:00,960 in the users table, then if you do two resets 229 00:14:00,960 --> 00:14:02,800 for two different users at the same time, 230 00:14:02,940 --> 00:14:05,860 then two different rows of this table are going to be edited 231 00:14:05,860 --> 00:14:07,660 and you're not going to have a collision. 232 00:14:08,500 --> 00:14:10,720 Meanwhile, if it's a password reset system 233 00:14:10,720 --> 00:14:14,140 that maybe SMSs you a pin and it stores the pin 234 00:14:14,480 --> 00:14:17,380 in your session, then you can use your single session 235 00:14:17,380 --> 00:14:20,020 to do resets for two users and cause a collision 236 00:14:20,020 --> 00:14:22,020 and maybe something interesting. 237 00:14:26,180 --> 00:14:27,840 Once you've built your requests, 238 00:14:28,080 --> 00:14:31,420 it's time to just take them and probe for clues. 239 00:14:31,760 --> 00:14:35,180 The essential thing here is that it's quite easy 240 00:14:35,180 --> 00:14:36,880 to fail to recognize a clue. 241 00:14:37,040 --> 00:14:39,040 So the first step is to benchmark 242 00:14:39,040 --> 00:14:42,020 the normal standard behavior of the application 243 00:14:42,020 --> 00:14:45,260 by sending your requests one at a time 244 00:14:45,260 --> 00:14:46,860 with a delay between each of them 245 00:14:46,860 --> 00:14:48,520 so you don't trigger any races. 246 00:14:49,030 --> 00:14:51,240 And then you just resend them all at once 247 00:14:51,240 --> 00:14:52,520 using the single packet attack 248 00:14:52,520 --> 00:14:56,500 and look for anomalies, clues, any deviation 249 00:14:57,080 --> 00:14:59,820 from the behavior that you saw during the baseline. 250 00:15:01,000 --> 00:15:03,720 If you don't see any, it might mean that they're secure 251 00:15:03,720 --> 00:15:05,920 or it could just mean that you need to tune 252 00:15:05,920 --> 00:15:07,940 your attack timing, which I'll talk more about 253 00:15:07,940 --> 00:15:09,700 in a case study later on. 254 00:15:11,520 --> 00:15:14,580 Finally, by this point, we should have found an anomaly. 255 00:15:14,660 --> 00:15:18,200 So all you need to do, which is often the hardest part, 256 00:15:18,380 --> 00:15:20,520 is actually understand what happened. 257 00:15:21,240 --> 00:15:23,420 Clean it up and replicate the behavior 258 00:15:23,420 --> 00:15:25,300 and explore the impact. 259 00:15:26,960 --> 00:15:29,100 Now, a word of warning here. 260 00:15:29,320 --> 00:15:32,180 Exploring the impact might sound kind of obvious, 261 00:15:32,780 --> 00:15:35,560 but if you're doing this methodology right 262 00:15:36,080 --> 00:15:37,960 and being ambitious with it, 263 00:15:38,020 --> 00:15:39,980 you're gonna run into some quite weird 264 00:15:39,980 --> 00:15:41,400 and unfamiliar behavior. 265 00:15:41,760 --> 00:15:44,360 And as a result, the path to maximum impact 266 00:15:44,840 --> 00:15:47,880 may be quite hard to find. 267 00:15:48,880 --> 00:15:51,220 So I would suggest thinking of, you know, 268 00:15:51,240 --> 00:15:54,960 of the behavior you found as a structural weakness 269 00:15:54,960 --> 00:15:56,520 and looking throughout the application 270 00:15:56,520 --> 00:15:59,320 to find security-relevant features 271 00:15:59,320 --> 00:16:00,540 that rely on that structure. 272 00:16:00,800 --> 00:16:02,540 And also, don't just stop and report 273 00:16:02,540 --> 00:16:05,060 the first exploit that you find. 274 00:16:05,480 --> 00:16:07,240 I actually made that mistake myself 275 00:16:07,240 --> 00:16:11,780 and lost out on around $5,000 of bug bounty as a result. 276 00:16:14,300 --> 00:16:17,600 So, now we're gonna take a look at a tiny slice 277 00:16:17,600 --> 00:16:20,680 of what you might find if you apply this approach. 278 00:16:21,240 --> 00:16:26,300 In the wild, GitLab lets you invite unregistered users 279 00:16:26,300 --> 00:16:29,300 to administer projects via their email address. 280 00:16:29,760 --> 00:16:32,920 And I thought, okay, sounds juicy, I'll test it. 281 00:16:33,260 --> 00:16:37,140 So as a baseline, I just invited one address six times. 282 00:16:37,820 --> 00:16:42,380 This created one invitation, one invitation email, 283 00:16:42,840 --> 00:16:45,520 and caused six responses saying, say to success. 284 00:16:47,060 --> 00:16:49,840 When I resent these requests in one packet, 285 00:16:51,240 --> 00:16:55,840 we saw one say to success, five error messages and two emails. 286 00:16:56,980 --> 00:17:00,560 So we've got two clues that we've hit a race condition here. 287 00:17:00,680 --> 00:17:03,140 The first clue is, obviously, two emails 288 00:17:03,140 --> 00:17:06,060 from six requests is quite suspicious. 289 00:17:07,060 --> 00:17:09,680 And the other one is that the responses that we got 290 00:17:09,680 --> 00:17:11,920 differed from when we did the baseline. 291 00:17:12,940 --> 00:17:16,380 Note that if we hadn't done the baseline 292 00:17:16,380 --> 00:17:18,620 and we'd just looked at those responses, 293 00:17:18,760 --> 00:17:19,940 we probably wouldn't have spotted 294 00:17:19,940 --> 00:17:27,140 that second clue so using that race I was able to create multiple invitations 295 00:17:27,140 --> 00:17:33,160 with the same email address which I the first thought well that's nice but kind 296 00:17:33,160 --> 00:17:39,520 of useless uh-huh but I noticed that the GitLab the page on GitLab that lists 297 00:17:39,520 --> 00:17:45,780 pending invitations only displays one invitation per email address because it 298 00:17:45,780 --> 00:17:50,240 doesn't think that multiple ones can exist so you can make a kind of a low 299 00:17:50,240 --> 00:17:54,540 privileged invitation and if an admin sees it and deletes it it actually 300 00:17:54,540 --> 00:17:58,980 effectively says user well it says user was successfully removed from project 301 00:17:58,980 --> 00:18:05,020 and replaces it with a higher level invitation behind the scenes now that 302 00:18:05,020 --> 00:18:09,040 impact isn't amazing because you need quite high privileges to exploit it in 303 00:18:09,040 --> 00:18:13,740 the first place but it got my attention kind of focused on GitLab 304 00:18:15,040 --> 00:18:15,600 and 305 00:18:15,780 --> 00:18:21,140 and it left me wondering well maybe there's another angle that I can take 306 00:18:21,140 --> 00:18:26,240 that's a bit more deliberate and will achieve a more serious impact now one 307 00:18:26,240 --> 00:18:32,420 approach to finding inspiration for these kinds of race conditions is to look to classic multi-step 308 00:18:32,420 --> 00:18:38,580 exploits and see if you can find a race condition adaption so for example there's 309 00:18:38,580 --> 00:18:45,320 a classic exploit where you add an extra product to your basket somewhere in the payment validation 310 00:18:46,240 --> 00:18:50,720 process after taking it to checkout and if you time that right you can get the 311 00:18:50,720 --> 00:18:56,420 extra product for free and I noticed that if you draw the state machine for 312 00:18:56,420 --> 00:19:04,100 GitLab's email verification process it looks kind of similar so maybe if we 313 00:19:04,100 --> 00:19:08,940 change our email address while GitLab is validating our previous email address 314 00:19:08,940 --> 00:19:14,480 it will end up validating the wrong one and that would be high impact because it 315 00:19:14,480 --> 00:19:15,660 would let me hijack 316 00:19:15,780 --> 00:19:18,880 administrator invitations intended for other users 317 00:19:20,420 --> 00:19:27,780 so I tried probing for this and it didn't get any clues or anomalies but I noticed that the email 318 00:19:27,780 --> 00:19:34,740 change response was arriving after the confirmation response every single time presumably because 319 00:19:34,740 --> 00:19:40,820 changing email was a slower operation so it was possible that there was a race condition present 320 00:19:40,820 --> 00:19:43,700 but I just wasn't lining the requests up correctly 321 00:19:43,700 --> 00:19:48,060 and after some trial and error I was I was able to fix this by sending 322 00:19:48,060 --> 00:19:54,660 the confirmation request 90 milliseconds after the email change but that approach 323 00:19:54,660 --> 00:19:58,700 although it did work on GitLab it's not ideal because it rolls out the single 324 00:19:58,700 --> 00:20:03,680 packet attack and I later discovered an alternative approach that I think is 325 00:20:03,680 --> 00:20:13,680 better web servers often delay requests that are sent too quickly and we can take advantage of that by sending a Tencent email instead pass ad students because if I get a false message we failed to reach our contact certainly there is no question for theブрезер 326 00:20:13,700 --> 00:20:19,720 single packet which contains first the slow processing request followed by a load of dummy 327 00:20:19,720 --> 00:20:25,280 requests that trigger the right amount of delay server-side and then finally the fast processing 328 00:20:25,280 --> 00:20:31,960 one at the end. So using that technique you can do a kind of staggered attack and because the 329 00:20:31,960 --> 00:20:38,180 delay is implemented for you server-side network jitter is not going to make that technique fail. 330 00:20:40,020 --> 00:20:46,320 Lining the race window up like this on GitLab revealed a massive clue. Sometimes the email 331 00:20:46,320 --> 00:20:52,160 confirmation token was sent to the wrong address. Unfortunately for me, although this looked 332 00:20:52,160 --> 00:20:58,800 really exciting, the misdirected code was only ever valid for confirming the already confirmed 333 00:20:58,800 --> 00:21:06,220 address and therefore it was useless. But it showed that there's at least one sub-state hidden 334 00:21:06,220 --> 00:21:08,160 inside GitLab's email confirmation token. So if you look at the email confirmation token 335 00:21:08,160 --> 00:21:12,320 you can see that there's an email change endpoint. And so it's worth digging further on that 336 00:21:12,320 --> 00:21:19,300 functionality. And I'm going to do this via means of a live demo on a remote server hosted in 337 00:21:19,300 --> 00:21:20,880 Ireland over the conference Wi-Fi. 338 00:21:29,440 --> 00:21:35,380 Cool. So here we have GitLab. And here I'm just going to show if I change my email address. 339 00:21:41,100 --> 00:21:45,500 Then the new one that I entered, it's just been set as pending, right? Because I have to click the 340 00:21:45,500 --> 00:21:52,900 confirmation link to prove that I own this email. So that's what we're going to be targeting. So let's 341 00:21:52,900 --> 00:22:01,620 see how it goes. I did test this earlier. It's not 100% reliable. So okay. On this Wi-Fi it was, I 342 00:22:01,620 --> 00:22:08,140 mean, it's never really 100% reliable, to be honest. Okay. So first, I'm going to do a little bit of a 343 00:22:08,160 --> 00:22:17,860 test. I'm going to probe for clues. So I'm going to try and change my email to six different email 344 00:22:17,860 --> 00:22:24,800 addresses in the same millisecond using the single packet attack. And I'm going to get all of these 345 00:22:24,800 --> 00:22:31,620 emails. They're all going to me, but every email address is unique. So I'm going to send this. The 346 00:22:31,620 --> 00:22:37,940 responses should arrive all at once. Yeah. Good. And the first kind of tiny little hint that 347 00:22:38,160 --> 00:22:43,700 something interesting might be happening is in this ex-runtime header. So we can see the server 348 00:22:43,700 --> 00:22:50,000 processed this request in 350 milliseconds. And for something that we know is sending an email, 349 00:22:51,100 --> 00:22:58,780 that's quite fast. It's almost like they're passing some data to a background thread. And the 350 00:22:58,780 --> 00:23:03,380 background thread is sending the email. And as soon as you've got data being passed between 351 00:23:03,380 --> 00:23:08,140 different threads, race conditions become a lot more likely. So that's interesting. 352 00:23:08,160 --> 00:23:13,620 A nice little hint. But it's definitely not evidence that there's a vulnerability there, right? For 353 00:23:13,620 --> 00:23:21,780 evidence, I'm going to check my inbox and we'll see what we have. Okay. So we've got our eight 354 00:23:21,780 --> 00:23:27,340 confirmation emails. And if I scroll through these with a bit of, right, there we go. Okay. So here, 355 00:23:27,440 --> 00:23:34,580 this was sent to demo six at portswigger.net. Sorry, it was sent to demo four, but it's intended to 356 00:23:34,580 --> 00:23:37,500 confirm demo six. So this is our clue. 357 00:23:38,160 --> 00:23:46,920 This has been sent to the wrong address. But it's not a vulnerability because this link isn't 358 00:23:46,920 --> 00:23:54,420 actually going to work. It's just going to say the confirmation token is invalid because that 359 00:23:54,420 --> 00:24:00,620 confirmation token has been overwritten by one of the ones that came after it and for some other 360 00:24:00,620 --> 00:24:07,180 reasons. So we've completed the probe phase, and now we're going to prove the vulnerability by 361 00:24:07,180 --> 00:24:07,600 switching. 362 00:24:10,180 --> 00:24:18,500 So this is where things get a little bit less reliable. So I'm just sending two requests in the 363 00:24:18,500 --> 00:24:24,000 single packet. One is setting an email address that goes to my inbox, and one is setting spoofed 364 00:24:24,000 --> 00:24:30,900 at local host, which is obviously not supposed to go to my inbox. And this is one other thing to 365 00:24:30,900 --> 00:24:37,700 mention here. This little line here. So in order for the misdirected confirmation token, 366 00:24:38,160 --> 00:24:45,540 to ever be valid, you have to trigger GitLab's resend token functionality, which you can do by changing 367 00:24:45,540 --> 00:24:52,020 your email address to the same value twice in a row. And if you don't do that, the token is never valid. 368 00:24:52,260 --> 00:25:00,760 And it took me around two months to discover that. So I'm going to run this, and if we're really lucky, 369 00:25:01,320 --> 00:25:05,120 we'll get a misdirected token. And if we're even luckier, the token will actually work. 370 00:25:12,460 --> 00:25:12,940 So it's going to work. 371 00:25:12,940 --> 00:25:18,880 Okay, so that looks promising. This is intended to go to spoofed at local host, and it went to me. 372 00:25:19,880 --> 00:25:27,300 The killer question is, is the link going to work? It does, first time. 373 00:25:29,240 --> 00:25:29,720 . 374 00:25:35,800 --> 00:25:38,140 I should have pretended it was always going to work. 375 00:25:38,160 --> 00:25:45,000 work first time. Cool. So yeah, that was that. So I originally found that vulnerability on 376 00:25:45,000 --> 00:25:50,740 GitLab.com and I could not resist obtaining the email address albinowaxed at GitLab.com 377 00:25:50,740 --> 00:25:57,440 and you can view that email address on my profile if you go there. But that shiny finding 378 00:25:57,440 --> 00:26:03,960 left me wondering about what the code looked like. And the vulnerable code starts out in 379 00:26:03,960 --> 00:26:10,440 a Ruby on Rails framework called Devise. And the problem is there's an inconsistency 380 00:26:10,440 --> 00:26:16,560 between how the system decides where to send the email and what to put inside it. The email 381 00:26:16,560 --> 00:26:23,460 is sent to an address stored in an instance variable which is passed directly to the thread 382 00:26:23,460 --> 00:26:30,200 that sends the message. Meanwhile, the body of the email is populated using data from 383 00:26:30,200 --> 00:26:33,900 a server-side template engine fetched from the database. 384 00:26:33,960 --> 00:26:39,940 Which means that the data in the database can change in the meantime, leading to this 385 00:26:40,520 --> 00:26:47,620 discrepancy. And the impact is quite significant. So as I mentioned, you can use this to hijack 386 00:26:47,620 --> 00:26:52,620 pending invitations intended for other people and just gain administrator access to random 387 00:26:52,620 --> 00:26:59,420 projects. But also, GitLab can be used as an open ID provider by third-party websites 388 00:26:59,740 --> 00:27:02,340 to create a sign-in with GitLab button. 389 00:27:03,240 --> 00:27:09,240 And depending on how the third-party website does that integration, this can enable a load 390 00:27:09,240 --> 00:27:14,480 of follow-up attacks against that third-party all the way up to arbitrary account hijacking 391 00:27:14,480 --> 00:27:15,500 if you're lucky. 392 00:27:16,780 --> 00:27:23,180 If you were to find this bug in a major open ID provider, it would be a pretty big deal. 393 00:27:23,840 --> 00:27:29,240 Now I reported this to GitLab and they patched it pretty fast. And then I reported it to 394 00:27:29,240 --> 00:27:32,320 Devise and things did not go so well. 395 00:27:33,660 --> 00:27:39,480 Over the span of 200 days, I reported to over four addresses and I received no reply 396 00:27:39,480 --> 00:27:45,720 from them until last week. And there's no patch available yet, but at least they've 397 00:27:45,720 --> 00:27:48,100 applied so maybe there'll be a patch soon. 398 00:27:48,600 --> 00:27:55,520 So I went hunting for other bug bounty sites using this library. And as it turns out, 399 00:27:55,540 --> 00:28:01,620 it's really popular. Loads of Rails-based sites use it. It's really easy to fingerprint 400 00:28:02,340 --> 00:28:06,940 because it registers an unauthenticated endpoint at slash users slash confirmation that you 401 00:28:06,940 --> 00:28:07,380 can just spot. 402 00:28:08,700 --> 00:28:13,340 And because of the way the library is written, every website integrates with it slightly 403 00:28:13,340 --> 00:28:18,220 differently. And as such, every exploitation journey is slightly different and it's great 404 00:28:18,220 --> 00:28:19,020 practice and good fun. 405 00:28:19,800 --> 00:28:26,280 So a couple of highlights that I encountered during this process were some sites had visible 406 00:28:26,280 --> 00:28:31,300 locking. They were obviously only processing one email change at a time, so they were secure. 407 00:28:32,340 --> 00:28:38,840 On another site, the confirmation email that they generated didn't tell you which address 408 00:28:39,340 --> 00:28:44,100 it was supposed to confirm. So there were no hints that the vulnerability was present 409 00:28:44,100 --> 00:28:49,360 and it was really unreliable on that site. So I had to write a script that would do the 410 00:28:49,360 --> 00:28:53,840 attack, receive the email, pause it, click the link and reload my profile to work out 411 00:28:53,840 --> 00:28:58,560 which email address had actually been confirmed. And then I had to run it for 14 hours to actually 412 00:28:59,180 --> 00:29:00,520 compromise another email. 413 00:29:01,700 --> 00:29:02,320 07.00 414 00:29:02,320 --> 00:29:08,120 On a couple of other targets, their visible email change functionality is secure against 415 00:29:08,120 --> 00:29:13,980 this attack, but device registers a different hidden endpoint for triggering an email resend 416 00:29:14,350 --> 00:29:15,460 and that was still vulnerable. 417 00:29:17,540 --> 00:29:24,480 Now with that, let's move on from GitLab and device. So race conditions are weird and 418 00:29:24,480 --> 00:29:29,960 I've saved the weirdest one for last. This was another token misrouting flaw, but the 419 00:29:29,960 --> 00:29:31,860 two requests that triggered it. 420 00:29:32,320 --> 00:29:35,160 It could be sent with a 20 minute delay in between them. 421 00:29:35,640 --> 00:29:40,740 So you might be thinking, well, that doesn't look like a race condition, but it was really 422 00:29:40,740 --> 00:29:46,480 unreliable so chances are it was. And after some analysis, what I think was happening 423 00:29:47,220 --> 00:29:52,940 is that my email change requests were getting put on a queue, which was then being processed 424 00:29:52,940 --> 00:29:59,980 by a multi-threaded batch job once every 30 minutes or so. So the timing of my request 425 00:29:59,980 --> 00:30:02,300 was practically irrelevant. 08.00 426 00:30:02,300 --> 00:30:07,840 And the vulnerability was triggered basically by my request volume rather than the timing. 427 00:30:08,140 --> 00:30:13,380 And also the only reason I discovered it is because I noticed two emails were sent to 428 00:30:13,380 --> 00:30:21,460 the same address, which over the course of this research, due to things like this, I've 429 00:30:21,460 --> 00:30:26,920 begun to regard spotting anomalies like that as the single most important skill for finding 430 00:30:27,500 --> 00:30:31,980 race conditions, especially for deferred ones like this where the response 431 00:30:31,980 --> 00:30:36,200 the application sends to your actual request is never going to tell you a vulnerability 432 00:30:36,200 --> 00:30:39,500 is present because the vulnerability hasn't even been triggered yet. 433 00:30:40,960 --> 00:30:47,080 Now, I focused on email-based attacks during my research, but where else can you find these 434 00:30:47,080 --> 00:30:53,220 things? Well, basically everywhere, but one pattern that you may well encounter is partial 435 00:30:53,220 --> 00:30:59,300 construction attacks. These occur when an object is created in multiple steps, creating 436 00:30:59,300 --> 00:31:01,960 an insecure middle stage. 08.00 437 00:31:01,980 --> 00:31:04,680 So, let's take a look at this data. Like you can see in the code snippet here where 438 00:31:04,680 --> 00:31:10,540 this token variable is briefly not set. I didn't use this as a case study because I 439 00:31:10,540 --> 00:31:14,580 actually wrote this code myself about 10 years ago, but it was not supposed to be vulnerable. 440 00:31:15,740 --> 00:31:23,040 Now, this type of attack is most likely to work on applications that support default 441 00:31:23,040 --> 00:31:30,640 or null type values and don't just throw exceptions when they encounter them. So think SQL, PHP. 442 00:31:31,400 --> 00:31:31,960 08.00 443 00:31:31,980 --> 00:31:36,880 But that's not a strict requirement, and for a completely different type of partial 444 00:31:36,880 --> 00:31:41,960 construction attack, check out the linked vulnerability found by Natalie Silvanovich 445 00:31:41,960 --> 00:31:45,180 in Google's WebRTC implementation in Duo. 446 00:31:45,520 --> 00:31:47,600 08.00 447 00:31:47,600 --> 00:31:53,580 Now, another angle for further research is exploring the root cause of race conditions 448 00:31:53,880 --> 00:31:59,400 from the ground up, which is unsafe combinations of data structures and locking strategies. 449 00:31:59,940 --> 00:32:01,960 There's three main strategies. 450 00:32:02,880 --> 00:32:03,460 08.00 451 00:32:03,460 --> 00:32:09,040 The classic defense is locking. So, for example, PHP's default session handler 452 00:32:09,570 --> 00:32:16,040 only processes one request at a time in a given session. So that means two things. Firstly, 453 00:32:16,200 --> 00:32:22,740 they're not going to have a session-based race condition, but also, if you try to trigger 454 00:32:22,740 --> 00:32:29,340 a database layer race condition using a single session, you'll fail to find it every time. 455 00:32:29,540 --> 00:32:31,960 So it's important to recognize... 08.00 456 00:32:31,960 --> 00:32:35,820 ...this behavior and work around it by doing things like using multiple sessions. 457 00:32:37,920 --> 00:32:38,460 08.00 458 00:32:38,460 --> 00:32:43,900 Probably the most common approach that you'll see in session handlers and ORMs is batching. 459 00:32:43,980 --> 00:32:50,040 So this is where they read the entire session, let's say, from the database into a local 460 00:32:50,040 --> 00:32:55,060 in-memory copy, and then any reads and writes that the application does during that request 461 00:32:55,060 --> 00:33:01,140 are applied to that local copy, and the whole copy is written back to the database at the 462 00:33:01,140 --> 00:33:09,700 end of the request life cycle. So this makes the values internally consistent during that 463 00:33:09,700 --> 00:33:15,580 request life cycle, but as we saw with device, as soon as data gets passed to a background 464 00:33:15,580 --> 00:33:21,380 thread, you're kind of outside the scope of that protection and everything falls apart. 465 00:33:21,920 --> 00:33:29,060 And also, if you have two requests operating on the same record simultaneously, then generally 466 00:33:29,060 --> 00:33:31,120 one will end up overwriting the request. 08.00 467 00:33:31,140 --> 00:33:33,000 So this is where the database changes from the other. 468 00:33:34,200 --> 00:33:34,980 08.00 469 00:33:34,980 --> 00:33:42,320 Finally, if there's no defense present, all the bets are off, basically, and you see 470 00:33:42,320 --> 00:33:46,480 that most commonly with databases where people aren't making adequate uses of transactions, 471 00:33:47,720 --> 00:33:52,120 but you'll also see it occasionally with custom session handlers. 472 00:33:52,440 --> 00:34:00,020 And if you find a session handler that has that property that's not doing batching or 473 00:34:00,020 --> 00:34:01,120 locking... 08.00 474 00:34:01,140 --> 00:34:06,680 That needs some really heavy testing because there's a whole load of completely plausible, 475 00:34:07,540 --> 00:34:12,560 reasonable code patterns that suddenly have critical vulnerabilities if they're built on 476 00:34:12,560 --> 00:34:20,740 top of a vulnerable session handler. So I would say I think it's almost impossible to 477 00:34:20,740 --> 00:34:26,000 write secure code at the application layer when you're building on top of a session handler 478 00:34:26,000 --> 00:34:29,380 that's not doing some kind of synchronization or batching. 479 00:34:30,880 --> 00:34:31,920 08.00 480 00:34:31,920 --> 00:34:38,600 Now, the final area for the research is improving the single-packet attack. So my implementation 481 00:34:39,440 --> 00:34:45,140 lets you get about 20 to 30 requests into one packet, and if you get more than that, 482 00:34:45,240 --> 00:34:50,720 the operating system just puts them in another packet shortly later. And I'm certain you 483 00:34:50,720 --> 00:34:56,940 can fit a lot more requests into a single packet with enough effort. You can totally 484 00:34:56,940 --> 00:34:59,360 do it with a custom TCP or TLS stack. 08.00 485 00:34:59,380 --> 00:35:04,660 And there may be other easier ways of making it happen that I didn't think of. I didn't 486 00:35:04,660 --> 00:35:10,100 try to push that side of the research that far, because 20 requests is enough to cause 487 00:35:10,460 --> 00:35:13,960 a lot of damage in the wild by itself. 08.00 488 00:35:13,960 --> 00:35:18,860 The other thing that will be really valuable on that angle is other ways of causing server-side 489 00:35:20,720 --> 00:35:27,080 delays, because that will let you trigger staggered attacks more reliably, and it will 490 00:35:27,080 --> 00:35:29,360 also help out with the timing attack side. 08.00 491 00:35:29,820 --> 00:35:41,340 Now, one final word of advice. This is a slide just for DEF CON, and this might be 492 00:35:41,340 --> 00:35:47,920 a controversial take. We'll see. Now, in this session, I've tried to squeeze six months 493 00:35:47,920 --> 00:35:53,400 of research into the space of 40 minutes. And one thing that can get lost in that condensing 494 00:35:53,400 --> 00:35:59,340 process is how big the gap can get between exploiting something that's already been done, 495 00:35:59,360 --> 00:36:06,560 and actually understanding it. So, for example, that GitLab vulnerability, I exploited GitLab.com 496 00:36:06,560 --> 00:36:12,040 successfully in, I can't remember, but I think maybe two days. Whereas, when I built my own 497 00:36:12,040 --> 00:36:18,560 local replica for the live demo, it took me, so I could get the token to be misrouted, 498 00:36:19,020 --> 00:36:26,120 but the token was never, ever valid. I ran attacks running every 10 seconds for weeks, 499 00:36:26,280 --> 00:36:29,340 and it was never valid. And it took me over two months to get the token to be misrouted. 500 00:36:29,360 --> 00:36:32,640 And it took me over two months to figure out why that was happening, and gain the 501 00:36:32,640 --> 00:36:39,220 understanding to actually replicate it successfully. And similarly, I've mentioned timing information 502 00:36:39,220 --> 00:36:45,260 can be really valuable, but front ends can do all kinds of different things with your 503 00:36:45,260 --> 00:36:52,000 requests, which can cause other timing delays and massive timing red herrings. Now, you 504 00:36:52,000 --> 00:36:58,240 can recognize that behavior and work around it, but what I'm getting at is, with this 505 00:36:58,240 --> 00:36:58,760 bug class, 506 00:36:59,360 --> 00:37:06,720 you will encounter things that don't make sense. And that's absolutely fine. My advice is just to 507 00:37:06,720 --> 00:37:12,040 embrace the chaos. Normally, I would say you should understand a system and then use that 508 00:37:12,040 --> 00:37:16,900 understanding to exploit it. But with race conditions, there's a risk that that limits 509 00:37:16,900 --> 00:37:22,160 you to finding vulnerabilities that make sense. And in my experience, the coolest race conditions 510 00:37:22,160 --> 00:37:29,160 make the least sense. In other words, it's nice to have an explanation, but all you really need 511 00:37:29,360 --> 00:37:30,020 is an exploit. 512 00:37:31,340 --> 00:37:38,740 Now, for defense, when a single request can push an application through multiple invisible 513 00:37:39,300 --> 00:37:44,120 substates, understanding that application and predicting its behavior is incredibly 514 00:37:44,120 --> 00:37:52,660 difficult. And defense is just not practical. So my advice is try to eliminate substates 515 00:37:52,660 --> 00:37:59,340 entirely. Like, the effects of each request should be atomic. You can achieve the same 516 00:37:59,360 --> 00:38:03,900 thing. You can achieve that generally using your data store consistency features. And another 517 00:38:03,900 --> 00:38:09,960 thing that will help with that is avoid mixing data sources. So device was vulnerable because they 518 00:38:09,960 --> 00:38:14,460 sent an e-mail to an address from an instance variable but took the contents from the database. 519 00:38:14,840 --> 00:38:19,420 If they took the e-mail address and the contents from the database, they would have been 520 00:38:19,420 --> 00:38:28,060 absolutely fine. The other key thing is to make sure that you know what kind of locking system your 521 00:38:28,060 --> 00:38:32,760 session handler is using because if it's not doing any locking, that's bad news. 522 00:38:34,960 --> 00:38:41,280 Now, there's a lot of further reading available. The three key things I would suggest are check out 523 00:38:41,280 --> 00:38:46,240 the white paper. That's basically the written up version of this presentation. It does have a little 524 00:38:46,240 --> 00:38:52,080 bit of extra info and some different angles on stuff. Have a practice on our online labs because 525 00:38:52,080 --> 00:38:58,040 there's no substitute for real experience with these vulnerabilities. And finally, if you're 526 00:38:58,060 --> 00:39:02,620 interested, grab my code, take the single packet, attack, and find some real vulnerabilities out in 527 00:39:02,620 --> 00:39:07,900 the wild. If you have any crazy findings with these techniques that you'd like to share, I'd 528 00:39:07,900 --> 00:39:14,860 absolutely love to hear all about it. And the three key things to take away are the single packet 529 00:39:14,860 --> 00:39:21,820 attack makes remote race conditions local. With race conditions, everything is potentially 530 00:39:21,820 --> 00:39:28,040 multi-step. And to find these bugs, predict, probe, and proof. I'm going to take five minutes 531 00:39:28,040 --> 00:39:32,560 of questions now. If you have any more after that, just come and chat to me at the back or chuck me an 532 00:39:32,560 --> 00:39:34,020 email. Thank you for listening. 533 00:39:45,340 --> 00:39:51,280 Any questions? Yeah. Can you use the mic? There's a microphone over in the middle. Sorry. 534 00:40:01,660 --> 00:40:08,740 Yeah. What severity did GitLab eventually rate that vulnerability as? 535 00:40:09,540 --> 00:40:20,160 So sadly for me, GitLab rated it as medium, which I don't think is accurate. I think part of that was 536 00:40:20,160 --> 00:40:26,860 because I hadn't discovered. So when I initially reported that, I didn't discover the invitation hijacking 537 00:40:26,860 --> 00:40:32,160 angle. I didn't realize getting a validated email would actually let you do that. And by the time I 538 00:40:32,160 --> 00:40:38,960 realized that, it was already fixed and paid out. So I think if I'd originally reported it with that 539 00:40:38,960 --> 00:40:44,900 impact, it would have got higher. Whereas as it was, it was only risky to people using GitLab via 540 00:40:44,900 --> 00:40:51,540 the signing with GitLab button, which thankfully not many people are doing. Anyone else? 541 00:40:59,740 --> 00:41:05,200 Thanks for the really interesting talk. You mentioned that frontends and load balancers cause issues 542 00:41:05,200 --> 00:41:09,400 with this sort of thing. And you said there are some workarounds. What are they? 543 00:41:09,960 --> 00:41:18,840 Yeah. They're not all trivial. But you basically, you have to observe what's happening. So you can 544 00:41:18,840 --> 00:41:25,680 notice if you send your requests in a batch and the first request always comes back faster, you can try 545 00:41:25,680 --> 00:41:26,840 changing these. 546 00:41:26,860 --> 00:41:27,040 Yeah. 547 00:41:27,040 --> 00:41:36,400 You can fix the order of the requests. And so sometimes by flipping the order, you can fix the issue or 548 00:41:36,400 --> 00:41:44,420 just adding a dummy request at the start. That's one way of dealing with it. But there's like so many 549 00:41:44,420 --> 00:41:49,840 different things that they can do. It's hard to give like a playbook for every kind of scenario. 550 00:41:51,420 --> 00:41:56,840 I think the most important thing there is when you see a delay, don't assume that it's going to happen 551 00:41:56,840 --> 00:42:04,280 server side. That could just be the load balancer. So test that assumption before you try and work 552 00:42:04,280 --> 00:42:12,680 around it. Cool. I think that's everyone. Thanks.