1 00:00:00,000 --> 00:00:02,360 That's it. Without further ado, Cameron Hotchkies. 2 00:00:08,500 --> 00:00:11,660 Alright, thanks everybody for showing up this early in the morning. 3 00:00:12,380 --> 00:00:18,840 My name is Cameron Hotchkies, and I will be presenting basics to OSX Reverse Engineering. 4 00:00:19,540 --> 00:00:22,560 Who I am, I work at Tipping Point's DV Labs. 5 00:00:23,240 --> 00:00:29,380 Part of my job is to work with the vulnerability research team, work on the ZDI team. 6 00:00:29,380 --> 00:00:36,440 So we do patch analysis, product security, reverse engineering of various formats. 7 00:00:36,640 --> 00:00:37,920 I do a lot of the Apple stuff. 8 00:00:38,500 --> 00:00:41,980 And we have our blog that I'm required to tell you all to check out. 9 00:00:42,040 --> 00:00:45,240 I write the line noise if anybody reads that. 10 00:00:46,260 --> 00:00:50,980 I also, in the past, have written and contributed to PyMay. 11 00:00:51,120 --> 00:00:56,420 If you've done any reversing or you use OpenRCE, that's Pedram's baby. 12 00:00:56,920 --> 00:00:58,920 And I worked on that a little bit. 13 00:00:59,700 --> 00:01:03,640 Farther back in the past, I wrote Absinthe, which is a SQL injection tool. 14 00:01:03,840 --> 00:01:05,360 But I don't really do the web stuff anymore. 15 00:01:05,660 --> 00:01:07,180 That's sort of an old thing. 16 00:01:07,280 --> 00:01:08,760 If you're like, hey, I think I saw that guy one time. 17 00:01:10,140 --> 00:01:16,540 But I also have a side project that I'm trying to push, like crack on everybody who's interested in OSX reversing, 18 00:01:16,540 --> 00:01:17,960 which I think is everybody in this room. 19 00:01:19,320 --> 00:01:21,760 Either that or you're just looking for a quiet place to sit down. 20 00:01:22,060 --> 00:01:24,620 But if you are interested in the stuff I'm talking about, 21 00:01:24,760 --> 00:01:26,560 I have the XSO mailing list. 22 00:01:27,180 --> 00:01:29,360 And there's a lot of really talented, smart people. 23 00:01:29,380 --> 00:01:31,660 There's a lot of people that are on that list. 24 00:01:31,740 --> 00:01:32,480 It's very low traffic. 25 00:01:32,800 --> 00:01:35,460 But if you have any questions, everybody's fairly friendly. 26 00:01:35,660 --> 00:01:39,060 And I can help you out with OSX-specific reversing stuff. 27 00:01:41,820 --> 00:01:45,540 So this is roughly the format I'm going to go through, the stuff I'm going to cover. 28 00:01:46,060 --> 00:01:49,840 Basic stuff on file formats, which is the macro file format. 29 00:01:50,100 --> 00:01:51,640 I'm not going to spend a lot of time on that, 30 00:01:51,740 --> 00:01:55,340 because you're not going to spend a lot of time working with that, for the most part. 31 00:01:55,880 --> 00:01:59,360 Various tools that are available for reverse engine. 32 00:01:59,380 --> 00:02:04,420 There's a lot of engineers on OSX, or people who are just reversing OSX stuff. 33 00:02:04,540 --> 00:02:06,120 You'll figure out why I'm clarifying that. 34 00:02:06,600 --> 00:02:08,620 And then I'll go into common disassembly patterns, 35 00:02:08,900 --> 00:02:13,020 which is always helpful to look at if you've never looked at any of these binaries before. 36 00:02:13,480 --> 00:02:16,460 Cover carbon and Objective-C, which is going to be the bulk of it. 37 00:02:16,580 --> 00:02:18,440 And then get onto a little bit on iPhones, 38 00:02:18,620 --> 00:02:21,240 so everybody can be like, yay, I learned about iPhone stuff. 39 00:02:23,280 --> 00:02:29,120 So on OSX, how many people actually here use OSX regularly? 40 00:02:29,120 --> 00:02:30,800 Like, we're all Apple users. 41 00:02:31,040 --> 00:02:34,700 Okay, so I'm sorry if I'm going to be talking down to you for the next little bit, 42 00:02:34,780 --> 00:02:36,100 and you're like, dude, I know what you're talking about. 43 00:02:36,260 --> 00:02:37,440 But it needs to be covered. 44 00:02:37,660 --> 00:02:41,880 App bundles, for the three people who aren't Apple users, 45 00:02:42,380 --> 00:02:45,520 what they are, it's a file folder structure 46 00:02:45,520 --> 00:02:48,080 where the actual applications are stored 47 00:02:48,080 --> 00:02:53,420 with all the extra libraries and images and graphics and whatnot. 48 00:02:53,700 --> 00:02:55,420 And those are referred to as bundles or packages. 49 00:02:56,920 --> 00:02:58,860 Finder will treat that as, like, 50 00:02:58,860 --> 00:03:01,620 its own single entity, this atomic thing, 51 00:03:01,740 --> 00:03:03,240 and when it's really a folder structure. 52 00:03:04,440 --> 00:03:06,660 And you already know probably all of that. 53 00:03:06,960 --> 00:03:10,360 But this is what an app bundle will look like for the most part. 54 00:03:10,640 --> 00:03:13,020 You'll have a top-level program, 55 00:03:13,860 --> 00:03:15,340 which will be the directory structure. 56 00:03:15,620 --> 00:03:20,300 Finder hides the .app extension. 57 00:03:20,880 --> 00:03:23,320 Underneath that, you have the contents directory sitting by itself. 58 00:03:23,640 --> 00:03:26,420 And inside of the contents directory, you have the package info file. 59 00:03:27,140 --> 00:03:28,360 Anything gray is a file. 60 00:03:28,860 --> 00:03:30,820 And white is a directory, just in case you're curious. 61 00:03:31,300 --> 00:03:32,560 Mac OS is a directory. 62 00:03:32,720 --> 00:03:33,960 And inside of that, you have program, 63 00:03:34,260 --> 00:03:39,480 which is going to be the same name as the app bundle name without the .app. 64 00:03:39,660 --> 00:03:41,400 Usually, it doesn't have to be. 65 00:03:41,740 --> 00:03:45,460 But for the most times, most of the time, people will do the same thing. 66 00:03:46,520 --> 00:03:51,000 Resources is where you put your nib files and PNG files, et cetera. 67 00:03:51,300 --> 00:03:53,840 Frameworks, plugins, shared frameworks, shared support. 68 00:03:54,120 --> 00:03:55,540 They're all optional directories, 69 00:03:55,540 --> 00:03:58,040 but they may end up in those directories 70 00:03:59,040 --> 00:04:01,620 if you're just going straight for binary reversing 71 00:04:01,620 --> 00:04:03,140 and you don't care about all the supporting data. 72 00:04:03,300 --> 00:04:04,920 You're just going to go straight to the Mac OS directory 73 00:04:05,900 --> 00:04:07,940 and take a look at the program binary. 74 00:04:09,460 --> 00:04:10,980 So the info.plist file, 75 00:04:12,340 --> 00:04:14,660 which you can see is right underneath package info. 76 00:04:14,840 --> 00:04:18,860 The info.plist file is going to store a lot of the application-specific properties. 77 00:04:19,180 --> 00:04:25,180 It has data such as the version numbers, icon names, 78 00:04:25,260 --> 00:04:28,520 anything that's supporting that you might want to change really quickly. 79 00:04:28,520 --> 00:04:30,000 Without having to recompile the binary. 80 00:04:30,300 --> 00:04:32,140 It's been fairly well documented by Apple, 81 00:04:32,220 --> 00:04:35,560 so I'm not going to spend a lot of time covering it right now. 82 00:04:36,600 --> 00:04:38,100 The one thing is a lot of people are like, 83 00:04:38,180 --> 00:04:39,020 this is an XML file. 84 00:04:39,240 --> 00:04:41,200 It isn't always going to be an XML file. 85 00:04:41,360 --> 00:04:42,880 Sometimes it's going to be a binary file. 86 00:04:43,280 --> 00:04:45,020 But for that, you have the PLU till. 87 00:04:45,180 --> 00:04:49,360 And that will just convert between the binary version and the XML version. 88 00:04:49,520 --> 00:04:52,560 So then it can become the XML version that your friend told you it always was. 89 00:04:52,760 --> 00:04:54,520 And you'll know secretly in your heart that it isn't. 90 00:04:54,840 --> 00:04:57,860 But just a little like hint that, 91 00:04:58,760 --> 00:05:02,640 some of the people at Apple are still kind of like that old school Unix crazy people. 92 00:05:03,160 --> 00:05:05,520 If you go to man, the PLU till utility, 93 00:05:06,200 --> 00:05:08,340 or to check out the man page is right at the bottom. 94 00:05:08,480 --> 00:05:09,580 There's just like this little thing. 95 00:05:09,700 --> 00:05:13,540 It's like the PLU till command obeys no one's rules but its own. 96 00:05:13,860 --> 00:05:15,760 It's sort of a non sequitur right at the bottom there. 97 00:05:15,820 --> 00:05:17,160 But you're like, okay, they're crazy. 98 00:05:19,720 --> 00:05:24,960 Package info is another supporting file that's going to, in theory, have metadata. 99 00:05:25,180 --> 00:05:27,320 But it's usually only going to be eight bytes long. 100 00:05:27,620 --> 00:05:28,420 It's going to have, 101 00:05:28,420 --> 00:05:32,460 you have APBL and a signature. 102 00:05:32,780 --> 00:05:34,460 So it's there. 103 00:05:34,600 --> 00:05:36,100 You're probably never going to use it. 104 00:05:37,840 --> 00:05:40,560 Now when you get into that Mac OS condense directory, 105 00:05:40,820 --> 00:05:44,220 you're going to be looking at a Mako file format file. 106 00:05:46,540 --> 00:05:48,940 This is the standard binary format on OS X. 107 00:05:49,400 --> 00:05:52,340 It has the feed face magic number. 108 00:05:52,620 --> 00:05:55,580 If you're on a 64-bit platform, it's going to be feed faqf, 109 00:05:56,280 --> 00:05:58,400 which is just identifying that you're on a 64-bit platform. 110 00:05:58,400 --> 00:05:59,560 You're dealing with a 64-bit. 111 00:05:59,820 --> 00:06:02,580 Now there's the fat universal binaries. 112 00:06:02,640 --> 00:06:05,500 So when Apple switched over to using the Intel chipset, 113 00:06:05,540 --> 00:06:12,280 they started putting both the PPC and the x86 code into the binaries together. 114 00:06:13,180 --> 00:06:15,400 And so they're just referred to the fat ones. 115 00:06:15,520 --> 00:06:16,960 And they're identified by CafeBabe. 116 00:06:17,400 --> 00:06:21,460 Now CafeBabe is also used in Java. 117 00:06:21,780 --> 00:06:24,860 So you're just like, how am I supposed to know the difference? 118 00:06:25,060 --> 00:06:27,280 You don't really need to know the difference. 119 00:06:27,280 --> 00:06:28,760 They'll figure it out on its own. 120 00:06:28,940 --> 00:06:36,920 But the interesting thing about Mako binaries is that you want to be really careful when you Google 121 00:06:37,680 --> 00:06:39,780 for extra information on it. 122 00:06:40,000 --> 00:06:45,620 I'd say put site colon apple.com or something similar that you trust, 123 00:06:45,740 --> 00:06:49,500 because otherwise you just get the most random screwed up stuff such as that. 124 00:06:49,640 --> 00:06:51,100 I read that paper. 125 00:06:51,240 --> 00:06:54,280 It was like a 12-page academic paper. 126 00:06:54,560 --> 00:06:56,760 And I read it about three times. 127 00:06:56,760 --> 00:06:58,280 I still have no idea what the hell it was about. 128 00:06:58,760 --> 00:07:00,960 I think it was one of those auto-generated ones. 129 00:07:01,560 --> 00:07:07,320 But the CafeBabe thing, coming from Java, it's not actually from Java. 130 00:07:07,660 --> 00:07:10,800 Java actually came after the Mako file format. 131 00:07:10,960 --> 00:07:14,380 And I'll get into that in the history of Objective-C stuff later. 132 00:07:15,540 --> 00:07:20,660 But if you're looking at the Mako file format, it's changed and adapted over the years. 133 00:07:21,320 --> 00:07:23,040 Some of it's going to be fairly constant. 134 00:07:23,200 --> 00:07:26,740 You have .text, which if you're used to Windows, it's going to seem as odd. 135 00:07:26,740 --> 00:07:34,700 And there's some stuff that's slowly been deprecated and removed and now is just not 136 00:07:34,700 --> 00:07:36,740 mentioned anywhere as if it never existed. 137 00:07:37,180 --> 00:07:44,320 So if you find really, really old docs, anything with the asterisks here is going to be older 138 00:07:44,320 --> 00:07:45,960 stuff that's not really relevant anymore. 139 00:07:46,120 --> 00:07:50,280 But if you're looking at old binaries, maybe some next step binaries, then these may very 140 00:07:50,280 --> 00:07:52,360 well be in the binary. 141 00:07:53,080 --> 00:07:54,620 So they're pretty straightforward. 142 00:07:55,000 --> 00:07:56,720 You have the code stored in the .txt. 143 00:07:56,720 --> 00:08:02,760 You have the constants stored in the constants section, static constants stored in the static 144 00:08:02,760 --> 00:08:05,760 constants section, and so on and so on all the way through it. 145 00:08:07,080 --> 00:08:12,340 In the data section, that's where you're going to have your variables, your symbol 146 00:08:12,340 --> 00:08:15,320 pointers, your constructors. 147 00:08:16,120 --> 00:08:19,020 So it's pretty straightforward as well. 148 00:08:19,220 --> 00:08:24,100 If you're using any modern disassembler, then it'll sort all this stuff out for you. 149 00:08:24,540 --> 00:08:26,700 This is the part that you actually want to pick. 150 00:08:26,720 --> 00:08:28,020 Pay attention to it, one second. 151 00:08:32,700 --> 00:08:37,680 The Objective-C segment is going to be storing, if you're looking at an Objective-C binary, 152 00:08:37,820 --> 00:08:42,380 which is going to be a lot of the binaries on Apple stuff, they're made by third parties, 153 00:08:43,660 --> 00:08:46,760 then a lot of metadata is stored in the Objective-C segment. 154 00:08:47,920 --> 00:08:52,300 A lot of stuff is passed around by strings, so they need to store the strings somewhere 155 00:08:52,300 --> 00:08:52,900 for reference. 156 00:08:54,460 --> 00:08:56,700 Now if you look at any documentation, there's a lot of stuff that's stored in the Objective-C segment. 157 00:08:56,720 --> 00:08:59,500 If you look at any documentation from Apple, they'll say all sections in the Objective-C 158 00:08:59,500 --> 00:09:04,200 segment, including old sections that are no longer used, future sections, whatever, 159 00:09:04,700 --> 00:09:06,700 they're reserved for the Objective-C compiler's use. 160 00:09:07,420 --> 00:09:10,880 So what they're saying is good luck, you're on your own, we're not going to tell you what 161 00:09:10,880 --> 00:09:11,120 they mean. 162 00:09:13,840 --> 00:09:19,500 Luckily, they're fairly decently named, so you can figure out their purpose, and the 163 00:09:19,500 --> 00:09:25,800 structure is a little weird if you're coming from somewhere else, but most of that's also 164 00:09:25,800 --> 00:09:25,980 documented. 165 00:09:26,500 --> 00:09:31,620 I have a Python script that's included on the DEF CON CD that will rebuild a lot of 166 00:09:31,620 --> 00:09:34,460 this for you, so you don't have to worry about it, but if you're curious about the structure 167 00:09:34,460 --> 00:09:37,000 of it, you can take a look at the Python script. 168 00:09:38,980 --> 00:09:44,600 Now this doesn't really fit anywhere else in the talk, but Tiller, when I was hanging 169 00:09:44,600 --> 00:09:47,700 out with him in Montreal, was talking to me, he was like, dude, you should put this in 170 00:09:47,700 --> 00:09:48,040 your slides. 171 00:09:49,000 --> 00:09:55,780 What this is, is VM Map is a tool available on OS X for map processing. 172 00:09:56,180 --> 00:09:59,140 Mapping the binary at run time, just figuring out where the memory is laid out. 173 00:09:59,540 --> 00:10:02,820 There's different tools on different platforms, this happens to be the one on OS X. 174 00:10:03,240 --> 00:10:06,480 Just out of curiosity, was anybody at Tiller and Dave's talk earlier? 175 00:10:07,700 --> 00:10:08,480 A few of you. 176 00:10:09,000 --> 00:10:14,700 If you missed it, what they did is they presented on retrace, and I'll get to that in a little 177 00:10:14,700 --> 00:10:17,640 bit, but you should definitely check out the slides, because they did some really interesting 178 00:10:17,640 --> 00:10:18,120 work there. 179 00:10:19,300 --> 00:10:24,000 So if you're on OS X doing some work, you're going to need a hex editor. 180 00:10:26,340 --> 00:10:28,300 I've got a couple I'm going to show you. 181 00:10:28,580 --> 00:10:34,820 Hexer is one that's written by Zynamix, formerly Saber, the same guys who do Bindiff. 182 00:10:36,340 --> 00:10:40,800 SP threw this together, and it's a fairly nice hex editor for OS X. 183 00:10:41,980 --> 00:10:46,520 It has a pretty solid architecture for building plugins and scripts. 184 00:10:46,620 --> 00:10:52,700 If you've used 010 editor on Windows, you can build very similar structures in either 185 00:10:52,700 --> 00:10:55,220 Ruby, Java, and Python, I believe. 186 00:10:55,300 --> 00:10:55,780 It's pretty good. 187 00:10:55,800 --> 00:10:58,040 But in the scripting architecture for Hexer. 188 00:10:58,920 --> 00:11:02,720 And if you ever have a question or a bug report, SP will probably answer you by the end of 189 00:11:02,720 --> 00:11:02,960 the day. 190 00:11:04,440 --> 00:11:10,120 Hex Fiend is another one that the Modisano guys pointed out about a year ago, I believe. 191 00:11:10,540 --> 00:11:14,080 And they asked him to open source it, and he did open source it. 192 00:11:14,140 --> 00:11:16,080 At that point, I think he stopped maintaining it. 193 00:11:16,260 --> 00:11:17,900 So it's an open source hex editor. 194 00:11:18,100 --> 00:11:22,480 It handles really large files fairly well, and it runs natively on OS X. 195 00:11:22,740 --> 00:11:25,640 So if you just want to mess around with that, it's available there. 196 00:11:27,980 --> 00:11:31,640 OXN, yet another one, takes plugins, you're like, are you really going to show me hex 197 00:11:31,640 --> 00:11:32,800 editors for the whole presentation? 198 00:11:33,120 --> 00:11:34,480 And the answer is, no, I'm going to stop now. 199 00:11:35,320 --> 00:11:36,720 I'm going to move on to some real stuff. 200 00:11:37,780 --> 00:11:38,180 OTool. 201 00:11:38,320 --> 00:11:44,020 This is what a lot of people sort of started using when they were reverse engineering binaries 202 00:11:44,020 --> 00:11:44,600 on OS X. 203 00:11:45,620 --> 00:11:48,440 Some of the people who have been doing it for longer, they're fairly comfortable with 204 00:11:48,440 --> 00:11:48,680 it. 205 00:11:49,100 --> 00:11:53,100 But it gives you AT&T, no, yes, AT&T syntax. 206 00:11:53,920 --> 00:11:55,140 Well, and this is what it does. 207 00:11:55,140 --> 00:11:55,200 It gives you AT&T syntax. 208 00:11:55,200 --> 00:11:55,620 Well, and this is what it does. 209 00:11:55,640 --> 00:11:56,760 It disassembles all of the binaries. 210 00:11:56,840 --> 00:11:59,120 It's like object dump, except they call it OTool. 211 00:12:01,520 --> 00:12:04,720 And you can list the libraries like you could in object dump. 212 00:12:06,920 --> 00:12:10,400 And the problem with OTool is that it's just straight disassembly. 213 00:12:10,500 --> 00:12:15,800 There's a lot of very, very basic stuff you could put together, and somebody did it. 214 00:12:16,240 --> 00:12:17,620 And OTX is that tool. 215 00:12:17,820 --> 00:12:19,680 I've colored it in blue so you can see. 216 00:12:20,460 --> 00:12:23,440 If you don't know Objective-C, this is probably meaningless to you, but don't worry. 217 00:12:23,480 --> 00:12:25,320 I'm going to give you a crash course in Objective-C. 218 00:12:25,940 --> 00:12:27,700 In about three minutes. 219 00:12:28,080 --> 00:12:34,160 But you can see the strings being dereferenced, the alloc here, the NSMutable array. 220 00:12:34,760 --> 00:12:39,340 So if you know Objective-C, you're like, oh, cool, that just saved me the 30 seconds 221 00:12:39,340 --> 00:12:41,500 it would take to figure it out on my own. 222 00:12:42,180 --> 00:12:45,580 But it works fairly fast, and it just takes the output of OTool. 223 00:12:45,700 --> 00:12:46,940 So you can pick it up there. 224 00:12:47,900 --> 00:12:48,620 Class dump. 225 00:12:50,160 --> 00:12:52,000 That's going to dump the headers for you. 226 00:12:52,160 --> 00:12:52,260 Now. 227 00:12:52,480 --> 00:12:55,620 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 00:12:55,620 --> 00:13:25,600 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 00:13:25,600 --> 00:13:29,720 of the verboseness of all the information it is giving you, so it's pretty cool for 230 00:13:29,720 --> 00:13:34,700 that stuff. Now you're like, Cam, you've gone crazy. 231 00:13:35,800 --> 00:13:43,280 IDA, that's a Windows tool. We're all Mac users. I use IDA on Parallels. I came from 232 00:13:43,280 --> 00:13:52,440 a Windows reverse engineering background. I just run Parallels. If you're running one 233 00:13:52,440 --> 00:14:02,620 instance of IDA, it'll be fairly stable. If you run two, then it looks roughly like this 234 00:14:02,620 --> 00:14:08,440 and it starts to choke up. But we've got two. We'll get to those in a little bit. But for 235 00:14:08,440 --> 00:14:14,580 the most part, some people like OTool. I like a lot more information. I like all the features 236 00:14:14,580 --> 00:14:21,880 that IDA has, and I'm really comfortable scripting and writing plug-ins in IDA, so I'll generally 237 00:14:21,880 --> 00:14:22,380 use it there. 238 00:14:22,380 --> 00:14:29,040 Now the second bullet point says IDA Pro for OS X runs on the console. It does. I have 239 00:14:29,040 --> 00:14:36,140 the 5.3 version, so the most recent version. It's really buggy. If you're creating just 240 00:14:37,080 --> 00:14:42,220 D words, it'll get segfault on you. So for the most part, unless I'm going to run it 241 00:14:42,220 --> 00:14:45,940 in batch mode, I'll keep using IDA on Windows. 242 00:14:47,060 --> 00:14:52,200 So there's IDA. There's Parallels. This isn't new to most of you guys. They're not 243 00:14:52,200 --> 00:14:55,360 free, but easily worth the money if you're going to be doing this seriously. 244 00:14:56,380 --> 00:15:02,720 And then Debuggers. This is one of the short... This is one of the weaker aspects of reversing 245 00:15:02,720 --> 00:15:07,100 on OS X. Nobody I've talked to has really settled on one that they're like, dude, this 246 00:15:07,100 --> 00:15:10,820 is totally awesome. They're like, it kind of works, and it fixes this one problem this 247 00:15:10,820 --> 00:15:11,720 other debugger had. 248 00:15:12,740 --> 00:15:18,800 But Charlie Miller ported PyDebug to OS X a while ago, which is the PyMay scriptable 249 00:15:18,800 --> 00:15:22,180 Python debugger. Obviously, GDB is going to be... 250 00:15:22,180 --> 00:15:27,980 On your stock install. When I say stock install, I mean stock install with Xcode. Does anybody 251 00:15:27,980 --> 00:15:33,020 here not know what Xcode is? All right, cool. I can save that in 30 seconds. 252 00:15:34,700 --> 00:15:40,440 So PyGDB, which is another Python interface through GDB, is available on Google Code. 253 00:15:42,760 --> 00:15:50,880 Vtrace, yet another debugger, is available at Kenshodo. And Tiller and Dave, the guys 254 00:15:50,880 --> 00:15:52,160 who were presenting earlier, are going to be using it. So it's going to be a lot easier. 255 00:15:52,180 --> 00:15:56,280 I don't know if they released it today, or they will be releasing it shortly, or if 256 00:15:56,280 --> 00:15:59,900 you just have to email them and they'll send it to you. But they have Redbug, which is 257 00:15:59,900 --> 00:16:05,040 a Ruby scriptable debugger as well, that's set to interface with the retrace set of tools. 258 00:16:05,600 --> 00:16:08,360 End of the day? Okay, that's cool. 259 00:16:09,400 --> 00:16:14,120 And end of the day, this is probably where you're going to want to go get it. Poppopret.org. 260 00:16:15,520 --> 00:16:21,560 What retrace is, is a Ruby framework to interact with Dtrace. And I'm not going to spend a 261 00:16:21,560 --> 00:16:22,160 lot of time on it. I'm going to spend a lot of time on it. I'm not going to spend a lot of time on it. 262 00:16:22,160 --> 00:16:25,300 Because you have all of their slides. And they wrote a really good white paper, so you 263 00:16:25,300 --> 00:16:30,160 can take a look at that after the fact. But it's just basically scripting Dtrace. 264 00:16:31,980 --> 00:16:39,940 So we're into the Objective-C portion of the talk. I think I'm talking extremely fast. 265 00:16:40,080 --> 00:16:45,580 I am. Okay, I'm just going to stand here for a second and stare at you. That guy. 266 00:16:46,400 --> 00:16:49,320 That guy got me a Redbull right beforehand, which was a bad idea. 267 00:16:51,600 --> 00:16:51,960 Okay. 268 00:16:51,960 --> 00:16:58,920 Okay. Objective-C is, or we're not even there. We're in the calling convention part. I'm 269 00:16:58,920 --> 00:17:05,780 not talking that fast. Okay. Calling conventions. I saw Objective-C and I panicked. The calling 270 00:17:05,780 --> 00:17:12,600 conventions are standard call, which is going to be pushing the variables onto the stack, 271 00:17:12,780 --> 00:17:20,440 except it's not pushing them. It pre-allocates the stack space. So if you're used to push-push-push-call, 272 00:17:20,440 --> 00:17:24,960 it's doing the exact same thing, but it's pre-allocated. So you can see right in the 273 00:17:24,960 --> 00:17:32,020 middle here, you've got var 98, which is actually just ESP with no modifier, and then 94, which 274 00:17:32,020 --> 00:17:37,680 is the plus four. And so it's just putting it on the stack space, and it'll call message 275 00:17:37,680 --> 00:17:42,140 send in this case. And it takes care of all of that. 276 00:17:42,220 --> 00:17:47,260 Now, the first tendency as somebody using IDA would be to write a quick script to rename 277 00:17:47,260 --> 00:17:50,420 all of these variables. But it will allocate all of these variables, and it will allocate 278 00:17:50,440 --> 00:17:55,600 all the stack space, and then possibly later allocate further stack space. So there's a 279 00:17:55,600 --> 00:18:01,000 little hiccup into the naming scheme. Once again, I've already done that in the Python 280 00:18:01,000 --> 00:18:08,920 script that's included. Just so you know, I'm not lying to you. Oh, totally lying to 281 00:18:08,920 --> 00:18:14,860 you. No, it's right here. This is the thing. It's just basically a scratch pad for stuff 282 00:18:14,860 --> 00:18:16,280 I've noticed when I've been working on this. 283 00:18:18,500 --> 00:18:18,980 So... 284 00:18:20,800 --> 00:18:25,820 That's the only major difference between various other binaries that are using standard call. 285 00:18:26,460 --> 00:18:31,500 So just whatever you do before you rename them, check the stack delta, and you should 286 00:18:31,500 --> 00:18:32,000 be good to go. 287 00:18:36,260 --> 00:18:42,960 Now, in pretty much every OSX binary, it's set up to be using position independent code. 288 00:18:44,140 --> 00:18:50,420 So you're going to be seeing this, like, EBX value that's all over the place. Now, just 289 00:18:50,420 --> 00:18:56,060 out of curiosity, how many people do use IDA for reversing purposes? A couple of you 290 00:18:56,060 --> 00:18:56,240 guys. 291 00:18:56,780 --> 00:19:01,740 So the rest of you, if you don't have IDA and you start to get IDA, you're going to 292 00:19:01,740 --> 00:19:06,980 get version 5.3, which fixes this. But for the four of you guys probably using 5.2 or 293 00:19:06,980 --> 00:19:07,920 older, I'm going to keep going. 294 00:19:08,920 --> 00:19:14,640 EBX is the Position Independent Anchor Point. So it's just basically... It's not the start 295 00:19:14,640 --> 00:19:17,140 of the function, it's just a random address in the function. 296 00:19:17,140 --> 00:19:23,340 function. They use that to reference all of the other position independent code or the 297 00:19:23,880 --> 00:19:27,320 data that it's going to be referring to. EBX is most frequently, I don't think I've ever 298 00:19:27,320 --> 00:19:31,700 seen anything that's not EBX, but I'm not going to say it won't be. I don't want you 299 00:19:31,700 --> 00:19:36,700 to wake up six months from now and be like, yeah, you lied to me, which I might. 300 00:19:38,240 --> 00:19:44,160 There's two ways to generate the anchor. The first one is it's going to call up a function. 301 00:19:44,160 --> 00:19:48,140 I just called it getPC because that's what it's doing. It's going to probably be some 302 00:19:49,500 --> 00:19:57,240 90476 when you see it. All it's doing is dereferencing the stack pointer, moving it into EBX, and 303 00:19:57,240 --> 00:20:03,740 returning, which is just going to be the return address, which is the exact same as calling 304 00:20:03,740 --> 00:20:11,640 five and popping EBX because the value would have been stored into EBX. If you've done 305 00:20:11,640 --> 00:20:14,140 any shell code, the second half of the code will be sent in. 306 00:20:14,140 --> 00:20:18,360 half. The second version looks very familiar because it's using a lot of shell code. 307 00:20:19,940 --> 00:20:25,800 This was all fixed in IDA 5.3. I wrote a script to fix it, and I was working on a plug-in 308 00:20:25,800 --> 00:20:30,220 to fix it, and then ILFAC fixed it himself, so you don't need any of my tools for this. 309 00:20:32,640 --> 00:20:39,500 And his works faster. So you can see at the top of this, you have 310 00:20:39,500 --> 00:20:50,760 the call plus 5, the pop EBX. That's saying that EBX is going to be the 1DO6 address value. 311 00:20:53,180 --> 00:20:58,640 And then later on, where is it? I can't even see it here. This is probably a bad example. 312 00:20:59,400 --> 00:21:03,540 No, you can see it. You can see the init. This is where the text is coming from. The 313 00:21:03,540 --> 00:21:09,380 EBX plus 1316 in hex is actually a string to the NS-Auto release pool. 314 00:21:10,400 --> 00:21:18,720 That's being called later. And depending on where it is in the binary, 315 00:21:18,900 --> 00:21:24,320 it's either going to be just a small little value, or it'll be this massive D word that's 316 00:21:24,760 --> 00:21:31,220 pulled from another section. Now there's two main ways of writing, or 317 00:21:31,220 --> 00:21:38,580 there's two main frameworks for writing code on OSX systems. Carbon is the C, C++ based 318 00:21:41,480 --> 00:21:46,220 framework that's going to be used. It was descended from the original Mac toolbox. 319 00:21:47,180 --> 00:21:52,240 So this is the point where I ask how long you guys have been using Mac. How many guys 320 00:21:52,240 --> 00:21:58,040 have been using Mac since they were actually next step machines? Okay, a couple of you 321 00:21:58,040 --> 00:22:02,840 guys. You guys are going to be... Feel free to correct me if I'm ever talking smack on 322 00:22:02,840 --> 00:22:08,320 this section, because I'm not much of a carbon coder. Now, do we have many carbon programmers 323 00:22:08,320 --> 00:22:14,860 in the house? That guy? All right, do we have any Objective-C programmers in the house? 324 00:22:16,000 --> 00:22:24,540 All right, a couple more. So carbon is the C, C++ stuff. It's the stuff Windows programmers 325 00:22:24,540 --> 00:22:29,320 feel most comfortable moving to, because they don't have to learn another language. Apple, 326 00:22:29,540 --> 00:22:35,380 in all their documentation, really encourages you to keep on trucking over to the cocoa-Objective-C 327 00:22:35,380 --> 00:22:38,300 world, but a lot of people in their... Yeah, I don't know if you know that, but I think 328 00:22:38,300 --> 00:22:44,700 attempt to get stuff ported over quickly, we'll be using Cocoa. POGR applications are 329 00:22:44,700 --> 00:22:53,080 written in Cocoa. There's usually a two-letter prefix on framework libraries, so HINCG is 330 00:22:53,080 --> 00:23:01,860 going to indicate that they're probably written in Carbon. Objective C, which is what I program 331 00:23:01,860 --> 00:23:10,560 in mainly now, is created in the 80s by StepStone. Then it was popularized by Next, so the five 332 00:23:10,560 --> 00:23:16,660 guys who were using Next in the late 80s remember this stuff. The original version of Doom, 333 00:23:16,740 --> 00:23:22,340 I believe, is written in it. It was inspired by Smalltalk, and so it's a set of decorators 334 00:23:22,340 --> 00:23:27,880 on top of C, which means they change it around. People, you start to try and explain to them, 335 00:23:27,920 --> 00:23:30,420 they're like, oh, it's like C++, and you're like, no, not really. 336 00:23:32,860 --> 00:23:37,380 But the functions aren't called. It's a message-sending architecture. 337 00:23:37,900 --> 00:23:41,740 When you see all these strings that I was showing you earlier that are just scattered 338 00:23:41,740 --> 00:23:47,460 around the binary, instead of having a direct cross-reference to those functions, it's 339 00:23:47,460 --> 00:23:54,220 going to pass in that string, and the underlying system will go through and figure out which 340 00:23:54,220 --> 00:24:00,240 function you're actually trying to call and translate it. Unicode strings are standard 341 00:24:00,240 --> 00:24:00,400 applications. They're not called. They're not called. They're not called. They're not 342 00:24:00,400 --> 00:24:04,820 standardized, but it's generally, like, two-byte Unicodes are supposed to be standardized, 343 00:24:05,020 --> 00:24:10,580 but it's actually stored internally, for the most part, as null-terminated UTF-8 strings, 344 00:24:11,360 --> 00:24:16,780 which is Unicode. But it looks like it was standard C libraries are referred to as frameworks, 345 00:24:16,960 --> 00:24:19,640 so I keep dropping that name. Now you know what I was talking about. 346 00:24:21,900 --> 00:24:29,220 Now Objective-C has a lot of framework classes to call from. It's like other managed languages, 347 00:24:29,320 --> 00:24:30,260 like .NET. 348 00:24:30,260 --> 00:24:36,940 or Java, where there's a whole huge set of frameworks that are all built together. The 349 00:24:36,940 --> 00:24:47,200 common framework classes, they all have the NS or CF prepended. NS is actually the Objective-C 350 00:24:47,200 --> 00:24:55,160 stuff, and CF might be derived from some of the other carbon, like C++ stuff. But pretty 351 00:24:55,160 --> 00:24:59,080 much every, it's standardized that every framework is going to have a two-capital letter prefix. 352 00:24:59,080 --> 00:25:10,080 And when people will use COCOA and Objective-C interchangeably, the system API for OSX is 353 00:25:10,080 --> 00:25:11,280 actually what COCOA is. 354 00:25:12,520 --> 00:25:19,660 AppKit is the set of GUI framework classes available on COCOA. If you're working on 355 00:25:19,660 --> 00:25:23,420 the iPhone, it's going to be UIKit, which is a scaled-down, slightly different, some 356 00:25:23,420 --> 00:25:29,060 totally different controls, custom libraries. So AppKit will be using the UIKit, which is 357 00:25:29,060 --> 00:25:31,760 using the NS prefix. And UI will be using UI. 358 00:25:32,740 --> 00:25:36,580 Now you're probably wondering why I'm giving a crash course into Objective-C programming 359 00:25:36,580 --> 00:25:41,220 if you're reverse engineering and not engineering, but it makes a huge difference if you understand 360 00:25:41,220 --> 00:25:46,040 what the original code was probably going to look like. And then when you see it in 361 00:25:46,040 --> 00:25:49,320 the binary, it's very easy to go backwards to what you think it might have been. 362 00:25:51,580 --> 00:25:57,820 So here's your super basic lesson in Objective-C programming. You have your variable here, 363 00:25:57,820 --> 00:26:05,420 your X, and then you have your statement, which is a method call. So you have the square 364 00:26:05,420 --> 00:26:10,280 brackets, which is your selector decorators, which is the way the Objective-C compiler 365 00:26:10,280 --> 00:26:14,520 will identify an Objective-C statement. And if you've got a lot of arrays, C arrays and 366 00:26:14,520 --> 00:26:21,220 Objective-C methods all on top of each other, it gets kind of confusing. But it stands out 367 00:26:21,220 --> 00:26:24,740 fairly well. You've got the recipient, which is the blue 368 00:26:24,740 --> 00:26:31,740 object here. Now, what that is, that's a pointer to any Objective-C-based object. And then 369 00:26:32,780 --> 00:26:38,420 we have the selectors, which are the text strings. It's very similar to named functions 370 00:26:38,420 --> 00:26:43,380 in, like, various other scripting languages, like Python, except you can't mess around 371 00:26:43,380 --> 00:26:47,400 with the order. They always have to be in the same order. But they are there, so it 372 00:26:47,400 --> 00:26:52,120 makes it very easy to read Objective-C code, because you haven't, basically, you have to 373 00:26:52,120 --> 00:26:54,720 describe what's, you don't have to. You can have a list of things that you want to 374 00:26:54,720 --> 00:26:58,940 have A, B, C, and B a dick. But for the most part, people are going to describe what the 375 00:26:58,940 --> 00:27:02,540 actual variables are supposed to be doing. And then you have the arguments, obviously. 376 00:27:05,020 --> 00:27:12,340 So calls to these selectors are just basically taken and converted to this one function call. 377 00:27:12,860 --> 00:27:16,420 And this is, well, there's a couple versions of it, but this is the main function call 378 00:27:16,420 --> 00:27:21,420 that you're going to see in Objective-C binaries. Now the problem with this is that if you've 379 00:27:21,420 --> 00:27:24,700 done any IDA work or various other functions, you're going to see a lot of these in Objective-C 380 00:27:26,440 --> 00:27:30,380 disassembly work where the cross-references are built up for you, you can do flow graphs, 381 00:27:30,660 --> 00:27:35,500 you can run bin diff, you can't do it because they're all calling that one function. So 382 00:27:35,500 --> 00:27:38,820 you have this awesome flow graph where everything calls message send and you're like, wow, that 383 00:27:38,820 --> 00:27:47,560 sucks. It does. So what it does is it translates the square brackets into this message send 384 00:27:47,560 --> 00:27:52,580 call. So you can see here the recipient's still there. It's the first thing being passed 385 00:27:52,580 --> 00:27:58,200 in. The selectors are all combined together and they're separated by the colons, but you 386 00:27:58,200 --> 00:28:01,200 can still tell how many arguments there are going to be by the number of colons there 387 00:28:01,200 --> 00:28:04,880 are. And then you have the arguments, which is just an ellipsis that will go on for as 388 00:28:04,880 --> 00:28:11,060 long as the arguments are being passed in. Message send super is another variation of 389 00:28:11,060 --> 00:28:17,640 the message send call. It's going to be very similar to the original message send call, 390 00:28:17,740 --> 00:28:21,040 but it's basically calling it on a superclass. 391 00:28:22,040 --> 00:28:22,440 So 392 00:28:22,440 --> 00:28:28,180 the big difference is it's passing in a pointer to this super, and then it's the exact same 393 00:28:28,180 --> 00:28:32,900 with the rest of the arguments coming after it. And the return value is still passed in. 394 00:28:33,020 --> 00:28:36,260 It's going to be passed in through EX all the time, but it's still passed in the same 395 00:28:36,260 --> 00:28:42,460 way. Then you have floating point return value version of message send. Instead of 396 00:28:42,460 --> 00:28:44,380 passing a pointer back, it's going to pass a double back. 397 00:28:46,500 --> 00:28:51,360 You have the structure version. Now this is the one where it changes slightly because 398 00:28:51,360 --> 00:28:57,160 the return value that's coming back is actually going to be the first argument being passed 399 00:28:57,160 --> 00:29:02,920 into the function. And then after that, it repeats the same thing. And then super strut. 400 00:29:03,820 --> 00:29:08,140 Once again, I'm sure we can all figure out what that one is. I believe in you. 401 00:29:09,080 --> 00:29:14,340 So in assembly, this is what it's going to look like. I've described it, but you can 402 00:29:14,340 --> 00:29:21,100 see the selectors being passed in right here with the colon. And that's your request. It's 403 00:29:21,100 --> 00:29:30,240 got a two-capital-letter prefix, so we all know that that's going to be one of the Objective-C-based 404 00:29:30,240 --> 00:29:34,920 framework classes. And this one's kind of weird because it sort of does it out of order, 405 00:29:35,060 --> 00:29:40,400 but I've added a script that will just go through and move these stuff around. So you've 406 00:29:40,400 --> 00:29:45,720 got A, which is going to be the return value coming back through EAX. And so you can see 407 00:29:46,180 --> 00:29:51,080 NSURL. So it's a class method. It's not an instance method. And then you've got the return 408 00:29:51,100 --> 00:29:56,280 value. And then it calls the selector URL with string with one argument, which is probably 409 00:29:56,280 --> 00:30:09,500 this one right here. And then it does it again for requestWithURL. But it's pretty straightforward 410 00:30:10,030 --> 00:30:16,240 because you can just see these Objective-C message send calls. I usually rename these 411 00:30:16,240 --> 00:30:19,720 just so it's easier for me. But the message send calls, they just come one right after 412 00:30:19,720 --> 00:30:23,240 after another. So you can imagine that if you're trying to trace this through, it's 413 00:30:23,240 --> 00:30:28,680 kind of a bitch because there's no way to double-click. You have to go through and figure 414 00:30:28,680 --> 00:30:39,980 out where the URLWithString function actually is. Luckily, you can do that. So the suspense 415 00:30:39,980 --> 00:30:45,100 was killing you. But yes, all of this stuff is stored in the Objective-C segment of the 416 00:30:45,100 --> 00:30:49,300 binary that I talked about earlier, where all this metadata is stored. You can figure 417 00:30:49,300 --> 00:30:54,740 out that this is a DownloadDelegate class here, and all of this stuff is stored in these 418 00:30:54,740 --> 00:30:59,300 structures. Depending on what version of IDA you're using, if you use it, it'll rebuild 419 00:30:59,300 --> 00:31:04,740 it for you. Or it's very, very easy to put together. You hit DD like three times in a 420 00:31:04,740 --> 00:31:05,640 row and then you're done. 421 00:31:06,400 --> 00:31:14,840 But for most OSX binaries with their Objective-C stuff, you got an offset to the string, which 422 00:31:14,840 --> 00:31:15,080 is the string. 423 00:31:15,080 --> 00:31:19,540 You have an offset to the actual selector string, you have an offset to these variable 424 00:31:19,540 --> 00:31:26,700 type arguments, and you have an offset to the actual function itself. So if you know 425 00:31:26,700 --> 00:31:30,540 the name of the function and the function itself, it's really not that much more of 426 00:31:30,540 --> 00:31:32,320 a step to go through and name those. 427 00:31:32,480 --> 00:31:38,400 This is one of the really cool things about Objective-C binaries and metadata, is that 428 00:31:38,400 --> 00:31:42,880 there is all this information just waiting for you to go through and pull it out and 429 00:31:42,880 --> 00:31:43,640 screw with it. 430 00:31:43,640 --> 00:31:47,860 So some of the stuff you don't have, like that you'd have on Windows, like cross-references, 431 00:31:47,980 --> 00:31:53,880 you do have a ton of information being presented to you that will make your life a little bit 432 00:31:53,880 --> 00:31:54,180 easier. 433 00:31:54,480 --> 00:31:57,900 So instead of having to figure that this calls this and this calls this and this, I figured 434 00:31:57,900 --> 00:32:02,240 out this one does this and I traced these back, it'll just tell you, it's like, I think 435 00:32:02,240 --> 00:32:06,640 it's going to download it and then the argument is going to be the amount of data it received. 436 00:32:07,300 --> 00:32:13,620 Just a guess, because it says that's what it's doing. Sometimes double-check and you'll 437 00:32:13,620 --> 00:32:14,100 find it. 438 00:32:14,100 --> 00:32:18,520 Some developers like to lie, but for the most part they're pretty trustworthy people. 439 00:32:19,700 --> 00:32:24,540 Now if you look right here in this middle, there's this almost gibberish-like thing. 440 00:32:25,200 --> 00:32:25,760 Almost. 441 00:32:26,340 --> 00:32:35,240 It's a type encoding, and what that is is a collection of various characters that are 442 00:32:35,240 --> 00:32:42,060 used to indicate what kind of data types and how big the data types are for the arguments 443 00:32:42,060 --> 00:32:43,000 and return value. 444 00:32:43,000 --> 00:32:46,380 So you can build up all the rest of it. So it's not only do you know you have two arguments, 445 00:32:46,580 --> 00:32:53,220 you know that one of them is a char and the other one is an ID. Now ID is this sort of 446 00:32:53,220 --> 00:32:58,700 concept of this, it's like a void pointer, but for Objective-C, saying that it's going 447 00:32:58,700 --> 00:33:04,040 to be an object. So it's slightly a bit less ambiguous than void pointer, but roughly that's 448 00:33:04,040 --> 00:33:10,600 what it is. You have all the rest of the data types are assigned, you can identify 449 00:33:10,600 --> 00:33:11,320 that it's an array. 450 00:33:13,120 --> 00:33:18,340 A bit field, etc. This is straight from Apple's docs, I just put it in a nice LaTeX table. 451 00:33:18,600 --> 00:33:22,240 So you can save your time if you want to not look for it. 452 00:33:23,280 --> 00:33:29,780 So this is one of the type encodings from one of the previous examples. And the first 453 00:33:29,780 --> 00:33:34,860 thing you're going to see is return, which is a V. Cryptically, it stands for void. 454 00:33:36,160 --> 00:33:42,980 The next thing being indicated is that there's an ID here. And so that means, you know, it's 455 00:33:43,000 --> 00:33:51,400 going to be an instance method. So it's not like you'll actually need the instance of 456 00:33:51,400 --> 00:34:00,820 the Cocoa object being passed into the selector. Then you have the selector itself. There's 457 00:34:00,820 --> 00:34:02,960 always going to be a colon in that case. 458 00:34:03,300 --> 00:34:11,920 The first argument is another at symbol, which is an ID object. Second one is also an ID 459 00:34:11,920 --> 00:34:12,420 object. 460 00:34:13,000 --> 00:34:16,420 This isn't the most cool, fun example, but it's pretty straightforward. 461 00:34:17,580 --> 00:34:23,000 So you also have these numbers, which I neglected to explain earlier. And what they are is stack 462 00:34:23,000 --> 00:34:32,680 offsets of where they are in the call stack, or like being passed in. And you can use that 463 00:34:32,680 --> 00:34:35,780 if it's a data type that you're not really sure what size it is. But for the most part, 464 00:34:35,860 --> 00:34:41,900 you're pretty sure what size it is, because most pointers are going to be 32-bit in 32-bit 465 00:34:41,900 --> 00:34:42,240 architecture. 466 00:34:43,000 --> 00:34:49,400 Which is the bulk of it. And most integers are going to be the same size after that. 467 00:34:50,700 --> 00:34:56,080 But the interesting thing is that you have this 16 that it starts with. And so that 468 00:34:56,080 --> 00:35:04,780 16 actually goes and lets you know that the last object is also going to be 4 bytes. It 469 00:35:04,780 --> 00:35:09,740 doesn't mean anything else. I've asked around, and nobody has any more insight to that. 470 00:35:10,120 --> 00:35:10,160 So. 471 00:35:12,380 --> 00:35:12,980 For me, it's pretty simple. I'm just going to go ahead and do a little bit more of this. 472 00:35:13,000 --> 00:35:19,480 For memory management in Objective-C, this is the way memories, or objects are created. 473 00:35:19,700 --> 00:35:26,480 It's not a malloc basis. You don't call malloc directly from the Objective-C stuff. You 474 00:35:26,480 --> 00:35:32,960 call alloc itself, which is a selector, and init. Doesn't have to always be an init on 475 00:35:32,960 --> 00:35:41,420 the developer's choice on that one. But when you see these in the binary, that's what's 476 00:35:41,420 --> 00:35:41,820 going on. 477 00:35:43,000 --> 00:35:45,420 Release is the equivalent of free. 478 00:35:47,340 --> 00:35:50,020 Generally, it's reference counting architecture, 479 00:35:50,860 --> 00:35:54,000 so release just decrements the references by one. 480 00:35:54,840 --> 00:35:56,580 And if you want to add a reference 481 00:35:56,580 --> 00:35:59,080 so that it doesn't get automatically cleaned up, 482 00:35:59,860 --> 00:36:02,780 then retain is going to be what you call for that. 483 00:36:04,540 --> 00:36:08,040 And the part of the Objective-C runtime 484 00:36:08,040 --> 00:36:09,580 that's going to clean up 485 00:36:09,580 --> 00:36:12,860 all of these zero-referenced objects 486 00:36:12,860 --> 00:36:14,880 is an auto-release pool for the most part. 487 00:36:15,440 --> 00:36:17,760 And so you'll see one of them declared 488 00:36:17,760 --> 00:36:18,800 at the beginning of a function. 489 00:36:19,600 --> 00:36:21,160 You'll see it released near the end 490 00:36:21,160 --> 00:36:22,440 or near any return statement 491 00:36:22,440 --> 00:36:23,640 if the code was written right. 492 00:36:24,340 --> 00:36:25,720 And they can be nested in loops. 493 00:36:25,940 --> 00:36:29,320 So if you see a pool getting allocated 494 00:36:29,320 --> 00:36:30,720 right at the beginning of a loop, 495 00:36:30,840 --> 00:36:32,900 you can try to find where that same pool 496 00:36:32,900 --> 00:36:33,780 would be getting released, 497 00:36:34,600 --> 00:36:36,280 and that'll help you figure out 498 00:36:36,280 --> 00:36:37,660 where the end of the loop is probably going to be. 499 00:36:38,140 --> 00:36:39,220 So I'm just showing you 500 00:36:39,220 --> 00:36:40,040 the Objective-C stuff, 501 00:36:40,200 --> 00:36:41,040 but it's pretty straightforward 502 00:36:41,040 --> 00:36:42,780 because you just have the same text strings 503 00:36:42,780 --> 00:36:44,260 all over in the binaries 504 00:36:44,260 --> 00:36:45,900 to save you the time. 505 00:36:47,880 --> 00:36:48,620 Garbage collection. 506 00:36:48,940 --> 00:36:52,660 This was added in OS X 10.5, 507 00:36:52,940 --> 00:36:53,880 the most recent version, 508 00:36:54,480 --> 00:36:59,300 and I haven't seen it used very much yet, 509 00:36:59,440 --> 00:37:01,280 but you'll probably start to see it used 510 00:37:01,280 --> 00:37:01,860 a little bit more 511 00:37:01,860 --> 00:37:03,220 because then people don't have to worry 512 00:37:03,220 --> 00:37:05,980 about calling release and retain as much, 513 00:37:06,120 --> 00:37:08,180 and developers tend to be really lazy. 514 00:37:09,220 --> 00:37:10,840 I know, I did that for a while, 515 00:37:11,540 --> 00:37:12,420 and I am lazy. 516 00:37:13,500 --> 00:37:15,340 So classes designed for garbage collection, 517 00:37:16,600 --> 00:37:18,460 they have a finalized selector 518 00:37:18,460 --> 00:37:20,140 somewhere in their class definitions. 519 00:37:20,940 --> 00:37:22,740 That's sort of your big tip-off right there. 520 00:37:22,980 --> 00:37:23,900 So you're like, okay, 521 00:37:24,360 --> 00:37:25,620 I'm not going to really need to look 522 00:37:25,620 --> 00:37:27,480 for any of the other memory allocation stuff. 523 00:37:28,660 --> 00:37:30,640 They can be triggered by collect exhaustively, 524 00:37:30,720 --> 00:37:31,300 collect if needed. 525 00:37:31,920 --> 00:37:33,360 So those are also going to indicate 526 00:37:33,360 --> 00:37:34,440 garbage collections going on. 527 00:37:34,500 --> 00:37:35,700 Those are probably a little bit more 528 00:37:37,080 --> 00:37:38,460 trustworthy than finalized 529 00:37:38,460 --> 00:37:39,200 because finalized collections are going to be more trustworthy. 530 00:37:39,220 --> 00:37:39,800 Finalized is one word. 531 00:37:39,840 --> 00:37:40,900 Maybe people want to use it 532 00:37:40,900 --> 00:37:43,220 just so that the code knows that they're serious. 533 00:37:45,140 --> 00:37:47,080 Garbage collection is not available on the iPhone. 534 00:37:47,400 --> 00:37:49,180 So if you see it on an iPhone binary, 535 00:37:49,860 --> 00:37:50,900 they're lying to you, 536 00:37:50,920 --> 00:37:51,680 and it's something else. 537 00:37:52,500 --> 00:37:53,960 And the iPhone developers are liars. 538 00:37:54,740 --> 00:37:55,620 Trust me on that one. 539 00:37:57,960 --> 00:37:58,680 But categories, 540 00:37:58,840 --> 00:38:00,600 this is one of those really crazy things 541 00:38:00,600 --> 00:38:02,700 that you really need to pay attention to at this point. 542 00:38:03,940 --> 00:38:04,920 A lot of the times, 543 00:38:05,500 --> 00:38:07,100 I've seen like three or four people 544 00:38:07,100 --> 00:38:09,140 write the same scripts I've written in IDA, 545 00:38:09,220 --> 00:38:11,120 because it really doesn't take 546 00:38:11,120 --> 00:38:12,540 that much extra time 547 00:38:13,740 --> 00:38:14,880 to figure it out. 548 00:38:15,160 --> 00:38:16,640 But if you don't want to spend the time, 549 00:38:16,660 --> 00:38:18,700 you can use one of the few ones that I show you at the end. 550 00:38:19,420 --> 00:38:20,660 But for some reason, 551 00:38:20,720 --> 00:38:22,780 when people start taking the metadata 552 00:38:22,780 --> 00:38:23,980 and renaming functions, 553 00:38:24,780 --> 00:38:26,600 they always pick the category section 554 00:38:26,600 --> 00:38:27,680 of the Objective-C first. 555 00:38:28,420 --> 00:38:31,080 I'm going to go right back and show you the Objective-C sections 556 00:38:32,060 --> 00:38:32,980 so you can 557 00:38:32,980 --> 00:38:34,560 see what the hell I'm talking about. 558 00:38:36,820 --> 00:38:37,420 Right here. 559 00:38:37,600 --> 00:38:37,820 Here. 560 00:38:39,220 --> 00:38:40,960 The first one down is cat class methods. 561 00:38:41,240 --> 00:38:43,140 The fourth one down is cat ints methods. 562 00:38:43,600 --> 00:38:44,800 These are the categories. 563 00:38:45,940 --> 00:38:46,540 Now, 564 00:38:47,960 --> 00:38:49,080 the structure 565 00:38:49,080 --> 00:38:50,900 is almost identical to 566 00:38:50,900 --> 00:38:52,540 oh, I went way too far. 567 00:38:52,780 --> 00:38:54,880 The structure is almost identical to 568 00:38:56,300 --> 00:38:57,380 the other 569 00:38:58,140 --> 00:38:59,100 the regular 570 00:38:59,100 --> 00:39:01,440 classes and the way that stuff's laid out. 571 00:39:01,720 --> 00:39:02,700 But the big thing is that 572 00:39:02,700 --> 00:39:04,120 a category is 573 00:39:04,120 --> 00:39:07,620 somebody overriding a class that they didn't 574 00:39:07,620 --> 00:39:08,560 write themselves. 575 00:39:09,220 --> 00:39:10,920 So you'd use a category to overwrite 576 00:39:11,440 --> 00:39:13,260 NSString, which is the default string type. 577 00:39:13,580 --> 00:39:14,900 And let's say you create a category 578 00:39:15,400 --> 00:39:17,080 for the string length, and 579 00:39:17,080 --> 00:39:18,180 you have it return 580 00:39:18,720 --> 00:39:20,940 the string length plus seven, just because 581 00:39:20,940 --> 00:39:23,160 you want to screw with anybody who wants to know the name of 582 00:39:23,160 --> 00:39:24,740 the length of your string, and you're 583 00:39:24,740 --> 00:39:26,520 just kind of a jerk. Well, 584 00:39:26,980 --> 00:39:28,360 if you go through and 585 00:39:28,360 --> 00:39:30,620 it's still going to be called length, so 586 00:39:31,140 --> 00:39:32,920 in the metadata, it's going to say length. 587 00:39:33,060 --> 00:39:34,280 You go through and you 588 00:39:35,640 --> 00:39:37,120 rename everything, and you're like, oh, that's just 589 00:39:37,120 --> 00:39:39,060 string length. I don't really care what that is. So, 590 00:39:39,220 --> 00:39:41,160 categories, pay attention to that 591 00:39:41,160 --> 00:39:42,880 because there's something extra going on 592 00:39:42,880 --> 00:39:44,880 and it's somebody messing with somebody else's code. 593 00:39:45,120 --> 00:39:47,080 So there might be some interesting stuff 594 00:39:47,080 --> 00:39:48,540 that you can find in those. 595 00:39:50,620 --> 00:39:51,400 But you can 596 00:39:52,920 --> 00:39:55,000 let's see, yeah, so it's 597 00:39:55,000 --> 00:39:56,500 just going to be in the cat sections of the binary. 598 00:39:57,800 --> 00:39:58,940 If you're renaming stuff, 599 00:39:59,460 --> 00:40:01,120 keep that in mind. Maybe put a cat 600 00:40:01,120 --> 00:40:02,980 or some other symbol that's going to be in the name 601 00:40:02,980 --> 00:40:04,960 so you know when you're going through it later that 602 00:40:04,960 --> 00:40:06,700 okay, there's something extra weird going on. 603 00:40:12,380 --> 00:40:12,980 Timers. 604 00:40:13,140 --> 00:40:14,940 This is probably only interesting 605 00:40:14,940 --> 00:40:16,880 to people who crack 606 00:40:16,880 --> 00:40:18,960 software. I'm talking about the people that 607 00:40:18,960 --> 00:40:20,900 crack software and totally pay for it afterwards 608 00:40:20,900 --> 00:40:21,860 because we're all honest. 609 00:40:23,920 --> 00:40:25,120 He knows 610 00:40:25,120 --> 00:40:25,660 what I'm talking about. 611 00:40:27,620 --> 00:40:28,940 They're commonly used in protection 612 00:40:28,940 --> 00:40:31,420 schemes. Objective C 613 00:40:31,420 --> 00:40:33,060 supports various ways to 614 00:40:33,060 --> 00:40:33,780 create a timer. 615 00:40:35,540 --> 00:40:37,120 You'll see NSTimer 616 00:40:37,120 --> 00:40:39,080 with NSThreading stuff. 617 00:40:39,220 --> 00:40:41,260 Or you'll see it with NSOperationQueue. 618 00:40:41,380 --> 00:40:42,780 This is a new one that's been added 619 00:40:42,780 --> 00:40:44,340 in 10.5 as well. 620 00:40:45,420 --> 00:40:46,840 And if you see these 621 00:40:46,840 --> 00:40:49,000 going on, it's pretty obvious 622 00:40:49,000 --> 00:40:51,320 what NSTimer is. NSOperationQueue 623 00:40:51,320 --> 00:40:52,780 is very frequently used with timers. 624 00:40:57,900 --> 00:40:59,040 Now, I mentioned 625 00:40:59,040 --> 00:41:00,200 I came from a Windows background. 626 00:41:01,560 --> 00:41:03,000 And the one benefit 627 00:41:03,000 --> 00:41:05,180 with Windows is that there's been decades of people 628 00:41:06,520 --> 00:41:06,960 Well, 629 00:41:07,060 --> 00:41:08,840 I don't know if it's really been decades. It's like 630 00:41:09,220 --> 00:41:09,660 1995, right? 631 00:41:09,980 --> 00:41:12,820 A while of people doing RCE 632 00:41:13,900 --> 00:41:14,780 on Windows. 633 00:41:15,040 --> 00:41:16,900 There's a lot of documentation. There's a lot of 634 00:41:16,900 --> 00:41:19,160 various advances that people have been doing over the years. 635 00:41:19,440 --> 00:41:21,040 And they're very public about it. 636 00:41:21,280 --> 00:41:22,700 A lot of the CragMe sites 637 00:41:22,700 --> 00:41:25,020 are going to be primarily Windows-based 638 00:41:25,020 --> 00:41:26,400 CragMe sites. All of the 639 00:41:26,400 --> 00:41:28,940 docs that people are still doing. You look on OpenRCE, 640 00:41:29,200 --> 00:41:30,880 you'll find the obscure ARM posts. 641 00:41:31,180 --> 00:41:33,160 And then most of them are just going to be Windows-based 642 00:41:33,160 --> 00:41:33,620 stuff. 643 00:41:34,780 --> 00:41:37,160 The interesting thing with Mac stuff 644 00:41:37,160 --> 00:41:39,080 is that now, the fact that I filled this 645 00:41:39,220 --> 00:41:40,640 room means that 646 00:41:41,080 --> 00:41:43,200 there's a lot more people starting to pay attention to Mac. 647 00:41:43,340 --> 00:41:45,140 And it's not just on our side. It's on the development 648 00:41:45,140 --> 00:41:47,160 side. So some guy walks up 649 00:41:47,160 --> 00:41:48,960 to their Windows developers and be like, 650 00:41:49,100 --> 00:41:51,040 oh, we totally need a Mac version of our 651 00:41:51,040 --> 00:41:53,080 product. And you 652 00:41:53,080 --> 00:41:55,200 need to write it. And they're just like, oh shit, I don't know anything 653 00:41:55,200 --> 00:41:56,420 about writing for Mac products. 654 00:41:56,720 --> 00:41:58,300 So usually they're going to switch over 655 00:41:59,900 --> 00:42:01,020 and write to Carbon. 656 00:42:01,420 --> 00:42:02,940 And you're going to see a lot of really 657 00:42:02,940 --> 00:42:05,180 weird stuff. Unless 658 00:42:05,180 --> 00:42:06,700 they move in the other direction. Because 659 00:42:06,700 --> 00:42:08,940 you work for Apple and they're like, we totally need 660 00:42:09,220 --> 00:42:10,340 Safari on Windows. 661 00:42:10,720 --> 00:42:12,280 Because that makes sense. 662 00:42:12,700 --> 00:42:13,080 But 663 00:42:14,640 --> 00:42:17,040 I don't work for Apple, in case you picked up on that. 664 00:42:17,760 --> 00:42:18,080 But 665 00:42:19,580 --> 00:42:21,100 there's going to be various stuff 666 00:42:21,100 --> 00:42:23,260 that's ported over. You can tell 667 00:42:23,260 --> 00:42:24,680 it's a Windows app because 668 00:42:26,160 --> 00:42:27,000 we know who 669 00:42:27,000 --> 00:42:29,120 develops Objective-C. Who here has 670 00:42:29,120 --> 00:42:30,200 developed Windows code 671 00:42:30,200 --> 00:42:33,180 in Visual C, something like that? 672 00:42:33,280 --> 00:42:33,960 Like real apps before? 673 00:42:34,900 --> 00:42:37,040 I mean real Windows apps. I'm not saying OSX 674 00:42:37,040 --> 00:42:38,860 are not real. Okay. So you've got a 675 00:42:39,220 --> 00:42:40,340 bunch of people, you know HWND? 676 00:42:40,640 --> 00:42:42,480 It's all over any Windows code. 677 00:42:42,940 --> 00:42:44,700 Yeah, it's not a Mac thing. 678 00:42:45,060 --> 00:42:46,880 So if you see HWND, 679 00:42:47,460 --> 00:42:49,200 like variables and functions 680 00:42:49,200 --> 00:42:50,940 with that name in there, 681 00:42:51,280 --> 00:42:53,160 chances are it was a Windows guy and he's 682 00:42:53,160 --> 00:42:55,120 just learning how to code for OSX 683 00:42:55,120 --> 00:42:57,160 right now. So take a little 684 00:42:57,160 --> 00:42:59,100 closer look because he's probably done some 685 00:42:59,100 --> 00:43:00,400 really other interesting, fun stuff. 686 00:43:00,840 --> 00:43:02,200 But it makes no sense. 687 00:43:04,040 --> 00:43:05,080 Now, there's 688 00:43:05,080 --> 00:43:07,020 benefits for looking at 689 00:43:07,020 --> 00:43:08,000 Mac executables. 690 00:43:08,760 --> 00:43:10,720 Compression and pack executables 691 00:43:10,720 --> 00:43:12,020 aren't really that common 692 00:43:12,800 --> 00:43:14,880 on OSX. They're not as common as 693 00:43:14,880 --> 00:43:15,580 they are on Windows. 694 00:43:16,140 --> 00:43:18,640 I have co-workers that 695 00:43:18,640 --> 00:43:20,780 recently busted into Disney's 696 00:43:20,780 --> 00:43:22,060 Pirates of the Caribbean game. 697 00:43:22,520 --> 00:43:24,460 You can see their videos on YouTube 698 00:43:24,460 --> 00:43:26,540 and then like a million teenagers being like 699 00:43:26,540 --> 00:43:28,060 OMG hacks, show me hows. 700 00:43:28,340 --> 00:43:30,960 But the one 701 00:43:30,960 --> 00:43:32,180 they spent about 702 00:43:32,180 --> 00:43:34,920 3-4 days just making 703 00:43:34,920 --> 00:43:36,480 this really nice unpacker for 704 00:43:37,020 --> 00:43:38,780 Disney stuff. And I'm like 705 00:43:38,780 --> 00:43:40,840 dude, check it out. There's no packing 706 00:43:40,840 --> 00:43:41,740 on the OSX version. 707 00:43:42,060 --> 00:43:44,060 The look they shot me was just like 708 00:43:44,060 --> 00:43:46,100 they were not pleasantly happy. 709 00:43:47,800 --> 00:43:48,900 I thought it was funny though. 710 00:43:49,420 --> 00:43:50,760 Because at one point 711 00:43:50,760 --> 00:43:52,700 we all used Apples and I'm the only guy left. 712 00:43:53,120 --> 00:43:54,940 But yay 713 00:43:54,940 --> 00:43:55,560 for the Apple guy. 714 00:43:57,040 --> 00:43:58,680 So as I mentioned, you can 715 00:43:58,680 --> 00:44:01,000 easily identify a lot of Windows stuff 716 00:44:01,000 --> 00:44:01,940 that's been ported over. 717 00:44:02,320 --> 00:44:03,720 Like the HWND stuff. 718 00:44:04,700 --> 00:44:06,460 If there is a Windows version 719 00:44:07,020 --> 00:44:08,520 don't be afraid to look at that as well. 720 00:44:08,640 --> 00:44:10,560 Because that's just yet another source of 721 00:44:10,560 --> 00:44:11,880 information that you can pull from. 722 00:44:12,560 --> 00:44:13,620 They're not going to be identical. 723 00:44:14,800 --> 00:44:16,340 A good example is QuickTime. 724 00:44:16,460 --> 00:44:18,200 QuickTime for Windows and QuickTime for Apple 725 00:44:18,200 --> 00:44:19,580 are fairly different animals. 726 00:44:19,860 --> 00:44:21,840 So there's going to be some weird stuff you find in 727 00:44:21,840 --> 00:44:23,760 QuickTime for Windows, but that's only because 728 00:44:23,760 --> 00:44:24,780 it was moved in the other direction. 729 00:44:25,940 --> 00:44:28,320 But you can find relative structures 730 00:44:28,320 --> 00:44:30,880 and you can get an idea of what it was going for. 731 00:44:30,980 --> 00:44:32,640 Especially if it was the code that somebody 732 00:44:32,640 --> 00:44:34,840 just forced to work on the other platform. 733 00:44:35,180 --> 00:44:36,400 So try looking at both of them. 734 00:44:37,020 --> 00:44:38,720 It'll just give you more of an idea 735 00:44:38,720 --> 00:44:39,300 of what's going on. 736 00:44:40,760 --> 00:44:42,980 So now we're in the iPhone section 737 00:44:42,980 --> 00:44:43,620 of the talk. 738 00:44:44,560 --> 00:44:45,380 Just in time. 739 00:44:46,860 --> 00:44:48,500 I don't do a ton of iPhone stuff. 740 00:44:48,760 --> 00:44:50,860 I actually just got my iPhone 741 00:44:50,860 --> 00:44:52,140 a few weeks ago. 742 00:44:52,220 --> 00:44:53,800 I was one of those guys who waited in line 743 00:44:53,800 --> 00:44:54,440 way too long. 744 00:44:56,580 --> 00:44:57,440 I'm not the only one. 745 00:44:57,480 --> 00:44:58,500 I saw the rest of you guys. 746 00:45:01,560 --> 00:45:02,660 Actually, is there anybody 747 00:45:02,660 --> 00:45:04,120 from the iPhone dev team here 748 00:45:04,120 --> 00:45:05,020 in the audience? 749 00:45:07,400 --> 00:45:08,160 That's too bad. 750 00:45:08,680 --> 00:45:10,580 I'll have a link to these guys. 751 00:45:10,760 --> 00:45:12,720 These are the guys who jail-braked the iPhone. 752 00:45:13,400 --> 00:45:15,240 They do a lot of the iPhone research. 753 00:45:15,580 --> 00:45:16,720 They do some badass stuff. 754 00:45:16,800 --> 00:45:18,040 They're pretty sharp guys. 755 00:45:18,380 --> 00:45:20,440 I wanted to applaud them if they're here. 756 00:45:20,540 --> 00:45:21,920 We can applaud them if they're not here, 757 00:45:22,020 --> 00:45:22,720 but it's sort of meaningless. 758 00:45:27,900 --> 00:45:29,540 The amount of stuff 759 00:45:29,540 --> 00:45:30,500 that's come from that 760 00:45:30,500 --> 00:45:31,720 is pretty impressive. 761 00:45:32,600 --> 00:45:34,800 The iPhone is an ARM chipset 762 00:45:34,800 --> 00:45:36,880 as opposed to the PPC and x86. 763 00:45:37,020 --> 00:45:37,920 You're going to be looking at it 764 00:45:37,920 --> 00:45:38,760 on regular Macs. 765 00:45:39,240 --> 00:45:40,500 It's Objective-C applications. 766 00:45:41,840 --> 00:45:43,600 That's why I still covered all that stuff. 767 00:45:44,120 --> 00:45:45,900 It uses UIKit instead of AppKit, 768 00:45:46,620 --> 00:45:47,700 which means you're going to be dealing 769 00:45:47,700 --> 00:45:48,720 with slightly different controls 770 00:45:48,720 --> 00:45:49,860 when you're looking at the binaries. 771 00:45:50,140 --> 00:45:51,340 The biggest thing is going to be ARM. 772 00:45:51,480 --> 00:45:52,240 If you don't know ARM, 773 00:45:52,420 --> 00:45:53,040 then you're just going to be like, 774 00:45:53,120 --> 00:45:54,720 wow, this is fucked up. 775 00:45:56,780 --> 00:45:57,720 If you do know ARM, 776 00:45:57,760 --> 00:45:58,500 you're like, dude, that's easy. 777 00:46:00,900 --> 00:46:01,780 The bundles. 778 00:46:02,380 --> 00:46:04,000 I said I wasn't going to lie to you. 779 00:46:04,220 --> 00:46:05,820 I was totally lying when I said that, 780 00:46:05,900 --> 00:46:06,800 so you got a conundrum. 781 00:46:06,960 --> 00:46:08,640 The bundles I showed you earlier 782 00:46:09,120 --> 00:46:11,220 don't apply on the iPhone. 783 00:46:11,460 --> 00:46:13,620 The iPhone flattened the whole directory structure. 784 00:46:14,400 --> 00:46:16,100 If you're used to looking at 785 00:46:16,100 --> 00:46:17,860 nicely organized bundles 786 00:46:17,860 --> 00:46:19,340 and you don't even have to worry about 787 00:46:19,340 --> 00:46:21,360 all the graphics being in the same area, 788 00:46:21,500 --> 00:46:22,180 no, it's all there. 789 00:46:23,200 --> 00:46:25,980 It's just this giant clusterfuck of files 790 00:46:26,320 --> 00:46:28,080 all in one directory. 791 00:46:28,780 --> 00:46:30,280 They have the code signature in there. 792 00:46:31,940 --> 00:46:33,280 It's really easy, though. 793 00:46:33,460 --> 00:46:35,260 I haven't seen an iPhone app 794 00:46:35,260 --> 00:46:36,620 that has a different name 795 00:46:37,100 --> 00:46:38,100 for the binary 796 00:46:38,100 --> 00:46:41,200 than for the actual folder structure. 797 00:46:41,600 --> 00:46:42,520 You can always use file 798 00:46:42,520 --> 00:46:43,460 just to tell what it is. 799 00:46:44,700 --> 00:46:46,140 The Objective-C sections, 800 00:46:47,300 --> 00:46:48,740 my previous slide that had 801 00:46:48,740 --> 00:46:49,540 the documented sections, 802 00:46:49,780 --> 00:46:50,900 that was before I got an iPhone. 803 00:46:51,400 --> 00:46:53,500 The Objective-C sections 804 00:46:54,160 --> 00:46:56,460 doesn't really look the same 805 00:46:56,460 --> 00:46:57,740 and isn't quite handled the same. 806 00:46:59,320 --> 00:47:01,200 The names don't quite line up exactly. 807 00:47:01,660 --> 00:47:02,880 I'll be spending tomorrow, 808 00:47:03,040 --> 00:47:04,360 instead of chilling at the Hard Rock, 809 00:47:04,480 --> 00:47:05,920 I'll be writing, updating my script 810 00:47:05,920 --> 00:47:06,860 for you guys for Monday. 811 00:47:07,980 --> 00:47:10,020 I should have some stuff to clean up 812 00:47:10,020 --> 00:47:11,860 some of the iPhone binaries by Monday. 813 00:47:12,920 --> 00:47:13,780 The other thing is, 814 00:47:13,820 --> 00:47:15,620 Apple really hasn't standardized anything here. 815 00:47:15,760 --> 00:47:16,680 I was hanging out with a couple 816 00:47:16,680 --> 00:47:18,360 of the Apple security guys at Black Hat. 817 00:47:18,600 --> 00:47:20,340 I was basically bitching at them. 818 00:47:20,460 --> 00:47:21,880 I'm like, dude, this makes my job 819 00:47:21,880 --> 00:47:23,500 far more of a pain in the ass. 820 00:47:23,780 --> 00:47:25,180 First off, we don't care. 821 00:47:28,780 --> 00:47:30,460 Apple still hasn't quite figured out 822 00:47:30,460 --> 00:47:32,420 the structure they want for all of these files yet. 823 00:47:32,500 --> 00:47:34,180 They're still changing it from patch to patch. 824 00:47:34,660 --> 00:47:36,540 When in doubt, refer to the iPhone dev team. 825 00:47:36,720 --> 00:47:38,380 They have a wiki up, which I'll link to. 826 00:47:39,380 --> 00:47:40,740 If they don't have the information, 827 00:47:41,660 --> 00:47:42,940 then if you figure it out, 828 00:47:42,960 --> 00:47:43,720 put it on the wiki. 829 00:47:47,660 --> 00:47:48,720 We've hit the end of my talk. 830 00:47:49,040 --> 00:47:50,020 You're like, dude, that was all you were saying 831 00:47:50,020 --> 00:47:51,160 about iPhones? I'm like, yeah, 832 00:47:51,500 --> 00:47:52,200 I'm kind of a jerk. 833 00:47:53,940 --> 00:47:56,220 This is a couple of links to get you started with. 834 00:47:57,720 --> 00:47:58,480 I can't not mention 835 00:47:58,500 --> 00:47:59,640 the first link. 836 00:47:59,740 --> 00:48:01,620 If you ever see any OSX talk, 837 00:48:01,920 --> 00:48:03,380 you gotta give props to Nemo. 838 00:48:03,480 --> 00:48:06,480 Nemo was doing stuff when nobody else was. 839 00:48:06,680 --> 00:48:07,680 He was working in a vacuum 840 00:48:07,680 --> 00:48:09,180 and it was a sad life. 841 00:48:10,500 --> 00:48:12,320 He gets all the respect finally 842 00:48:12,320 --> 00:48:12,840 years later. 843 00:48:13,980 --> 00:48:15,460 That's who we should also applaud. 844 00:48:15,980 --> 00:48:18,320 Big ups for Nemo. He's not here right now. 845 00:48:22,100 --> 00:48:23,960 He was doing a lot of this work 846 00:48:23,960 --> 00:48:25,120 years and years and years ago. 847 00:48:26,160 --> 00:48:27,740 I can't not mention him. 848 00:48:28,500 --> 00:48:30,720 He wrote an Objective-C 849 00:48:30,720 --> 00:48:32,400 fixer-upper script in IDC. 850 00:48:32,640 --> 00:48:33,880 I was talking about mine. 851 00:48:34,000 --> 00:48:35,940 This is a separate one. It works just as well. 852 00:48:36,900 --> 00:48:38,840 FileOffset also did the same thing. 853 00:48:39,280 --> 00:48:40,520 Went through OTX 854 00:48:40,520 --> 00:48:41,380 and wrote a LUIS script 855 00:48:41,380 --> 00:48:43,340 that will convert the 856 00:48:44,180 --> 00:48:45,000 OTX output 857 00:48:45,000 --> 00:48:48,120 into IDC and stick that in IDA. 858 00:48:48,180 --> 00:48:49,700 We all take different approaches 859 00:48:49,700 --> 00:48:50,620 for the same thing. 860 00:48:51,760 --> 00:48:53,940 Then there's a couple other Objective-C 861 00:48:54,500 --> 00:48:56,400 based reversing or just Objective-C 862 00:48:56,400 --> 00:48:57,200 coding, debugging. 863 00:48:59,860 --> 00:49:02,200 Then you have the iPhone dev team. 864 00:49:02,320 --> 00:49:04,320 You have the blog.iphone.dev 865 00:49:04,320 --> 00:49:05,200 which is just going to keep their 866 00:49:05,200 --> 00:49:07,340 up-to-date and then their wiki at the bottom. 867 00:49:07,720 --> 00:49:09,440 They did release a new jailbreak 868 00:49:09,440 --> 00:49:10,740 for any of you guys who accidentally 869 00:49:10,740 --> 00:49:12,060 updated earlier this week. 870 00:49:12,120 --> 00:49:13,340 You should be able to fix your phone. 871 00:49:15,320 --> 00:49:16,720 The other thing that I'm really 872 00:49:16,720 --> 00:49:18,380 excited coming out soon 873 00:49:18,380 --> 00:49:19,920 is Dino and Charlie. 874 00:49:20,240 --> 00:49:22,160 The guys who have won the CanSec 875 00:49:22,160 --> 00:49:24,260 West Pwn2Own contest. 876 00:49:24,860 --> 00:49:26,040 Charlie took out the 877 00:49:26,720 --> 00:49:27,900 MacBook this year. 878 00:49:28,500 --> 00:49:30,340 On the second day in the first 35 seconds. 879 00:49:31,200 --> 00:49:32,500 He knows a little bit 880 00:49:32,500 --> 00:49:33,460 about exploiting stuff. 881 00:49:34,280 --> 00:49:36,220 He has Feng Shui ported 882 00:49:36,220 --> 00:49:36,900 to the iPhone. 883 00:49:37,200 --> 00:49:38,960 So your iPhone is totally not safe 884 00:49:38,960 --> 00:49:40,580 even though there's not a huge memory footprint. 885 00:49:41,120 --> 00:49:42,340 You're like, you couldn't heap-spray me? 886 00:49:42,780 --> 00:49:44,300 He kind of screwed you. 887 00:49:46,220 --> 00:49:48,060 They're writing a book and it's going to cover 888 00:49:48,060 --> 00:49:48,760 reverse engineering. 889 00:49:49,220 --> 00:49:50,460 It's going to cover exploitation. 890 00:49:50,840 --> 00:49:53,200 It's like shell-coded handbook for Apple users 891 00:49:53,200 --> 00:49:54,600 by two really smart guys. 892 00:49:55,380 --> 00:49:57,800 They're going to be releasing a tool when this book comes out 893 00:49:58,500 --> 00:49:59,820 to fix that cross-references problem 894 00:49:59,820 --> 00:50:00,700 that I was talking about. 895 00:50:01,700 --> 00:50:04,020 He basically took Chris Eagle's emulator 896 00:50:04,020 --> 00:50:05,800 and just 897 00:50:06,360 --> 00:50:07,320 went ninja on it 898 00:50:07,320 --> 00:50:09,500 and made it rebuild all the cross-references. 899 00:50:09,680 --> 00:50:11,260 So that will come out at the same time 900 00:50:11,260 --> 00:50:13,100 so I can't not pimp them. 901 00:50:14,580 --> 00:50:15,820 That's the bulk of my talk. 902 00:50:16,100 --> 00:50:17,820 I will be available for Q&A 903 00:50:17,820 --> 00:50:19,300 right across the hall right after this. 904 00:50:19,400 --> 00:50:20,600 Thank you guys for showing up. 905 00:50:20,840 --> 00:50:21,780 Really appreciate it.