start	end	text
8740	11740	Are you guys sure you're in the right talk?
11740	15320	I didn't expect this many people to show up for this talk.
15320	17400	So thank you all for being here.
17400	18400	It means a lot to me.
18400	19860	I see some familiar faces.
20240	23260	I probably see a lot of other screen names that I don't know.
23260	27020	So like a pitcher, send a DM if you see me.
27740	28640	My name is Xavier D.
28640	29380	Johnson.
29480	31960	I've been in tech since forever.
31960	36600	Started programming in 2004, so I guess I've been around for a while.
36600	39860	Basic, C-sharp, everything but Java.
41160	51020	Today, mostly focused on reverse engineering, mobile penetration testing, and security research is kind of like the broad term.
51020	57060	So today, I want to talk to you guys about, or you folks, about hacking iOS.
57060	60060	It's kind of like this mystique around iOS.
60060	62320	That's probably why a lot of you guys are here like, okay, what is he going to do?
62320	63480	Is he going to show me something cool?
63540	64240	I am.
64240	70880	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.
71440	75200	Fun fact about these slides, this is the last five years of my life.
75420	80040	So if it sucks...
80040	80680	Xavier D.
80680	82900	Johnson, yes, the D means something.
83320	85020	Everybody else calls me infinite.
85840	86960	So hello.
87320	91280	These slides will contain writer downers.
91280	92740	Get your pen ready.
92880	95760	20 years of experience, wrote my first line of code in 2004.
95820	98480	Been chasing that high ever since.
98960	100900	High school, did FIRST Robotics.
101040	102820	As a young adult, did web applications.
102820	105400	Wrote a lot of shitty PHP apps, I won't lie.
105740	109660	I thought I was going to be Mark Zuckerberg, but of course, I'm here with you, so I'm not.
109660	110680	Because I'm loved.
112520	115120	Today's agenda, we're going to keep it short and sweet.
115120	116640	Just an hour worth of content.
117440	120360	Intro to ARM Assembler.
120600	122820	The differences between ARM and Intel.
122880	128100	I'm pretty sure many of you, or some of you, know a thing or two about IA-32, Intel.
128100	130400	So this should be like a fresher, right?
130400	132440	You'll be up to speed by the end of it.
132780	134680	iOS internals, which...
135340	137740	I read three really thick books about this.
137740	139780	So I'm hoping it comes through.
139780	142500	And exploitation, which is my favorite, right?
142500	145200	Everybody wants to do an exploit, so...
145200	147500	Your slides are not in the presentation.
147500	148440	Oh, God.
148440	149320	I was wondering.
149320	151060	It's on the presentation part?
151060	154020	You can see it on the top left, but it's the presentation.
154020	155040	At least it's not full screen.
155040	155600	Oh.
155960	157880	You can't see my presentation.
158420	160100	Okay, give me one second.
164530	165850	Technical difficulties.
168190	169070	Nope.
169090	171130	Do you have a button to swap it?
171130	173830	I don't have a button to swap the display.
174470	177450	It usually just works.
179210	180070	Oh, yeah.
180070	181170	It's up here, huh?
188490	190170	There we go.
213050	213810	Okay.
215570	217750	I can't even see it anymore.
217750	219010	It's moved all the way over.
221610	222290	That's better?
222290	223330	I can't control it.
223870	224970	I can't control it.
229150	230910	Do we have speaker ops?
231490	233390	Somebody here to help with the tech part of this?
233390	234610	I just plugged into a USB.
234610	235710	I have no idea.
239710	241770	I can't see what you guys see on that screen.
241770	242850	I think it's the problem.
244770	247090	Yeah, I want to do it down there.
247750	248550	Let's see.
252010	254230	If I bring it, it's cable.
258510	259310	Speaker ops.
259310	260110	Do we have speaker ops?
260110	260490	No?
260490	260970	All right, cool.
260970	262230	I guess I'll just...
263390	264630	do it live.
268590	269950	Can you guys see anything yet?
272370	273490	What can you guys see?
273490	274390	Because I don't have a...
279850	281030	You see my mouse?
281130	281850	All right, fuck it.
281850	282870	We're going to do it like this then.
283250	284970	We're going to do it like this.
285470	286310	Presenter view.
286670	287230	Presenter view?
287230	287770	Yeah.
293850	295170	It doesn't work.
295170	295990	It's not working.
296710	297550	Play from slide?
297670	298670	Watch this.
298950	299890	There you go.
300310	302590	Well, now we're in it together.
305390	307790	So, we're going to run it like this.
310770	311910	I don't mind.
311910	312510	You guys don't mind.
312510	312890	I don't mind.
312890	313630	Let's get it.
314910	316430	We're going to jump straight into ARM.
317490	318650	Let's get to it.
319050	319850	Fundamentals.
320370	321590	Let's get it going.
321590	325630	So, the difference between ARM and Intel Assembler is really three key details.
325630	334570	ARM has 31 general purpose registers, which the registers are kind of like how data moves in and out of RAM.
334570	338930	How the computer actually is managing its data flow.
339310	342450	Intel x86 has 16 general purpose registers.
342690	345970	ARM is based on RISC, which is supposed to be faster.
346150	347190	Typically, it is faster.
347190	349930	You'll find these kind of things on mobile phones.
349930	350870	IOT.
350870	352490	ARM is kind of like the next thing.
352490	353170	Satellites.
353170	353650	Who knows?
353650	354770	Let's ask Elon.
355250	359210	ARM 64 was around since iPhone 5S.
359270	360810	Before then, it was 32.
361050	362630	32-bit ARM.
362810	366170	Just a bit of a higher overview of the registers.
366790	370550	Again, small area inside the CPU that stores a specific value.
370890	376710	For 64-bit, registers X0 through X30 represent the 31 available registers.
376710	379130	For 32-bit, it's W0 through 30.
379810	386690	These are some of the points in which the registers actually identify, so to speak.
386690	389610	The frame pointer is always going to be X29.
389790	391710	Link register is always going to be X30.
392010	393850	Program counter is always going to be PC.
393850	395550	You don't have to worry about those sorts of things.
396270	398590	0 through 28 are general purpose.
398590	399690	This is holding your data.
399690	403090	This is where the data is actually flowing through the application.
405210	407310	This data can be volatile or non-volatile.
407310	412070	A volatile register basically means that it does not persist through the end of a function.
412350	414030	It is effectively not a global.
414030	416590	It dies once the process is done.
416690	425830	A non-volatile means that it is carly saved or that it actually saves the content so that it can continue to be used.
426190	431850	The first 19 registers are volatile and the rest are non-volatile.
433130	435050	There's three types of instructions.
435110	440010	When we talk about code, what we really are talking about is a bunch of conditions.
440010	448570	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.
448830	462430	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.
462430	463450	Those conditions.
463470	465690	What I like to call AI Hadouken.
466890	472590	So the if-else statements in ARM64 use branch instructions.
472590	480330	So branch instructions basically are controlling the flow of the application kind of in, you know, if-else.
480770	492050	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.
492050	494490	And then we talk about calling conventions.
494490	502250	Now, calling convention is how data is actually put into functions.
502250	511910	So like, effectively for ARM64 you are looking at arguments stored in between the first eight registers.
511910	514250	So X0 to X7.
514490	518390	And subroutines are typically stored in X0.
518390	521550	And all of this stuff will matter as we move into exploitation.
521550	523490	This is kind of fundamental groundwork.
524490	533530	Returns addresses are in X30, so we'll talk about that for ROP and JOP return-oriented programming.
534050	538150	And the way that the stack grows is actually important.
538430	541550	Stack frame actually grows downward in memory.
541550	544570	Sometimes you'll have things grow upward in memory.
545910	547030	That's pretty interesting.
547030	549370	It's also stack frame 16 bytes.
550890	552630	A few things there.
552810	558110	A function in ARM assembler contains three different components.
558110	560430	A prologue or the start.
560770	565690	The body, which actually does anything with the data or the actual logic.
565690	567830	And an epilogue, which is kind of ending the function.
567830	573250	So think about when you're writing in C, you kind of got main and then eventually you're going to return something.
573250	574970	Hopefully not a negative one.
577130	579050	The prologue is just the first few lines.
579050	582050	This is an example of kind of like the hello world prologue.
582210	584890	Sub SP and SP.
585170	590510	Basically putting this into putting 20 into SP.
590510	594050	It starts the prologue and it's making space on the stack.
594070	599730	And then it's saving the frame pointer and link register to the stack.
599730	603430	And then calculating a new frame pointer to the stack, etc.
603430	611430	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.
611430	615790	This, when you're looking at your function, will tell you what is the start of a function.
615870	619750	So this is very important when you're just handed a binary, go here figure it out.
619750	621750	You're like, I don't really know where functions start.
621750	625150	This will always be kind of your indicator of the beginning of a function.
625150	626050	Always looks the same.
627870	631070	Epilogue is to restore the program to its original state.
631070	637010	Basically, put the program back to what it was before the last function was running.
637010	639930	So this is kind of a restorative thing.
640690	643550	So now I'm moving fast, because there's a lot of content here.
643550	644890	So we're going to jump into syscalls.
645310	646250	Syscalls are fun.
646250	646970	I'm pretty sure all of you...
646970	648930	who out here knows what syscalls are?
649050	649950	That's a lot of hands.
649950	650270	Cool.
650270	651390	So I'm going to keep a high level .
651390	652330	System calls.
652330	656690	System calls basically act as the interface between user space and kernel space.
656690	658410	So that's the fun...
658410	660330	that's the fun part, right?
660330	665410	Figuring out how to be able to manipulate or take advantage of these system calls.
665570	669770	Potentially break them or leverage them in your exploitation.
670750	677190	But the thing about these syscalls is they move over into kernel mode, they do something, and then they make a return back over.
677190	679010	So think about like an fopen.
679010	680190	That's standard.
680190	681890	Or a chmod .
681890	683150	That's standard.
683150	684270	That's everywhere.
684270	687290	Those are a part of the Linux syscalls.
687290	688610	They're kind of Unix syscalls.
688610	692370	They're a little bit of everywhere that leverages Nix.
693810	695810	Typical syscall flow, right?
695810	698490	A function will make a call to something like fopen.
698490	703130	The user will, you know, leverage syscalls...
703130	704170	the syscall number.
704170	705730	So every syscall has its own number.
705730	707730	And it will leverage the syscall number.
707810	716110	And the kernel will then execute, request that service, and then actually return control back to user mode.
716110	719510	So you don't get to do anything as a user, or from userland.
719830	726010	You're just invoking the syscall so it can go and run that subroutine and then give you the results back over in userland.
727630	732190	We all know why we don't want to run user code in kernel mode, right?
732870	736150	Of course we want to run user code in kernel mode, right?
736210	737970	That's the whole point.
737970	738930	That's privilege escalation.
738930	740290	That's the zero-day part.
741470	746770	So yeah, syscalls all have a correlating system number, a syscall number.
747430	749110	Memory management.
749650	753210	So memory management is very important when you get down to this level.
753210	758450	Loading, storing, branching, arithmetic, all of that is happening in the memory, leveraging those registers.
759170	761550	ARM operates on a load store.
761670	769430	So basically, memory can only be accessed and manipulated from specific load and store instructions.
769430	778410	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.
778470	780030	That's the way I can explain it.
780210	786210	To perform load and store memory instructions, you do LDRs, LDPs, STPs.
786210	787470	The meanings are there.
787470	788830	I won't go into it.
788830	794770	Again, if you want to know more about this, I suggest you go and actually read the ARM documentation.
795030	801390	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.
801390	803510	So you might as well get used to it.
805450	809570	These instructions, they handle different sizes of data, right?
809570	812990	So bytes or 8 bits all the way up to double words at 64 bit.
813250	813970	ARM64.
815070	816010	All right.
816470	817590	Did I lose anybody?
817590	818950	I only lost like two or three people.
818950	820510	So I feel like I'm doing good.
820530	821550	I feel like I'm doing good.
821550	827030	We made it through basically the hard part, like the really shitty part of the talk, which is like the assembler part.
827070	828650	The rest of it is going to be pretty fun.
828650	830170	So I'm jumping into internals.
830570	832350	Now, internals...
834330	839270	Well, I don't know if you guys know, like, iOS is kind of open source, but kind of not, right?
839270	841110	Like, part of the kernel is on GitHub.
841110	843750	You can just go and like look at it and fucks around with it.
843750	850090	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.
850090	853250	It's like ah, I don't really know exactly how it works underneath.
853250	855470	And there's no like real clear cut documentation.
855490	861890	Unfortunately, Pavel, the guy who wrote the Windows internals books, didn't write them for iOS.
861890	868670	But a really cool guy named Jonathan Levin wrote a series of books which is called the Moxel Trilogy.
868670	875690	Effectively, it's the user space, kernel space, and security internals, well known internals book.
875710	878550	You guys should go buy it and support.
879630	882250	This is where I got a lot of this information from.
882530	883450	Jailbreaking.
883790	885650	So that's like a prior requirement.
885650	886950	Oh, I got a question?
888750	890970	M-O-X-I-L
897850	906650	M-O-X-I-L M-O-X-I-L M-O-X-I-L We talk about a walled garden.
907190	909690	How many people here have jailbroken an iPhone?
909910	912470	I got a lot of jailbreakers in here.
912470	913050	Okay.
913050	913550	Okay.
913550	915270	So this is going to be a really boring part.
915310	919150	Long story short, this is how you're able to get root on iPhone.
919150	920650	We call it jailbreaking.
920890	924070	It gives you write access to all the partitions.
924070	925270	Basically, you can do what you want.
929070	938350	Historically, people have leveraged kernel patching to bypass code signing, which is a control to slow you down.
938350	940050	So that's one bypass.
940370	945370	Modifying the AFC service for root access is another methodology.
945630	947530	AFC is the Apple File Conduit.
947530	952630	It's basically the way that all of the Apple devices manage their file system.
952930	955150	And there's a few different types of jailbreaks.
955330	959290	You've got untethered, you've got tethered, you've got semi-untethered, you've got semi-tethered.
959290	962310	So some of this stuff you're like, okay, well, you guys already know.
962330	965410	But for the people at home, you're probably wondering, well, what does this mean?
965430	971470	Tethered means that it only persists for one boot and it has to be restarted.
971950	974410	The device will no longer have the jailbreak.
974410	980310	So let's say you're working and you're fuzzing around and it crashes, it'll reboot in a non-jailbroken state.
981370	983990	And it may not even really fully reboot.
983990	988330	I've seen it go into recovery mode, which is fun, because that's kind of like the danger zone for bricking a phone.
988450	992050	Which is a whole other fun topic, which I think is a talk that I'll do next year.
992050	996430	How do you get around bricking your jailbreaking devices?
997350	1003370	Untethered means that you can kind of turn the device on and off and it'll persist, which is kind of like...
1003850	1006150	that's like next-level golden status.
1006150	1010290	I don't think any of the current jailbreaks that are actually useful you can actually do that with.
1011110	1015810	Semi-tethered means that the jailbreak won't persist when you restart it, but at least you can reboot it.
1015810	1018030	And that's the majority of the world right now.
1018030	1019390	It's kind of semi-tethered.
1019410	1022650	Uncover is a semi-tethered jailbreak.
1022650	1033150	And semi-untethered means that the first boot won't be jailbreaking, however, a kernel patch will be applied via like city impactor.
1033150	1037050	So like after it boots up, it'll just patch.
1037070	1038710	I leverage uncover.
1038710	1039890	If you don't, you should.
1039890	1040650	It's pretty cool.
1040650	1046630	But that's kind of like the thing that I've used that's widely available and pretty stable, from my opinion.
1047030	1051310	So moving over into APFS, Apple File System, right?
1051310	1053470	iOS leverages APFS.
1053490	1073610	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.
1073690	1076350	And so effectively, the devices became faster.
1077210	1083450	Of course, we want to take advantage of sweet, sweet SSD speeds, so APFS is supposed to lean into that.
1083570	1087610	And as well as full disk encryption and file encryption.
1087810	1090350	So if you want to learn more about that, check out iPhone Wiki.
1090370	1091830	It's a really great resource.
1093690	1094710	File system, right?
1094710	1097890	What makes the iOS file system different than any other file system?
1097890	1099470	Here's the real diff for you.
1100190	1105490	A regular file system, a typical Linux file system will have bin, boot, dev, blah, blah, blah, user bar, right?
1105490	1115390	Directories that are in iOS, macOS that are specific, slash applications, cores, developer, library, system, user, private.
1115390	1125390	These are kind of where the core differences in a regular Linux file system and Apple file system for iOS and macOS.
1126770	1131030	Apps do not directly communicate with the hardware.
1131030	1132450	There is a sandbox.
1132850	1135410	There is different layers of the sandbox.
1135410	1140170	You have the touch layer, the media layer, the services layer, and the actual core OS.
1140370	1144150	So Cocoa Touch is kind of the infrastructure for all the applications.
1144150	1145890	It's the way that you actually touch the screen.
1145890	1147050	It's this touch, right?
1147130	1151090	The media layer allows us to be able to deal with all the AV media.
1151090	1152110	Kind of makes sense.
1152110	1155210	Core services is kind of like that, the hardcore stuff.
1155210	1159390	Network, location, all the stuff you really want to leak out.
1159390	1163830	Things that are pertinent to your device specifically.
1164170	1168470	And the core OS is kind of like, I'll call it the kernel for lack of a good term, right?
1168470	1176550	It's the actual base operating system that kind of like does things that the applications above them is asking for.
1177430	1180110	So I'm going to jump right into static analysis.
1180410	1182130	This is really high level.
1182130	1184390	Everybody is going to have different methodologies.
1184890	1187570	Some people will use scanning tools.
1187570	1191730	Some people kind of get old school like me and just kind of start to rip apart stuff.
1192610	1201570	Joker and JTool used to be Otool are also really good options for this as well.
1201650	1205230	But I'm going to talk mostly about Otool and then in page stuff.
1205230	1208110	Just kind of like briefly giving you an understanding.
1208850	1210850	IPA file is basically a .zip.
1210850	1211830	Funny, funny.
1211830	1214350	You can actually turn a .zip to a .ipa.
1214410	1217370	Won't install, but it will be an IPA file.
1217750	1219270	Works on my machine.
1220630	1224890	Basically, you unzip an IPA file and you will be able to find all of the resources.
1224950	1228270	In those resources you will be able to find a folder called payload.
1228470	1229970	That will actually have binaries in it.
1230030	1233650	Frameworks, shared libraries, dynamic libraries, those sorts of things.
1233650	1237230	So like statically linked things that are in the application.
1237950	1241050	Tools used for this, again Otool and then in page stuff.
1241650	1244170	Otool, widely available in Xcode.
1244170	1245830	If you install Xcode, it's there.
1245970	1249650	We use the check for depreciated APIs like string copy.
1250830	1253530	And to check to see if DRM is enabled.
1253530	1255190	Is the app encrypted?
1255490	1257170	Alright, DRM.
1257370	1259050	That's a fun part of the talk.
1259890	1263830	Encryption is one of the ways that Apple... that's one of the walls.
1263830	1265690	I'll call it multiple walls now.
1265690	1267350	We're dealing with defense in depth.
1267350	1268810	We're taking a layered approach.
1269750	1282310	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.
1282690	1292090	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.
1292090	1297890	And if ASLR is enabled, address space layout randomization.
1297950	1300690	So this is an example of me running Otool.
1301370	1304870	These four down here are kind of like some easy, fast wins.
1304870	1307090	You want to go on GitHub and just start looking for this stuff?
1307090	1307590	There you go.
1307610	1309830	Memcpy, Stringcopy, Stringland.
1309830	1312210	These are like quick, fast, dirty.
1312210	1317050	I'm pretty sure you guys could tell me even some more, but I'll leave that for another talk.
1318190	1319110	A&M.
1319190	1321050	So this displays symbols.
1321610	1323290	Does everybody know what symbols are?
1323850	1324510	Okay.
1324510	1326330	I see way less hands.
1326330	1326650	All right.
1327130	1327450	Symbols.
1327450	1328110	Oh, there they go.
1328110	1328790	Another popping up.
1328790	1330150	They're like, no, no, don't tell me about symbols.
1330150	1330430	Screw it.
1330430	1331470	You're too late now.
1332830	1336170	Symbols is basically like how functions are named.
1336430	1341110	And you can either include them or obfuscate them or not include them entirely.
1341490	1346710	But this, for me as a reverse engineer, is a good way for me to understand how the application is working.
1347010	1355050	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.
1355070	1358050	Like, for example, do I have jailbreak detection?
1358050	1361470	Well, jailbreak's probably in the name of one of the symbols.
1361810	1369590	If it is, then I probably want to go to that routine, read the assembler, figure out those branch instructions, try and patch it.
1369690	1373290	Usually it'll come down to 1 or 0.
1373290	1374290	It's true or false.
1374290	1375350	Is it jailbroken?
1375350	1376070	True?
1376170	1379350	Okay, well, let's change that to always be false.
1379390	1383430	Even though it's jailbroken, it's just patched application it'll return false always.
1384150	1385910	Nm, right?
1386190	1398650	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.
1398650	1411350	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.
1411350	1415390	So when you go into that payload folder, there'll be the name of the application.
1415390	1417630	Let's say the application is HackerTracker.
1417850	1422750	If you go and you look at the HackerTracker application, you'll be able to unzip it, right?
1422750	1427830	You'll look into the payload folder, you'll scroll, scroll, scroll, and all of a sudden you'll see HackerTracker as a binary.
1427950	1429990	That's what you really want to be pulling nm to.
1429990	1433430	That'll show you if they've stripped symbols or not, and if they haven't, have fun.
1435270	1435810	PageStuff.
1435870	1439830	Basically, it lets you review the structure of a mock O file.
1439830	1448430	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.
1449030	1460610	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.
1461950	1463630	I'm a Geedra guy, personally.
1463830	1466150	If it's good enough for you, it's good enough for me.
1466150	1466890	Question?
1467130	1467830	Yeah.
1467970	1469590	I have an Apple question.
1469850	1473690	Where do you get information about the actual format?
1474230	1475650	The macro format?
1475650	1475950	Yeah.
1475950	1480270	Apple has really good documentation about that sort of stuff.
1480270	1483370	So I've been able to find that on my blog post, but...
1483370	1485050	Not on their public?
1485570	1486130	Hmm.
1486130	1488050	Another good space is to read that book.
1488050	1491990	That's where I got the information from myself, because I was too lazy to read the documentation.
1493090	1495390	So that book by Jonathan Levin, check it out.
1495390	1496070	It's a really good book.
1496070	1502110	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.
1502570	1502950	All right.
1502950	1504130	Here's the meat of the talk.
1504630	1505310	Exploitation.
1505310	1508690	I'll probably get you guys out of here like 15 minutes early, because I got an advanced class.
1508690	1509830	I like this.
1510930	1511990	Everybody's phone's coming out.
1512030	1512710	Exploitation time.
1512710	1513350	All right.
1513790	1515650	First, we're going to talk about mitigations.
1515650	1517730	We already talked about one, which is code signing.
1518510	1521790	Basically, just make sure that the code is from a known source.
1522270	1528070	The components of code signing will be certificates, bundle IDs, provisioning profiles.
1528150	1534570	And so a provisioning profile is basically like a file that has the bundle ID and what cert to use.
1534570	1537910	So that's how those three kind of basically come together.
1537910	1538710	You need a certificate.
1538710	1539710	You need a bundle.
1539750	1540950	Those are kind of like prereqs.
1540950	1545290	And you need a provisioning profile that actually leverages those certs and bundle IDs.
1545770	1555650	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.
1555650	1558530	Core trust bugs are no longer around, unfortunately.
1558850	1562290	It was added in iOS 12 to prevent fake signing, right?
1562290	1568270	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.
1569870	1575570	Jailbroken phones still require signing, fun fact, but you can fake sign on a jailbroken phone.
1575570	1578350	So non-jailbroken phone, no more fake signing.
1578350	1581570	Real jailbroken phone, you can't co-sign.
1581570	1593070	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.
1593150	1595010	AltServer and AltStore.
1595070	1601890	This really, really good and easy way to be able to get decrypted applications siloed onto your iPhone.
1601890	1607790	Because, you know, I believe there was some legislation that came out that said Apple had to allow you to silo.
1607830	1608710	Question?
1610630	1613630	AltStore, A-L-T and AltServer.
1615390	1618930	The first one, when you look at the website, there's two options.
1618930	1620970	One option is like asking you to pay money.
1620970	1623410	That's only for the people in the EU.
1623510	1627630	I think they were like the main drivers behind like the legislation being changed.
1627630	1630990	Same way we got USB-C on iPhone, basically.
1630990	1633930	So they charge over there for some reason.
1633930	1634870	But in the U.S., U.S.
1634870	1636350	servers are totally fine.
1636350	1639830	Basically what it does is it spins up a server on your phone.
1639890	1641530	You tether your phone.
1641530	1645190	Excuse me, it spins up a server on your MacBook.
1645550	1646950	You plug up your phone.
1646950	1650330	You have the AltStore on your phone.
1650330	1656710	And then you're able to sideload applications directly from your computer to your phone with it being signed.
1656710	1658670	So it manages that signing for you.
1658670	1660610	What do you mean by known source?
1660610	1662050	Is it an Apple signing?
1662990	1664310	Say that one more time.
1664310	1666250	Or maybe it's both signing.
1668410	1669850	Oh, yeah.
1669850	1674710	So known source would be like Instagram, Facebook, TikTok.
1674710	1684910	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.
1685550	1693730	So it's kind of like think about it like a way to remove tampering.
1693730	1698910	I can take an Instagram application and I can decrypt it.
1698910	1700770	Then I can re-sign it with my cert.
1701290	1708490	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.
1708490	1721330	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.
1721570	1723430	And they'll know of my key.
1723430	1728450	And so when you go to go download it from the App Store, it'll be a known application to your trust store.
1729590	1731350	Your certificate trust store.
1731550	1732230	Question?
1732950	1733830	Gotcha.
1734530	1737210	That means I'm doing good for you preemptively answering questions.
1737210	1738070	Come on now.
1740370	1741630	Read the green.
1741630	1742970	The green is fun.
1742970	1744570	Bypass, bypass, bypass.
1744570	1747050	I don't want to tell you how to bypass it.
1747050	1748890	DEP, data execution prevention.
1748890	1750150	This is nothing new.
1750150	1751350	This has been around.
1751350	1758530	Prevents code from being executed in memory portions that are marked as non-executable in X.
1758710	1760310	The letter N, the letter X.
1761750	1764910	To bypass this, we use ROP.
1765950	1769830	Return Oriented Programming.
1769990	1771370	Then you have ASLR.
1771370	1774350	Randomizes the location where executables are loaded into memory.
1774350	1779970	Fun fact, without ASLR, it is predetermined where your start and end is for your binary.
1779970	1782330	And you can actually see that statically.
1782330	1790070	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.
1790070	1800690	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.
1801030	1808330	You'll be able to hard-code memory addresses because it always loads between 0x1000 and 0x2000.
1808790	1813290	All of the logic will always happen in that region of memory.
1813590	1816710	ASLR will make it so that you no longer have that.
1816950	1821270	It'll load in 0x3000, it'll load in 0x10000.
1822370	1823050	KSLR.
1823050	1825730	This is the kernel address-based layout randomization.
1825730	1826690	Oh, sorry.
1827590	1828250	ASLR.
1828250	1829630	How to bypass.
1829770	1837570	We leverage information leak bugs, which I'll get into later, or we brute force, and I'll talk about that.
1838910	1843510	Kernel address-based layout randomization prevents attackers from being able to view kernel data.
1843610	1855250	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.
1855250	1856930	This is a really good protection.
1857030	1861330	Again, one good way to do this is leveraging information leaks.
1861330	1867350	This is how you're able to see, based on the information that's actually live, where the kernel's being loaded.
1867350	1870510	And you're going to have to take advantage of some other vulnerabilities to get there.
1871910	1872870	Mitigations.
1873250	1874570	I love mitigations.
1874570	1875630	There's so many of them.
1875630	1878490	There's some that's not even here, believe it or not.
1878490	1879950	Kernel patch protection.
1880070	1881990	Kernel text read-only region.
1882790	1883590	KTRR.
1883590	1884230	This?
1884230	1885510	That was new to me.
1885730	1888250	I don't do a lot of kernel research.
1888250	1892410	I have been now that I know a lot more about it, so maybe I'll get an iOS bug one day.
1892950	1898030	But KTRR basically is kind of newer.
1898030	1899430	It's been around since 8.10.
1901750	1903290	It locks down the MMU.
1903290	1908790	This is the memory management unit, which is a whole separate chip on the board.
1910550	1911950	So I'll leave it at that.
1914150	1914950	Pack.
1915890	1917910	Pointer authentication codes.
1918190	1919330	Introduced in 8.12.
1919330	1920650	These are some of the newer things.
1920650	1922150	You notice how the green went away?
1922150	1923070	That's crazy, right?
1923070	1925850	The new stuff is way harder to get around than the old stuff.
1925850	1928370	If you're on like 14.9, stay there.
1929030	1931390	Anything after that is kind of like Wild West.
1931390	1932230	Good luck.
1933710	1936310	Effectively, PAC signs the pointers.
1936350	1937270	So this is pointer signing.
1937270	1940410	This is authenticating that the pointer is actually the pointer.
1940410	1945090	And they're not really that important in local PrivEsc, to be honest with you.
1945090	1946110	Privilege access never.
1946110	1946970	This is another new one.
1946970	1947350	PAN.
1947350	1949510	I was like, man, that's interesting.
1949670	1952610	This is something that is basically like SMAP.
1952610	1956910	If you've ever messed around on an Intel world, so to speak.
1957150	1958390	Supervisor mode.
1958510	1959950	That's what SMAP is.
1959950	1961650	Supervisor mode access prevention.
1961710	1964750	And basically, this stops the kernel.
1965250	1971030	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.
1971030	1972270	That's how you get root.
1973270	1973910	PPL.
1973910	1974950	Page Protection Layer.
1975070	1976890	Again, introduced in 8.12.
1978070	1979210	And these are the chipsets.
1979730	1983210	Prevent user space code from being modified after verification is complete.
1985170	1986170	Yeah, I'll leave it at that.
1986170	1987330	You guys got a picture of it.
1987970	1989670	And so now we're going to talk about the fun stuff.
1989670	1990530	Stack Overflow.
1990570	1993110	So remember, like, the OSCP used to be so easy.
1993110	1996650	You could just, like, do a buffer overflow in, like, 30 minutes, pass it, be, like, good.
1996650	1998670	Now they, like, made it all AD.
1998970	2004650	Anyway, when it was the buffer overflow, it was really Stack Overflow.
2004650	2006930	It's a type of memory corruption bug.
2007710	2013930	Basically, there's, like, you know, I'm putting stuff on the stack without even checking it for bounds.
2013930	2019410	Is it like, you know, like, can I fit a Tesla on a chair kind of deal, right?
2019410	2022130	Like, you're not even seeing if you can fit in a spot.
2022130	2023810	That's the best way I can put it.
2024930	2025890	Example.
2026070	2027550	This is a fun example.
2027690	2029490	User gives me input, first name.
2029490	2031030	First name is really, really long.
2031030	2032730	I thought it was only going to be 10 characters.
2032790	2034370	I don't know why.
2034850	2040790	Program does not check if more than 10 characters are put into the program.
2040810	2043870	And then what happens is that data then overflows onto the stack.
2044110	2049770	And if you get, like, really tricky, you can actually take control over the runtime, right?
2049770	2051630	Like, you can take control over the process.
2051630	2053210	I'm pretty sure a lot of you know this.
2054350	2055550	Heap overflow.
2055690	2058210	Now, heap is used for dynamic memory allocation.
2058210	2061470	This is something that you as a developer control of.
2061490	2070710	You can actually store things on a heap that's supposed to live longer in the application's lifespan, right?
2070710	2072570	So, like, what would you put in a heap?
2072750	2073510	Tokens, right?
2073510	2075390	Something that you'll need, right?
2075390	2077230	When's the last time you had to sign into Instagram?
2079330	2086950	Of course, there's a whole lot of other stuff that go into that, but nevertheless, heap memory is allocated and deallocated by you.
2086950	2088610	It is by the programmer.
2090330	2095130	Heap overflow is kind of like a buffer overflow, but it just takes advantage of the heap, right?
2095130	2107930	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.
2107930	2110570	Remember when we were little and they used to line us up short to tall?
2110570	2111690	Kind of deal, right?
2111690	2119230	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.
2119230	2122690	It'll just, like, kind of be near each other, like, organized, so to speak.
2123930	2136910	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?
2136910	2149310	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.
2149310	2151630	It's also 1,024 bytes.
2153950	2157270	Dynamic memory in malloc, right?
2157270	2159270	In malloc, memory allocation.
2159270	2163130	I know those bugs are, like, prevalent and people are still using it.
2163130	2169910	And so, like, that's an example of, you know, dynamic memory being allocated onto the heap.
2170710	2171670	Oh.
2172310	2173450	Oh, I'm right.
2173470	2174590	USector Free.
2174650	2175610	UAF.
2175690	2180830	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.
2180830	2181730	I'm happy.
2182310	2189190	Memory corruption bugs, basically, it's another type of a memory corruption bug.
2189690	2202750	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.
2203070	2204590	That data's still sitting there.
2204590	2207690	So, like, that becomes a USector Free thing.
2207750	2212790	You may be able to take advantage of that for code execution or corrupting data.
2213010	2215170	Just depends on what you're trying to do.
2215170	2216330	Denial of service.
2217730	2218610	Heapspring.
2218610	2222190	This is one of the ways that a UAF bug is triggered.
2222190	2225870	So, basically, this is the, quote-unquote, brute force.
2225870	2230770	You're just, like, spraying onto the heap until you write over the actual freed area.
2231170	2239670	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.
2239850	2244930	So, that's a really kind of an interesting type of attack.
2245090	2247910	And then we're going to get into rock chains.
2247910	2248910	Got 20 minutes left.
2248910	2249590	All right.
2249670	2250550	ROP.
2250970	2252970	You guys have heard ROP a few times already.
2252970	2255510	Return Oriented Programming.
2255910	2256710	I'll be honest.
2256710	2259970	I really started to pick up ROP like in the last three years.
2259970	2261490	Mostly on the Intel side.
2261490	2264290	Kind of more recently on the iOS side.
2265530	2270690	This is a way for us to be able to bypass that non-executable region of memory, right?
2270690	2271450	The NX.
2271450	2275170	So, effectively, you're trying to chain together a bunch of gadgets.
2275170	2277270	And gadgets have certain memory addresses.
2277270	2279470	So, you're going to pass a bunch of garbage data.
2279470	2285130	X, Y, Z, 1, 2, 3, and then a memory address for the gadget that you're actually trying to take advantage of.
2285130	2287030	And then a bunch of more garbage data.
2288250	2291910	A, B, C, 1, 2, 3, and then the gadget 2 address.
2292330	2294770	Typically, we don't use A, B, C, 1, 2, 3.
2294910	2295910	We use A's.
2295910	2298230	That was my demonstration there.
2299990	2306030	Dynamic libraries allow for applications to be able to load code that's already...
2307430	2309370	to load code into the address space.
2309370	2311230	So, it's basically like a DLL.
2311750	2319710	A dynamic link editor, or a DYOD, is basically native to the operating system of Mac.
2319710	2323110	And, effectively, it's responsible for loading and linking.
2324530	2330470	So, this is for loading and linking dynamic libraries while the application is running, which is very important.
2330570	2339790	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.
2340010	2342730	And it's called DYOD Shared Cache.
2343230	2349190	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.
2350890	2353290	This is how you're going to find your ROP gadgets.
2353610	2358290	You're trying to figure out this really cool and unique...
2358870	2365370	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.
2365410	2367870	So, you're going to leverage that's considered a gadget.
2367870	2369410	So, you're going to leverage the ROP gadgets.
2369410	2380670	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.
2382830	2386770	So, when we're running these tools, because it's a tool, so don't just run it blindly.
2386770	2389450	You want to ask yourself, is this going to meet my objective?
2390670	2392470	What dilibs are loaded?
2392470	2394050	What dynamic libraries are loaded?
2394110	2396790	And what dynamic libraries should I be looking in?
2396990	2403250	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.
2403350	2409850	And you're going to want to use LLDB and leverage ImageList.
2409890	2411650	And from here, I'm showing a screenshot.
2411650	2418910	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.
2418910	2425890	Things like CommonCrypto or MacO or SystemC, right?
2425890	2426990	Those sorts of things.
2427050	2428910	So, the fun part.
2429230	2432750	Finding gadgets in dynamic libraries.
2432770	2436170	I leverage a tool called Ropper because I like the name of it.
2436170	2439510	Like, seriously, this is just other tools, but Ropper is, like, one of my favorites.
2439730	2448510	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.
2448510	2449610	What are you trying to do?
2449610	2450830	Are you trying to move?
2451310	2451630	Alright?
2451630	2452950	Are you trying to copy?
2452970	2454450	Are you trying to do something else?
2455310	2465670	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.
2465670	2469010	Remember, we talked about ABC123, gadget address.
2469010	2472010	Well, right there in the red is your gadget address.
2472010	2473310	Alright?
2475430	2476890	Jop chains.
2476910	2482510	Now, Jop, this is something that I'm really starting to get into in the last couple months.
2482930	2490070	So, this is, like, the top of where we are right now for exploitation on the iOS systems.
2490070	2494970	In real world exploitation, you probably won't find a full Rop chain.
2495010	2496210	It just won't happen.
2496230	2499650	But you will use Jop and Rop together.
2499790	2502570	And so Jop is Jop-oriented programming.
2502570	2504110	It's different than Rop.
2504610	2510030	Rop's generally end in a return and Jop's will end in an indirect jump.
2510210	2514650	So we're looking to be able to control the flow of the program.
2514830	2518130	We want to make it do a dance for us.
2518330	2521170	So, we don't really want to kill the program.
2521170	2522090	We don't want it to return.
2522090	2522790	We don't want it to end.
2522790	2525210	We want it to branch to the next instruction.
2525890	2532270	So that's where you kind of get that BRX1 is branching over to that register.
2532270	2534890	Versus in Rop, where you're doing a return.
2535390	2542350	But also, as we're branching over to X1, make sure that that register contains the address of the next instruction.
