[00:08.740 --> 00:11.740] Are you guys sure you're in the right talk? [00:11.740 --> 00:15.320] I didn't expect this many people to show up for this talk. [00:15.320 --> 00:17.400] So thank you all for being here. [00:17.400 --> 00:18.400] It means a lot to me. [00:18.400 --> 00:19.860] I see some familiar faces. [00:20.240 --> 00:23.260] I probably see a lot of other screen names that I don't know. [00:23.260 --> 00:27.020] So like a pitcher, send a DM if you see me. [00:27.740 --> 00:28.640] My name is Xavier D. [00:28.640 --> 00:29.380] Johnson. [00:29.480 --> 00:31.960] I've been in tech since forever. [00:31.960 --> 00:36.600] Started programming in 2004, so I guess I've been around for a while. [00:36.600 --> 00:39.860] Basic, C-sharp, everything but Java. [00:41.160 --> 00:51.020] Today, mostly focused on reverse engineering, mobile penetration testing, and security research is kind of like the broad term. [00:51.020 --> 00:57.060] So today, I want to talk to you guys about, or you folks, about hacking iOS. [00:57.060 --> 01:00.060] It's kind of like this mystique around iOS. [01:00.060 --> 01:02.320] That's probably why a lot of you guys are here like, okay, what is he going to do? [01:02.320 --> 01:03.480] Is he going to show me something cool? [01:03.540 --> 01:04.240] I am. [01:04.240 --> 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. [01:11.440 --> 01:15.200] Fun fact about these slides, this is the last five years of my life. [01:15.420 --> 01:20.040] So if it sucks... [01:20.040 --> 01:20.680] Xavier D. [01:20.680 --> 01:22.900] Johnson, yes, the D means something. [01:23.320 --> 01:25.020] Everybody else calls me infinite. [01:25.840 --> 01:26.960] So hello. [01:27.320 --> 01:31.280] These slides will contain writer downers. [01:31.280 --> 01:32.740] Get your pen ready. [01:32.880 --> 01:35.760] 20 years of experience, wrote my first line of code in 2004. [01:35.820 --> 01:38.480] Been chasing that high ever since. [01:38.960 --> 01:40.900] High school, did FIRST Robotics. [01:41.040 --> 01:42.820] As a young adult, did web applications. [01:42.820 --> 01:45.400] Wrote a lot of shitty PHP apps, I won't lie. [01:45.740 --> 01:49.660] I thought I was going to be Mark Zuckerberg, but of course, I'm here with you, so I'm not. [01:49.660 --> 01:50.680] Because I'm loved. [01:52.520 --> 01:55.120] Today's agenda, we're going to keep it short and sweet. [01:55.120 --> 01:56.640] Just an hour worth of content. [01:57.440 --> 02:00.360] Intro to ARM Assembler. [02:00.600 --> 02:02.820] The differences between ARM and Intel. [02:02.880 --> 02:08.100] I'm pretty sure many of you, or some of you, know a thing or two about IA-32, Intel. [02:08.100 --> 02:10.400] So this should be like a fresher, right? [02:10.400 --> 02:12.440] You'll be up to speed by the end of it. [02:12.780 --> 02:14.680] iOS internals, which... [02:15.340 --> 02:17.740] I read three really thick books about this. [02:17.740 --> 02:19.780] So I'm hoping it comes through. [02:19.780 --> 02:22.500] And exploitation, which is my favorite, right? [02:22.500 --> 02:25.200] Everybody wants to do an exploit, so... [02:25.200 --> 02:27.500] Your slides are not in the presentation. [02:27.500 --> 02:28.440] Oh, God. [02:28.440 --> 02:29.320] I was wondering. [02:29.320 --> 02:31.060] It's on the presentation part? [02:31.060 --> 02:34.020] You can see it on the top left, but it's the presentation. [02:34.020 --> 02:35.040] At least it's not full screen. [02:35.040 --> 02:35.600] Oh. [02:35.960 --> 02:37.880] You can't see my presentation. [02:38.420 --> 02:40.100] Okay, give me one second. [02:44.530 --> 02:45.850] Technical difficulties. [02:48.190 --> 02:49.070] Nope. [02:49.090 --> 02:51.130] Do you have a button to swap it? [02:51.130 --> 02:53.830] I don't have a button to swap the display. [02:54.470 --> 02:57.450] It usually just works. [02:59.210 --> 03:00.070] Oh, yeah. [03:00.070 --> 03:01.170] It's up here, huh? [03:08.490 --> 03:10.170] There we go. [03:33.050 --> 03:33.810] Okay. [03:35.570 --> 03:37.750] I can't even see it anymore. [03:37.750 --> 03:39.010] It's moved all the way over. [03:41.610 --> 03:42.290] That's better? [03:42.290 --> 03:43.330] I can't control it. [03:43.870 --> 03:44.970] I can't control it. [03:49.150 --> 03:50.910] Do we have speaker ops? [03:51.490 --> 03:53.390] Somebody here to help with the tech part of this? [03:53.390 --> 03:54.610] I just plugged into a USB. [03:54.610 --> 03:55.710] I have no idea. [03:59.710 --> 04:01.770] I can't see what you guys see on that screen. [04:01.770 --> 04:02.850] I think it's the problem. [04:04.770 --> 04:07.090] Yeah, I want to do it down there. [04:07.750 --> 04:08.550] Let's see. [04:12.010 --> 04:14.230] If I bring it, it's cable. [04:18.510 --> 04:19.310] Speaker ops. [04:19.310 --> 04:20.110] Do we have speaker ops? [04:20.110 --> 04:20.490] No? [04:20.490 --> 04:20.970] All right, cool. [04:20.970 --> 04:22.230] I guess I'll just... [04:23.390 --> 04:24.630] do it live. [04:28.590 --> 04:29.950] Can you guys see anything yet? [04:32.370 --> 04:33.490] What can you guys see? [04:33.490 --> 04:34.390] Because I don't have a... [04:39.850 --> 04:41.030] You see my mouse? [04:41.130 --> 04:41.850] All right, fuck it. [04:41.850 --> 04:42.870] We're going to do it like this then. [04:43.250 --> 04:44.970] We're going to do it like this. [04:45.470 --> 04:46.310] Presenter view. [04:46.670 --> 04:47.230] Presenter view? [04:47.230 --> 04:47.770] Yeah. [04:53.850 --> 04:55.170] It doesn't work. [04:55.170 --> 04:55.990] It's not working. [04:56.710 --> 04:57.550] Play from slide? [04:57.670 --> 04:58.670] Watch this. [04:58.950 --> 04:59.890] There you go. [05:00.310 --> 05:02.590] Well, now we're in it together. [05:05.390 --> 05:07.790] So, we're going to run it like this. [05:10.770 --> 05:11.910] I don't mind. [05:11.910 --> 05:12.510] You guys don't mind. [05:12.510 --> 05:12.890] I don't mind. [05:12.890 --> 05:13.630] Let's get it. [05:14.910 --> 05:16.430] We're going to jump straight into ARM. [05:17.490 --> 05:18.650] Let's get to it. [05:19.050 --> 05:19.850] Fundamentals. [05:20.370 --> 05:21.590] Let's get it going. [05:21.590 --> 05:25.630] So, the difference between ARM and Intel Assembler is really three key details. [05:25.630 --> 05:34.570] ARM has 31 general purpose registers, which the registers are kind of like how data moves in and out of RAM. [05:34.570 --> 05:38.930] How the computer actually is managing its data flow. [05:39.310 --> 05:42.450] Intel x86 has 16 general purpose registers. [05:42.690 --> 05:45.970] ARM is based on RISC, which is supposed to be faster. [05:46.150 --> 05:47.190] Typically, it is faster. [05:47.190 --> 05:49.930] You'll find these kind of things on mobile phones. [05:49.930 --> 05:50.870] IOT. [05:50.870 --> 05:52.490] ARM is kind of like the next thing. [05:52.490 --> 05:53.170] Satellites. [05:53.170 --> 05:53.650] Who knows? [05:53.650 --> 05:54.770] Let's ask Elon. [05:55.250 --> 05:59.210] ARM 64 was around since iPhone 5S. [05:59.270 --> 06:00.810] Before then, it was 32. [06:01.050 --> 06:02.630] 32-bit ARM. [06:02.810 --> 06:06.170] Just a bit of a higher overview of the registers. [06:06.790 --> 06:10.550] Again, small area inside the CPU that stores a specific value. [06:10.890 --> 06:16.710] For 64-bit, registers X0 through X30 represent the 31 available registers. [06:16.710 --> 06:19.130] For 32-bit, it's W0 through 30. [06:19.810 --> 06:26.690] These are some of the points in which the registers actually identify, so to speak. [06:26.690 --> 06:29.610] The frame pointer is always going to be X29. [06:29.790 --> 06:31.710] Link register is always going to be X30. [06:32.010 --> 06:33.850] Program counter is always going to be PC. [06:33.850 --> 06:35.550] You don't have to worry about those sorts of things. [06:36.270 --> 06:38.590] 0 through 28 are general purpose. [06:38.590 --> 06:39.690] This is holding your data. [06:39.690 --> 06:43.090] This is where the data is actually flowing through the application. [06:45.210 --> 06:47.310] This data can be volatile or non-volatile. [06:47.310 --> 06:52.070] A volatile register basically means that it does not persist through the end of a function. [06:52.350 --> 06:54.030] It is effectively not a global. [06:54.030 --> 06:56.590] It dies once the process is done. [06:56.690 --> 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. [07:06.190 --> 07:11.850] The first 19 registers are volatile and the rest are non-volatile. [07:13.130 --> 07:15.050] There's three types of instructions. [07:15.110 --> 07:20.010] When we talk about code, what we really are talking about is a bunch of conditions. [07:20.010 --> 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. [07:28.830 --> 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. [07:42.430 --> 07:43.450] Those conditions. [07:43.470 --> 07:45.690] What I like to call AI Hadouken. [07:46.890 --> 07:52.590] So the if-else statements in ARM64 use branch instructions. [07:52.590 --> 08:00.330] So branch instructions basically are controlling the flow of the application kind of in, you know, if-else. [08:00.770 --> 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. [08:12.050 --> 08:14.490] And then we talk about calling conventions. [08:14.490 --> 08:22.250] Now, calling convention is how data is actually put into functions. [08:22.250 --> 08:31.910] So like, effectively for ARM64 you are looking at arguments stored in between the first eight registers. [08:31.910 --> 08:34.250] So X0 to X7. [08:34.490 --> 08:38.390] And subroutines are typically stored in X0. [08:38.390 --> 08:41.550] And all of this stuff will matter as we move into exploitation. [08:41.550 --> 08:43.490] This is kind of fundamental groundwork. [08:44.490 --> 08:53.530] Returns addresses are in X30, so we'll talk about that for ROP and JOP return-oriented programming. [08:54.050 --> 08:58.150] And the way that the stack grows is actually important. [08:58.430 --> 09:01.550] Stack frame actually grows downward in memory. [09:01.550 --> 09:04.570] Sometimes you'll have things grow upward in memory. [09:05.910 --> 09:07.030] That's pretty interesting. [09:07.030 --> 09:09.370] It's also stack frame 16 bytes. [09:10.890 --> 09:12.630] A few things there. [09:12.810 --> 09:18.110] A function in ARM assembler contains three different components. [09:18.110 --> 09:20.430] A prologue or the start. [09:20.770 --> 09:25.690] The body, which actually does anything with the data or the actual logic. [09:25.690 --> 09:27.830] And an epilogue, which is kind of ending the function. [09:27.830 --> 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. [09:33.250 --> 09:34.970] Hopefully not a negative one. [09:37.130 --> 09:39.050] The prologue is just the first few lines. [09:39.050 --> 09:42.050] This is an example of kind of like the hello world prologue. [09:42.210 --> 09:44.890] Sub SP and SP. [09:45.170 --> 09:50.510] Basically putting this into putting 20 into SP. [09:50.510 --> 09:54.050] It starts the prologue and it's making space on the stack. [09:54.070 --> 09:59.730] And then it's saving the frame pointer and link register to the stack. [09:59.730 --> 10:03.430] And then calculating a new frame pointer to the stack, etc. [10:03.430 --> 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. [10:11.430 --> 10:15.790] This, when you're looking at your function, will tell you what is the start of a function. [10:15.870 --> 10:19.750] So this is very important when you're just handed a binary, go here figure it out. [10:19.750 --> 10:21.750] You're like, I don't really know where functions start. [10:21.750 --> 10:25.150] This will always be kind of your indicator of the beginning of a function. [10:25.150 --> 10:26.050] Always looks the same. [10:27.870 --> 10:31.070] Epilogue is to restore the program to its original state. [10:31.070 --> 10:37.010] Basically, put the program back to what it was before the last function was running. [10:37.010 --> 10:39.930] So this is kind of a restorative thing. [10:40.690 --> 10:43.550] So now I'm moving fast, because there's a lot of content here. [10:43.550 --> 10:44.890] So we're going to jump into syscalls. [10:45.310 --> 10:46.250] Syscalls are fun. [10:46.250 --> 10:46.970] I'm pretty sure all of you... [10:46.970 --> 10:48.930] who out here knows what syscalls are? [10:49.050 --> 10:49.950] That's a lot of hands. [10:49.950 --> 10:50.270] Cool. [10:50.270 --> 10:51.390] So I'm going to keep a high level . [10:51.390 --> 10:52.330] System calls. [10:52.330 --> 10:56.690] System calls basically act as the interface between user space and kernel space. [10:56.690 --> 10:58.410] So that's the fun... [10:58.410 --> 11:00.330] that's the fun part, right? [11:00.330 --> 11:05.410] Figuring out how to be able to manipulate or take advantage of these system calls. [11:05.570 --> 11:09.770] Potentially break them or leverage them in your exploitation. [11:10.750 --> 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. [11:17.190 --> 11:19.010] So think about like an fopen. [11:19.010 --> 11:20.190] That's standard. [11:20.190 --> 11:21.890] Or a chmod . [11:21.890 --> 11:23.150] That's standard. [11:23.150 --> 11:24.270] That's everywhere. [11:24.270 --> 11:27.290] Those are a part of the Linux syscalls. [11:27.290 --> 11:28.610] They're kind of Unix syscalls. [11:28.610 --> 11:32.370] They're a little bit of everywhere that leverages Nix. [11:33.810 --> 11:35.810] Typical syscall flow, right? [11:35.810 --> 11:38.490] A function will make a call to something like fopen. [11:38.490 --> 11:43.130] The user will, you know, leverage syscalls... [11:43.130 --> 11:44.170] the syscall number. [11:44.170 --> 11:45.730] So every syscall has its own number. [11:45.730 --> 11:47.730] And it will leverage the syscall number. [11:47.810 --> 11:56.110] And the kernel will then execute, request that service, and then actually return control back to user mode. [11:56.110 --> 11:59.510] So you don't get to do anything as a user, or from userland. [11:59.830 --> 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. [12:07.630 --> 12:12.190] We all know why we don't want to run user code in kernel mode, right? [12:12.870 --> 12:16.150] Of course we want to run user code in kernel mode, right? [12:16.210 --> 12:17.970] That's the whole point. [12:17.970 --> 12:18.930] That's privilege escalation. [12:18.930 --> 12:20.290] That's the zero-day part. [12:21.470 --> 12:26.770] So yeah, syscalls all have a correlating system number, a syscall number. [12:27.430 --> 12:29.110] Memory management. [12:29.650 --> 12:33.210] So memory management is very important when you get down to this level. [12:33.210 --> 12:38.450] Loading, storing, branching, arithmetic, all of that is happening in the memory, leveraging those registers. [12:39.170 --> 12:41.550] ARM operates on a load store. [12:41.670 --> 12:49.430] So basically, memory can only be accessed and manipulated from specific load and store instructions. [12:49.430 --> 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. [12:58.470 --> 13:00.030] That's the way I can explain it. [13:00.210 --> 13:06.210] To perform load and store memory instructions, you do LDRs, LDPs, STPs. [13:06.210 --> 13:07.470] The meanings are there. [13:07.470 --> 13:08.830] I won't go into it. [13:08.830 --> 13:14.770] Again, if you want to know more about this, I suggest you go and actually read the ARM documentation. [13:15.030 --> 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. [13:21.390 --> 13:23.510] So you might as well get used to it. [13:25.450 --> 13:29.570] These instructions, they handle different sizes of data, right? [13:29.570 --> 13:32.990] So bytes or 8 bits all the way up to double words at 64 bit. [13:33.250 --> 13:33.970] ARM64. [13:35.070 --> 13:36.010] All right. [13:36.470 --> 13:37.590] Did I lose anybody? [13:37.590 --> 13:38.950] I only lost like two or three people. [13:38.950 --> 13:40.510] So I feel like I'm doing good. [13:40.530 --> 13:41.550] I feel like I'm doing good. [13:41.550 --> 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. [13:47.070 --> 13:48.650] The rest of it is going to be pretty fun. [13:48.650 --> 13:50.170] So I'm jumping into internals. [13:50.570 --> 13:52.350] Now, internals... [13:54.330 --> 13:59.270] Well, I don't know if you guys know, like, iOS is kind of open source, but kind of not, right? [13:59.270 --> 14:01.110] Like, part of the kernel is on GitHub. [14:01.110 --> 14:03.750] You can just go and like look at it and fucks around with it. [14:03.750 --> 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. [14:10.090 --> 14:13.250] It's like ah, I don't really know exactly how it works underneath. [14:13.250 --> 14:15.470] And there's no like real clear cut documentation. [14:15.490 --> 14:21.890] Unfortunately, Pavel, the guy who wrote the Windows internals books, didn't write them for iOS. [14:21.890 --> 14:28.670] But a really cool guy named Jonathan Levin wrote a series of books which is called the Moxel Trilogy. [14:28.670 --> 14:35.690] Effectively, it's the user space, kernel space, and security internals, well known internals book. [14:35.710 --> 14:38.550] You guys should go buy it and support. [14:39.630 --> 14:42.250] This is where I got a lot of this information from. [14:42.530 --> 14:43.450] Jailbreaking. [14:43.790 --> 14:45.650] So that's like a prior requirement. [14:45.650 --> 14:46.950] Oh, I got a question? [14:48.750 --> 14:50.970] M-O-X-I-L [14:57.850 --> 15:06.650] M-O-X-I-L M-O-X-I-L M-O-X-I-L We talk about a walled garden. [15:07.190 --> 15:09.690] How many people here have jailbroken an iPhone? [15:09.910 --> 15:12.470] I got a lot of jailbreakers in here. [15:12.470 --> 15:13.050] Okay. [15:13.050 --> 15:13.550] Okay. [15:13.550 --> 15:15.270] So this is going to be a really boring part. [15:15.310 --> 15:19.150] Long story short, this is how you're able to get root on iPhone. [15:19.150 --> 15:20.650] We call it jailbreaking. [15:20.890 --> 15:24.070] It gives you write access to all the partitions. [15:24.070 --> 15:25.270] Basically, you can do what you want. [15:29.070 --> 15:38.350] Historically, people have leveraged kernel patching to bypass code signing, which is a control to slow you down. [15:38.350 --> 15:40.050] So that's one bypass. [15:40.370 --> 15:45.370] Modifying the AFC service for root access is another methodology. [15:45.630 --> 15:47.530] AFC is the Apple File Conduit. [15:47.530 --> 15:52.630] It's basically the way that all of the Apple devices manage their file system. [15:52.930 --> 15:55.150] And there's a few different types of jailbreaks. [15:55.330 --> 15:59.290] You've got untethered, you've got tethered, you've got semi-untethered, you've got semi-tethered. [15:59.290 --> 16:02.310] So some of this stuff you're like, okay, well, you guys already know. [16:02.330 --> 16:05.410] But for the people at home, you're probably wondering, well, what does this mean? [16:05.430 --> 16:11.470] Tethered means that it only persists for one boot and it has to be restarted. [16:11.950 --> 16:14.410] The device will no longer have the jailbreak. [16:14.410 --> 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. [16:21.370 --> 16:23.990] And it may not even really fully reboot. [16:23.990 --> 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. [16:28.450 --> 16:32.050] Which is a whole other fun topic, which I think is a talk that I'll do next year. [16:32.050 --> 16:36.430] How do you get around bricking your jailbreaking devices? [16:37.350 --> 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... [16:43.850 --> 16:46.150] that's like next-level golden status. [16:46.150 --> 16:50.290] I don't think any of the current jailbreaks that are actually useful you can actually do that with. [16:51.110 --> 16:55.810] Semi-tethered means that the jailbreak won't persist when you restart it, but at least you can reboot it. [16:55.810 --> 16:58.030] And that's the majority of the world right now. [16:58.030 --> 16:59.390] It's kind of semi-tethered. [16:59.410 --> 17:02.650] Uncover is a semi-tethered jailbreak. [17:02.650 --> 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. [17:13.150 --> 17:17.050] So like after it boots up, it'll just patch. [17:17.070 --> 17:18.710] I leverage uncover. [17:18.710 --> 17:19.890] If you don't, you should. [17:19.890 --> 17:20.650] It's pretty cool. [17:20.650 --> 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. [17:27.030 --> 17:31.310] So moving over into APFS, Apple File System, right? [17:31.310 --> 17:33.470] iOS leverages APFS. [17:33.490 --> 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. [17:53.690 --> 17:56.350] And so effectively, the devices became faster. [17:57.210 --> 18:03.450] Of course, we want to take advantage of sweet, sweet SSD speeds, so APFS is supposed to lean into that. [18:03.570 --> 18:07.610] And as well as full disk encryption and file encryption. [18:07.810 --> 18:10.350] So if you want to learn more about that, check out iPhone Wiki. [18:10.370 --> 18:11.830] It's a really great resource. [18:13.690 --> 18:14.710] File system, right? [18:14.710 --> 18:17.890] What makes the iOS file system different than any other file system? [18:17.890 --> 18:19.470] Here's the real diff for you. [18:20.190 --> 18:25.490] A regular file system, a typical Linux file system will have bin, boot, dev, blah, blah, blah, user bar, right? [18:25.490 --> 18:35.390] Directories that are in iOS, macOS that are specific, slash applications, cores, developer, library, system, user, private. [18:35.390 --> 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. [18:46.770 --> 18:51.030] Apps do not directly communicate with the hardware. [18:51.030 --> 18:52.450] There is a sandbox. [18:52.850 --> 18:55.410] There is different layers of the sandbox. [18:55.410 --> 19:00.170] You have the touch layer, the media layer, the services layer, and the actual core OS. [19:00.370 --> 19:04.150] So Cocoa Touch is kind of the infrastructure for all the applications. [19:04.150 --> 19:05.890] It's the way that you actually touch the screen. [19:05.890 --> 19:07.050] It's this touch, right? [19:07.130 --> 19:11.090] The media layer allows us to be able to deal with all the AV media. [19:11.090 --> 19:12.110] Kind of makes sense. [19:12.110 --> 19:15.210] Core services is kind of like that, the hardcore stuff. [19:15.210 --> 19:19.390] Network, location, all the stuff you really want to leak out. [19:19.390 --> 19:23.830] Things that are pertinent to your device specifically. [19:24.170 --> 19:28.470] And the core OS is kind of like, I'll call it the kernel for lack of a good term, right? [19:28.470 --> 19:36.550] It's the actual base operating system that kind of like does things that the applications above them is asking for. [19:37.430 --> 19:40.110] So I'm going to jump right into static analysis. [19:40.410 --> 19:42.130] This is really high level. [19:42.130 --> 19:44.390] Everybody is going to have different methodologies. [19:44.890 --> 19:47.570] Some people will use scanning tools. [19:47.570 --> 19:51.730] Some people kind of get old school like me and just kind of start to rip apart stuff. [19:52.610 --> 20:01.570] Joker and JTool used to be Otool are also really good options for this as well. [20:01.650 --> 20:05.230] But I'm going to talk mostly about Otool and then in page stuff. [20:05.230 --> 20:08.110] Just kind of like briefly giving you an understanding. [20:08.850 --> 20:10.850] IPA file is basically a .zip. [20:10.850 --> 20:11.830] Funny, funny. [20:11.830 --> 20:14.350] You can actually turn a .zip to a .ipa. [20:14.410 --> 20:17.370] Won't install, but it will be an IPA file. [20:17.750 --> 20:19.270] Works on my machine. [20:20.630 --> 20:24.890] Basically, you unzip an IPA file and you will be able to find all of the resources. [20:24.950 --> 20:28.270] In those resources you will be able to find a folder called payload. [20:28.470 --> 20:29.970] That will actually have binaries in it. [20:30.030 --> 20:33.650] Frameworks, shared libraries, dynamic libraries, those sorts of things. [20:33.650 --> 20:37.230] So like statically linked things that are in the application. [20:37.950 --> 20:41.050] Tools used for this, again Otool and then in page stuff. [20:41.650 --> 20:44.170] Otool, widely available in Xcode. [20:44.170 --> 20:45.830] If you install Xcode, it's there. [20:45.970 --> 20:49.650] We use the check for depreciated APIs like string copy. [20:50.830 --> 20:53.530] And to check to see if DRM is enabled. [20:53.530 --> 20:55.190] Is the app encrypted? [20:55.490 --> 20:57.170] Alright, DRM. [20:57.370 --> 20:59.050] That's a fun part of the talk. [20:59.890 --> 21:03.830] Encryption is one of the ways that Apple... that's one of the walls. [21:03.830 --> 21:05.690] I'll call it multiple walls now. [21:05.690 --> 21:07.350] We're dealing with defense in depth. [21:07.350 --> 21:08.810] We're taking a layered approach. [21:09.750 --> 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. [21:22.690 --> 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. [21:32.090 --> 21:37.890] And if ASLR is enabled, address space layout randomization. [21:37.950 --> 21:40.690] So this is an example of me running Otool. [21:41.370 --> 21:44.870] These four down here are kind of like some easy, fast wins. [21:44.870 --> 21:47.090] You want to go on GitHub and just start looking for this stuff? [21:47.090 --> 21:47.590] There you go. [21:47.610 --> 21:49.830] Memcpy, Stringcopy, Stringland. [21:49.830 --> 21:52.210] These are like quick, fast, dirty. [21:52.210 --> 21:57.050] I'm pretty sure you guys could tell me even some more, but I'll leave that for another talk. [21:58.190 --> 21:59.110] A&M. [21:59.190 --> 22:01.050] So this displays symbols. [22:01.610 --> 22:03.290] Does everybody know what symbols are? [22:03.850 --> 22:04.510] Okay. [22:04.510 --> 22:06.330] I see way less hands. [22:06.330 --> 22:06.650] All right. [22:07.130 --> 22:07.450] Symbols. [22:07.450 --> 22:08.110] Oh, there they go. [22:08.110 --> 22:08.790] Another popping up. [22:08.790 --> 22:10.150] They're like, no, no, don't tell me about symbols. [22:10.150 --> 22:10.430] Screw it. [22:10.430 --> 22:11.470] You're too late now. [22:12.830 --> 22:16.170] Symbols is basically like how functions are named. [22:16.430 --> 22:21.110] And you can either include them or obfuscate them or not include them entirely. [22:21.490 --> 22:26.710] But this, for me as a reverse engineer, is a good way for me to understand how the application is working. [22:27.010 --> 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. [22:35.070 --> 22:38.050] Like, for example, do I have jailbreak detection? [22:38.050 --> 22:41.470] Well, jailbreak's probably in the name of one of the symbols. [22:41.810 --> 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. [22:49.690 --> 22:53.290] Usually it'll come down to 1 or 0. [22:53.290 --> 22:54.290] It's true or false. [22:54.290 --> 22:55.350] Is it jailbroken? [22:55.350 --> 22:56.070] True? [22:56.170 --> 22:59.350] Okay, well, let's change that to always be false. [22:59.390 --> 23:03.430] Even though it's jailbroken, it's just patched application it'll return false always. [23:04.150 --> 23:05.910] Nm, right? [23:06.190 --> 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. [23:18.650 --> 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. [23:31.350 --> 23:35.390] So when you go into that payload folder, there'll be the name of the application. [23:35.390 --> 23:37.630] Let's say the application is HackerTracker. [23:37.850 --> 23:42.750] If you go and you look at the HackerTracker application, you'll be able to unzip it, right? [23:42.750 --> 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. [23:47.950 --> 23:49.990] That's what you really want to be pulling nm to. [23:49.990 --> 23:53.430] That'll show you if they've stripped symbols or not, and if they haven't, have fun. [23:55.270 --> 23:55.810] PageStuff. [23:55.870 --> 23:59.830] Basically, it lets you review the structure of a mock O file. [23:59.830 --> 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. [24:09.030 --> 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. [24:21.950 --> 24:23.630] I'm a Geedra guy, personally. [24:23.830 --> 24:26.150] If it's good enough for you, it's good enough for me. [24:26.150 --> 24:26.890] Question? [24:27.130 --> 24:27.830] Yeah. [24:27.970 --> 24:29.590] I have an Apple question. [24:29.850 --> 24:33.690] Where do you get information about the actual format? [24:34.230 --> 24:35.650] The macro format? [24:35.650 --> 24:35.950] Yeah. [24:35.950 --> 24:40.270] Apple has really good documentation about that sort of stuff. [24:40.270 --> 24:43.370] So I've been able to find that on my blog post, but... [24:43.370 --> 24:45.050] Not on their public? [24:45.570 --> 24:46.130] Hmm. [24:46.130 --> 24:48.050] Another good space is to read that book. [24:48.050 --> 24:51.990] That's where I got the information from myself, because I was too lazy to read the documentation. [24:53.090 --> 24:55.390] So that book by Jonathan Levin, check it out. [24:55.390 --> 24:56.070] It's a really good book. [24:56.070 --> 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. [25:02.570 --> 25:02.950] All right. [25:02.950 --> 25:04.130] Here's the meat of the talk. [25:04.630 --> 25:05.310] Exploitation. [25:05.310 --> 25:08.690] I'll probably get you guys out of here like 15 minutes early, because I got an advanced class. [25:08.690 --> 25:09.830] I like this. [25:10.930 --> 25:11.990] Everybody's phone's coming out. [25:12.030 --> 25:12.710] Exploitation time. [25:12.710 --> 25:13.350] All right. [25:13.790 --> 25:15.650] First, we're going to talk about mitigations. [25:15.650 --> 25:17.730] We already talked about one, which is code signing. [25:18.510 --> 25:21.790] Basically, just make sure that the code is from a known source. [25:22.270 --> 25:28.070] The components of code signing will be certificates, bundle IDs, provisioning profiles. [25:28.150 --> 25:34.570] And so a provisioning profile is basically like a file that has the bundle ID and what cert to use. [25:34.570 --> 25:37.910] So that's how those three kind of basically come together. [25:37.910 --> 25:38.710] You need a certificate. [25:38.710 --> 25:39.710] You need a bundle. [25:39.750 --> 25:40.950] Those are kind of like prereqs. [25:40.950 --> 25:45.290] And you need a provisioning profile that actually leverages those certs and bundle IDs. [25:45.770 --> 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. [25:55.650 --> 25:58.530] Core trust bugs are no longer around, unfortunately. [25:58.850 --> 26:02.290] It was added in iOS 12 to prevent fake signing, right? [26:02.290 --> 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. [26:09.870 --> 26:15.570] Jailbroken phones still require signing, fun fact, but you can fake sign on a jailbroken phone. [26:15.570 --> 26:18.350] So non-jailbroken phone, no more fake signing. [26:18.350 --> 26:21.570] Real jailbroken phone, you can't co-sign. [26:21.570 --> 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. [26:33.150 --> 26:35.010] AltServer and AltStore. [26:35.070 --> 26:41.890] This really, really good and easy way to be able to get decrypted applications siloed onto your iPhone. [26:41.890 --> 26:47.790] Because, you know, I believe there was some legislation that came out that said Apple had to allow you to silo. [26:47.830 --> 26:48.710] Question? [26:50.630 --> 26:53.630] AltStore, A-L-T and AltServer. [26:55.390 --> 26:58.930] The first one, when you look at the website, there's two options. [26:58.930 --> 27:00.970] One option is like asking you to pay money. [27:00.970 --> 27:03.410] That's only for the people in the EU. [27:03.510 --> 27:07.630] I think they were like the main drivers behind like the legislation being changed. [27:07.630 --> 27:10.990] Same way we got USB-C on iPhone, basically. [27:10.990 --> 27:13.930] So they charge over there for some reason. [27:13.930 --> 27:14.870] But in the U.S., U.S. [27:14.870 --> 27:16.350] servers are totally fine. [27:16.350 --> 27:19.830] Basically what it does is it spins up a server on your phone. [27:19.890 --> 27:21.530] You tether your phone. [27:21.530 --> 27:25.190] Excuse me, it spins up a server on your MacBook. [27:25.550 --> 27:26.950] You plug up your phone. [27:26.950 --> 27:30.330] You have the AltStore on your phone. [27:30.330 --> 27:36.710] And then you're able to sideload applications directly from your computer to your phone with it being signed. [27:36.710 --> 27:38.670] So it manages that signing for you. [27:38.670 --> 27:40.610] What do you mean by known source? [27:40.610 --> 27:42.050] Is it an Apple signing? [27:42.990 --> 27:44.310] Say that one more time. [27:44.310 --> 27:46.250] Or maybe it's both signing. [27:48.410 --> 27:49.850] Oh, yeah. [27:49.850 --> 27:54.710] So known source would be like Instagram, Facebook, TikTok. [27:54.710 --> 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. [28:05.550 --> 28:13.730] So it's kind of like think about it like a way to remove tampering. [28:13.730 --> 28:18.910] I can take an Instagram application and I can decrypt it. [28:18.910 --> 28:20.770] Then I can re-sign it with my cert. [28:21.290 --> 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. [28:28.490 --> 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. [28:41.570 --> 28:43.430] And they'll know of my key. [28:43.430 --> 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. [28:49.590 --> 28:51.350] Your certificate trust store. [28:51.550 --> 28:52.230] Question? [28:52.950 --> 28:53.830] Gotcha. [28:54.530 --> 28:57.210] That means I'm doing good for you preemptively answering questions. [28:57.210 --> 28:58.070] Come on now. [29:00.370 --> 29:01.630] Read the green. [29:01.630 --> 29:02.970] The green is fun. [29:02.970 --> 29:04.570] Bypass, bypass, bypass. [29:04.570 --> 29:07.050] I don't want to tell you how to bypass it. [29:07.050 --> 29:08.890] DEP, data execution prevention. [29:08.890 --> 29:10.150] This is nothing new. [29:10.150 --> 29:11.350] This has been around. [29:11.350 --> 29:18.530] Prevents code from being executed in memory portions that are marked as non-executable in X. [29:18.710 --> 29:20.310] The letter N, the letter X. [29:21.750 --> 29:24.910] To bypass this, we use ROP. [29:25.950 --> 29:29.830] Return Oriented Programming. [29:29.990 --> 29:31.370] Then you have ASLR. [29:31.370 --> 29:34.350] Randomizes the location where executables are loaded into memory. [29:34.350 --> 29:39.970] Fun fact, without ASLR, it is predetermined where your start and end is for your binary. [29:39.970 --> 29:42.330] And you can actually see that statically. [29:42.330 --> 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. [29:50.070 --> 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. [30:01.030 --> 30:08.330] You'll be able to hard-code memory addresses because it always loads between 0x1000 and 0x2000. [30:08.790 --> 30:13.290] All of the logic will always happen in that region of memory. [30:13.590 --> 30:16.710] ASLR will make it so that you no longer have that. [30:16.950 --> 30:21.270] It'll load in 0x3000, it'll load in 0x10000. [30:22.370 --> 30:23.050] KSLR. [30:23.050 --> 30:25.730] This is the kernel address-based layout randomization. [30:25.730 --> 30:26.690] Oh, sorry. [30:27.590 --> 30:28.250] ASLR. [30:28.250 --> 30:29.630] How to bypass. [30:29.770 --> 30:37.570] We leverage information leak bugs, which I'll get into later, or we brute force, and I'll talk about that. [30:38.910 --> 30:43.510] Kernel address-based layout randomization prevents attackers from being able to view kernel data. [30:43.610 --> 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. [30:55.250 --> 30:56.930] This is a really good protection. [30:57.030 --> 31:01.330] Again, one good way to do this is leveraging information leaks. [31:01.330 --> 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. [31:07.350 --> 31:10.510] And you're going to have to take advantage of some other vulnerabilities to get there. [31:11.910 --> 31:12.870] Mitigations. [31:13.250 --> 31:14.570] I love mitigations. [31:14.570 --> 31:15.630] There's so many of them. [31:15.630 --> 31:18.490] There's some that's not even here, believe it or not. [31:18.490 --> 31:19.950] Kernel patch protection. [31:20.070 --> 31:21.990] Kernel text read-only region. [31:22.790 --> 31:23.590] KTRR. [31:23.590 --> 31:24.230] This? [31:24.230 --> 31:25.510] That was new to me. [31:25.730 --> 31:28.250] I don't do a lot of kernel research. [31:28.250 --> 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. [31:32.950 --> 31:38.030] But KTRR basically is kind of newer. [31:38.030 --> 31:39.430] It's been around since 8.10. [31:41.750 --> 31:43.290] It locks down the MMU. [31:43.290 --> 31:48.790] This is the memory management unit, which is a whole separate chip on the board. [31:50.550 --> 31:51.950] So I'll leave it at that. [31:54.150 --> 31:54.950] Pack. [31:55.890 --> 31:57.910] Pointer authentication codes. [31:58.190 --> 31:59.330] Introduced in 8.12. [31:59.330 --> 32:00.650] These are some of the newer things. [32:00.650 --> 32:02.150] You notice how the green went away? [32:02.150 --> 32:03.070] That's crazy, right? [32:03.070 --> 32:05.850] The new stuff is way harder to get around than the old stuff. [32:05.850 --> 32:08.370] If you're on like 14.9, stay there. [32:09.030 --> 32:11.390] Anything after that is kind of like Wild West. [32:11.390 --> 32:12.230] Good luck. [32:13.710 --> 32:16.310] Effectively, PAC signs the pointers. [32:16.350 --> 32:17.270] So this is pointer signing. [32:17.270 --> 32:20.410] This is authenticating that the pointer is actually the pointer. [32:20.410 --> 32:25.090] And they're not really that important in local PrivEsc, to be honest with you. [32:25.090 --> 32:26.110] Privilege access never. [32:26.110 --> 32:26.970] This is another new one. [32:26.970 --> 32:27.350] PAN. [32:27.350 --> 32:29.510] I was like, man, that's interesting. [32:29.670 --> 32:32.610] This is something that is basically like SMAP. [32:32.610 --> 32:36.910] If you've ever messed around on an Intel world, so to speak. [32:37.150 --> 32:38.390] Supervisor mode. [32:38.510 --> 32:39.950] That's what SMAP is. [32:39.950 --> 32:41.650] Supervisor mode access prevention. [32:41.710 --> 32:44.750] And basically, this stops the kernel. [32:45.250 --> 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. [32:51.030 --> 32:52.270] That's how you get root. [32:53.270 --> 32:53.910] PPL. [32:53.910 --> 32:54.950] Page Protection Layer. [32:55.070 --> 32:56.890] Again, introduced in 8.12. [32:58.070 --> 32:59.210] And these are the chipsets. [32:59.730 --> 33:03.210] Prevent user space code from being modified after verification is complete. [33:05.170 --> 33:06.170] Yeah, I'll leave it at that. [33:06.170 --> 33:07.330] You guys got a picture of it. [33:07.970 --> 33:09.670] And so now we're going to talk about the fun stuff. [33:09.670 --> 33:10.530] Stack Overflow. [33:10.570 --> 33:13.110] So remember, like, the OSCP used to be so easy. [33:13.110 --> 33:16.650] You could just, like, do a buffer overflow in, like, 30 minutes, pass it, be, like, good. [33:16.650 --> 33:18.670] Now they, like, made it all AD. [33:18.970 --> 33:24.650] Anyway, when it was the buffer overflow, it was really Stack Overflow. [33:24.650 --> 33:26.930] It's a type of memory corruption bug. [33:27.710 --> 33:33.930] Basically, there's, like, you know, I'm putting stuff on the stack without even checking it for bounds. [33:33.930 --> 33:39.410] Is it like, you know, like, can I fit a Tesla on a chair kind of deal, right? [33:39.410 --> 33:42.130] Like, you're not even seeing if you can fit in a spot. [33:42.130 --> 33:43.810] That's the best way I can put it. [33:44.930 --> 33:45.890] Example. [33:46.070 --> 33:47.550] This is a fun example. [33:47.690 --> 33:49.490] User gives me input, first name. [33:49.490 --> 33:51.030] First name is really, really long. [33:51.030 --> 33:52.730] I thought it was only going to be 10 characters. [33:52.790 --> 33:54.370] I don't know why. [33:54.850 --> 34:00.790] Program does not check if more than 10 characters are put into the program. [34:00.810 --> 34:03.870] And then what happens is that data then overflows onto the stack. [34:04.110 --> 34:09.770] And if you get, like, really tricky, you can actually take control over the runtime, right? [34:09.770 --> 34:11.630] Like, you can take control over the process. [34:11.630 --> 34:13.210] I'm pretty sure a lot of you know this. [34:14.350 --> 34:15.550] Heap overflow. [34:15.690 --> 34:18.210] Now, heap is used for dynamic memory allocation. [34:18.210 --> 34:21.470] This is something that you as a developer control of. [34:21.490 --> 34:30.710] You can actually store things on a heap that's supposed to live longer in the application's lifespan, right? [34:30.710 --> 34:32.570] So, like, what would you put in a heap? [34:32.750 --> 34:33.510] Tokens, right? [34:33.510 --> 34:35.390] Something that you'll need, right? [34:35.390 --> 34:37.230] When's the last time you had to sign into Instagram? [34:39.330 --> 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. [34:46.950 --> 34:48.610] It is by the programmer. [34:50.330 --> 34:55.130] Heap overflow is kind of like a buffer overflow, but it just takes advantage of the heap, right? [34:55.130 --> 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. [35:07.930 --> 35:10.570] Remember when we were little and they used to line us up short to tall? [35:10.570 --> 35:11.690] Kind of deal, right? [35:11.690 --> 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. [35:19.230 --> 35:22.690] It'll just, like, kind of be near each other, like, organized, so to speak. [35:23.930 --> 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? [35:36.910 --> 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. [35:49.310 --> 35:51.630] It's also 1,024 bytes. [35:53.950 --> 35:57.270] Dynamic memory in malloc, right? [35:57.270 --> 35:59.270] In malloc, memory allocation. [35:59.270 --> 36:03.130] I know those bugs are, like, prevalent and people are still using it. [36:03.130 --> 36:09.910] And so, like, that's an example of, you know, dynamic memory being allocated onto the heap. [36:10.710 --> 36:11.670] Oh. [36:12.310 --> 36:13.450] Oh, I'm right. [36:13.470 --> 36:14.590] USector Free. [36:14.650 --> 36:15.610] UAF. [36:15.690 --> 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. [36:20.830 --> 36:21.730] I'm happy. [36:22.310 --> 36:29.190] Memory corruption bugs, basically, it's another type of a memory corruption bug. [36:29.690 --> 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. [36:43.070 --> 36:44.590] That data's still sitting there. [36:44.590 --> 36:47.690] So, like, that becomes a USector Free thing. [36:47.750 --> 36:52.790] You may be able to take advantage of that for code execution or corrupting data. [36:53.010 --> 36:55.170] Just depends on what you're trying to do. [36:55.170 --> 36:56.330] Denial of service. [36:57.730 --> 36:58.610] Heapspring. [36:58.610 --> 37:02.190] This is one of the ways that a UAF bug is triggered. [37:02.190 --> 37:05.870] So, basically, this is the, quote-unquote, brute force. [37:05.870 --> 37:10.770] You're just, like, spraying onto the heap until you write over the actual freed area. [37:11.170 --> 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. [37:19.850 --> 37:24.930] So, that's a really kind of an interesting type of attack. [37:25.090 --> 37:27.910] And then we're going to get into rock chains. [37:27.910 --> 37:28.910] Got 20 minutes left. [37:28.910 --> 37:29.590] All right. [37:29.670 --> 37:30.550] ROP. [37:30.970 --> 37:32.970] You guys have heard ROP a few times already. [37:32.970 --> 37:35.510] Return Oriented Programming. [37:35.910 --> 37:36.710] I'll be honest. [37:36.710 --> 37:39.970] I really started to pick up ROP like in the last three years. [37:39.970 --> 37:41.490] Mostly on the Intel side. [37:41.490 --> 37:44.290] Kind of more recently on the iOS side. [37:45.530 --> 37:50.690] This is a way for us to be able to bypass that non-executable region of memory, right? [37:50.690 --> 37:51.450] The NX. [37:51.450 --> 37:55.170] So, effectively, you're trying to chain together a bunch of gadgets. [37:55.170 --> 37:57.270] And gadgets have certain memory addresses. [37:57.270 --> 37:59.470] So, you're going to pass a bunch of garbage data. [37:59.470 --> 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. [38:05.130 --> 38:07.030] And then a bunch of more garbage data. [38:08.250 --> 38:11.910] A, B, C, 1, 2, 3, and then the gadget 2 address. [38:12.330 --> 38:14.770] Typically, we don't use A, B, C, 1, 2, 3. [38:14.910 --> 38:15.910] We use A's. [38:15.910 --> 38:18.230] That was my demonstration there. [38:19.990 --> 38:26.030] Dynamic libraries allow for applications to be able to load code that's already... [38:27.430 --> 38:29.370] to load code into the address space. [38:29.370 --> 38:31.230] So, it's basically like a DLL. [38:31.750 --> 38:39.710] A dynamic link editor, or a DYOD, is basically native to the operating system of Mac. [38:39.710 --> 38:43.110] And, effectively, it's responsible for loading and linking. [38:44.530 --> 38:50.470] So, this is for loading and linking dynamic libraries while the application is running, which is very important. [38:50.570 --> 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. [39:00.010 --> 39:02.730] And it's called DYOD Shared Cache. [39:03.230 --> 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. [39:10.890 --> 39:13.290] This is how you're going to find your ROP gadgets. [39:13.610 --> 39:18.290] You're trying to figure out this really cool and unique... [39:18.870 --> 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. [39:25.410 --> 39:27.870] So, you're going to leverage that's considered a gadget. [39:27.870 --> 39:29.410] So, you're going to leverage the ROP gadgets. [39:29.410 --> 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. [39:42.830 --> 39:46.770] So, when we're running these tools, because it's a tool, so don't just run it blindly. [39:46.770 --> 39:49.450] You want to ask yourself, is this going to meet my objective? [39:50.670 --> 39:52.470] What dilibs are loaded? [39:52.470 --> 39:54.050] What dynamic libraries are loaded? [39:54.110 --> 39:56.790] And what dynamic libraries should I be looking in? [39:56.990 --> 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. [40:03.350 --> 40:09.850] And you're going to want to use LLDB and leverage ImageList. [40:09.890 --> 40:11.650] And from here, I'm showing a screenshot. [40:11.650 --> 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. [40:18.910 --> 40:25.890] Things like CommonCrypto or MacO or SystemC, right? [40:25.890 --> 40:26.990] Those sorts of things. [40:27.050 --> 40:28.910] So, the fun part. [40:29.230 --> 40:32.750] Finding gadgets in dynamic libraries. [40:32.770 --> 40:36.170] I leverage a tool called Ropper because I like the name of it. [40:36.170 --> 40:39.510] Like, seriously, this is just other tools, but Ropper is, like, one of my favorites. [40:39.730 --> 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. [40:48.510 --> 40:49.610] What are you trying to do? [40:49.610 --> 40:50.830] Are you trying to move? [40:51.310 --> 40:51.630] Alright? [40:51.630 --> 40:52.950] Are you trying to copy? [40:52.970 --> 40:54.450] Are you trying to do something else? [40:55.310 --> 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. [41:05.670 --> 41:09.010] Remember, we talked about ABC123, gadget address. [41:09.010 --> 41:12.010] Well, right there in the red is your gadget address. [41:12.010 --> 41:13.310] Alright? [41:15.430 --> 41:16.890] Jop chains. [41:16.910 --> 41:22.510] Now, Jop, this is something that I'm really starting to get into in the last couple months. [41:22.930 --> 41:30.070] So, this is, like, the top of where we are right now for exploitation on the iOS systems. [41:30.070 --> 41:34.970] In real world exploitation, you probably won't find a full Rop chain. [41:35.010 --> 41:36.210] It just won't happen. [41:36.230 --> 41:39.650] But you will use Jop and Rop together. [41:39.790 --> 41:42.570] And so Jop is Jop-oriented programming. [41:42.570 --> 41:44.110] It's different than Rop. [41:44.610 --> 41:50.030] Rop's generally end in a return and Jop's will end in an indirect jump. [41:50.210 --> 41:54.650] So we're looking to be able to control the flow of the program. [41:54.830 --> 41:58.130] We want to make it do a dance for us. [41:58.330 --> 42:01.170] So, we don't really want to kill the program. [42:01.170 --> 42:02.090] We don't want it to return. [42:02.090 --> 42:02.790] We don't want it to end. [42:02.790 --> 42:05.210] We want it to branch to the next instruction. [42:05.890 --> 42:12.270] So that's where you kind of get that BRX1 is branching over to that register. [42:12.270 --> 42:14.890] Versus in Rop, where you're doing a return. [42:15.390 --> 42:22.350] But also, as we're branching over to X1, make sure that that register contains the address of the next instruction.