1 00:00:08,740 --> 00:00:11,740 Are you guys sure you're in the right talk? 2 00:00:11,740 --> 00:00:15,320 I didn't expect this many people to show up for this talk. 3 00:00:15,320 --> 00:00:17,400 So thank you all for being here. 4 00:00:17,400 --> 00:00:18,400 It means a lot to me. 5 00:00:18,400 --> 00:00:19,860 I see some familiar faces. 6 00:00:20,240 --> 00:00:23,260 I probably see a lot of other screen names that I don't know. 7 00:00:23,260 --> 00:00:27,020 So like a pitcher, send a DM if you see me. 8 00:00:27,740 --> 00:00:28,640 My name is Xavier D. 9 00:00:28,640 --> 00:00:29,380 Johnson. 10 00:00:29,480 --> 00:00:31,960 I've been in tech since forever. 11 00:00:31,960 --> 00:00:36,600 Started programming in 2004, so I guess I've been around for a while. 12 00:00:36,600 --> 00:00:39,860 Basic, C-sharp, everything but Java. 13 00:00:41,160 --> 00:00:51,020 Today, mostly focused on reverse engineering, mobile penetration testing, and security research is kind of like the broad term. 14 00:00:51,020 --> 00:00:57,060 So today, I want to talk to you guys about, or you folks, about hacking iOS. 15 00:00:57,060 --> 00:01:00,060 It's kind of like this mystique around iOS. 16 00:01:00,060 --> 00:01:02,320 That's probably why a lot of you guys are here like, okay, what is he going to do? 17 00:01:02,320 --> 00:01:03,480 Is he going to show me something cool? 18 00:01:03,540 --> 00:01:04,240 I am. 19 00:01:04,240 --> 00:01:10,880 But before I get into it, make sure you take pictures of the slides because I'm not sending you a copy of these slides. 20 00:01:11,440 --> 00:01:15,200 Fun fact about these slides, this is the last five years of my life. 21 00:01:15,420 --> 00:01:20,040 So if it sucks... 22 00:01:20,040 --> 00:01:20,680 Xavier D. 23 00:01:20,680 --> 00:01:22,900 Johnson, yes, the D means something. 24 00:01:23,320 --> 00:01:25,020 Everybody else calls me infinite. 25 00:01:25,840 --> 00:01:26,960 So hello. 26 00:01:27,320 --> 00:01:31,280 These slides will contain writer downers. 27 00:01:31,280 --> 00:01:32,740 Get your pen ready. 28 00:01:32,880 --> 00:01:35,760 20 years of experience, wrote my first line of code in 2004. 29 00:01:35,820 --> 00:01:38,480 Been chasing that high ever since. 30 00:01:38,960 --> 00:01:40,900 High school, did FIRST Robotics. 31 00:01:41,040 --> 00:01:42,820 As a young adult, did web applications. 32 00:01:42,820 --> 00:01:45,400 Wrote a lot of shitty PHP apps, I won't lie. 33 00:01:45,740 --> 00:01:49,660 I thought I was going to be Mark Zuckerberg, but of course, I'm here with you, so I'm not. 34 00:01:49,660 --> 00:01:50,680 Because I'm loved. 35 00:01:52,520 --> 00:01:55,120 Today's agenda, we're going to keep it short and sweet. 36 00:01:55,120 --> 00:01:56,640 Just an hour worth of content. 37 00:01:57,440 --> 00:02:00,360 Intro to ARM Assembler. 38 00:02:00,600 --> 00:02:02,820 The differences between ARM and Intel. 39 00:02:02,880 --> 00:02:08,100 I'm pretty sure many of you, or some of you, know a thing or two about IA-32, Intel. 40 00:02:08,100 --> 00:02:10,400 So this should be like a fresher, right? 41 00:02:10,400 --> 00:02:12,440 You'll be up to speed by the end of it. 42 00:02:12,780 --> 00:02:14,680 iOS internals, which... 43 00:02:15,340 --> 00:02:17,740 I read three really thick books about this. 44 00:02:17,740 --> 00:02:19,780 So I'm hoping it comes through. 45 00:02:19,780 --> 00:02:22,500 And exploitation, which is my favorite, right? 46 00:02:22,500 --> 00:02:25,200 Everybody wants to do an exploit, so... 47 00:02:25,200 --> 00:02:27,500 Your slides are not in the presentation. 48 00:02:27,500 --> 00:02:28,440 Oh, God. 49 00:02:28,440 --> 00:02:29,320 I was wondering. 50 00:02:29,320 --> 00:02:31,060 It's on the presentation part? 51 00:02:31,060 --> 00:02:34,020 You can see it on the top left, but it's the presentation. 52 00:02:34,020 --> 00:02:35,040 At least it's not full screen. 53 00:02:35,040 --> 00:02:35,600 Oh. 54 00:02:35,960 --> 00:02:37,880 You can't see my presentation. 55 00:02:38,420 --> 00:02:40,100 Okay, give me one second. 56 00:02:44,530 --> 00:02:45,850 Technical difficulties. 57 00:02:48,190 --> 00:02:49,070 Nope. 58 00:02:49,090 --> 00:02:51,130 Do you have a button to swap it? 59 00:02:51,130 --> 00:02:53,830 I don't have a button to swap the display. 60 00:02:54,470 --> 00:02:57,450 It usually just works. 61 00:02:59,210 --> 00:03:00,070 Oh, yeah. 62 00:03:00,070 --> 00:03:01,170 It's up here, huh? 63 00:03:08,490 --> 00:03:10,170 There we go. 64 00:03:33,050 --> 00:03:33,810 Okay. 65 00:03:35,570 --> 00:03:37,750 I can't even see it anymore. 66 00:03:37,750 --> 00:03:39,010 It's moved all the way over. 67 00:03:41,610 --> 00:03:42,290 That's better? 68 00:03:42,290 --> 00:03:43,330 I can't control it. 69 00:03:43,870 --> 00:03:44,970 I can't control it. 70 00:03:49,150 --> 00:03:50,910 Do we have speaker ops? 71 00:03:51,490 --> 00:03:53,390 Somebody here to help with the tech part of this? 72 00:03:53,390 --> 00:03:54,610 I just plugged into a USB. 73 00:03:54,610 --> 00:03:55,710 I have no idea. 74 00:03:59,710 --> 00:04:01,770 I can't see what you guys see on that screen. 75 00:04:01,770 --> 00:04:02,850 I think it's the problem. 76 00:04:04,770 --> 00:04:07,090 Yeah, I want to do it down there. 77 00:04:07,750 --> 00:04:08,550 Let's see. 78 00:04:12,010 --> 00:04:14,230 If I bring it, it's cable. 79 00:04:18,510 --> 00:04:19,310 Speaker ops. 80 00:04:19,310 --> 00:04:20,110 Do we have speaker ops? 81 00:04:20,110 --> 00:04:20,490 No? 82 00:04:20,490 --> 00:04:20,970 All right, cool. 83 00:04:20,970 --> 00:04:22,230 I guess I'll just... 84 00:04:23,390 --> 00:04:24,630 do it live. 85 00:04:28,590 --> 00:04:29,950 Can you guys see anything yet? 86 00:04:32,370 --> 00:04:33,490 What can you guys see? 87 00:04:33,490 --> 00:04:34,390 Because I don't have a... 88 00:04:39,850 --> 00:04:41,030 You see my mouse? 89 00:04:41,130 --> 00:04:41,850 All right, fuck it. 90 00:04:41,850 --> 00:04:42,870 We're going to do it like this then. 91 00:04:43,250 --> 00:04:44,970 We're going to do it like this. 92 00:04:45,470 --> 00:04:46,310 Presenter view. 93 00:04:46,670 --> 00:04:47,230 Presenter view? 94 00:04:47,230 --> 00:04:47,770 Yeah. 95 00:04:53,850 --> 00:04:55,170 It doesn't work. 96 00:04:55,170 --> 00:04:55,990 It's not working. 97 00:04:56,710 --> 00:04:57,550 Play from slide? 98 00:04:57,670 --> 00:04:58,670 Watch this. 99 00:04:58,950 --> 00:04:59,890 There you go. 100 00:05:00,310 --> 00:05:02,590 Well, now we're in it together. 101 00:05:05,390 --> 00:05:07,790 So, we're going to run it like this. 102 00:05:10,770 --> 00:05:11,910 I don't mind. 103 00:05:11,910 --> 00:05:12,510 You guys don't mind. 104 00:05:12,510 --> 00:05:12,890 I don't mind. 105 00:05:12,890 --> 00:05:13,630 Let's get it. 106 00:05:14,910 --> 00:05:16,430 We're going to jump straight into ARM. 107 00:05:17,490 --> 00:05:18,650 Let's get to it. 108 00:05:19,050 --> 00:05:19,850 Fundamentals. 109 00:05:20,370 --> 00:05:21,590 Let's get it going. 110 00:05:21,590 --> 00:05:25,630 So, the difference between ARM and Intel Assembler is really three key details. 111 00:05:25,630 --> 00:05:34,570 ARM has 31 general purpose registers, which the registers are kind of like how data moves in and out of RAM. 112 00:05:34,570 --> 00:05:38,930 How the computer actually is managing its data flow. 113 00:05:39,310 --> 00:05:42,450 Intel x86 has 16 general purpose registers. 114 00:05:42,690 --> 00:05:45,970 ARM is based on RISC, which is supposed to be faster. 115 00:05:46,150 --> 00:05:47,190 Typically, it is faster. 116 00:05:47,190 --> 00:05:49,930 You'll find these kind of things on mobile phones. 117 00:05:49,930 --> 00:05:50,870 IOT. 118 00:05:50,870 --> 00:05:52,490 ARM is kind of like the next thing. 119 00:05:52,490 --> 00:05:53,170 Satellites. 120 00:05:53,170 --> 00:05:53,650 Who knows? 121 00:05:53,650 --> 00:05:54,770 Let's ask Elon. 122 00:05:55,250 --> 00:05:59,210 ARM 64 was around since iPhone 5S. 123 00:05:59,270 --> 00:06:00,810 Before then, it was 32. 124 00:06:01,050 --> 00:06:02,630 32-bit ARM. 125 00:06:02,810 --> 00:06:06,170 Just a bit of a higher overview of the registers. 126 00:06:06,790 --> 00:06:10,550 Again, small area inside the CPU that stores a specific value. 127 00:06:10,890 --> 00:06:16,710 For 64-bit, registers X0 through X30 represent the 31 available registers. 128 00:06:16,710 --> 00:06:19,130 For 32-bit, it's W0 through 30. 129 00:06:19,810 --> 00:06:26,690 These are some of the points in which the registers actually identify, so to speak. 130 00:06:26,690 --> 00:06:29,610 The frame pointer is always going to be X29. 131 00:06:29,790 --> 00:06:31,710 Link register is always going to be X30. 132 00:06:32,010 --> 00:06:33,850 Program counter is always going to be PC. 133 00:06:33,850 --> 00:06:35,550 You don't have to worry about those sorts of things. 134 00:06:36,270 --> 00:06:38,590 0 through 28 are general purpose. 135 00:06:38,590 --> 00:06:39,690 This is holding your data. 136 00:06:39,690 --> 00:06:43,090 This is where the data is actually flowing through the application. 137 00:06:45,210 --> 00:06:47,310 This data can be volatile or non-volatile. 138 00:06:47,310 --> 00:06:52,070 A volatile register basically means that it does not persist through the end of a function. 139 00:06:52,350 --> 00:06:54,030 It is effectively not a global. 140 00:06:54,030 --> 00:06:56,590 It dies once the process is done. 141 00:06:56,690 --> 00:07:05,830 A non-volatile means that it is carly saved or that it actually saves the content so that it can continue to be used. 142 00:07:06,190 --> 00:07:11,850 The first 19 registers are volatile and the rest are non-volatile. 143 00:07:13,130 --> 00:07:15,050 There's three types of instructions. 144 00:07:15,110 --> 00:07:20,010 When we talk about code, what we really are talking about is a bunch of conditions. 145 00:07:20,010 --> 00:07:28,570 How do we accept some data, send some data, show some data, but in reality it comes down to the conditions of how we are supposed to manipulate or handle this data. 146 00:07:28,830 --> 00:07:42,430 Typically, you fall into a few different categories of arithmetic, math, logic, data movement, moving data around from either one function to the next function, persisting an object, etc., and control flow. 147 00:07:42,430 --> 00:07:43,450 Those conditions. 148 00:07:43,470 --> 00:07:45,690 What I like to call AI Hadouken. 149 00:07:46,890 --> 00:07:52,590 So the if-else statements in ARM64 use branch instructions. 150 00:07:52,590 --> 00:08:00,330 So branch instructions basically are controlling the flow of the application kind of in, you know, if-else. 151 00:08:00,770 --> 00:08:12,050 If this, if equal, if greater than, if greater than or equal to, or greater than or less than, these are all of the instructions in ARMAssembler to be able to do those sorts of things. 152 00:08:12,050 --> 00:08:14,490 And then we talk about calling conventions. 153 00:08:14,490 --> 00:08:22,250 Now, calling convention is how data is actually put into functions. 154 00:08:22,250 --> 00:08:31,910 So like, effectively for ARM64 you are looking at arguments stored in between the first eight registers. 155 00:08:31,910 --> 00:08:34,250 So X0 to X7. 156 00:08:34,490 --> 00:08:38,390 And subroutines are typically stored in X0. 157 00:08:38,390 --> 00:08:41,550 And all of this stuff will matter as we move into exploitation. 158 00:08:41,550 --> 00:08:43,490 This is kind of fundamental groundwork. 159 00:08:44,490 --> 00:08:53,530 Returns addresses are in X30, so we'll talk about that for ROP and JOP return-oriented programming. 160 00:08:54,050 --> 00:08:58,150 And the way that the stack grows is actually important. 161 00:08:58,430 --> 00:09:01,550 Stack frame actually grows downward in memory. 162 00:09:01,550 --> 00:09:04,570 Sometimes you'll have things grow upward in memory. 163 00:09:05,910 --> 00:09:07,030 That's pretty interesting. 164 00:09:07,030 --> 00:09:09,370 It's also stack frame 16 bytes. 165 00:09:10,890 --> 00:09:12,630 A few things there. 166 00:09:12,810 --> 00:09:18,110 A function in ARM assembler contains three different components. 167 00:09:18,110 --> 00:09:20,430 A prologue or the start. 168 00:09:20,770 --> 00:09:25,690 The body, which actually does anything with the data or the actual logic. 169 00:09:25,690 --> 00:09:27,830 And an epilogue, which is kind of ending the function. 170 00:09:27,830 --> 00:09:33,250 So think about when you're writing in C, you kind of got main and then eventually you're going to return something. 171 00:09:33,250 --> 00:09:34,970 Hopefully not a negative one. 172 00:09:37,130 --> 00:09:39,050 The prologue is just the first few lines. 173 00:09:39,050 --> 00:09:42,050 This is an example of kind of like the hello world prologue. 174 00:09:42,210 --> 00:09:44,890 Sub SP and SP. 175 00:09:45,170 --> 00:09:50,510 Basically putting this into putting 20 into SP. 176 00:09:50,510 --> 00:09:54,050 It starts the prologue and it's making space on the stack. 177 00:09:54,070 --> 00:09:59,730 And then it's saving the frame pointer and link register to the stack. 178 00:09:59,730 --> 00:10:03,430 And then calculating a new frame pointer to the stack, etc. 179 00:10:03,430 --> 00:10:11,430 So this is basically when you're looking at assembler, if you go take the binary out of the IPA and you put it into Ghidra, you've already done all that. 180 00:10:11,430 --> 00:10:15,790 This, when you're looking at your function, will tell you what is the start of a function. 181 00:10:15,870 --> 00:10:19,750 So this is very important when you're just handed a binary, go here figure it out. 182 00:10:19,750 --> 00:10:21,750 You're like, I don't really know where functions start. 183 00:10:21,750 --> 00:10:25,150 This will always be kind of your indicator of the beginning of a function. 184 00:10:25,150 --> 00:10:26,050 Always looks the same. 185 00:10:27,870 --> 00:10:31,070 Epilogue is to restore the program to its original state. 186 00:10:31,070 --> 00:10:37,010 Basically, put the program back to what it was before the last function was running. 187 00:10:37,010 --> 00:10:39,930 So this is kind of a restorative thing. 188 00:10:40,690 --> 00:10:43,550 So now I'm moving fast, because there's a lot of content here. 189 00:10:43,550 --> 00:10:44,890 So we're going to jump into syscalls. 190 00:10:45,310 --> 00:10:46,250 Syscalls are fun. 191 00:10:46,250 --> 00:10:46,970 I'm pretty sure all of you... 192 00:10:46,970 --> 00:10:48,930 who out here knows what syscalls are? 193 00:10:49,050 --> 00:10:49,950 That's a lot of hands. 194 00:10:49,950 --> 00:10:50,270 Cool. 195 00:10:50,270 --> 00:10:51,390 So I'm going to keep a high level . 196 00:10:51,390 --> 00:10:52,330 System calls. 197 00:10:52,330 --> 00:10:56,690 System calls basically act as the interface between user space and kernel space. 198 00:10:56,690 --> 00:10:58,410 So that's the fun... 199 00:10:58,410 --> 00:11:00,330 that's the fun part, right? 200 00:11:00,330 --> 00:11:05,410 Figuring out how to be able to manipulate or take advantage of these system calls. 201 00:11:05,570 --> 00:11:09,770 Potentially break them or leverage them in your exploitation. 202 00:11:10,750 --> 00:11:17,190 But the thing about these syscalls is they move over into kernel mode, they do something, and then they make a return back over. 203 00:11:17,190 --> 00:11:19,010 So think about like an fopen. 204 00:11:19,010 --> 00:11:20,190 That's standard. 205 00:11:20,190 --> 00:11:21,890 Or a chmod . 206 00:11:21,890 --> 00:11:23,150 That's standard. 207 00:11:23,150 --> 00:11:24,270 That's everywhere. 208 00:11:24,270 --> 00:11:27,290 Those are a part of the Linux syscalls. 209 00:11:27,290 --> 00:11:28,610 They're kind of Unix syscalls. 210 00:11:28,610 --> 00:11:32,370 They're a little bit of everywhere that leverages Nix. 211 00:11:33,810 --> 00:11:35,810 Typical syscall flow, right? 212 00:11:35,810 --> 00:11:38,490 A function will make a call to something like fopen. 213 00:11:38,490 --> 00:11:43,130 The user will, you know, leverage syscalls... 214 00:11:43,130 --> 00:11:44,170 the syscall number. 215 00:11:44,170 --> 00:11:45,730 So every syscall has its own number. 216 00:11:45,730 --> 00:11:47,730 And it will leverage the syscall number. 217 00:11:47,810 --> 00:11:56,110 And the kernel will then execute, request that service, and then actually return control back to user mode. 218 00:11:56,110 --> 00:11:59,510 So you don't get to do anything as a user, or from userland. 219 00:11:59,830 --> 00:12:06,010 You're just invoking the syscall so it can go and run that subroutine and then give you the results back over in userland. 220 00:12:07,630 --> 00:12:12,190 We all know why we don't want to run user code in kernel mode, right? 221 00:12:12,870 --> 00:12:16,150 Of course we want to run user code in kernel mode, right? 222 00:12:16,210 --> 00:12:17,970 That's the whole point. 223 00:12:17,970 --> 00:12:18,930 That's privilege escalation. 224 00:12:18,930 --> 00:12:20,290 That's the zero-day part. 225 00:12:21,470 --> 00:12:26,770 So yeah, syscalls all have a correlating system number, a syscall number. 226 00:12:27,430 --> 00:12:29,110 Memory management. 227 00:12:29,650 --> 00:12:33,210 So memory management is very important when you get down to this level. 228 00:12:33,210 --> 00:12:38,450 Loading, storing, branching, arithmetic, all of that is happening in the memory, leveraging those registers. 229 00:12:39,170 --> 00:12:41,550 ARM operates on a load store. 230 00:12:41,670 --> 00:12:49,430 So basically, memory can only be accessed and manipulated from specific load and store instructions. 231 00:12:49,430 --> 00:12:58,410 So there's an entire world kind of set up for you from ARM that says, hey, if you want to manage memory, you're going to have to load some and store some. 232 00:12:58,470 --> 00:13:00,030 That's the way I can explain it. 233 00:13:00,210 --> 00:13:06,210 To perform load and store memory instructions, you do LDRs, LDPs, STPs. 234 00:13:06,210 --> 00:13:07,470 The meanings are there. 235 00:13:07,470 --> 00:13:08,830 I won't go into it. 236 00:13:08,830 --> 00:13:14,770 Again, if you want to know more about this, I suggest you go and actually read the ARM documentation. 237 00:13:15,030 --> 00:13:21,390 I know it sounds like it sucks, but eventually, even if I told you everything, you would end up opening it up and referencing it. 238 00:13:21,390 --> 00:13:23,510 So you might as well get used to it. 239 00:13:25,450 --> 00:13:29,570 These instructions, they handle different sizes of data, right? 240 00:13:29,570 --> 00:13:32,990 So bytes or 8 bits all the way up to double words at 64 bit. 241 00:13:33,250 --> 00:13:33,970 ARM64. 242 00:13:35,070 --> 00:13:36,010 All right. 243 00:13:36,470 --> 00:13:37,590 Did I lose anybody? 244 00:13:37,590 --> 00:13:38,950 I only lost like two or three people. 245 00:13:38,950 --> 00:13:40,510 So I feel like I'm doing good. 246 00:13:40,530 --> 00:13:41,550 I feel like I'm doing good. 247 00:13:41,550 --> 00:13:47,030 We made it through basically the hard part, like the really shitty part of the talk, which is like the assembler part. 248 00:13:47,070 --> 00:13:48,650 The rest of it is going to be pretty fun. 249 00:13:48,650 --> 00:13:50,170 So I'm jumping into internals. 250 00:13:50,570 --> 00:13:52,350 Now, internals... 251 00:13:54,330 --> 00:13:59,270 Well, I don't know if you guys know, like, iOS is kind of open source, but kind of not, right? 252 00:13:59,270 --> 00:14:01,110 Like, part of the kernel is on GitHub. 253 00:14:01,110 --> 00:14:03,750 You can just go and like look at it and fucks around with it. 254 00:14:03,750 --> 00:14:10,090 But a lot of it is kind of like this mysterious like walled garden is what me and my friends used to call it back in the day. 255 00:14:10,090 --> 00:14:13,250 It's like ah, I don't really know exactly how it works underneath. 256 00:14:13,250 --> 00:14:15,470 And there's no like real clear cut documentation. 257 00:14:15,490 --> 00:14:21,890 Unfortunately, Pavel, the guy who wrote the Windows internals books, didn't write them for iOS. 258 00:14:21,890 --> 00:14:28,670 But a really cool guy named Jonathan Levin wrote a series of books which is called the Moxel Trilogy. 259 00:14:28,670 --> 00:14:35,690 Effectively, it's the user space, kernel space, and security internals, well known internals book. 260 00:14:35,710 --> 00:14:38,550 You guys should go buy it and support. 261 00:14:39,630 --> 00:14:42,250 This is where I got a lot of this information from. 262 00:14:42,530 --> 00:14:43,450 Jailbreaking. 263 00:14:43,790 --> 00:14:45,650 So that's like a prior requirement. 264 00:14:45,650 --> 00:14:46,950 Oh, I got a question? 265 00:14:48,750 --> 00:14:50,970 M-O-X-I-L 266 00:14:57,850 --> 00:15:06,650 M-O-X-I-L M-O-X-I-L M-O-X-I-L We talk about a walled garden. 267 00:15:07,190 --> 00:15:09,690 How many people here have jailbroken an iPhone? 268 00:15:09,910 --> 00:15:12,470 I got a lot of jailbreakers in here. 269 00:15:12,470 --> 00:15:13,050 Okay. 270 00:15:13,050 --> 00:15:13,550 Okay. 271 00:15:13,550 --> 00:15:15,270 So this is going to be a really boring part. 272 00:15:15,310 --> 00:15:19,150 Long story short, this is how you're able to get root on iPhone. 273 00:15:19,150 --> 00:15:20,650 We call it jailbreaking. 274 00:15:20,890 --> 00:15:24,070 It gives you write access to all the partitions. 275 00:15:24,070 --> 00:15:25,270 Basically, you can do what you want. 276 00:15:29,070 --> 00:15:38,350 Historically, people have leveraged kernel patching to bypass code signing, which is a control to slow you down. 277 00:15:38,350 --> 00:15:40,050 So that's one bypass. 278 00:15:40,370 --> 00:15:45,370 Modifying the AFC service for root access is another methodology. 279 00:15:45,630 --> 00:15:47,530 AFC is the Apple File Conduit. 280 00:15:47,530 --> 00:15:52,630 It's basically the way that all of the Apple devices manage their file system. 281 00:15:52,930 --> 00:15:55,150 And there's a few different types of jailbreaks. 282 00:15:55,330 --> 00:15:59,290 You've got untethered, you've got tethered, you've got semi-untethered, you've got semi-tethered. 283 00:15:59,290 --> 00:16:02,310 So some of this stuff you're like, okay, well, you guys already know. 284 00:16:02,330 --> 00:16:05,410 But for the people at home, you're probably wondering, well, what does this mean? 285 00:16:05,430 --> 00:16:11,470 Tethered means that it only persists for one boot and it has to be restarted. 286 00:16:11,950 --> 00:16:14,410 The device will no longer have the jailbreak. 287 00:16:14,410 --> 00:16:20,310 So let's say you're working and you're fuzzing around and it crashes, it'll reboot in a non-jailbroken state. 288 00:16:21,370 --> 00:16:23,990 And it may not even really fully reboot. 289 00:16:23,990 --> 00:16:28,330 I've seen it go into recovery mode, which is fun, because that's kind of like the danger zone for bricking a phone. 290 00:16:28,450 --> 00:16:32,050 Which is a whole other fun topic, which I think is a talk that I'll do next year. 291 00:16:32,050 --> 00:16:36,430 How do you get around bricking your jailbreaking devices? 292 00:16:37,350 --> 00:16:43,370 Untethered means that you can kind of turn the device on and off and it'll persist, which is kind of like... 293 00:16:43,850 --> 00:16:46,150 that's like next-level golden status. 294 00:16:46,150 --> 00:16:50,290 I don't think any of the current jailbreaks that are actually useful you can actually do that with. 295 00:16:51,110 --> 00:16:55,810 Semi-tethered means that the jailbreak won't persist when you restart it, but at least you can reboot it. 296 00:16:55,810 --> 00:16:58,030 And that's the majority of the world right now. 297 00:16:58,030 --> 00:16:59,390 It's kind of semi-tethered. 298 00:16:59,410 --> 00:17:02,650 Uncover is a semi-tethered jailbreak. 299 00:17:02,650 --> 00:17:13,150 And semi-untethered means that the first boot won't be jailbreaking, however, a kernel patch will be applied via like city impactor. 300 00:17:13,150 --> 00:17:17,050 So like after it boots up, it'll just patch. 301 00:17:17,070 --> 00:17:18,710 I leverage uncover. 302 00:17:18,710 --> 00:17:19,890 If you don't, you should. 303 00:17:19,890 --> 00:17:20,650 It's pretty cool. 304 00:17:20,650 --> 00:17:26,630 But that's kind of like the thing that I've used that's widely available and pretty stable, from my opinion. 305 00:17:27,030 --> 00:17:31,310 So moving over into APFS, Apple File System, right? 306 00:17:31,310 --> 00:17:33,470 iOS leverages APFS. 307 00:17:33,490 --> 00:17:53,610 And so basically this was developed for all of their products, macOS, tvOS, iOS, watchOS, and HFS Plus was originally, if you're an old school Apple guy or person, it was the original file system type, but then in 2016, they launched a replacement. 308 00:17:53,690 --> 00:17:56,350 And so effectively, the devices became faster. 309 00:17:57,210 --> 00:18:03,450 Of course, we want to take advantage of sweet, sweet SSD speeds, so APFS is supposed to lean into that. 310 00:18:03,570 --> 00:18:07,610 And as well as full disk encryption and file encryption. 311 00:18:07,810 --> 00:18:10,350 So if you want to learn more about that, check out iPhone Wiki. 312 00:18:10,370 --> 00:18:11,830 It's a really great resource. 313 00:18:13,690 --> 00:18:14,710 File system, right? 314 00:18:14,710 --> 00:18:17,890 What makes the iOS file system different than any other file system? 315 00:18:17,890 --> 00:18:19,470 Here's the real diff for you. 316 00:18:20,190 --> 00:18:25,490 A regular file system, a typical Linux file system will have bin, boot, dev, blah, blah, blah, user bar, right? 317 00:18:25,490 --> 00:18:35,390 Directories that are in iOS, macOS that are specific, slash applications, cores, developer, library, system, user, private. 318 00:18:35,390 --> 00:18:45,390 These are kind of where the core differences in a regular Linux file system and Apple file system for iOS and macOS. 319 00:18:46,770 --> 00:18:51,030 Apps do not directly communicate with the hardware. 320 00:18:51,030 --> 00:18:52,450 There is a sandbox. 321 00:18:52,850 --> 00:18:55,410 There is different layers of the sandbox. 322 00:18:55,410 --> 00:19:00,170 You have the touch layer, the media layer, the services layer, and the actual core OS. 323 00:19:00,370 --> 00:19:04,150 So Cocoa Touch is kind of the infrastructure for all the applications. 324 00:19:04,150 --> 00:19:05,890 It's the way that you actually touch the screen. 325 00:19:05,890 --> 00:19:07,050 It's this touch, right? 326 00:19:07,130 --> 00:19:11,090 The media layer allows us to be able to deal with all the AV media. 327 00:19:11,090 --> 00:19:12,110 Kind of makes sense. 328 00:19:12,110 --> 00:19:15,210 Core services is kind of like that, the hardcore stuff. 329 00:19:15,210 --> 00:19:19,390 Network, location, all the stuff you really want to leak out. 330 00:19:19,390 --> 00:19:23,830 Things that are pertinent to your device specifically. 331 00:19:24,170 --> 00:19:28,470 And the core OS is kind of like, I'll call it the kernel for lack of a good term, right? 332 00:19:28,470 --> 00:19:36,550 It's the actual base operating system that kind of like does things that the applications above them is asking for. 333 00:19:37,430 --> 00:19:40,110 So I'm going to jump right into static analysis. 334 00:19:40,410 --> 00:19:42,130 This is really high level. 335 00:19:42,130 --> 00:19:44,390 Everybody is going to have different methodologies. 336 00:19:44,890 --> 00:19:47,570 Some people will use scanning tools. 337 00:19:47,570 --> 00:19:51,730 Some people kind of get old school like me and just kind of start to rip apart stuff. 338 00:19:52,610 --> 00:20:01,570 Joker and JTool used to be Otool are also really good options for this as well. 339 00:20:01,650 --> 00:20:05,230 But I'm going to talk mostly about Otool and then in page stuff. 340 00:20:05,230 --> 00:20:08,110 Just kind of like briefly giving you an understanding. 341 00:20:08,850 --> 00:20:10,850 IPA file is basically a .zip. 342 00:20:10,850 --> 00:20:11,830 Funny, funny. 343 00:20:11,830 --> 00:20:14,350 You can actually turn a .zip to a .ipa. 344 00:20:14,410 --> 00:20:17,370 Won't install, but it will be an IPA file. 345 00:20:17,750 --> 00:20:19,270 Works on my machine. 346 00:20:20,630 --> 00:20:24,890 Basically, you unzip an IPA file and you will be able to find all of the resources. 347 00:20:24,950 --> 00:20:28,270 In those resources you will be able to find a folder called payload. 348 00:20:28,470 --> 00:20:29,970 That will actually have binaries in it. 349 00:20:30,030 --> 00:20:33,650 Frameworks, shared libraries, dynamic libraries, those sorts of things. 350 00:20:33,650 --> 00:20:37,230 So like statically linked things that are in the application. 351 00:20:37,950 --> 00:20:41,050 Tools used for this, again Otool and then in page stuff. 352 00:20:41,650 --> 00:20:44,170 Otool, widely available in Xcode. 353 00:20:44,170 --> 00:20:45,830 If you install Xcode, it's there. 354 00:20:45,970 --> 00:20:49,650 We use the check for depreciated APIs like string copy. 355 00:20:50,830 --> 00:20:53,530 And to check to see if DRM is enabled. 356 00:20:53,530 --> 00:20:55,190 Is the app encrypted? 357 00:20:55,490 --> 00:20:57,170 Alright, DRM. 358 00:20:57,370 --> 00:20:59,050 That's a fun part of the talk. 359 00:20:59,890 --> 00:21:03,830 Encryption is one of the ways that Apple... that's one of the walls. 360 00:21:03,830 --> 00:21:05,690 I'll call it multiple walls now. 361 00:21:05,690 --> 00:21:07,350 We're dealing with defense in depth. 362 00:21:07,350 --> 00:21:08,810 We're taking a layered approach. 363 00:21:09,750 --> 00:21:22,310 App encryption is one of the ways that Apple says, oh, you can't just sideload anything or you can't just pass an application around or you can't man in the middle of an update and take away system integrity. 364 00:21:22,690 --> 00:21:32,090 So that's one of those areas where if you're doing an engagement for a customer and you want to know if they're actually doing what they're supposed to be doing, you check to see if that's encrypted. 365 00:21:32,090 --> 00:21:37,890 And if ASLR is enabled, address space layout randomization. 366 00:21:37,950 --> 00:21:40,690 So this is an example of me running Otool. 367 00:21:41,370 --> 00:21:44,870 These four down here are kind of like some easy, fast wins. 368 00:21:44,870 --> 00:21:47,090 You want to go on GitHub and just start looking for this stuff? 369 00:21:47,090 --> 00:21:47,590 There you go. 370 00:21:47,610 --> 00:21:49,830 Memcpy, Stringcopy, Stringland. 371 00:21:49,830 --> 00:21:52,210 These are like quick, fast, dirty. 372 00:21:52,210 --> 00:21:57,050 I'm pretty sure you guys could tell me even some more, but I'll leave that for another talk. 373 00:21:58,190 --> 00:21:59,110 A&M. 374 00:21:59,190 --> 00:22:01,050 So this displays symbols. 375 00:22:01,610 --> 00:22:03,290 Does everybody know what symbols are? 376 00:22:03,850 --> 00:22:04,510 Okay. 377 00:22:04,510 --> 00:22:06,330 I see way less hands. 378 00:22:06,330 --> 00:22:06,650 All right. 379 00:22:07,130 --> 00:22:07,450 Symbols. 380 00:22:07,450 --> 00:22:08,110 Oh, there they go. 381 00:22:08,110 --> 00:22:08,790 Another popping up. 382 00:22:08,790 --> 00:22:10,150 They're like, no, no, don't tell me about symbols. 383 00:22:10,150 --> 00:22:10,430 Screw it. 384 00:22:10,430 --> 00:22:11,470 You're too late now. 385 00:22:12,830 --> 00:22:16,170 Symbols is basically like how functions are named. 386 00:22:16,430 --> 00:22:21,110 And you can either include them or obfuscate them or not include them entirely. 387 00:22:21,490 --> 00:22:26,710 But this, for me as a reverse engineer, is a good way for me to understand how the application is working. 388 00:22:27,010 --> 00:22:35,050 Symbols are exported and I can know if they're using a particular framework or even outside of that, if they have just certain routines I want to look for. 389 00:22:35,070 --> 00:22:38,050 Like, for example, do I have jailbreak detection? 390 00:22:38,050 --> 00:22:41,470 Well, jailbreak's probably in the name of one of the symbols. 391 00:22:41,810 --> 00:22:49,590 If it is, then I probably want to go to that routine, read the assembler, figure out those branch instructions, try and patch it. 392 00:22:49,690 --> 00:22:53,290 Usually it'll come down to 1 or 0. 393 00:22:53,290 --> 00:22:54,290 It's true or false. 394 00:22:54,290 --> 00:22:55,350 Is it jailbroken? 395 00:22:55,350 --> 00:22:56,070 True? 396 00:22:56,170 --> 00:22:59,350 Okay, well, let's change that to always be false. 397 00:22:59,390 --> 00:23:03,430 Even though it's jailbroken, it's just patched application it'll return false always. 398 00:23:04,150 --> 00:23:05,910 Nm, right? 399 00:23:06,190 --> 00:23:18,650 So basically, symbols are created by the compiler, maintained by the compiler, and so, for example, vStackLayout is used in Swift for views, for the touch layer. 400 00:23:18,650 --> 00:23:31,350 So if you're looking for any particular symbol, a good way to do it is just nm space, go into your .app or .ipa slash payload into the actual binary. 401 00:23:31,350 --> 00:23:35,390 So when you go into that payload folder, there'll be the name of the application. 402 00:23:35,390 --> 00:23:37,630 Let's say the application is HackerTracker. 403 00:23:37,850 --> 00:23:42,750 If you go and you look at the HackerTracker application, you'll be able to unzip it, right? 404 00:23:42,750 --> 00:23:47,830 You'll look into the payload folder, you'll scroll, scroll, scroll, and all of a sudden you'll see HackerTracker as a binary. 405 00:23:47,950 --> 00:23:49,990 That's what you really want to be pulling nm to. 406 00:23:49,990 --> 00:23:53,430 That'll show you if they've stripped symbols or not, and if they haven't, have fun. 407 00:23:55,270 --> 00:23:55,810 PageStuff. 408 00:23:55,870 --> 00:23:59,830 Basically, it lets you review the structure of a mock O file. 409 00:23:59,830 --> 00:24:08,430 So mock O is kind of the specific file format for iOS, and this lets us know more information about symbols, of course, code signature, headers, segments. 410 00:24:09,030 --> 00:24:20,610 Basically, if somebody hands you an app and you don't know anything about it, this is the initial, low-hanging fruit, easy way to get a good understanding before you start throwing it into your IDA or your Benjo or whatever you're using these days. 411 00:24:21,950 --> 00:24:23,630 I'm a Geedra guy, personally. 412 00:24:23,830 --> 00:24:26,150 If it's good enough for you, it's good enough for me. 413 00:24:26,150 --> 00:24:26,890 Question? 414 00:24:27,130 --> 00:24:27,830 Yeah. 415 00:24:27,970 --> 00:24:29,590 I have an Apple question. 416 00:24:29,850 --> 00:24:33,690 Where do you get information about the actual format? 417 00:24:34,230 --> 00:24:35,650 The macro format? 418 00:24:35,650 --> 00:24:35,950 Yeah. 419 00:24:35,950 --> 00:24:40,270 Apple has really good documentation about that sort of stuff. 420 00:24:40,270 --> 00:24:43,370 So I've been able to find that on my blog post, but... 421 00:24:43,370 --> 00:24:45,050 Not on their public? 422 00:24:45,570 --> 00:24:46,130 Hmm. 423 00:24:46,130 --> 00:24:48,050 Another good space is to read that book. 424 00:24:48,050 --> 00:24:51,990 That's where I got the information from myself, because I was too lazy to read the documentation. 425 00:24:53,090 --> 00:24:55,390 So that book by Jonathan Levin, check it out. 426 00:24:55,390 --> 00:24:56,070 It's a really good book. 427 00:24:56,070 --> 00:25:02,110 It'll give you a deep understanding in history of macro, where it comes from, the reason why it's that, and that sort of thing. 428 00:25:02,570 --> 00:25:02,950 All right. 429 00:25:02,950 --> 00:25:04,130 Here's the meat of the talk. 430 00:25:04,630 --> 00:25:05,310 Exploitation. 431 00:25:05,310 --> 00:25:08,690 I'll probably get you guys out of here like 15 minutes early, because I got an advanced class. 432 00:25:08,690 --> 00:25:09,830 I like this. 433 00:25:10,930 --> 00:25:11,990 Everybody's phone's coming out. 434 00:25:12,030 --> 00:25:12,710 Exploitation time. 435 00:25:12,710 --> 00:25:13,350 All right. 436 00:25:13,790 --> 00:25:15,650 First, we're going to talk about mitigations. 437 00:25:15,650 --> 00:25:17,730 We already talked about one, which is code signing. 438 00:25:18,510 --> 00:25:21,790 Basically, just make sure that the code is from a known source. 439 00:25:22,270 --> 00:25:28,070 The components of code signing will be certificates, bundle IDs, provisioning profiles. 440 00:25:28,150 --> 00:25:34,570 And so a provisioning profile is basically like a file that has the bundle ID and what cert to use. 441 00:25:34,570 --> 00:25:37,910 So that's how those three kind of basically come together. 442 00:25:37,910 --> 00:25:38,710 You need a certificate. 443 00:25:38,710 --> 00:25:39,710 You need a bundle. 444 00:25:39,750 --> 00:25:40,950 Those are kind of like prereqs. 445 00:25:40,950 --> 00:25:45,290 And you need a provisioning profile that actually leverages those certs and bundle IDs. 446 00:25:45,770 --> 00:25:55,650 Now, core trust, if you guys know core trust bugs, jailbreakers, you know it's no longer around, but it was well, it's here. 447 00:25:55,650 --> 00:25:58,530 Core trust bugs are no longer around, unfortunately. 448 00:25:58,850 --> 00:26:02,290 It was added in iOS 12 to prevent fake signing, right? 449 00:26:02,290 --> 00:26:08,270 Being able to take an application from Jack Mob and just put it on my phone and since it's jailbroken I just boom, fake sign it. 450 00:26:09,870 --> 00:26:15,570 Jailbroken phones still require signing, fun fact, but you can fake sign on a jailbroken phone. 451 00:26:15,570 --> 00:26:18,350 So non-jailbroken phone, no more fake signing. 452 00:26:18,350 --> 00:26:21,570 Real jailbroken phone, you can't co-sign. 453 00:26:21,570 --> 00:26:33,070 Fun fact, while we're kind of talking about this whole you know, bypassing medications thing, there's an application that I use that is called AltStore. 454 00:26:33,150 --> 00:26:35,010 AltServer and AltStore. 455 00:26:35,070 --> 00:26:41,890 This really, really good and easy way to be able to get decrypted applications siloed onto your iPhone. 456 00:26:41,890 --> 00:26:47,790 Because, you know, I believe there was some legislation that came out that said Apple had to allow you to silo. 457 00:26:47,830 --> 00:26:48,710 Question? 458 00:26:50,630 --> 00:26:53,630 AltStore, A-L-T and AltServer. 459 00:26:55,390 --> 00:26:58,930 The first one, when you look at the website, there's two options. 460 00:26:58,930 --> 00:27:00,970 One option is like asking you to pay money. 461 00:27:00,970 --> 00:27:03,410 That's only for the people in the EU. 462 00:27:03,510 --> 00:27:07,630 I think they were like the main drivers behind like the legislation being changed. 463 00:27:07,630 --> 00:27:10,990 Same way we got USB-C on iPhone, basically. 464 00:27:10,990 --> 00:27:13,930 So they charge over there for some reason. 465 00:27:13,930 --> 00:27:14,870 But in the U.S., U.S. 466 00:27:14,870 --> 00:27:16,350 servers are totally fine. 467 00:27:16,350 --> 00:27:19,830 Basically what it does is it spins up a server on your phone. 468 00:27:19,890 --> 00:27:21,530 You tether your phone. 469 00:27:21,530 --> 00:27:25,190 Excuse me, it spins up a server on your MacBook. 470 00:27:25,550 --> 00:27:26,950 You plug up your phone. 471 00:27:26,950 --> 00:27:30,330 You have the AltStore on your phone. 472 00:27:30,330 --> 00:27:36,710 And then you're able to sideload applications directly from your computer to your phone with it being signed. 473 00:27:36,710 --> 00:27:38,670 So it manages that signing for you. 474 00:27:38,670 --> 00:27:40,610 What do you mean by known source? 475 00:27:40,610 --> 00:27:42,050 Is it an Apple signing? 476 00:27:42,990 --> 00:27:44,310 Say that one more time. 477 00:27:44,310 --> 00:27:46,250 Or maybe it's both signing. 478 00:27:48,410 --> 00:27:49,850 Oh, yeah. 479 00:27:49,850 --> 00:27:54,710 So known source would be like Instagram, Facebook, TikTok. 480 00:27:54,710 --> 00:28:04,910 When you look at the applications at rest, they'll have certificates that are issued by the companies that actually are giving the binary away. 481 00:28:05,550 --> 00:28:13,730 So it's kind of like think about it like a way to remove tampering. 482 00:28:13,730 --> 00:28:18,910 I can take an Instagram application and I can decrypt it. 483 00:28:18,910 --> 00:28:20,770 Then I can re-sign it with my cert. 484 00:28:21,290 --> 00:28:28,490 Now, at that point, it will no longer be able to run on your device because Apple does not trust my cert on your device. 485 00:28:28,490 --> 00:28:41,330 But if I have created Instanon and I actually go through the Apple process of submitting it to the App Store, what they'll do is they'll sign it with my production key. 486 00:28:41,570 --> 00:28:43,430 And they'll know of my key. 487 00:28:43,430 --> 00:28:48,450 And so when you go to go download it from the App Store, it'll be a known application to your trust store. 488 00:28:49,590 --> 00:28:51,350 Your certificate trust store. 489 00:28:51,550 --> 00:28:52,230 Question? 490 00:28:52,950 --> 00:28:53,830 Gotcha. 491 00:28:54,530 --> 00:28:57,210 That means I'm doing good for you preemptively answering questions. 492 00:28:57,210 --> 00:28:58,070 Come on now. 493 00:29:00,370 --> 00:29:01,630 Read the green. 494 00:29:01,630 --> 00:29:02,970 The green is fun. 495 00:29:02,970 --> 00:29:04,570 Bypass, bypass, bypass. 496 00:29:04,570 --> 00:29:07,050 I don't want to tell you how to bypass it. 497 00:29:07,050 --> 00:29:08,890 DEP, data execution prevention. 498 00:29:08,890 --> 00:29:10,150 This is nothing new. 499 00:29:10,150 --> 00:29:11,350 This has been around. 500 00:29:11,350 --> 00:29:18,530 Prevents code from being executed in memory portions that are marked as non-executable in X. 501 00:29:18,710 --> 00:29:20,310 The letter N, the letter X. 502 00:29:21,750 --> 00:29:24,910 To bypass this, we use ROP. 503 00:29:25,950 --> 00:29:29,830 Return Oriented Programming. 504 00:29:29,990 --> 00:29:31,370 Then you have ASLR. 505 00:29:31,370 --> 00:29:34,350 Randomizes the location where executables are loaded into memory. 506 00:29:34,350 --> 00:29:39,970 Fun fact, without ASLR, it is predetermined where your start and end is for your binary. 507 00:29:39,970 --> 00:29:42,330 And you can actually see that statically. 508 00:29:42,330 --> 00:29:50,070 So if you are a reverse engineer and they don't have ASLR enabled, you'll always know in what memory positions that binary will load in. 509 00:29:50,070 --> 00:30:00,690 What that means is as you're writing your exploits, you'll have great luck in always being able to trigger the gadgets and things that you need within that runtime. 510 00:30:01,030 --> 00:30:08,330 You'll be able to hard-code memory addresses because it always loads between 0x1000 and 0x2000. 511 00:30:08,790 --> 00:30:13,290 All of the logic will always happen in that region of memory. 512 00:30:13,590 --> 00:30:16,710 ASLR will make it so that you no longer have that. 513 00:30:16,950 --> 00:30:21,270 It'll load in 0x3000, it'll load in 0x10000. 514 00:30:22,370 --> 00:30:23,050 KSLR. 515 00:30:23,050 --> 00:30:25,730 This is the kernel address-based layout randomization. 516 00:30:25,730 --> 00:30:26,690 Oh, sorry. 517 00:30:27,590 --> 00:30:28,250 ASLR. 518 00:30:28,250 --> 00:30:29,630 How to bypass. 519 00:30:29,770 --> 00:30:37,570 We leverage information leak bugs, which I'll get into later, or we brute force, and I'll talk about that. 520 00:30:38,910 --> 00:30:43,510 Kernel address-based layout randomization prevents attackers from being able to view kernel data. 521 00:30:43,610 --> 00:30:55,250 Basically, it randomizes the kernel base image every time it loads up, so you don't really have no way of knowing how to shoot at it, and it's really hard to debug the kernel for you to really know what memory addresses the kernel has been loaded into. 522 00:30:55,250 --> 00:30:56,930 This is a really good protection. 523 00:30:57,030 --> 00:31:01,330 Again, one good way to do this is leveraging information leaks. 524 00:31:01,330 --> 00:31:07,350 This is how you're able to see, based on the information that's actually live, where the kernel's being loaded. 525 00:31:07,350 --> 00:31:10,510 And you're going to have to take advantage of some other vulnerabilities to get there. 526 00:31:11,910 --> 00:31:12,870 Mitigations. 527 00:31:13,250 --> 00:31:14,570 I love mitigations. 528 00:31:14,570 --> 00:31:15,630 There's so many of them. 529 00:31:15,630 --> 00:31:18,490 There's some that's not even here, believe it or not. 530 00:31:18,490 --> 00:31:19,950 Kernel patch protection. 531 00:31:20,070 --> 00:31:21,990 Kernel text read-only region. 532 00:31:22,790 --> 00:31:23,590 KTRR. 533 00:31:23,590 --> 00:31:24,230 This? 534 00:31:24,230 --> 00:31:25,510 That was new to me. 535 00:31:25,730 --> 00:31:28,250 I don't do a lot of kernel research. 536 00:31:28,250 --> 00:31:32,410 I have been now that I know a lot more about it, so maybe I'll get an iOS bug one day. 537 00:31:32,950 --> 00:31:38,030 But KTRR basically is kind of newer. 538 00:31:38,030 --> 00:31:39,430 It's been around since 8.10. 539 00:31:41,750 --> 00:31:43,290 It locks down the MMU. 540 00:31:43,290 --> 00:31:48,790 This is the memory management unit, which is a whole separate chip on the board. 541 00:31:50,550 --> 00:31:51,950 So I'll leave it at that. 542 00:31:54,150 --> 00:31:54,950 Pack. 543 00:31:55,890 --> 00:31:57,910 Pointer authentication codes. 544 00:31:58,190 --> 00:31:59,330 Introduced in 8.12. 545 00:31:59,330 --> 00:32:00,650 These are some of the newer things. 546 00:32:00,650 --> 00:32:02,150 You notice how the green went away? 547 00:32:02,150 --> 00:32:03,070 That's crazy, right? 548 00:32:03,070 --> 00:32:05,850 The new stuff is way harder to get around than the old stuff. 549 00:32:05,850 --> 00:32:08,370 If you're on like 14.9, stay there. 550 00:32:09,030 --> 00:32:11,390 Anything after that is kind of like Wild West. 551 00:32:11,390 --> 00:32:12,230 Good luck. 552 00:32:13,710 --> 00:32:16,310 Effectively, PAC signs the pointers. 553 00:32:16,350 --> 00:32:17,270 So this is pointer signing. 554 00:32:17,270 --> 00:32:20,410 This is authenticating that the pointer is actually the pointer. 555 00:32:20,410 --> 00:32:25,090 And they're not really that important in local PrivEsc, to be honest with you. 556 00:32:25,090 --> 00:32:26,110 Privilege access never. 557 00:32:26,110 --> 00:32:26,970 This is another new one. 558 00:32:26,970 --> 00:32:27,350 PAN. 559 00:32:27,350 --> 00:32:29,510 I was like, man, that's interesting. 560 00:32:29,670 --> 00:32:32,610 This is something that is basically like SMAP. 561 00:32:32,610 --> 00:32:36,910 If you've ever messed around on an Intel world, so to speak. 562 00:32:37,150 --> 00:32:38,390 Supervisor mode. 563 00:32:38,510 --> 00:32:39,950 That's what SMAP is. 564 00:32:39,950 --> 00:32:41,650 Supervisor mode access prevention. 565 00:32:41,710 --> 00:32:44,750 And basically, this stops the kernel. 566 00:32:45,250 --> 00:32:51,030 This stops you being able to reach the kernel from user space, which is kind of like stopping LPE, which is what we really want. 567 00:32:51,030 --> 00:32:52,270 That's how you get root. 568 00:32:53,270 --> 00:32:53,910 PPL. 569 00:32:53,910 --> 00:32:54,950 Page Protection Layer. 570 00:32:55,070 --> 00:32:56,890 Again, introduced in 8.12. 571 00:32:58,070 --> 00:32:59,210 And these are the chipsets. 572 00:32:59,730 --> 00:33:03,210 Prevent user space code from being modified after verification is complete. 573 00:33:05,170 --> 00:33:06,170 Yeah, I'll leave it at that. 574 00:33:06,170 --> 00:33:07,330 You guys got a picture of it. 575 00:33:07,970 --> 00:33:09,670 And so now we're going to talk about the fun stuff. 576 00:33:09,670 --> 00:33:10,530 Stack Overflow. 577 00:33:10,570 --> 00:33:13,110 So remember, like, the OSCP used to be so easy. 578 00:33:13,110 --> 00:33:16,650 You could just, like, do a buffer overflow in, like, 30 minutes, pass it, be, like, good. 579 00:33:16,650 --> 00:33:18,670 Now they, like, made it all AD. 580 00:33:18,970 --> 00:33:24,650 Anyway, when it was the buffer overflow, it was really Stack Overflow. 581 00:33:24,650 --> 00:33:26,930 It's a type of memory corruption bug. 582 00:33:27,710 --> 00:33:33,930 Basically, there's, like, you know, I'm putting stuff on the stack without even checking it for bounds. 583 00:33:33,930 --> 00:33:39,410 Is it like, you know, like, can I fit a Tesla on a chair kind of deal, right? 584 00:33:39,410 --> 00:33:42,130 Like, you're not even seeing if you can fit in a spot. 585 00:33:42,130 --> 00:33:43,810 That's the best way I can put it. 586 00:33:44,930 --> 00:33:45,890 Example. 587 00:33:46,070 --> 00:33:47,550 This is a fun example. 588 00:33:47,690 --> 00:33:49,490 User gives me input, first name. 589 00:33:49,490 --> 00:33:51,030 First name is really, really long. 590 00:33:51,030 --> 00:33:52,730 I thought it was only going to be 10 characters. 591 00:33:52,790 --> 00:33:54,370 I don't know why. 592 00:33:54,850 --> 00:34:00,790 Program does not check if more than 10 characters are put into the program. 593 00:34:00,810 --> 00:34:03,870 And then what happens is that data then overflows onto the stack. 594 00:34:04,110 --> 00:34:09,770 And if you get, like, really tricky, you can actually take control over the runtime, right? 595 00:34:09,770 --> 00:34:11,630 Like, you can take control over the process. 596 00:34:11,630 --> 00:34:13,210 I'm pretty sure a lot of you know this. 597 00:34:14,350 --> 00:34:15,550 Heap overflow. 598 00:34:15,690 --> 00:34:18,210 Now, heap is used for dynamic memory allocation. 599 00:34:18,210 --> 00:34:21,470 This is something that you as a developer control of. 600 00:34:21,490 --> 00:34:30,710 You can actually store things on a heap that's supposed to live longer in the application's lifespan, right? 601 00:34:30,710 --> 00:34:32,570 So, like, what would you put in a heap? 602 00:34:32,750 --> 00:34:33,510 Tokens, right? 603 00:34:33,510 --> 00:34:35,390 Something that you'll need, right? 604 00:34:35,390 --> 00:34:37,230 When's the last time you had to sign into Instagram? 605 00:34:39,330 --> 00:34:46,950 Of course, there's a whole lot of other stuff that go into that, but nevertheless, heap memory is allocated and deallocated by you. 606 00:34:46,950 --> 00:34:48,610 It is by the programmer. 607 00:34:50,330 --> 00:34:55,130 Heap overflow is kind of like a buffer overflow, but it just takes advantage of the heap, right? 608 00:34:55,130 --> 00:35:07,930 So, like, there's this thing called kalloc, and they have zones, and basically it says that you're going to take objects that are similar sizes and put them near each other. 609 00:35:07,930 --> 00:35:10,570 Remember when we were little and they used to line us up short to tall? 610 00:35:10,570 --> 00:35:11,690 Kind of deal, right? 611 00:35:11,690 --> 00:35:19,230 So, like, data that is 120-something bits is always going to be next to other data that's 130-something bits up to 140-something bits. 612 00:35:19,230 --> 00:35:22,690 It'll just, like, kind of be near each other, like, organized, so to speak. 613 00:35:23,930 --> 00:35:36,910 When a heap overflow does occur, basically it'll overflow into the next memory region, which will be effectively the same size as the memory region that you're dealing with right now, right? 614 00:35:36,910 --> 00:35:49,310 So, basically it'll be, like, if you're overflowing something as 1,024 bytes, then you're probably going to overflow into something that's adjacent to it. 615 00:35:49,310 --> 00:35:51,630 It's also 1,024 bytes. 616 00:35:53,950 --> 00:35:57,270 Dynamic memory in malloc, right? 617 00:35:57,270 --> 00:35:59,270 In malloc, memory allocation. 618 00:35:59,270 --> 00:36:03,130 I know those bugs are, like, prevalent and people are still using it. 619 00:36:03,130 --> 00:36:09,910 And so, like, that's an example of, you know, dynamic memory being allocated onto the heap. 620 00:36:10,710 --> 00:36:11,670 Oh. 621 00:36:12,310 --> 00:36:13,450 Oh, I'm right. 622 00:36:13,470 --> 00:36:14,590 USector Free. 623 00:36:14,650 --> 00:36:15,610 UAF. 624 00:36:15,690 --> 00:36:20,830 I love that you guys are taking pictures because it's, like, you're going to be able to go back and just, like, you're getting value here. 625 00:36:20,830 --> 00:36:21,730 I'm happy. 626 00:36:22,310 --> 00:36:29,190 Memory corruption bugs, basically, it's another type of a memory corruption bug. 627 00:36:29,690 --> 00:36:42,750 Effectively, you're dealing with a runtime where the program has put some data into a register and then, like, it's died or killed itself or done whatever, but it didn't do anything with that data. 628 00:36:43,070 --> 00:36:44,590 That data's still sitting there. 629 00:36:44,590 --> 00:36:47,690 So, like, that becomes a USector Free thing. 630 00:36:47,750 --> 00:36:52,790 You may be able to take advantage of that for code execution or corrupting data. 631 00:36:53,010 --> 00:36:55,170 Just depends on what you're trying to do. 632 00:36:55,170 --> 00:36:56,330 Denial of service. 633 00:36:57,730 --> 00:36:58,610 Heapspring. 634 00:36:58,610 --> 00:37:02,190 This is one of the ways that a UAF bug is triggered. 635 00:37:02,190 --> 00:37:05,870 So, basically, this is the, quote-unquote, brute force. 636 00:37:05,870 --> 00:37:10,770 You're just, like, spraying onto the heap until you write over the actual freed area. 637 00:37:11,170 --> 00:37:19,670 Basically, the goal is when a UAF bug happens, the program's going to execute whatever data you put into that register because it's going back to it. 638 00:37:19,850 --> 00:37:24,930 So, that's a really kind of an interesting type of attack. 639 00:37:25,090 --> 00:37:27,910 And then we're going to get into rock chains. 640 00:37:27,910 --> 00:37:28,910 Got 20 minutes left. 641 00:37:28,910 --> 00:37:29,590 All right. 642 00:37:29,670 --> 00:37:30,550 ROP. 643 00:37:30,970 --> 00:37:32,970 You guys have heard ROP a few times already. 644 00:37:32,970 --> 00:37:35,510 Return Oriented Programming. 645 00:37:35,910 --> 00:37:36,710 I'll be honest. 646 00:37:36,710 --> 00:37:39,970 I really started to pick up ROP like in the last three years. 647 00:37:39,970 --> 00:37:41,490 Mostly on the Intel side. 648 00:37:41,490 --> 00:37:44,290 Kind of more recently on the iOS side. 649 00:37:45,530 --> 00:37:50,690 This is a way for us to be able to bypass that non-executable region of memory, right? 650 00:37:50,690 --> 00:37:51,450 The NX. 651 00:37:51,450 --> 00:37:55,170 So, effectively, you're trying to chain together a bunch of gadgets. 652 00:37:55,170 --> 00:37:57,270 And gadgets have certain memory addresses. 653 00:37:57,270 --> 00:37:59,470 So, you're going to pass a bunch of garbage data. 654 00:37:59,470 --> 00:38:05,130 X, Y, Z, 1, 2, 3, and then a memory address for the gadget that you're actually trying to take advantage of. 655 00:38:05,130 --> 00:38:07,030 And then a bunch of more garbage data. 656 00:38:08,250 --> 00:38:11,910 A, B, C, 1, 2, 3, and then the gadget 2 address. 657 00:38:12,330 --> 00:38:14,770 Typically, we don't use A, B, C, 1, 2, 3. 658 00:38:14,910 --> 00:38:15,910 We use A's. 659 00:38:15,910 --> 00:38:18,230 That was my demonstration there. 660 00:38:19,990 --> 00:38:26,030 Dynamic libraries allow for applications to be able to load code that's already... 661 00:38:27,430 --> 00:38:29,370 to load code into the address space. 662 00:38:29,370 --> 00:38:31,230 So, it's basically like a DLL. 663 00:38:31,750 --> 00:38:39,710 A dynamic link editor, or a DYOD, is basically native to the operating system of Mac. 664 00:38:39,710 --> 00:38:43,110 And, effectively, it's responsible for loading and linking. 665 00:38:44,530 --> 00:38:50,470 So, this is for loading and linking dynamic libraries while the application is running, which is very important. 666 00:38:50,570 --> 00:38:59,790 So, all of the public and private libraries have been combined into one big cache file that you can go get today on your laptop. 667 00:39:00,010 --> 00:39:02,730 And it's called DYOD Shared Cache. 668 00:39:03,230 --> 00:39:09,190 And to be able to go get that, let's take a picture of this, so you can go to that directory on your computer. 669 00:39:10,890 --> 00:39:13,290 This is how you're going to find your ROP gadgets. 670 00:39:13,610 --> 00:39:18,290 You're trying to figure out this really cool and unique... 671 00:39:18,870 --> 00:39:25,370 I don't know how unique, but just like a really specific instruction that you're looking for, that you're trying to get the application to actually do. 672 00:39:25,410 --> 00:39:27,870 So, you're going to leverage that's considered a gadget. 673 00:39:27,870 --> 00:39:29,410 So, you're going to leverage the ROP gadgets. 674 00:39:29,410 --> 00:39:40,670 To be able to find these gadgets, you're going to look at this Shared Cache and to be able to extract, you're going to be leveraging these two GitHub projects, a DYOD extractor and a Shared Cache extractor. 675 00:39:42,830 --> 00:39:46,770 So, when we're running these tools, because it's a tool, so don't just run it blindly. 676 00:39:46,770 --> 00:39:49,450 You want to ask yourself, is this going to meet my objective? 677 00:39:50,670 --> 00:39:52,470 What dilibs are loaded? 678 00:39:52,470 --> 00:39:54,050 What dynamic libraries are loaded? 679 00:39:54,110 --> 00:39:56,790 And what dynamic libraries should I be looking in? 680 00:39:56,990 --> 00:40:03,250 So, basically, to be able to find out what dynamic libraries are loaded in your program, you're going to need to debug it while it's running. 681 00:40:03,350 --> 00:40:09,850 And you're going to want to use LLDB and leverage ImageList. 682 00:40:09,890 --> 00:40:11,650 And from here, I'm showing a screenshot. 683 00:40:11,650 --> 00:40:18,910 I don't know if you can see it really well, but there's a screenshot here that kind of shows you the memory regions and the names of the dynamic libraries. 684 00:40:18,910 --> 00:40:25,890 Things like CommonCrypto or MacO or SystemC, right? 685 00:40:25,890 --> 00:40:26,990 Those sorts of things. 686 00:40:27,050 --> 00:40:28,910 So, the fun part. 687 00:40:29,230 --> 00:40:32,750 Finding gadgets in dynamic libraries. 688 00:40:32,770 --> 00:40:36,170 I leverage a tool called Ropper because I like the name of it. 689 00:40:36,170 --> 00:40:39,510 Like, seriously, this is just other tools, but Ropper is, like, one of my favorites. 690 00:40:39,730 --> 00:40:48,510 Basically, you just run it against a dynamic library that's been loaded into your target, and you'll be able to look for specific instructions or gadgets that match your objective. 691 00:40:48,510 --> 00:40:49,610 What are you trying to do? 692 00:40:49,610 --> 00:40:50,830 Are you trying to move? 693 00:40:51,310 --> 00:40:51,630 Alright? 694 00:40:51,630 --> 00:40:52,950 Are you trying to copy? 695 00:40:52,970 --> 00:40:54,450 Are you trying to do something else? 696 00:40:55,310 --> 00:41:05,670 Basically, all of the different areas in memory where that loads up will come, and it'll actually show you the instructions so that you can pick from the gadget that you want using that address. 697 00:41:05,670 --> 00:41:09,010 Remember, we talked about ABC123, gadget address. 698 00:41:09,010 --> 00:41:12,010 Well, right there in the red is your gadget address. 699 00:41:12,010 --> 00:41:13,310 Alright? 700 00:41:15,430 --> 00:41:16,890 Jop chains. 701 00:41:16,910 --> 00:41:22,510 Now, Jop, this is something that I'm really starting to get into in the last couple months. 702 00:41:22,930 --> 00:41:30,070 So, this is, like, the top of where we are right now for exploitation on the iOS systems. 703 00:41:30,070 --> 00:41:34,970 In real world exploitation, you probably won't find a full Rop chain. 704 00:41:35,010 --> 00:41:36,210 It just won't happen. 705 00:41:36,230 --> 00:41:39,650 But you will use Jop and Rop together. 706 00:41:39,790 --> 00:41:42,570 And so Jop is Jop-oriented programming. 707 00:41:42,570 --> 00:41:44,110 It's different than Rop. 708 00:41:44,610 --> 00:41:50,030 Rop's generally end in a return and Jop's will end in an indirect jump. 709 00:41:50,210 --> 00:41:54,650 So we're looking to be able to control the flow of the program. 710 00:41:54,830 --> 00:41:58,130 We want to make it do a dance for us. 711 00:41:58,330 --> 00:42:01,170 So, we don't really want to kill the program. 712 00:42:01,170 --> 00:42:02,090 We don't want it to return. 713 00:42:02,090 --> 00:42:02,790 We don't want it to end. 714 00:42:02,790 --> 00:42:05,210 We want it to branch to the next instruction. 715 00:42:05,890 --> 00:42:12,270 So that's where you kind of get that BRX1 is branching over to that register. 716 00:42:12,270 --> 00:42:14,890 Versus in Rop, where you're doing a return. 717 00:42:15,390 --> 00:42:22,350 But also, as we're branching over to X1, make sure that that register contains the address of the next instruction.