1 00:00:00,000 --> 00:00:00,620 So let's just begin. 2 00:00:05,260 --> 00:00:07,140 You don't like the music? 3 00:00:09,900 --> 00:00:11,960 Can somebody make me more important than the music? 4 00:00:14,480 --> 00:00:15,120 Very good. 5 00:00:15,880 --> 00:00:19,460 No, the music was to keep you guys kind of from getting out of hand, 6 00:00:20,070 --> 00:00:23,240 because you're all real patient and docile at the moment, right? 7 00:00:24,140 --> 00:00:24,560 Yeah. 8 00:00:25,760 --> 00:00:27,500 Well, it wasn't my fault. 9 00:00:27,560 --> 00:00:29,280 Just so you know, don't blame me. 10 00:00:29,280 --> 00:00:30,360 We're in this together. 11 00:00:33,280 --> 00:00:34,000 Anyway, introduction. 12 00:00:34,200 --> 00:00:34,740 I'm Atlas. 13 00:00:34,900 --> 00:00:35,560 Nice to meet you all. 14 00:00:38,440 --> 00:00:40,920 There are only a couple differences from what you got on the CD 15 00:00:40,920 --> 00:00:42,240 than what you're going to see up here, 16 00:00:42,360 --> 00:00:44,940 namely my email address and my blog site. 17 00:00:45,060 --> 00:00:46,700 So make sure you write those down when they come up, 18 00:00:48,480 --> 00:00:50,560 because there's stuff later on in the slides that says, 19 00:00:50,680 --> 00:00:54,680 oh, yeah, Atlas' brain-dead tips to reverse engineering, 20 00:00:55,240 --> 00:00:57,320 they're on my blog later on tonight. 21 00:00:57,880 --> 00:00:58,880 They're not in the pre-zone. 22 00:00:59,280 --> 00:00:59,500 Okay? 23 00:01:01,480 --> 00:01:01,880 Good. 24 00:01:04,960 --> 00:01:07,860 Let me start out by saying that I am not better than any of you guys. 25 00:01:08,020 --> 00:01:10,680 This is not a, hey, look at me, I'm great talk. 26 00:01:11,040 --> 00:01:13,500 This is kind of what happened to me. 27 00:01:14,140 --> 00:01:15,680 I've been doing a lot of fun stuff. 28 00:01:16,960 --> 00:01:20,060 Most people in this room probably could do what I've been doing. 29 00:01:21,080 --> 00:01:22,160 I'm going to show you somehow. 30 00:01:22,960 --> 00:01:23,580 Is that good? 31 00:01:24,240 --> 00:01:24,640 Good? 32 00:01:25,500 --> 00:01:26,620 I've been very blessed. 33 00:01:26,920 --> 00:01:27,880 Very, uh... 34 00:01:28,520 --> 00:01:30,040 Just giving a lot of curiosity. 35 00:01:30,860 --> 00:01:32,480 Probably above average intelligence, 36 00:01:32,740 --> 00:01:34,580 but that probably describes everybody here, right? 37 00:01:39,260 --> 00:01:41,180 Except for the one guy in the back. 38 00:01:43,440 --> 00:01:44,600 All right, here it is. 39 00:01:44,620 --> 00:01:45,160 Write it down. 40 00:01:45,900 --> 00:01:47,260 Atlas at ratboy.com. 41 00:01:47,320 --> 00:01:49,860 I'm sorry, r4780y.com. 42 00:01:51,900 --> 00:01:55,040 The blog site, atlas.yadayada. 43 00:01:58,660 --> 00:01:59,700 A little bit about me. 44 00:01:59,740 --> 00:02:02,120 I was expecting to have a traveling microphone here. 45 00:02:02,240 --> 00:02:03,240 I like to move around. 46 00:02:06,340 --> 00:02:06,980 This is good. 47 00:02:07,120 --> 00:02:07,480 All right. 48 00:02:08,220 --> 00:02:09,240 A little bit about me. 49 00:02:10,440 --> 00:02:11,600 Dad worked for IBM. 50 00:02:11,780 --> 00:02:13,140 I got a PC when I was seven. 51 00:02:13,380 --> 00:02:14,800 Started programming when I was eight. 52 00:02:14,860 --> 00:02:15,420 Thank you, brother. 53 00:02:15,660 --> 00:02:17,760 Because my brother was teaching me. 54 00:02:17,960 --> 00:02:19,460 You know, he's like eight years older than me. 55 00:02:19,500 --> 00:02:20,140 He's like, hey, look. 56 00:02:20,360 --> 00:02:24,600 You do the CLS, and it clears the screen. 57 00:02:24,940 --> 00:02:25,300 Sweet! 58 00:02:26,000 --> 00:02:27,600 So I've been programming since I was eight. 59 00:02:27,880 --> 00:02:29,580 If you consider advanced basic programming. 60 00:02:30,120 --> 00:02:31,800 Some of you probably don't, but that's all right. 61 00:02:34,380 --> 00:02:37,360 Started college as a vocal performance major. 62 00:02:39,040 --> 00:02:40,420 You should have been gone! 63 00:02:41,560 --> 00:02:43,620 Anyway, you probably should have been before that. 64 00:02:45,080 --> 00:02:50,180 Hit pre-med before deciding that I had run away from my first love long enough. 65 00:02:50,460 --> 00:02:52,320 Got my bachelor's degree in computer science. 66 00:02:52,680 --> 00:02:54,540 Again, something you guys could have done. 67 00:02:55,160 --> 00:02:56,340 Just something that I chose. 68 00:02:58,000 --> 00:03:00,520 After college, I got out, became a network engineer. 69 00:03:00,720 --> 00:03:01,800 Thought I was done with programming. 70 00:03:02,760 --> 00:03:04,580 Got into teaching, consulting. 71 00:03:05,060 --> 00:03:06,900 A lot of good money there. 72 00:03:07,520 --> 00:03:10,700 You don't have to know a lot about stuff to make a lot of money. 73 00:03:10,900 --> 00:03:12,720 You guys have probably put that together, haven't you? 74 00:03:13,660 --> 00:03:14,900 Well, that's where I was heading. 75 00:03:15,940 --> 00:03:20,140 Moved into telecom, where I got away from dealing with all the angry users a lot, 76 00:03:20,240 --> 00:03:21,840 and I moved into the more technical field. 77 00:03:22,000 --> 00:03:22,460 And you know what? 78 00:03:22,500 --> 00:03:23,640 I didn't even get a pay increase. 79 00:03:24,060 --> 00:03:28,060 So, telecom introduced me to Hacking Exposed, 80 00:03:28,160 --> 00:03:30,760 because I started taking over the firewalls and doing all that stuff. 81 00:03:36,060 --> 00:03:38,620 After I'd been telecom a couple years, I went. 82 00:03:38,760 --> 00:03:40,600 My boss says, I want you to go to SANS. 83 00:03:41,260 --> 00:03:43,540 And I want you to take, think outside the box. 84 00:03:43,620 --> 00:03:44,780 Don't think about telecom. 85 00:03:44,960 --> 00:03:46,040 Think something else. 86 00:03:46,080 --> 00:03:47,260 I said, hacker track, dude. 87 00:03:47,820 --> 00:03:48,380 Must be. 88 00:03:48,740 --> 00:03:52,960 And I took the hacker course with Ed Skodas, who promised me he was going to be here, 89 00:03:53,080 --> 00:03:53,620 and he didn't. 90 00:03:53,620 --> 00:03:55,720 And if he's here, can somebody, like, point him out? 91 00:03:56,860 --> 00:03:59,720 And if he's not, everybody boo him when you see him later. 92 00:04:00,020 --> 00:04:01,180 His wife is pissed. 93 00:04:02,600 --> 00:04:06,460 So, if you go check out the CTF, you'll probably know where to find him. 94 00:04:07,420 --> 00:04:09,560 Anyway, good friend of mine now, he was a mentor. 95 00:04:10,220 --> 00:04:14,520 Capture the flag, according to his teaching, was very different. 96 00:04:14,760 --> 00:04:19,080 So, when I saw DEF CON say, hey, we got this capture the flag, I'm thinking, 97 00:04:19,220 --> 00:04:20,760 hmm, dude, I know Metasploit. 98 00:04:22,740 --> 00:04:27,900 I know Nessus, I can find the vulnerabilities, I can go download some script, I'm in. 99 00:04:28,080 --> 00:04:28,620 All right. 100 00:04:28,740 --> 00:04:31,260 So, I signed up really, really naively. 101 00:04:33,320 --> 00:04:37,660 Actually, I asked a bunch of guys to join a team, but that's a long story. 102 00:04:39,540 --> 00:04:44,200 So, about June 3rd, so when pre-qual started last year, probably some of you guys knew that. 103 00:04:45,260 --> 00:04:46,460 June 3rd, I had forgotten. 104 00:04:47,500 --> 00:04:50,740 I said, okay, I got an e-mail from them. 105 00:04:50,740 --> 00:04:54,680 One of these Ken Shoto guys that says, 10 o'clock tonight, I'm supposed to be doing something. 106 00:04:54,960 --> 00:04:55,940 Oh, my gosh. 107 00:04:56,520 --> 00:05:00,020 We had visitors coming in from out of town, like four hours away. 108 00:05:00,520 --> 00:05:02,520 I had just adopted a little baby. 109 00:05:02,740 --> 00:05:03,640 Those are my kids. 110 00:05:04,420 --> 00:05:05,380 I'm a happy father. 111 00:05:05,980 --> 00:05:08,320 And we'd adopted like a week and a half before. 112 00:05:08,780 --> 00:05:10,200 So, I've got this screaming baby. 113 00:05:10,300 --> 00:05:11,080 We got her out of the hospital. 114 00:05:11,660 --> 00:05:12,600 Not a good thing. 115 00:05:12,860 --> 00:05:14,660 So, I was already used to no sleep, though. 116 00:05:14,760 --> 00:05:17,840 So, sleep deprivation was good for my hacking career. 117 00:05:19,120 --> 00:05:20,720 But I was limited to about... 118 00:05:21,260 --> 00:05:22,700 Midnight to about 5 in the morning. 119 00:05:24,320 --> 00:05:28,060 You and me going to rumble. 120 00:05:28,840 --> 00:05:30,120 You can't have her back. 121 00:05:32,960 --> 00:05:37,700 To make matters worse, all my buddies that I said, hey, let's go be a team, they didn't show up. 122 00:05:38,620 --> 00:05:44,280 Ken Shoto very nicely said, ah, we'll give you the individual status so you can keep hacking. 123 00:05:46,100 --> 00:05:48,560 So, briefly, show of hands. 124 00:05:48,780 --> 00:05:50,440 Who's done Nessus? 125 00:05:50,740 --> 00:05:54,100 Maybe some Metasploit, download some code, and exploit machines. 126 00:05:55,780 --> 00:05:56,220 Excellent. 127 00:05:56,380 --> 00:06:00,320 Who remembers the first time they saw a C prompt on their Linux box? 128 00:06:01,840 --> 00:06:02,720 Oh, yeah. 129 00:06:03,320 --> 00:06:05,280 That is one of those turning points in life. 130 00:06:06,260 --> 00:06:07,240 It's very memorable. 131 00:06:08,420 --> 00:06:10,520 So, I started out, cool. 132 00:06:10,700 --> 00:06:12,180 This is capture the flag. 133 00:06:12,320 --> 00:06:13,240 I'm going to learn about this box. 134 00:06:13,420 --> 00:06:18,560 The only thing we were told was dujour.kenshoto.com is the only machine you can hack. 135 00:06:18,700 --> 00:06:19,120 Go ahead. 136 00:06:19,360 --> 00:06:20,540 Go forth and be... 137 00:06:20,740 --> 00:06:20,920 I'm malicious. 138 00:06:22,380 --> 00:06:22,780 Okay. 139 00:06:22,820 --> 00:06:23,320 That's cool. 140 00:06:23,400 --> 00:06:23,920 I can deal with that. 141 00:06:24,180 --> 00:06:26,080 So, I start Reconnaissance. 142 00:06:26,340 --> 00:06:26,640 Okay. 143 00:06:26,740 --> 00:06:27,140 Reconnaissance. 144 00:06:27,180 --> 00:06:29,200 Going back to my sans days. 145 00:06:29,980 --> 00:06:32,900 Well, I got everything that I got right there because they just brought up the site. 146 00:06:33,300 --> 00:06:34,320 Their email was it. 147 00:06:34,580 --> 00:06:35,700 So, I move into scanning. 148 00:06:36,800 --> 00:06:38,560 Nmap scan showed up three ports. 149 00:06:40,560 --> 00:06:41,360 22, SSH. 150 00:06:41,600 --> 00:06:43,160 Port 80, Apache. 151 00:06:43,560 --> 00:06:45,040 And 69, 69. 152 00:06:45,200 --> 00:06:48,200 Some sort of really weird sex port or something. 153 00:06:50,740 --> 00:06:51,900 Anybody would go to ShmooCon this year? 154 00:06:52,780 --> 00:06:53,320 All right. 155 00:06:55,400 --> 00:06:57,500 22 was totally patched. 156 00:06:57,500 --> 00:06:58,060 Up to date. 157 00:06:58,140 --> 00:06:59,000 No known vulnerabilities. 158 00:07:00,820 --> 00:07:01,920 Apache, same thing. 159 00:07:02,820 --> 00:07:03,740 Going, what the heck? 160 00:07:03,880 --> 00:07:04,620 This kind of sucks. 161 00:07:05,420 --> 00:07:06,320 So, I dig in. 162 00:07:06,360 --> 00:07:07,580 Maybe they got a web app. 163 00:07:07,720 --> 00:07:08,800 I check out the web app. 164 00:07:10,040 --> 00:07:11,420 Web app has a hidden field. 165 00:07:11,680 --> 00:07:12,080 All right. 166 00:07:12,100 --> 00:07:12,640 I'm in now. 167 00:07:12,760 --> 00:07:13,820 I can understand this. 168 00:07:13,960 --> 00:07:15,640 Hidden field, I tweak around with it. 169 00:07:15,700 --> 00:07:20,180 Got a whole lot of errors until finally I find out file not found. 170 00:07:20,320 --> 00:07:20,720 I'm in. 171 00:07:20,720 --> 00:07:21,640 Okay. 172 00:07:22,560 --> 00:07:26,840 So, I was able to directory traversal up and view any file on the system. 173 00:07:26,980 --> 00:07:27,600 Didn't get me in. 174 00:07:27,900 --> 00:07:29,040 But it got me a lot. 175 00:07:29,240 --> 00:07:30,580 Including the password file. 176 00:07:31,000 --> 00:07:32,960 A little bit of cracking of the password file. 177 00:07:33,840 --> 00:07:38,480 Mind you, I zoomed right over the first key because it was stuck in the password file. 178 00:07:38,760 --> 00:07:40,160 I was too interested in getting the box. 179 00:07:41,060 --> 00:07:43,640 Anyway, in the password file, I throw it into John. 180 00:07:43,920 --> 00:07:44,920 You guys have probably done this. 181 00:07:45,060 --> 00:07:45,740 That's cool stuff. 182 00:07:46,020 --> 00:07:46,600 Really cool. 183 00:07:46,720 --> 00:07:47,620 John is great. 184 00:07:48,140 --> 00:07:50,620 John spits out immediately, within one minute. 185 00:07:50,620 --> 00:07:52,220 The root password. 186 00:07:53,580 --> 00:07:55,000 And some break me password. 187 00:07:57,780 --> 00:07:59,600 No remote root. 188 00:08:00,620 --> 00:08:01,040 Suck. 189 00:08:01,740 --> 00:08:02,720 So, I wasn't in. 190 00:08:03,340 --> 00:08:04,600 But this break me. 191 00:08:04,960 --> 00:08:06,080 Break me was kind of cool. 192 00:08:06,560 --> 00:08:07,500 I hit break me. 193 00:08:07,620 --> 00:08:09,480 And my screen just went wild. 194 00:08:09,680 --> 00:08:11,000 And it spit out the key. 195 00:08:11,200 --> 00:08:12,120 Key number two. 196 00:08:12,300 --> 00:08:12,760 Wait a minute. 197 00:08:12,800 --> 00:08:13,620 Where did key number one go? 198 00:08:14,160 --> 00:08:16,120 Well, that was back in the etsy passwords file. 199 00:08:17,240 --> 00:08:19,100 So, key number two got spit out to me. 200 00:08:19,100 --> 00:08:21,320 And I had to try it again to see what that was. 201 00:08:21,560 --> 00:08:22,660 Dumped it to a file. 202 00:08:22,940 --> 00:08:30,000 Turns out, the login script dumps a base 64 encoded binary. 203 00:08:31,140 --> 00:08:33,840 And then clears the screen a bunch of times. 204 00:08:34,540 --> 00:08:35,660 And spits out the key. 205 00:08:39,020 --> 00:08:39,820 What the heck? 206 00:08:44,700 --> 00:08:45,940 On base 64. 207 00:08:46,020 --> 00:08:47,280 You know the pearl. 208 00:08:48,620 --> 00:08:49,660 What is that? 209 00:08:49,940 --> 00:08:52,520 Use the base 64 mime thing. 210 00:08:53,000 --> 00:08:54,460 And spit out a binary. 211 00:08:54,740 --> 00:08:55,960 I run file on it. 212 00:08:56,080 --> 00:08:57,860 Unless you guys here with security expertise. 213 00:08:58,140 --> 00:08:59,180 Maybe in forensics. 214 00:08:59,260 --> 00:08:59,960 You know what file does. 215 00:09:01,260 --> 00:09:02,300 File spits out. 216 00:09:02,360 --> 00:09:02,800 Oh, my gosh. 217 00:09:02,860 --> 00:09:04,040 It's an elf 32 binary. 218 00:09:05,400 --> 00:09:06,240 That's kind of scary. 219 00:09:06,780 --> 00:09:07,220 Okay. 220 00:09:08,120 --> 00:09:09,000 I'm trembling. 221 00:09:10,140 --> 00:09:11,480 I do strings on it. 222 00:09:11,540 --> 00:09:13,580 And I see protocol failure. 223 00:09:14,080 --> 00:09:14,740 Oh, crap. 224 00:09:14,860 --> 00:09:15,460 And I remembered. 225 00:09:15,460 --> 00:09:18,860 Back during my initial scanning this port 6969. 226 00:09:19,180 --> 00:09:20,320 When I hit it wrong. 227 00:09:20,660 --> 00:09:22,620 It spits protocol failure. 228 00:09:23,540 --> 00:09:23,760 Oh. 229 00:09:25,640 --> 00:09:28,020 To quote one of my favorite lines out of speed. 230 00:09:28,760 --> 00:09:29,540 Oh, darn. 231 00:09:34,180 --> 00:09:35,200 So, at that point. 232 00:09:35,360 --> 00:09:36,900 I was in mental surrender, dude. 233 00:09:37,060 --> 00:09:44,160 Like, I have never considered writing a binary exploit. 234 00:09:44,160 --> 00:09:44,660 Never. 235 00:09:45,480 --> 00:09:47,560 That is the realm of the gods. 236 00:09:47,600 --> 00:09:48,560 So, I'm here to tell you it's not. 237 00:09:48,900 --> 00:09:49,300 Okay. 238 00:09:49,600 --> 00:09:51,040 Most of you could probably do it. 239 00:09:52,280 --> 00:09:53,420 Some of you probably have. 240 00:09:53,700 --> 00:09:54,620 So, you know. 241 00:09:54,640 --> 00:09:56,480 No disrespect to you guys. 242 00:09:57,460 --> 00:09:59,420 I had tons of fear, uncertainty, and doubt. 243 00:09:59,540 --> 00:10:00,460 And it was well founded. 244 00:10:00,480 --> 00:10:01,260 Because I knew nothing. 245 00:10:01,500 --> 00:10:03,040 I was way out of my comfort zone. 246 00:10:03,280 --> 00:10:05,460 All I remembered was stuff from my forensics exam. 247 00:10:05,820 --> 00:10:07,280 That taught me about abs dump. 248 00:10:08,300 --> 00:10:09,240 And read elf. 249 00:10:10,420 --> 00:10:12,600 And a couple others that I just started poking around. 250 00:10:16,000 --> 00:10:17,560 Which is, of course, the next slide. 251 00:10:17,620 --> 00:10:17,820 Sorry. 252 00:10:19,320 --> 00:10:21,920 And then, of course, I find a new hope. 253 00:10:22,840 --> 00:10:24,740 I thought, I can do this. 254 00:10:25,620 --> 00:10:26,900 They're expecting me to do this. 255 00:10:27,100 --> 00:10:28,280 I better give it a shot. 256 00:10:28,360 --> 00:10:31,380 Or I'm just going to give up and go crawl in a hole. 257 00:10:32,380 --> 00:10:34,660 I had been reading a book that my in-laws bought me. 258 00:10:36,380 --> 00:10:38,300 Called hacking, the art of exploitation. 259 00:10:38,640 --> 00:10:39,640 Who here has that book? 260 00:10:40,820 --> 00:10:41,540 Excellent book. 261 00:10:42,220 --> 00:10:42,580 Excellent book. 262 00:10:42,600 --> 00:10:42,900 Excellent book. 263 00:10:43,080 --> 00:10:43,940 I got bored. 264 00:10:44,160 --> 00:10:45,940 And I quit reading it at page 20. 265 00:10:46,060 --> 00:10:47,380 Because it was basically recap. 266 00:10:47,760 --> 00:10:48,540 It's all theoretical. 267 00:10:49,940 --> 00:10:57,060 When I went back, I found page 23 is when they get into writing buffer overflow exploits. 268 00:10:58,880 --> 00:11:00,320 Could have already had all this knowledge. 269 00:11:00,560 --> 00:11:02,080 So, I start reading like crazy. 270 00:11:03,080 --> 00:11:04,820 And I learn, oh, my gosh. 271 00:11:04,880 --> 00:11:05,440 I can do this. 272 00:11:05,660 --> 00:11:06,840 Got it on my Linux box. 273 00:11:07,360 --> 00:11:10,060 I was able to write an exploit. 274 00:11:10,460 --> 00:11:10,900 Sweet. 275 00:11:10,900 --> 00:11:17,600 Also found a paper on exploit X on writing remote buffer overflow exploits. 276 00:11:17,740 --> 00:11:18,980 Very different game. 277 00:11:19,140 --> 00:11:20,960 Because then you got the whole network thing involved. 278 00:11:22,700 --> 00:11:25,980 But the thing that got me through it was sheer simple determination. 279 00:11:26,800 --> 00:11:29,200 I was looking really desperately for a good picture. 280 00:11:29,720 --> 00:11:30,800 I like the bear. 281 00:11:39,440 --> 00:11:41,420 So, that's pretty much all about me. 282 00:11:42,040 --> 00:11:45,760 Now, we're really going to get into what happened, what I learned. 283 00:11:46,080 --> 00:11:49,000 This is more of a, oh, my gosh, I was really stupid type thing. 284 00:11:49,100 --> 00:11:51,960 And I learned a lot in trying to brain dump some of that. 285 00:11:53,280 --> 00:11:54,800 What I used was OBSDUMP. 286 00:11:55,200 --> 00:12:00,780 Really cool tool with a ton of ability to analyze and decipher binary data. 287 00:12:00,780 --> 00:12:01,440 Binary executables. 288 00:12:01,980 --> 00:12:03,600 Works on ELF for UNIX. 289 00:12:03,860 --> 00:12:08,400 Works on the PE file, which is the standard Windows XE and DLL. 290 00:12:10,140 --> 00:12:12,180 I used read ELF, very limited. 291 00:12:12,520 --> 00:12:14,880 OBSDUMP did everything that I really wanted and I got used to it. 292 00:12:15,000 --> 00:12:16,360 But read ELF, I had to poke into it. 293 00:12:16,560 --> 00:12:17,920 It's another very cool tool. 294 00:12:18,020 --> 00:12:21,740 Doesn't do the disassembly part, but does just about everything else that OBSDUMP does. 295 00:12:23,500 --> 00:12:27,020 I got to know GDB as the GNU debugger. 296 00:12:28,020 --> 00:12:29,580 I remember a long time ago. 297 00:12:29,580 --> 00:12:35,640 Copying and pasting stuff into debug for the DOS and Windows machines to hack up DOS axes. 298 00:12:37,060 --> 00:12:37,940 GDB, wow. 299 00:12:39,700 --> 00:12:42,480 If you talk to people in the industry, they're going to say, yeah, it's a piece of crap. 300 00:12:43,140 --> 00:12:44,720 And indeed, it has a lot of weaknesses. 301 00:12:45,140 --> 00:12:47,680 But it helped a lot and it taught me a lot. 302 00:12:48,760 --> 00:12:57,860 I worked with KTrace and KDUMP, which is the kernel hooker as the program will talk to the kernel 303 00:12:57,860 --> 00:13:04,500 to make calls like read and close and printf and all that stuff. 304 00:13:04,980 --> 00:13:13,900 This sucker intercepts it and spits it out in a format that you can make some logical identification out of. 305 00:13:14,720 --> 00:13:16,640 And now I wrote a tool called Disass. 306 00:13:16,920 --> 00:13:20,800 Because I wasn't happy with what OBSDUMP spit out, especially for some binaries. 307 00:13:22,160 --> 00:13:23,540 I wanted to know more. 308 00:13:24,060 --> 00:13:26,720 And I wanted not to have to go through and manually do more. 309 00:13:26,720 --> 00:13:28,100 It's not an excellent tool. 310 00:13:28,260 --> 00:13:29,160 It helps me out. 311 00:13:29,420 --> 00:13:35,260 And in my release of the utility belt, which you guys will find on my blog later on too, 312 00:13:36,080 --> 00:13:37,040 you'll find Disass. 313 00:13:37,220 --> 00:13:38,000 Lots of fun. 314 00:13:40,940 --> 00:13:42,740 So we'll run through the tools just a little bit. 315 00:13:43,620 --> 00:13:44,740 Can any of you read this? 316 00:13:45,540 --> 00:13:45,940 Sorry. 317 00:13:46,820 --> 00:13:47,540 I'll summarize. 318 00:13:47,760 --> 00:13:51,300 This is OBSDUMP, the help output. 319 00:13:52,660 --> 00:13:56,340 Basically, it allows you to look at the various header files in an executable. 320 00:13:57,100 --> 00:13:58,980 Which tells a ton of information. 321 00:13:59,660 --> 00:14:04,880 It allows you to disassemble the text or all sections. 322 00:14:06,160 --> 00:14:08,140 Anybody done assembly in here? 323 00:14:09,660 --> 00:14:10,140 Good. 324 00:14:10,240 --> 00:14:11,720 You'll like it better than the rest of you. 325 00:14:12,000 --> 00:14:15,580 If you don't know assembly, there are tons of good books out there. 326 00:14:15,660 --> 00:14:17,940 I could probably hook you up with some interesting stuff. 327 00:14:18,840 --> 00:14:22,420 Reverse engineering of a binary that you don't know. 328 00:14:22,780 --> 00:14:26,180 You've really got to hunker down and learn your ASM. 329 00:14:29,640 --> 00:14:32,780 OBSDUMP also spits out relocation points. 330 00:14:33,280 --> 00:14:39,780 So in a file, you've got everything laid out in a very different fashion than it's going to appear in memory. 331 00:14:40,700 --> 00:14:45,700 And some of the stuff that's copied into memory, you want to call it by name. 332 00:14:46,000 --> 00:14:47,460 The computer knows it by number. 333 00:14:47,700 --> 00:14:53,920 So the relocation points allow you to basically do a DNS lookup on these locations. 334 00:14:57,060 --> 00:14:59,380 OBSDUMP-D, you probably can't see that either. 335 00:14:59,580 --> 00:15:02,240 You can read it on the PDF that you've got on the CD. 336 00:15:02,720 --> 00:15:07,880 This is the very beginning of the disassembly for the bash shell. 337 00:15:15,640 --> 00:15:16,700 Again, Readelf's help. 338 00:15:17,020 --> 00:15:19,200 You'll see a lot of interesting stuff. 339 00:15:19,420 --> 00:15:21,680 I print these out kind of as a placeholder. 340 00:15:21,900 --> 00:15:25,000 So if you're reading the PDF later, you'll stop and think, 341 00:15:25,140 --> 00:15:26,500 well, let's go play around with that a little bit. 342 00:15:26,720 --> 00:15:28,860 Because playing around is the name of the game. 343 00:15:32,320 --> 00:15:35,260 If you couldn't read that before, you really can't read this. 344 00:15:35,460 --> 00:15:36,500 Again, it is on the PDF. 345 00:15:36,920 --> 00:15:42,920 This is a K-trace output of stage 3, actually. 346 00:15:43,560 --> 00:15:49,760 I use a K-trace call, give it the process ID of the binary. 347 00:15:50,220 --> 00:15:52,980 And it says, okay, we're going to call this. 348 00:15:53,260 --> 00:15:54,580 And it returns this. 349 00:15:54,700 --> 00:15:55,340 Call this. 350 00:15:55,340 --> 00:15:56,260 And it returns this. 351 00:15:56,660 --> 00:15:57,900 It's calling select. 352 00:15:58,260 --> 00:15:59,300 Anybody done programming? 353 00:15:59,540 --> 00:16:00,420 Do you know what select does? 354 00:16:01,720 --> 00:16:06,880 Select, if you've got like a file descriptor or something that points at an object, 355 00:16:07,120 --> 00:16:13,900 like a file or a device, select will allow you to say, 356 00:16:14,060 --> 00:16:18,720 is anything waiting to come in on this file descriptor? 357 00:16:18,980 --> 00:16:19,860 Very helpful. 358 00:16:23,240 --> 00:16:24,360 It goes down. 359 00:16:24,360 --> 00:16:25,700 It hits accept. 360 00:16:26,020 --> 00:16:29,140 And if you're not into network programming, there are great books to learn. 361 00:16:29,680 --> 00:16:33,400 Accept is the first call for, anybody yell it out? 362 00:16:33,560 --> 00:16:34,280 What kind of connection? 363 00:16:36,160 --> 00:16:37,240 A TCP connection. 364 00:16:37,840 --> 00:16:41,180 You hit accept, you've got a listener, and then you call accept, 365 00:16:41,280 --> 00:16:43,560 and it just kind of sits there and waits for somebody to connect. 366 00:16:44,200 --> 00:16:44,680 Hey, how's it going? 367 00:16:46,400 --> 00:16:47,200 Somebody connects. 368 00:16:48,000 --> 00:16:52,060 Accept returns an active file descriptor to a network socket. 369 00:16:52,280 --> 00:16:53,180 It's really cool stuff. 370 00:16:53,180 --> 00:16:56,520 You can read and write to it almost like you were reading and writing to a file. 371 00:16:58,520 --> 00:17:01,300 So I know that that's where it starts the network connection. 372 00:17:01,440 --> 00:17:07,000 It goes down, calls a fork, which is a way of spinning off a little child process and running. 373 00:17:09,920 --> 00:17:11,660 Calls, oh, it calls read. 374 00:17:11,940 --> 00:17:12,860 Wow, go figure. 375 00:17:13,420 --> 00:17:16,920 And it gives information on the memory location where that stuff goes. 376 00:17:18,100 --> 00:17:19,440 This is a wealth of information. 377 00:17:19,620 --> 00:17:21,840 I'm not going to cover it as well as I should. 378 00:17:23,180 --> 00:17:28,200 You'll see near the bottom, bacon colon my name colon my password colon something else. 379 00:17:30,680 --> 00:17:35,480 That's kdump telling me what I put in there from the network connection. 380 00:17:35,820 --> 00:17:38,820 My little client that I wrote spits that in there. 381 00:17:38,960 --> 00:17:40,000 Kdump tells me that. 382 00:17:40,160 --> 00:17:42,940 It also prints out all the stuff that's written back. 383 00:17:43,020 --> 00:17:45,500 Like, down below it, it says tag failure. 384 00:17:45,680 --> 00:17:46,420 I screwed up. 385 00:17:46,460 --> 00:17:47,480 I didn't know what I was doing. 386 00:17:47,660 --> 00:17:48,820 I was just trying stuff. 387 00:17:55,560 --> 00:17:57,880 So I made a conscious decision. 388 00:17:58,560 --> 00:18:01,540 I'm going to work this until it kills me or until I get it. 389 00:18:03,720 --> 00:18:05,500 So I bring up BSD on VMware. 390 00:18:07,600 --> 00:18:11,780 Run the stage three binary, which used to be called binary in the previous slides. 391 00:18:11,920 --> 00:18:13,420 I renamed it to stage three. 392 00:18:13,840 --> 00:18:17,920 Ran it with 6969 because it wants a port number. 393 00:18:19,680 --> 00:18:22,360 I wanted it to look just like it would on Ken Shoto's box, right? 394 00:18:22,360 --> 00:18:22,460 All right. 395 00:18:24,680 --> 00:18:26,460 Then I started Ktrace. 396 00:18:27,940 --> 00:18:31,200 Ktrace watches how the program executes. 397 00:18:31,500 --> 00:18:32,800 Start a Netcat session. 398 00:18:33,040 --> 00:18:35,200 Who here used Netcat? 399 00:18:36,640 --> 00:18:37,520 Let me hear it. 400 00:18:37,960 --> 00:18:40,260 Netcat is your friend. 401 00:18:40,680 --> 00:18:41,380 Very good. 402 00:18:42,340 --> 00:18:43,120 Some of you. 403 00:18:43,240 --> 00:18:43,940 Let's hear it again. 404 00:18:44,340 --> 00:18:46,100 Netcat is your friend. 405 00:18:46,960 --> 00:18:50,900 Unless, of course, you're trying to shove Perl into it with unbuffered IO. 406 00:18:51,640 --> 00:18:52,160 Yeah. 407 00:18:52,360 --> 00:18:52,720 Anyway. 408 00:18:55,220 --> 00:18:59,200 So I shove in Netcat to 6969 on the local host. 409 00:18:59,280 --> 00:19:00,380 This is my own machine I'm hacking. 410 00:19:01,800 --> 00:19:05,280 I give Bacon my name, my password, something else. 411 00:19:05,520 --> 00:19:06,680 And then I run Kdump. 412 00:19:06,720 --> 00:19:08,300 And you see the output on the previous slide. 413 00:19:09,460 --> 00:19:10,740 Then I get into GDB. 414 00:19:11,820 --> 00:19:13,100 Very cool stuff. 415 00:19:14,660 --> 00:19:15,380 Very scary. 416 00:19:16,320 --> 00:19:17,660 GDB stage three. 417 00:19:17,780 --> 00:19:18,720 And then I put in the PID. 418 00:19:18,840 --> 00:19:21,240 And what you'll see on there is an operating system. 419 00:19:21,240 --> 00:19:25,160 A Unix call to grab the PID of stage three. 420 00:19:29,600 --> 00:19:31,240 And I analyze Ktrace. 421 00:19:31,380 --> 00:19:36,360 Because I was too freaked out of assembly and actual reverse engineering. 422 00:19:36,640 --> 00:19:37,420 So it's okay. 423 00:19:38,540 --> 00:19:42,260 If you get to a point where you're like, dude, I'm just not comfortable with that. 424 00:19:42,340 --> 00:19:43,080 I don't know what I'm doing. 425 00:19:43,380 --> 00:19:44,020 That's cool. 426 00:19:44,160 --> 00:19:44,700 That's fine. 427 00:19:45,220 --> 00:19:45,860 Do something. 428 00:19:46,120 --> 00:19:46,840 Keep going. 429 00:19:49,880 --> 00:19:51,960 In the Ktrace, wait a minute. 430 00:19:52,020 --> 00:19:53,320 I just saw most of that. 431 00:19:55,380 --> 00:19:55,980 Okay. 432 00:19:56,960 --> 00:19:59,380 This is a continuation of what happened. 433 00:20:00,500 --> 00:20:01,940 And so on. 434 00:20:02,020 --> 00:20:02,740 Nothing of interest. 435 00:20:06,480 --> 00:20:10,260 So basically I'm playing, dude, where's my shell? 436 00:20:10,420 --> 00:20:10,920 All over. 437 00:20:11,180 --> 00:20:13,740 And I'm traipsing around using GDB. 438 00:20:15,140 --> 00:20:16,560 Traipsing around memory space. 439 00:20:16,840 --> 00:20:19,500 Trying to find my input. 440 00:20:20,680 --> 00:20:21,860 It told me. 441 00:20:22,300 --> 00:20:24,020 Ktrace told me where the thing was going. 442 00:20:24,540 --> 00:20:29,240 I could have probably found out from many other places a good idea of where to look. 443 00:20:29,420 --> 00:20:30,020 But I didn't know. 444 00:20:30,400 --> 00:20:31,060 And that's okay. 445 00:20:31,700 --> 00:20:34,480 I just, what's at this memory location? 446 00:20:34,800 --> 00:20:35,240 Keep going. 447 00:20:35,500 --> 00:20:36,140 Oh, my gosh. 448 00:20:36,220 --> 00:20:39,200 I ran into a boundary that can't actually spit back anything. 449 00:20:39,900 --> 00:20:41,500 I was learning a lot about virtual memory. 450 00:20:42,360 --> 00:20:46,640 Virtual memory is basically the computer assigning a huge memory. 451 00:20:46,640 --> 00:20:49,000 A huge memory space to an application even though you don't have that much memory. 452 00:20:51,240 --> 00:20:53,880 Figuring that you'll run out of memory if you run out of memory. 453 00:20:54,020 --> 00:20:55,860 And they want to give you as much leeway as they can. 454 00:20:59,140 --> 00:21:03,660 I had no idea that all this stuff was identified in the ELF binary itself. 455 00:21:04,240 --> 00:21:05,160 The memory locations. 456 00:21:06,600 --> 00:21:10,040 And so I just kept meandering. 457 00:21:11,540 --> 00:21:11,940 . 458 00:21:15,980 --> 00:21:19,520 OBSDUMP-X would have told me a lot of what I need to know. 459 00:21:20,060 --> 00:21:23,900 And so I'm going to share with you just a little bit about what it means. 460 00:21:25,040 --> 00:21:30,480 OBSDUMP-X means dump all header information. 461 00:21:31,440 --> 00:21:32,620 Not just the section. 462 00:21:32,740 --> 00:21:33,420 Not that section. 463 00:21:33,620 --> 00:21:34,620 All of it. 464 00:21:37,400 --> 00:21:39,220 It's broken into four parts. 465 00:21:39,540 --> 00:21:40,060 Whoops. 466 00:21:41,940 --> 00:21:42,640 The file header. 467 00:21:43,160 --> 00:21:44,580 You've got an ELF binary. 468 00:21:44,840 --> 00:21:45,880 So it's an ELF file. 469 00:21:46,080 --> 00:21:48,220 It comes with its own little header at the very beginning. 470 00:21:48,700 --> 00:21:51,540 That tells about the rest of what you're going to see in the file. 471 00:21:51,880 --> 00:21:53,940 It also prints out the program headers. 472 00:21:54,140 --> 00:22:00,880 The program headers say we're going to map this part of the binary to this part of virtual memory. 473 00:22:02,980 --> 00:22:03,500 Cool. 474 00:22:04,540 --> 00:22:06,580 It also lists some dynamic stuff. 475 00:22:06,840 --> 00:22:10,960 We require this library. 476 00:22:10,960 --> 00:22:12,440 This library before we can run. 477 00:22:12,960 --> 00:22:14,600 So if you don't have it, boom, you get an error. 478 00:22:14,940 --> 00:22:17,740 And it also spits out section information. 479 00:22:18,840 --> 00:22:19,860 Assembly coders. 480 00:22:20,220 --> 00:22:26,500 What section, as oddball as it may sound, what section does your code go in? 481 00:22:27,980 --> 00:22:28,540 Text. 482 00:22:28,860 --> 00:22:29,340 Okay. 483 00:22:30,340 --> 00:22:30,900 Yeah. 484 00:22:31,280 --> 00:22:31,840 Okay. 485 00:22:31,920 --> 00:22:32,220 No. 486 00:22:32,400 --> 00:22:32,880 I'm sorry. 487 00:22:33,000 --> 00:22:35,440 Your strings don't go in text. 488 00:22:36,000 --> 00:22:38,360 Your code goes there. 489 00:22:39,300 --> 00:22:41,660 So text is one of many sections. 490 00:22:42,500 --> 00:22:44,420 So we're going to talk about some of that. 491 00:22:45,540 --> 00:22:49,420 Because in the end, we're not talking about assembly being converted to machine language. 492 00:22:49,520 --> 00:22:51,560 That's actually an oxymoron. 493 00:22:51,740 --> 00:22:55,020 Assembly is a representation of machine language. 494 00:22:55,460 --> 00:22:56,540 It's a one-to-one. 495 00:22:56,720 --> 00:22:58,380 There's no compiling going on. 496 00:22:58,700 --> 00:23:02,560 The compilers take it from C down to assembler. 497 00:23:04,060 --> 00:23:08,280 Then it runs an assembler to convert the assembly into machine. 498 00:23:08,360 --> 00:23:11,620 It's a machine language to make an object. 499 00:23:12,020 --> 00:23:15,260 And then the linker comes along as if we didn't do enough work. 500 00:23:15,500 --> 00:23:19,040 The linker comes along and says, yes, you're blessed. 501 00:23:19,320 --> 00:23:20,440 You may start. 502 00:23:20,700 --> 00:23:26,180 And starts mapping real addresses based on requirements of other libraries. 503 00:23:26,580 --> 00:23:27,640 It's very cool stuff. 504 00:23:28,100 --> 00:23:33,780 I just bought at the prodding of my good friend Visigoth from Capture the Flag. 505 00:23:34,380 --> 00:23:34,940 Yeah. 506 00:23:35,000 --> 00:23:35,800 The Ken Chodo guy. 507 00:23:35,920 --> 00:23:36,340 He's awesome. 508 00:23:36,340 --> 00:23:39,200 At his prodding, I just bought Loaders and Linkers. 509 00:23:40,140 --> 00:23:41,340 Or Linkers and Loaders. 510 00:23:41,480 --> 00:23:41,700 Whatever. 511 00:23:41,880 --> 00:23:42,760 It's a really good book. 512 00:23:42,960 --> 00:23:43,420 What's that? 513 00:23:44,600 --> 00:23:45,380 Linkers and Loaders. 514 00:23:45,900 --> 00:23:46,520 Exceptional book. 515 00:23:46,860 --> 00:23:47,580 Really scary. 516 00:23:47,800 --> 00:23:50,660 Had I read this a year ago, I would have been totally over my head. 517 00:23:51,960 --> 00:23:54,440 So at the very beginning, we get the file header. 518 00:23:54,920 --> 00:24:01,860 The ELF file header, it says, hey, this is an ELF 32 made for the i386 instruction set. 519 00:24:02,100 --> 00:24:02,500 Okay. 520 00:24:02,520 --> 00:24:02,960 That's cool. 521 00:24:03,260 --> 00:24:05,700 So it's not like some Mac that runs. 522 00:24:05,920 --> 00:24:06,320 Sorry. 523 00:24:06,340 --> 00:24:06,900 Not a MacTel. 524 00:24:06,980 --> 00:24:09,260 But an actual Motorola Mac, the old days. 525 00:24:11,120 --> 00:24:14,140 It has some of the things that it can do. 526 00:24:14,260 --> 00:24:15,880 And a starting address. 527 00:24:16,180 --> 00:24:25,340 So after the loader stuff loads from the file into memory, it drops the instruction pointer into this location. 528 00:24:26,020 --> 00:24:28,000 Kind of like in Demolition Man. 529 00:24:28,220 --> 00:24:32,660 You know, they had him all filled up with that really weird goopy stuff. 530 00:24:33,080 --> 00:24:33,360 Naked. 531 00:24:33,620 --> 00:24:35,260 Kind of scarring me. 532 00:24:35,260 --> 00:24:39,340 And they drop this one little blue thing. 533 00:24:39,720 --> 00:24:41,120 God only knows what it is. 534 00:24:41,300 --> 00:24:41,800 Boom. 535 00:24:41,860 --> 00:24:42,200 Hits. 536 00:24:42,340 --> 00:24:43,860 And everything happens. 537 00:24:44,200 --> 00:24:45,800 That's the starting address here. 538 00:24:48,120 --> 00:24:51,440 The program headers, you'll notice, overlap. 539 00:24:52,420 --> 00:24:55,720 There is some, I'm sorry, they encompass each other. 540 00:24:56,080 --> 00:25:02,700 You'll notice on the left-hand side, there are different types of program headers. 541 00:25:02,700 --> 00:25:05,280 I don't want you guys to be afraid here. 542 00:25:05,860 --> 00:25:08,220 This is like part of the visual effect. 543 00:25:14,940 --> 00:25:17,340 You've got different types of program headers. 544 00:25:20,000 --> 00:25:22,260 The first one is the program header header. 545 00:25:24,640 --> 00:25:29,660 Well, basically, that defines where the program header is going to exist. 546 00:25:29,920 --> 00:25:30,540 That's fine. 547 00:25:30,540 --> 00:25:34,720 The two of most importance are the load header types. 548 00:25:35,080 --> 00:25:39,400 These actually will load from the file into virtual memory space. 549 00:25:41,340 --> 00:25:45,860 The first one starts off at byte zero in the file. 550 00:25:46,740 --> 00:25:50,220 And it maps to 8048000. 551 00:25:50,760 --> 00:25:52,460 This is a BSD box. 552 00:25:53,520 --> 00:25:55,440 That number will vary. 553 00:25:55,740 --> 00:25:59,340 And oftentimes it will look different between platforms. 554 00:25:59,340 --> 00:26:01,960 Not very important, but just something you'll know. 555 00:26:02,720 --> 00:26:07,060 So that actually maps your binary into virtual memory, 556 00:26:07,460 --> 00:26:11,800 even including the ELF header stuff that the OS only cares about. 557 00:26:12,120 --> 00:26:16,020 So if you go in GDB and show that memory location and keep going, 558 00:26:16,200 --> 00:26:20,940 you'll actually be seeing the bytes from the executable file. 559 00:26:21,720 --> 00:26:26,280 The second one starts at 8048000. 560 00:26:27,700 --> 00:26:29,280 And offset two. 561 00:26:29,280 --> 00:26:31,340 And offset 2000 inside the binary file. 562 00:26:31,600 --> 00:26:33,040 Boy, those are really round numbers. 563 00:26:33,200 --> 00:26:35,880 You think maybe they pad things so that it works out that way? 564 00:26:36,600 --> 00:26:37,260 Uh-huh. 565 00:26:38,280 --> 00:26:41,640 That plays into binary manipulation, which this talk won't get into. 566 00:26:41,820 --> 00:26:45,000 But if you ever go that far, that's a lot of fun stuff. 567 00:26:45,660 --> 00:26:50,300 The others you'll find map into the other loadables. 568 00:26:51,880 --> 00:26:56,420 The loadables have certain flags basically saying, 569 00:26:56,420 --> 00:27:02,040 I can read, I can write, and I can execute this memory section. 570 00:27:03,520 --> 00:27:07,300 So if you want to put in your code, 571 00:27:07,560 --> 00:27:10,740 you want to inject some code somewhere in an ELF executable, 572 00:27:11,200 --> 00:27:13,260 don't go for the second one in this example, 573 00:27:13,460 --> 00:27:17,200 because it only has read and write permissions turned on. 574 00:27:18,680 --> 00:27:20,120 I'm going way too deep, aren't I? 575 00:27:20,480 --> 00:27:21,200 I'll move on. 576 00:27:22,840 --> 00:27:23,280 Anyway. 577 00:27:23,280 --> 00:27:28,500 The program headers are awesome and very important. 578 00:27:29,880 --> 00:27:31,800 The dynamic section is quite interesting. 579 00:27:32,120 --> 00:27:35,900 It lists several disparate things. 580 00:27:36,000 --> 00:27:37,660 It's kind of like the miscellaneous area. 581 00:27:38,500 --> 00:27:41,560 It says, okay, I need these libraries to run. 582 00:27:41,860 --> 00:27:42,600 That's cool. 583 00:27:42,720 --> 00:27:43,900 Those are OS libraries. 584 00:27:44,080 --> 00:27:46,580 They don't really mean that I have to install anything. 585 00:27:47,400 --> 00:27:50,200 It talks about where the initialization is, 586 00:27:50,260 --> 00:27:51,800 where the finishing is. 587 00:27:53,100 --> 00:27:55,460 Several other things I won't get into, 588 00:27:55,620 --> 00:27:58,820 except maybe the GOT, the global offset table, 589 00:27:59,000 --> 00:28:03,620 and the PLT, the program linkage table. 590 00:28:04,380 --> 00:28:07,260 These are used by your program, 591 00:28:07,440 --> 00:28:09,340 because you don't want to rewrite printf. 592 00:28:10,000 --> 00:28:14,520 They are used by your program to jump to a local little section of code, 593 00:28:16,180 --> 00:28:20,120 which gets transferred to wherever printf was mapped into memory. 594 00:28:21,900 --> 00:28:22,740 Cool stuff. 595 00:28:23,260 --> 00:28:26,300 This is like a long time of research. 596 00:28:27,000 --> 00:28:28,720 Something that you want to get into, though, 597 00:28:28,740 --> 00:28:29,300 if you're interested. 598 00:28:31,380 --> 00:28:32,740 Now we get into the sections. 599 00:28:32,980 --> 00:28:34,940 Now, what was that section again where your code goes? 600 00:28:36,560 --> 00:28:37,000 Text. 601 00:28:38,220 --> 00:28:40,700 Text is section nine in this binary. 602 00:28:41,640 --> 00:28:43,040 There are a lot of other sections. 603 00:28:43,140 --> 00:28:44,100 You'll notice the PLT, 604 00:28:44,940 --> 00:28:46,480 and you'll notice the... 605 00:28:48,340 --> 00:28:48,980 Where is it? 606 00:28:49,860 --> 00:28:50,880 You'll notice the GOT, 607 00:28:52,280 --> 00:28:53,840 and you'll notice a lot of other stuff. 608 00:28:54,020 --> 00:28:55,520 Read-only data, RO data, 609 00:28:55,960 --> 00:28:58,060 that can be very helpful when reversing a binary. 610 00:28:58,400 --> 00:28:59,520 I won't go into the rest of them, 611 00:28:59,580 --> 00:29:03,380 but it says the section of code, 612 00:29:03,840 --> 00:29:05,820 or of whatever that's in the file, 613 00:29:06,800 --> 00:29:08,900 it lives in the file with this offset, 614 00:29:09,120 --> 00:29:11,120 and it needs to be mapped into memory here. 615 00:29:12,920 --> 00:29:14,640 Again, by looking at this information, 616 00:29:14,900 --> 00:29:18,060 I can tell what virtual memory space looks like. 617 00:29:21,500 --> 00:29:24,200 Now remember, when I was a year ago, 618 00:29:24,320 --> 00:29:25,420 I didn't know this stuff. 619 00:29:25,560 --> 00:29:26,860 I was poking around. 620 00:29:27,140 --> 00:29:29,040 I'm trying to share this with you 621 00:29:29,040 --> 00:29:31,960 so that if you decide to take this assignment, 622 00:29:32,820 --> 00:29:34,840 you won't have to do a lot of the meandering 623 00:29:34,840 --> 00:29:36,840 and silly, pointless things that I did. 624 00:29:37,280 --> 00:29:38,300 Well, they weren't pointless. 625 00:29:39,660 --> 00:29:41,160 We also see the symbol table. 626 00:29:41,380 --> 00:29:45,180 This can show everything from the section information 627 00:29:46,880 --> 00:29:47,840 and your... 628 00:29:47,840 --> 00:29:51,480 even your own written code functions, methods, 629 00:29:53,580 --> 00:29:54,860 and where they map to. 630 00:29:55,080 --> 00:29:58,520 This is your little look-up service area. 631 00:29:59,380 --> 00:30:01,460 So when you want to know what lives where, 632 00:30:01,920 --> 00:30:04,740 let's say I want to know where main lives in memory. 633 00:30:05,160 --> 00:30:05,960 Boom, right here. 634 00:30:06,060 --> 00:30:06,700 I look for main. 635 00:30:07,200 --> 00:30:09,020 As long as these symbols aren't stripped, 636 00:30:10,200 --> 00:30:11,140 it helps me out. 637 00:30:12,120 --> 00:30:13,340 Every binary is different. 638 00:30:13,660 --> 00:30:15,020 It's important to realize that 639 00:30:15,020 --> 00:30:16,820 if you're really good on one binary, 640 00:30:16,820 --> 00:30:18,760 it doesn't mean that they can't make a binary 641 00:30:18,760 --> 00:30:21,040 that you would love to hate 642 00:30:21,480 --> 00:30:22,900 and would make your eyes bleed. 643 00:30:23,380 --> 00:30:24,420 Kenshodo does this. 644 00:30:24,720 --> 00:30:26,920 I know last year they had a finger demon 645 00:30:26,920 --> 00:30:29,300 where everything was statically compiled. 646 00:30:29,520 --> 00:30:30,560 It means these shared libraries 647 00:30:30,560 --> 00:30:33,360 were sucked into the overall binary, 648 00:30:33,540 --> 00:30:35,060 and then they stripped all the symbols 649 00:30:35,060 --> 00:30:36,300 so we didn't know what was what. 650 00:30:37,820 --> 00:30:38,700 Real buzzer. 651 00:30:39,660 --> 00:30:41,040 So was it a waste of time? 652 00:30:41,760 --> 00:30:43,540 Well, obviously not, because I'm here talking. 653 00:30:43,740 --> 00:30:46,480 But no, this was not a waste of time. 654 00:30:47,020 --> 00:30:48,800 The most difficult thing for me to get over 655 00:30:48,800 --> 00:30:50,020 was the fact that I thought 656 00:30:50,020 --> 00:30:51,620 I needed to be doing something 657 00:30:51,620 --> 00:30:54,320 and having some tangible results 658 00:30:55,300 --> 00:30:56,680 for it to be worth my time. 659 00:30:57,880 --> 00:30:59,000 But to this day, 660 00:30:59,060 --> 00:31:00,640 you'll come in and watch us. 661 00:31:00,820 --> 00:31:02,460 I lead the Last Place team 662 00:31:02,460 --> 00:31:04,300 for Capture the Flag. 663 00:31:04,440 --> 00:31:05,340 We're called Last Place. 664 00:31:05,460 --> 00:31:06,720 I'm not hoping to end up there. 665 00:31:07,480 --> 00:31:08,900 But come check us out. 666 00:31:09,920 --> 00:31:11,980 Things that I learned during that meandering 667 00:31:11,980 --> 00:31:12,800 around memory space, 668 00:31:13,660 --> 00:31:16,000 they still play into the way that I play the game. 669 00:31:16,820 --> 00:31:18,480 And anything else that I do reverse engineering. 670 00:31:22,260 --> 00:31:23,840 Again, I'm not going to go over all this. 671 00:31:23,960 --> 00:31:27,040 This is for your own visual enjoyment later. 672 00:31:27,520 --> 00:31:29,060 When you go back and you play with GDB, 673 00:31:29,260 --> 00:31:32,600 these are some of my favorite parts of GDB 674 00:31:32,600 --> 00:31:33,900 that help me get around. 675 00:31:34,840 --> 00:31:36,760 Like way to print out what's in memory, 676 00:31:36,940 --> 00:31:40,400 the way to print out what a register holds in it, 677 00:31:40,500 --> 00:31:42,680 and how to set a breakpoint, 678 00:31:42,800 --> 00:31:44,180 how to continue after a breakpoint. 679 00:31:44,260 --> 00:31:46,620 Because GDB's documentation is really good 680 00:31:46,820 --> 00:31:46,920 right? 681 00:31:48,560 --> 00:31:49,280 Uh-uh. 682 00:31:53,140 --> 00:31:56,140 Also, you can set up memory locations 683 00:31:56,140 --> 00:31:58,500 you want to be spit out at you 684 00:31:58,500 --> 00:31:59,660 every time you stop. 685 00:31:59,860 --> 00:32:01,140 After every instruction, 686 00:32:01,280 --> 00:32:03,380 or after a breakpoint. 687 00:32:03,740 --> 00:32:05,580 And that can be set up using the display. 688 00:32:05,960 --> 00:32:07,160 Just some really good stuff. 689 00:32:07,360 --> 00:32:09,240 Get into GDB on your favorite binary. 690 00:32:09,620 --> 00:32:11,060 Just plug this stuff in. 691 00:32:11,120 --> 00:32:11,940 Do a help on it. 692 00:32:12,100 --> 00:32:14,500 Help info. 693 00:32:14,660 --> 00:32:15,620 Help display. 694 00:32:15,620 --> 00:32:16,540 Help NI. 695 00:32:20,300 --> 00:32:23,020 I also like to go through a binary, 696 00:32:23,140 --> 00:32:24,180 and as long as it's not too big, 697 00:32:24,980 --> 00:32:28,400 I'll actually, my script will grab every call 698 00:32:28,400 --> 00:32:30,340 and create a breakpoint for it. 699 00:32:30,760 --> 00:32:32,920 This is really good for initial reverse engineering. 700 00:32:33,460 --> 00:32:35,400 I just hit continue, and continue, 701 00:32:35,600 --> 00:32:38,300 and I get to see what points in memory I'm stopping at 702 00:32:38,300 --> 00:32:41,060 for, you know, basically watching the logic. 703 00:32:41,180 --> 00:32:43,000 And I'll sit there and I'll look at my dead listing, 704 00:32:43,180 --> 00:32:44,820 which is the disassembly. 705 00:32:45,640 --> 00:32:48,880 And I'll watch what the program's doing as it runs. 706 00:32:50,080 --> 00:32:53,060 I'll also start out with some very basic display settings, 707 00:32:53,220 --> 00:32:56,600 which show me EIP in the surrounding area. 708 00:32:56,740 --> 00:32:59,580 That's, I'm sorry, ESP in the surrounding area. 709 00:32:59,660 --> 00:33:00,440 That's the stack pointer. 710 00:33:01,760 --> 00:33:03,460 EBP, which is the base pointer. 711 00:33:03,620 --> 00:33:05,120 They both point to the stack. 712 00:33:06,200 --> 00:33:09,580 But they give me a good idea of what's going on 713 00:33:09,580 --> 00:33:10,640 on the stack memory. 714 00:33:11,080 --> 00:33:12,720 It prints out several registers. 715 00:33:12,980 --> 00:33:13,900 This is what I use. 716 00:33:13,900 --> 00:33:15,520 You can make your own. 717 00:33:15,620 --> 00:33:16,680 You can download them as well. 718 00:33:21,040 --> 00:33:23,740 So from that point, I went into pseudo-fuzzing mode. 719 00:33:24,420 --> 00:33:27,140 I really cringed to call what I was doing fuzzing. 720 00:33:27,220 --> 00:33:29,580 It was not anything elite. 721 00:33:29,940 --> 00:33:32,520 But I started throwing data at it. 722 00:33:34,540 --> 00:33:36,620 Basically, I was running Perl, 723 00:33:36,720 --> 00:33:38,100 piping it to Netcat, 724 00:33:38,580 --> 00:33:40,180 and seeing if I could break this thing. 725 00:33:40,360 --> 00:33:41,080 And I did. 726 00:33:43,460 --> 00:33:45,520 But, yeah, later on, 727 00:33:46,880 --> 00:33:48,180 it didn't work out so well. 728 00:33:48,860 --> 00:33:49,340 Metasploit. 729 00:33:49,380 --> 00:33:51,540 I was strapping my Perl code, 730 00:33:51,760 --> 00:33:52,900 which is very minimal, 731 00:33:53,640 --> 00:33:54,980 a Metasploit exploit, 732 00:33:55,220 --> 00:33:56,240 which is Perl. 733 00:33:56,260 --> 00:33:57,080 There he was. 734 00:33:57,900 --> 00:34:00,020 I'll have to learn Ruby now if I want to use it, I suppose. 735 00:34:01,660 --> 00:34:05,780 I took a Perl, or a Metasploit exploit shellcode, 736 00:34:06,620 --> 00:34:08,020 shoved it into my Perl program, 737 00:34:08,200 --> 00:34:10,200 which then was shoved into Netcat. 738 00:34:11,080 --> 00:34:12,800 Pretty kludgy, but it works. 739 00:34:13,540 --> 00:34:14,100 Kinda. 740 00:34:16,660 --> 00:34:18,560 And here's how it didn't work. 741 00:34:18,860 --> 00:34:20,720 It's very important when writing a network exploit 742 00:34:20,720 --> 00:34:22,560 to run a sniffer. 743 00:34:23,660 --> 00:34:24,220 Why? 744 00:34:25,660 --> 00:34:27,020 Any Perl coders here? 745 00:34:28,320 --> 00:34:29,560 You can admit it. 746 00:34:29,680 --> 00:34:30,440 Perl's great. 747 00:34:31,960 --> 00:34:33,400 The very first line here. 748 00:34:34,180 --> 00:34:35,300 Dollar sign pipe. 749 00:34:36,740 --> 00:34:38,040 Well, depending on... 750 00:34:38,040 --> 00:34:38,760 This is a variable. 751 00:34:39,120 --> 00:34:39,580 Okay? 752 00:34:39,580 --> 00:34:40,380 Dollar sign pipe. 753 00:34:40,720 --> 00:34:42,260 Depending on what the value is, 754 00:34:42,400 --> 00:34:47,100 your program may or may not use buffered IO. 755 00:34:48,100 --> 00:34:49,120 Why is that important? 756 00:34:51,100 --> 00:34:56,180 Because if you do multiple line input onto a binary over the network, 757 00:34:56,440 --> 00:35:01,180 you may want to give the service a little time in between lines, 758 00:35:01,380 --> 00:35:03,760 because otherwise it may not work real well. 759 00:35:06,720 --> 00:35:08,400 Buffered IO was saying, 760 00:35:08,400 --> 00:35:12,000 okay, I'm only going to wait until you get to this much data 761 00:35:12,000 --> 00:35:14,120 before I send anything or until you close it. 762 00:35:14,540 --> 00:35:17,320 So I was sending the first line and then waiting a second, 763 00:35:17,380 --> 00:35:18,160 sending the second line, 764 00:35:18,280 --> 00:35:19,900 and it waited until I sent the second line 765 00:35:19,900 --> 00:35:21,220 to send the first line. 766 00:35:21,460 --> 00:35:22,980 So you want to run a sniffer 767 00:35:23,600 --> 00:35:25,100 while running a remote exploit. 768 00:35:29,180 --> 00:35:30,160 I ended up, 769 00:35:30,160 --> 00:35:31,960 because I didn't really realize what I was doing, 770 00:35:32,020 --> 00:35:33,300 I was still learning Perl at the time. 771 00:35:34,500 --> 00:35:36,020 I ended up just rewriting 772 00:35:36,660 --> 00:35:38,160 using Perl network code, 773 00:35:38,400 --> 00:35:39,540 instead of piping it to Netcat, 774 00:35:39,700 --> 00:35:41,480 because I really needed that delay. 775 00:35:41,800 --> 00:35:45,360 The binary couldn't handle just shoving stuff down it. 776 00:35:49,260 --> 00:35:51,160 This will show up better in your PDF, too. 777 00:35:51,220 --> 00:35:51,460 Sorry. 778 00:35:52,420 --> 00:35:54,960 This is output from Disass. 779 00:35:55,180 --> 00:35:57,700 This is the disassembler that I wrote. 780 00:35:59,740 --> 00:36:00,480 Nothing great. 781 00:36:00,620 --> 00:36:02,500 It actually just harnesses objdump 782 00:36:02,500 --> 00:36:05,840 to grab all the information that it can out of the binary, 783 00:36:06,140 --> 00:36:07,360 write up some tables, 784 00:36:07,360 --> 00:36:09,960 and spit out basically 785 00:36:10,480 --> 00:36:13,020 a more human understanding of what's going on. 786 00:36:13,140 --> 00:36:13,940 For example, 787 00:36:15,080 --> 00:36:16,660 for those of you who can read this, 788 00:36:17,340 --> 00:36:18,800 down to a call, 789 00:36:18,940 --> 00:36:21,700 the very first break in the upper section 790 00:36:22,160 --> 00:36:22,840 is a call. 791 00:36:23,460 --> 00:36:24,900 And it says call to, 792 00:36:25,460 --> 00:36:27,000 and on this one it actually says 793 00:36:27,000 --> 00:36:28,580 except in the PLT, 794 00:36:28,680 --> 00:36:30,620 which is shared library. 795 00:36:32,800 --> 00:36:34,460 The first time I did that, 796 00:36:34,540 --> 00:36:35,440 I don't know what I had wrong. 797 00:36:35,600 --> 00:36:36,860 It didn't tell me 798 00:36:36,860 --> 00:36:37,680 what it was writing, 799 00:36:38,300 --> 00:36:39,260 or what it was calling. 800 00:36:41,200 --> 00:36:42,460 So, Disass spits out, 801 00:36:42,520 --> 00:36:44,220 calls to the got table, 802 00:36:44,720 --> 00:36:45,100 except. 803 00:36:47,340 --> 00:36:48,480 So I'm going to run through, 804 00:36:48,900 --> 00:36:51,840 try to just listen to me if you can't see it. 805 00:36:53,580 --> 00:36:54,420 Believe it or not, 806 00:36:54,460 --> 00:36:56,040 I wasn't expecting this many people. 807 00:36:56,120 --> 00:36:57,380 I thought maybe, you know, half of you. 808 00:36:58,440 --> 00:36:59,500 So, thanks for coming. 809 00:37:01,160 --> 00:37:02,260 So we hit the except. 810 00:37:02,380 --> 00:37:03,200 That's the first call. 811 00:37:04,620 --> 00:37:05,960 When we come back from except, 812 00:37:06,040 --> 00:37:06,620 what do we have? 813 00:37:06,860 --> 00:37:07,880 We've got an active socket. 814 00:37:08,360 --> 00:37:09,800 One that's been initialized, 815 00:37:09,940 --> 00:37:10,580 and we got, you know, 816 00:37:10,620 --> 00:37:11,800 this two-way communication, 817 00:37:12,100 --> 00:37:13,740 the TCP three-way handshakes taking place, 818 00:37:13,820 --> 00:37:14,380 all that good stuff. 819 00:37:16,660 --> 00:37:18,040 Little bit farther down, 820 00:37:18,100 --> 00:37:18,660 it says, okay, 821 00:37:18,740 --> 00:37:21,500 call this child request subroutine. 822 00:37:21,740 --> 00:37:22,720 It's just a handler. 823 00:37:23,380 --> 00:37:25,920 So we jump into the child request subroutine. 824 00:37:26,000 --> 00:37:27,420 That's the third section down, 825 00:37:28,560 --> 00:37:29,460 on the right. 826 00:37:30,020 --> 00:37:33,540 And child request does the little initialization routine. 827 00:37:33,800 --> 00:37:35,700 Every subroutine starts out with, 828 00:37:36,440 --> 00:37:38,160 push ESP out of the stack, 829 00:37:38,700 --> 00:37:39,580 or I'm sorry, 830 00:37:39,660 --> 00:37:41,260 push EBP out of the stack, 831 00:37:41,440 --> 00:37:44,880 and then move the stack pointer into the EBP. 832 00:37:45,040 --> 00:37:47,700 So what we did is we've created a new frame 833 00:37:47,700 --> 00:37:49,160 so that this stack area, 834 00:37:49,300 --> 00:37:51,100 it belongs to the subroutine. 835 00:37:51,320 --> 00:37:52,000 It's really cool. 836 00:37:52,180 --> 00:37:53,940 Very intelligent people made this up. 837 00:37:55,820 --> 00:37:57,560 The same very intelligent people, 838 00:37:57,660 --> 00:37:58,080 by the way, 839 00:37:58,140 --> 00:38:00,080 that decided to grow the stack down, 840 00:38:00,360 --> 00:38:03,640 so that when we start putting in stuff in a buffer, 841 00:38:03,780 --> 00:38:05,240 we can overwrite stuff, 842 00:38:05,240 --> 00:38:07,360 lower on the stack, 843 00:38:07,540 --> 00:38:08,700 like the return pointer. 844 00:38:12,600 --> 00:38:13,680 So in here, 845 00:38:13,780 --> 00:38:14,700 we call memset. 846 00:38:14,900 --> 00:38:16,920 Memset just basically clears out the memory space 847 00:38:16,920 --> 00:38:18,200 as a stick of zero here, 848 00:38:18,300 --> 00:38:18,620 a null. 849 00:38:19,400 --> 00:38:22,120 And then we call authenticate. 850 00:38:23,160 --> 00:38:24,620 Authenticate just goes through 851 00:38:24,620 --> 00:38:27,740 and it takes in the user ID and password 852 00:38:27,740 --> 00:38:28,540 that I handed in 853 00:38:28,540 --> 00:38:31,400 and checks it against my user ID and password 854 00:38:31,400 --> 00:38:32,320 on the Unix system. 855 00:38:32,940 --> 00:38:33,880 Pretty cool stuff. 856 00:38:33,880 --> 00:38:35,880 There was no vulnerabilities there, though. 857 00:38:35,920 --> 00:38:36,460 I'm skipping it. 858 00:38:37,180 --> 00:38:44,720 Comes back and it calls to a write, 859 00:38:46,080 --> 00:38:48,920 moves down and accesses input buffer. 860 00:38:49,080 --> 00:38:51,060 The thing that I want you to pay attention to here 861 00:38:51,640 --> 00:38:52,660 is right here. 862 00:38:52,920 --> 00:38:55,080 This is like my brainchild. 863 00:38:55,260 --> 00:38:57,100 I enjoy this very much because 864 00:38:57,100 --> 00:38:59,680 it caused me great excruciating pain 865 00:38:59,680 --> 00:39:01,340 before I wrote this. 866 00:39:01,900 --> 00:39:03,720 This goes through a subroutine, 867 00:39:03,880 --> 00:39:05,580 looks for local memory calls 868 00:39:05,580 --> 00:39:08,340 and calls to parameters that are passed in, 869 00:39:08,440 --> 00:39:09,740 and it spits them out here. 870 00:39:12,120 --> 00:39:13,980 Sorry, it's hexadecimal. 871 00:39:14,020 --> 00:39:16,020 This is a signed hex number. 872 00:39:17,220 --> 00:39:19,240 The big numbers, the FFF ones, 873 00:39:19,360 --> 00:39:20,180 those are negative numbers. 874 00:39:20,420 --> 00:39:22,260 The small ones are positive numbers. 875 00:39:22,520 --> 00:39:25,140 So everything is based around that base pointer. 876 00:39:25,300 --> 00:39:27,240 You know the stack base pointer we're talking about? 877 00:39:27,640 --> 00:39:31,060 The base pointer is the delimiter. 878 00:39:31,140 --> 00:39:32,880 If you're going against a parameter, 879 00:39:32,880 --> 00:39:35,860 you can say the base pointer plus eight, 880 00:39:36,060 --> 00:39:38,920 or plus 12, or plus 16. 881 00:39:39,980 --> 00:39:41,860 If you're talking about a local variable, 882 00:39:42,020 --> 00:39:46,120 the base pointer minus whatever that converts to, 883 00:39:46,280 --> 00:39:46,820 and you know what? 884 00:39:46,860 --> 00:39:47,460 I don't really care. 885 00:39:47,580 --> 00:39:48,520 I do it in my head sometimes. 886 00:39:49,620 --> 00:39:51,200 What's most important here 887 00:39:52,140 --> 00:39:54,160 is that this tells me 888 00:39:54,840 --> 00:39:57,640 that between here, this variable start, 889 00:39:57,960 --> 00:39:59,700 and the next variable up, 890 00:39:59,820 --> 00:40:01,940 which is below it on the stack, 891 00:40:03,400 --> 00:40:05,700 is hexadecimal four zero C. 892 00:40:06,660 --> 00:40:09,340 For you guys who don't care about hex right now, 893 00:40:09,460 --> 00:40:12,220 just consider that a roughly hex 400, 894 00:40:12,540 --> 00:40:13,720 because it's easy to say. 895 00:40:14,480 --> 00:40:17,180 And then take a look over here 896 00:40:19,460 --> 00:40:21,620 where we do our read. 897 00:40:24,060 --> 00:40:25,720 This is a call to a read. 898 00:40:26,780 --> 00:40:28,880 So we've come into child request. 899 00:40:29,240 --> 00:40:30,760 We've cleared out the memory space. 900 00:40:30,760 --> 00:40:31,880 We called authenticate. 901 00:40:32,900 --> 00:40:35,480 And it says, yes, you're good, or no, you're bad. 902 00:40:35,740 --> 00:40:38,140 And it spits out the results in this write. 903 00:40:40,100 --> 00:40:41,760 And then we get a read call 904 00:40:41,760 --> 00:40:44,020 to read in the next line. 905 00:40:45,480 --> 00:40:46,880 And the parameters, 906 00:40:47,140 --> 00:40:49,280 kind of cool, interesting tidbit. 907 00:40:49,480 --> 00:40:52,740 On a call, where do you think the parameters are at? 908 00:40:53,080 --> 00:40:55,200 Well, they're being pushed on the stack 909 00:40:55,760 --> 00:40:58,320 in reverse order from the way they appear 910 00:40:58,320 --> 00:40:59,780 in a C program. 911 00:41:00,760 --> 00:41:00,920 OK? 912 00:41:01,340 --> 00:41:02,360 Let me demonstrate. 913 00:41:03,160 --> 00:41:08,440 Call accepts, what is it, three parameters. 914 00:41:09,620 --> 00:41:14,800 The first parameter happened to be EBP plus eight. 915 00:41:14,980 --> 00:41:17,100 Oh, that's the parameter to this subroutine. 916 00:41:17,320 --> 00:41:17,720 OK. 917 00:41:18,520 --> 00:41:19,780 The second parameter, 918 00:41:20,060 --> 00:41:22,660 that's the file descriptor, by the way, the socket. 919 00:41:23,340 --> 00:41:26,100 The second parameter, which you go one up 920 00:41:26,500 --> 00:41:27,680 in your disassembly, 921 00:41:29,680 --> 00:41:31,360 is a pointer to a memory location. 922 00:41:32,200 --> 00:41:33,520 It's a CAN memory location. 923 00:41:33,680 --> 00:41:34,400 It's not going to change. 924 00:41:35,500 --> 00:41:36,700 804A200 in this case. 925 00:41:37,060 --> 00:41:38,360 And the third parameter, 926 00:41:38,460 --> 00:41:42,100 who can tell me what third parameter to a read call is? 927 00:41:42,180 --> 00:41:43,080 Network programmers, anyone? 928 00:41:46,660 --> 00:41:47,100 Limitation. 929 00:41:47,780 --> 00:41:50,080 How big will I allow 930 00:41:51,740 --> 00:41:53,080 this read to pull in? 931 00:41:53,180 --> 00:41:53,900 The size of the buffer. 932 00:41:53,960 --> 00:41:54,240 Thank you. 933 00:41:55,900 --> 00:41:56,960 Can't read that probably, 934 00:41:56,960 --> 00:41:58,300 but I'll read it to you. 935 00:41:58,720 --> 00:42:00,460 Hexadecimal 7FF. 936 00:42:00,640 --> 00:42:02,820 Just shy of hexadecimal 800. 937 00:42:03,240 --> 00:42:08,020 So we've got a storage location of roughly hex 400 938 00:42:08,020 --> 00:42:13,040 and a read in of approximately maximum of 800. 939 00:42:15,060 --> 00:42:15,700 OK. 940 00:42:15,760 --> 00:42:16,200 Do the math. 941 00:42:18,100 --> 00:42:20,300 Might not jump out at you the first time through, 942 00:42:20,400 --> 00:42:23,900 but this is a good indicator that we might have something here. 943 00:42:25,300 --> 00:42:26,720 It doesn't happen, 944 00:42:26,760 --> 00:42:28,980 the overflow doesn't actually happen here, though. 945 00:42:29,700 --> 00:42:32,040 We've read in seven, 946 00:42:32,120 --> 00:42:35,260 up to seven FF bytes into this memory location, 947 00:42:35,580 --> 00:42:36,820 which we looked up, 948 00:42:36,940 --> 00:42:37,900 disass looked up, 949 00:42:38,020 --> 00:42:41,480 and came up with a variable called input buffer. 950 00:42:41,640 --> 00:42:42,100 Cool. 951 00:42:42,220 --> 00:42:43,220 I know what that is. 952 00:42:43,640 --> 00:42:44,200 Makes sense. 953 00:42:45,740 --> 00:42:48,160 We follow along just a little bit farther, 954 00:42:50,640 --> 00:42:52,680 and we see a call to, 955 00:42:54,940 --> 00:42:55,440 sscanf. 956 00:42:55,940 --> 00:42:57,900 Anybody know what sscanf is? 957 00:42:58,940 --> 00:42:59,680 What is it? 958 00:43:05,760 --> 00:43:06,760 It reads, 959 00:43:06,900 --> 00:43:08,540 it's like a formatted read. 960 00:43:08,800 --> 00:43:10,900 What is the sscanf for? 961 00:43:12,460 --> 00:43:12,960 String. 962 00:43:13,060 --> 00:43:14,300 We're not reading from a keyboard, 963 00:43:14,600 --> 00:43:17,080 we're not reading from a file descriptor, 964 00:43:17,120 --> 00:43:18,160 we're reading from a string. 965 00:43:18,400 --> 00:43:19,300 So what do we do? 966 00:43:19,460 --> 00:43:20,680 Our parameters say, 967 00:43:21,880 --> 00:43:26,620 well, our input string is 804A200A, 968 00:43:26,660 --> 00:43:27,000 I know that, 969 00:43:27,000 --> 00:43:28,180 that's the input buffer. 970 00:43:30,820 --> 00:43:36,300 Our output is 8049C0A, 971 00:43:37,300 --> 00:43:40,680 and we've got some EAX, 972 00:43:41,360 --> 00:43:46,340 which actually is just a pointer to a memory location 973 00:43:47,180 --> 00:43:48,660 inside the local sub. 974 00:43:48,840 --> 00:43:49,200 Oh, wait. 975 00:43:49,200 --> 00:43:51,600 Do you think that might be the memory location 976 00:43:53,020 --> 00:43:54,560 that's like 400 bytes long? 977 00:43:55,460 --> 00:43:56,280 I think so. 978 00:43:57,820 --> 00:43:58,680 Let's double check. 979 00:43:59,580 --> 00:44:02,680 That one is called FFFF FBE8. 980 00:44:05,420 --> 00:44:07,180 Thanks for staying as long as you guys did. 981 00:44:07,400 --> 00:44:08,360 I enjoy your company. 982 00:44:11,960 --> 00:44:13,120 And this is, 983 00:44:13,640 --> 00:44:14,300 oh wait, 984 00:44:14,460 --> 00:44:15,560 load effective address, 985 00:44:15,700 --> 00:44:16,420 that's the assembly, 986 00:44:17,500 --> 00:44:17,980 FFFF, 987 00:44:19,880 --> 00:44:20,440 FBE8, 988 00:44:21,540 --> 00:44:22,660 before EBP. 989 00:44:23,060 --> 00:44:26,020 Well, that's the address pointer of that 990 00:44:26,020 --> 00:44:27,220 is loaded into EAX, 991 00:44:27,300 --> 00:44:28,680 so EAX is actually looking at 992 00:44:28,680 --> 00:44:30,480 that direct point in memory. 993 00:44:30,900 --> 00:44:33,080 So we read in this input buffer 994 00:44:33,080 --> 00:44:34,280 using SSCANF, 995 00:44:34,460 --> 00:44:36,980 looking specifically for the word bacon, 996 00:44:38,080 --> 00:44:39,000 which happened, 997 00:44:39,200 --> 00:44:39,960 little trivia, 998 00:44:41,160 --> 00:44:42,780 a lot of the Kenshodo guys, 999 00:44:43,000 --> 00:44:44,620 before they became Kenshodo, 1000 00:44:44,700 --> 00:44:47,220 actually did a CTF team there called Bacon. 1001 00:44:48,120 --> 00:44:49,780 The interview that I read said 1002 00:44:49,780 --> 00:44:50,880 it was because it was the only thing 1003 00:44:50,880 --> 00:44:52,060 that they all had in common, 1004 00:44:52,180 --> 00:44:53,000 they liked bacon. 1005 00:44:57,180 --> 00:44:58,240 So what do we have? 1006 00:44:58,860 --> 00:45:01,100 Well, we've got a potential buffer overflow here, right? 1007 00:45:02,080 --> 00:45:02,520 Why? 1008 00:45:02,780 --> 00:45:04,160 Well, we take a string in 1009 00:45:04,160 --> 00:45:05,380 that can be, 1010 00:45:06,340 --> 00:45:08,460 for lack of a better word, 1011 00:45:08,660 --> 00:45:09,520 800 bytes long, 1012 00:45:09,680 --> 00:45:10,040 hex. 1013 00:45:11,500 --> 00:45:13,340 And we shove it into a buffer 1014 00:45:13,340 --> 00:45:14,680 that could be 400 bytes long, 1015 00:45:14,840 --> 00:45:15,140 hex. 1016 00:45:17,280 --> 00:45:19,380 Well, yeah, but it's SSCANF, 1017 00:45:19,740 --> 00:45:20,560 we're like formatted. 1018 00:45:20,720 --> 00:45:21,380 Yeah, but, 1019 00:45:22,360 --> 00:45:23,700 SSCANF will peel off, 1020 00:45:23,840 --> 00:45:25,320 what, six bytes? 1021 00:45:26,120 --> 00:45:27,780 So clearly we've got issues here. 1022 00:45:28,760 --> 00:45:30,220 This is the buffer overflow. 1023 00:45:33,600 --> 00:45:34,720 Once overflowed, 1024 00:45:35,540 --> 00:45:36,660 you keep writing, 1025 00:45:37,920 --> 00:45:39,900 and you overwrite, first of all, 1026 00:45:39,920 --> 00:45:41,840 whatever's between that variable 1027 00:45:41,840 --> 00:45:43,900 and the base pointer. 1028 00:45:43,900 --> 00:45:47,260 You overwrite the previous frame's base pointer, 1029 00:45:47,360 --> 00:45:49,260 because that lives right at the base pointer. 1030 00:45:49,520 --> 00:45:52,760 And then you overwrite EBP plus four. 1031 00:45:53,640 --> 00:45:56,120 You won't actually see EBP plus four 1032 00:45:56,120 --> 00:45:57,700 mentioned anywhere in the code. 1033 00:45:58,260 --> 00:45:58,820 Why? 1034 00:45:59,220 --> 00:46:00,880 Well, because EBP plus four 1035 00:46:00,880 --> 00:46:01,920 is the return pointer. 1036 00:46:02,800 --> 00:46:04,100 It always is. 1037 00:46:04,420 --> 00:46:06,420 That's just the way that this works. 1038 00:46:08,120 --> 00:46:10,140 You know this because at the end of a, 1039 00:46:11,020 --> 00:46:12,860 at the end of a subroutine, 1040 00:46:12,860 --> 00:46:15,260 if you watch the leave and the ret function, 1041 00:46:15,540 --> 00:46:17,060 and I recommend that you do this. 1042 00:46:19,340 --> 00:46:20,040 Holy crap. 1043 00:46:20,400 --> 00:46:20,840 Okay. 1044 00:46:21,560 --> 00:46:23,020 I was just giving you a warning. 1045 00:46:23,100 --> 00:46:23,660 It's time. 1046 00:46:23,700 --> 00:46:23,960 Wow. 1047 00:46:24,120 --> 00:46:24,540 We gotta go. 1048 00:46:24,960 --> 00:46:25,400 Anyway, 1049 00:46:26,280 --> 00:46:27,940 you overwrite the return pointer, 1050 00:46:28,060 --> 00:46:30,200 and hopefully the subroutine keeps going. 1051 00:46:30,620 --> 00:46:32,340 You may have to actually manipulate 1052 00:46:32,340 --> 00:46:33,540 what you stick in there 1053 00:46:33,540 --> 00:46:35,860 to make it so that it's sane 1054 00:46:35,860 --> 00:46:37,400 until it gets to the ret. 1055 00:46:38,080 --> 00:46:39,280 When it gets to the return, 1056 00:46:40,080 --> 00:46:41,340 it reads that in, 1057 00:46:41,400 --> 00:46:42,580 and EIP, 1058 00:46:42,580 --> 00:46:44,660 the instruction pointer gets redirected 1059 00:46:44,660 --> 00:46:45,960 to wherever you want it to go. 1060 00:46:47,240 --> 00:46:48,000 Fun, fun? 1061 00:46:48,460 --> 00:46:49,220 Very cool. 1062 00:46:49,400 --> 00:46:51,280 I'm gonna slam through a couple more slides. 1063 00:46:52,500 --> 00:46:57,000 This is using my favorite GDB display variables. 1064 00:46:57,260 --> 00:47:02,100 So I'm doing 32 of these little four byte segments 1065 00:47:03,740 --> 00:47:04,860 starting with ESP. 1066 00:47:05,040 --> 00:47:06,060 So this is ESP, 1067 00:47:06,140 --> 00:47:06,980 blah, blah, blah, 1068 00:47:07,080 --> 00:47:09,520 ESP plus hex 10, 1069 00:47:09,800 --> 00:47:10,400 hex 20, 1070 00:47:10,560 --> 00:47:11,020 hex 30, 1071 00:47:11,020 --> 00:47:11,420 hex 40. 1072 00:47:12,020 --> 00:47:12,460 Meanwhile, 1073 00:47:12,660 --> 00:47:13,960 EBP minus 92. 1074 00:47:14,500 --> 00:47:14,660 Well, 1075 00:47:14,680 --> 00:47:15,340 why did I do that? 1076 00:47:15,420 --> 00:47:19,520 Because I know that EBP is now going to be right here. 1077 00:47:19,580 --> 00:47:20,400 Every time, 1078 00:47:20,440 --> 00:47:21,660 EBP is right there. 1079 00:47:21,980 --> 00:47:22,860 Why do I care? 1080 00:47:23,080 --> 00:47:23,320 Well, 1081 00:47:23,340 --> 00:47:25,740 because a lot of stuff that's in front of EBP, 1082 00:47:25,780 --> 00:47:26,420 I care about, 1083 00:47:26,600 --> 00:47:27,760 because that's local variables, right? 1084 00:47:27,880 --> 00:47:29,160 That'll show up earlier. 1085 00:47:29,780 --> 00:47:32,620 A lot of stuff that shows up after, 1086 00:47:32,660 --> 00:47:33,740 I'm very interested in, 1087 00:47:33,780 --> 00:47:34,260 like this, 1088 00:47:34,520 --> 00:47:36,420 which happens to be the return pointer. 1089 00:47:40,360 --> 00:47:43,380 And when I'm done running the exploit, 1090 00:47:44,400 --> 00:47:45,720 here's my 90s, 1091 00:47:45,720 --> 00:47:46,140 not sled, 1092 00:47:46,260 --> 00:47:46,460 anybody? 1093 00:47:47,720 --> 00:47:48,420 Hex 90. 1094 00:47:49,780 --> 00:47:50,880 Here's my shellcode. 1095 00:47:51,600 --> 00:47:52,120 Actually, 1096 00:47:52,220 --> 00:47:52,440 sorry, 1097 00:47:52,620 --> 00:47:57,760 the shellcode started back here somewhere, 1098 00:47:57,840 --> 00:47:58,060 actually. 1099 00:47:59,020 --> 00:48:00,000 I overwrote, 1100 00:48:00,020 --> 00:48:01,000 here's the return pointer. 1101 00:48:01,660 --> 00:48:02,180 Starting, 1102 00:48:02,260 --> 00:48:02,500 starting, 1103 00:48:02,600 --> 00:48:03,020 boom. 1104 00:48:03,940 --> 00:48:04,460 Well, 1105 00:48:04,460 --> 00:48:06,180 that's where the return pointer is supposed to be. 1106 00:48:06,920 --> 00:48:08,280 What I ended up shoving in, 1107 00:48:08,340 --> 00:48:09,420 made it to the end of the subroutine, 1108 00:48:09,680 --> 00:48:10,580 they called leave, 1109 00:48:10,660 --> 00:48:12,740 which moves the base pointer, 1110 00:48:13,460 --> 00:48:14,920 stack pointer magic, 1111 00:48:15,960 --> 00:48:20,740 and then return starts execution of my program. 1112 00:48:25,940 --> 00:48:26,460 Hello? 1113 00:48:30,980 --> 00:48:31,820 Sex port, 1114 00:48:32,040 --> 00:48:32,500 69, 1115 00:48:32,500 --> 00:48:32,680 69, 1116 00:48:33,240 --> 00:48:34,600 and the thrill of conquest. 1117 00:48:35,520 --> 00:48:36,280 It worked. 1118 00:48:36,980 --> 00:48:38,000 Ran the exploit, 1119 00:48:38,700 --> 00:48:41,160 printed out authenticate team 19, 1120 00:48:41,560 --> 00:48:43,260 my password at the time, 1121 00:48:43,380 --> 00:48:44,300 it says okay, 1122 00:48:44,500 --> 00:48:44,700 hey, 1123 00:48:44,780 --> 00:48:45,200 that's cool. 1124 00:48:45,560 --> 00:48:48,660 Then I feed in this bacon prefix thing, 1125 00:48:50,260 --> 00:48:52,000 with a whole bunch of gibberish. 1126 00:48:53,600 --> 00:48:54,840 I start a netcat, 1127 00:48:54,980 --> 00:48:57,240 go to 31337 on that system, 1128 00:48:57,380 --> 00:48:58,620 and I get a shell. 1129 00:49:01,860 --> 00:49:02,420 ID, 1130 00:49:02,420 --> 00:49:03,060 ID, 1131 00:49:04,080 --> 00:49:04,520 PWD, 1132 00:49:05,120 --> 00:49:05,920 cat the key, 1133 00:49:06,020 --> 00:49:07,140 and here's stage three's key. 1134 00:49:10,620 --> 00:49:11,660 Stages four through seven, 1135 00:49:12,280 --> 00:49:12,880 lots of fun, 1136 00:49:13,000 --> 00:49:13,700 no time. 1137 00:49:16,840 --> 00:49:19,260 I did go on to complete them before CTF, 1138 00:49:19,260 --> 00:49:20,020 it took me a couple weeks, 1139 00:49:20,120 --> 00:49:21,240 because I was still really newbie. 1140 00:49:21,700 --> 00:49:22,580 Stick with it. 1141 00:49:22,660 --> 00:49:23,400 If you're interested, 1142 00:49:23,600 --> 00:49:24,100 do it. 1143 00:49:24,660 --> 00:49:27,020 This is not the realm of the gods here, guys. 1144 00:49:27,460 --> 00:49:28,820 This is the realm of curious, 1145 00:49:28,980 --> 00:49:29,820 determined people, 1146 00:49:29,940 --> 00:49:30,940 like you and me. 1147 00:49:30,940 --> 00:49:32,780 And the more of us, 1148 00:49:32,820 --> 00:49:34,240 that can do this stuff, 1149 00:49:35,160 --> 00:49:37,880 the more secure or insecure the world will be. 1150 00:49:40,360 --> 00:49:42,280 But it'll be you making the decision, 1151 00:49:42,460 --> 00:49:43,140 not other people. 1152 00:49:44,280 --> 00:49:45,200 So what's coming, 1153 00:49:45,320 --> 00:49:46,340 what's gonna happen to me? 1154 00:49:47,020 --> 00:49:48,800 Well, it's become an addictive habit. 1155 00:49:49,020 --> 00:49:51,760 I average four to five hours of sleep a night, 1156 00:49:52,480 --> 00:49:53,840 and have for the last year. 1157 00:49:54,800 --> 00:49:58,580 I will continue until my fingers and eyes no longer work, 1158 00:49:58,740 --> 00:50:00,660 because to me this is binary porn. 1159 00:50:05,740 --> 00:50:07,180 I'm not gonna go through this stuff. 1160 00:50:07,720 --> 00:50:08,440 Read it. 1161 00:50:09,020 --> 00:50:10,180 Download the toolkit. 1162 00:50:10,480 --> 00:50:11,580 It's not exceptional. 1163 00:50:11,840 --> 00:50:13,080 It helps me out. 1164 00:50:13,240 --> 00:50:14,480 Hopefully it'll help you out. 1165 00:50:14,600 --> 00:50:15,700 Maybe it'll help you get started. 1166 00:50:16,680 --> 00:50:17,720 Cool tools, 1167 00:50:18,320 --> 00:50:20,000 just like even an un, 1168 00:50:20,040 --> 00:50:23,520 or a base 64 encoder, decoder. 1169 00:50:24,020 --> 00:50:26,500 Just a lot of fun tools that I find useful. 1170 00:50:27,600 --> 00:50:28,360 Format strings. 1171 00:50:28,780 --> 00:50:30,860 Anybody love to hate format strings? 1172 00:50:30,860 --> 00:50:32,480 It's got a format string generator. 1173 00:50:33,480 --> 00:50:34,160 Yeah. 1174 00:50:34,400 --> 00:50:35,560 I love it. 1175 00:50:37,960 --> 00:50:39,120 Yeah, let's, 1176 00:50:39,120 --> 00:50:42,240 I got probably like negative 30 seconds here. 1177 00:50:45,740 --> 00:50:47,780 There is an outtake. 1178 00:50:49,660 --> 00:50:52,080 Because about through day four, 1179 00:50:52,440 --> 00:50:53,600 something like that, 1180 00:50:53,760 --> 00:50:57,580 I was typing at five in the morning, 1181 00:50:59,960 --> 00:51:01,000 and I'll tell you what, 1182 00:51:01,520 --> 00:51:03,440 it's really funny when you wake up typing, 1183 00:51:05,680 --> 00:51:07,380 and it almost looks like words. 1184 00:51:08,920 --> 00:51:09,940 This is the result. 1185 00:51:14,400 --> 00:51:15,800 Here's to complete the transformation. 1186 00:51:17,340 --> 00:51:18,300 No longer kitty. 1187 00:51:18,900 --> 00:51:19,880 Thank you very much. 1188 00:51:21,640 --> 00:51:22,080 . 1189 00:51:22,520 --> 00:51:22,960 . 1190 00:51:24,180 --> 00:51:24,780 . 1191 00:51:27,880 --> 00:51:28,480 . 1192 00:51:28,480 --> 00:51:28,500 . 1193 00:51:28,500 --> 00:51:28,520 . 1194 00:51:28,520 --> 00:51:28,820 . 1195 00:51:28,820 --> 00:51:28,860 . 1196 00:51:28,860 --> 00:51:29,640 .