So let's just begin. You don't like the music? Can somebody make me more important than the music? Very good. No, the music was to keep you guys kind of from getting out of hand, because you're all real patient and docile at the moment, right? Yeah. Well, it wasn't my fault. Just so you know, don't blame me. We're in this together. Anyway, introduction. I'm Atlas. Nice to meet you all. There are only a couple differences from what you got on the CD than what you're going to see up here, namely my email address and my blog site. So make sure you write those down when they come up, because there's stuff later on in the slides that says, oh, yeah, Atlas' brain-dead tips to reverse engineering, they're on my blog later on tonight. They're not in the pre-zone. Okay? Good. Let me start out by saying that I am not better than any of you guys. This is not a, hey, look at me, I'm great talk. This is kind of what happened to me. I've been doing a lot of fun stuff. Most people in this room probably could do what I've been doing. I'm going to show you somehow. Is that good? Good? I've been very blessed. Very, uh... Just giving a lot of curiosity. Probably above average intelligence, but that probably describes everybody here, right? Except for the one guy in the back. All right, here it is. Write it down. Atlas at ratboy.com. I'm sorry, r4780y.com. The blog site, atlas.yadayada. A little bit about me. I was expecting to have a traveling microphone here. I like to move around. This is good. All right. A little bit about me. Dad worked for IBM. I got a PC when I was seven. Started programming when I was eight. Thank you, brother. Because my brother was teaching me. You know, he's like eight years older than me. He's like, hey, look. You do the CLS, and it clears the screen. Sweet! So I've been programming since I was eight. If you consider advanced basic programming. Some of you probably don't, but that's all right. Started college as a vocal performance major. You should have been gone! Anyway, you probably should have been before that. Hit pre-med before deciding that I had run away from my first love long enough. Got my bachelor's degree in computer science. Again, something you guys could have done. Just something that I chose. After college, I got out, became a network engineer. Thought I was done with programming. Got into teaching, consulting. A lot of good money there. You don't have to know a lot about stuff to make a lot of money. You guys have probably put that together, haven't you? Well, that's where I was heading. Moved into telecom, where I got away from dealing with all the angry users a lot, and I moved into the more technical field. And you know what? I didn't even get a pay increase. So, telecom introduced me to Hacking Exposed, because I started taking over the firewalls and doing all that stuff. After I'd been telecom a couple years, I went. My boss says, I want you to go to SANS. And I want you to take, think outside the box. Don't think about telecom. Think something else. I said, hacker track, dude. Must be. And I took the hacker course with Ed Skodas, who promised me he was going to be here, and he didn't. And if he's here, can somebody, like, point him out? And if he's not, everybody boo him when you see him later. His wife is pissed. So, if you go check out the CTF, you'll probably know where to find him. Anyway, good friend of mine now, he was a mentor. Capture the flag, according to his teaching, was very different. So, when I saw DEF CON say, hey, we got this capture the flag, I'm thinking, hmm, dude, I know Metasploit. I know Nessus, I can find the vulnerabilities, I can go download some script, I'm in. All right. So, I signed up really, really naively. Actually, I asked a bunch of guys to join a team, but that's a long story. So, about June 3rd, so when pre-qual started last year, probably some of you guys knew that. June 3rd, I had forgotten. I said, okay, I got an e-mail from them. One of these Ken Shoto guys that says, 10 o'clock tonight, I'm supposed to be doing something. Oh, my gosh. We had visitors coming in from out of town, like four hours away. I had just adopted a little baby. Those are my kids. I'm a happy father. And we'd adopted like a week and a half before. So, I've got this screaming baby. We got her out of the hospital. Not a good thing. So, I was already used to no sleep, though. So, sleep deprivation was good for my hacking career. But I was limited to about... Midnight to about 5 in the morning. You and me going to rumble. You can't have her back. To make matters worse, all my buddies that I said, hey, let's go be a team, they didn't show up. Ken Shoto very nicely said, ah, we'll give you the individual status so you can keep hacking. So, briefly, show of hands. Who's done Nessus? Maybe some Metasploit, download some code, and exploit machines. Excellent. Who remembers the first time they saw a C prompt on their Linux box? Oh, yeah. That is one of those turning points in life. It's very memorable. So, I started out, cool. This is capture the flag. I'm going to learn about this box. The only thing we were told was dujour.kenshoto.com is the only machine you can hack. Go ahead. Go forth and be... I'm malicious. Okay. That's cool. I can deal with that. So, I start Reconnaissance. Okay. Reconnaissance. Going back to my sans days. Well, I got everything that I got right there because they just brought up the site. Their email was it. So, I move into scanning. Nmap scan showed up three ports. 22, SSH. Port 80, Apache. And 69, 69. Some sort of really weird sex port or something. Anybody would go to ShmooCon this year? All right. 22 was totally patched. Up to date. No known vulnerabilities. Apache, same thing. Going, what the heck? This kind of sucks. So, I dig in. Maybe they got a web app. I check out the web app. Web app has a hidden field. All right. I'm in now. I can understand this. Hidden field, I tweak around with it. Got a whole lot of errors until finally I find out file not found. I'm in. Okay. So, I was able to directory traversal up and view any file on the system. Didn't get me in. But it got me a lot. Including the password file. A little bit of cracking of the password file. Mind you, I zoomed right over the first key because it was stuck in the password file. I was too interested in getting the box. Anyway, in the password file, I throw it into John. You guys have probably done this. That's cool stuff. Really cool. John is great. John spits out immediately, within one minute. The root password. And some break me password. No remote root. Suck. So, I wasn't in. But this break me. Break me was kind of cool. I hit break me. And my screen just went wild. And it spit out the key. Key number two. Wait a minute. Where did key number one go? Well, that was back in the etsy passwords file. So, key number two got spit out to me. And I had to try it again to see what that was. Dumped it to a file. Turns out, the login script dumps a base 64 encoded binary. And then clears the screen a bunch of times. And spits out the key. What the heck? On base 64. You know the pearl. What is that? Use the base 64 mime thing. And spit out a binary. I run file on it. Unless you guys here with security expertise. Maybe in forensics. You know what file does. File spits out. Oh, my gosh. It's an elf 32 binary. That's kind of scary. Okay. I'm trembling. I do strings on it. And I see protocol failure. Oh, crap. And I remembered. Back during my initial scanning this port 6969. When I hit it wrong. It spits protocol failure. Oh. To quote one of my favorite lines out of speed. Oh, darn. So, at that point. I was in mental surrender, dude. Like, I have never considered writing a binary exploit. Never. That is the realm of the gods. So, I'm here to tell you it's not. Okay. Most of you could probably do it. Some of you probably have. So, you know. No disrespect to you guys. I had tons of fear, uncertainty, and doubt. And it was well founded. Because I knew nothing. I was way out of my comfort zone. All I remembered was stuff from my forensics exam. That taught me about abs dump. And read elf. And a couple others that I just started poking around. Which is, of course, the next slide. Sorry. And then, of course, I find a new hope. I thought, I can do this. They're expecting me to do this. I better give it a shot. Or I'm just going to give up and go crawl in a hole. I had been reading a book that my in-laws bought me. Called hacking, the art of exploitation. Who here has that book? Excellent book. Excellent book. Excellent book. I got bored. And I quit reading it at page 20. Because it was basically recap. It's all theoretical. When I went back, I found page 23 is when they get into writing buffer overflow exploits. Could have already had all this knowledge. So, I start reading like crazy. And I learn, oh, my gosh. I can do this. Got it on my Linux box. I was able to write an exploit. Sweet. Also found a paper on exploit X on writing remote buffer overflow exploits. Very different game. Because then you got the whole network thing involved. But the thing that got me through it was sheer simple determination. I was looking really desperately for a good picture. I like the bear. So, that's pretty much all about me. Now, we're really going to get into what happened, what I learned. This is more of a, oh, my gosh, I was really stupid type thing. And I learned a lot in trying to brain dump some of that. What I used was OBSDUMP. Really cool tool with a ton of ability to analyze and decipher binary data. Binary executables. Works on ELF for UNIX. Works on the PE file, which is the standard Windows XE and DLL. I used read ELF, very limited. OBSDUMP did everything that I really wanted and I got used to it. But read ELF, I had to poke into it. It's another very cool tool. Doesn't do the disassembly part, but does just about everything else that OBSDUMP does. I got to know GDB as the GNU debugger. I remember a long time ago. Copying and pasting stuff into debug for the DOS and Windows machines to hack up DOS axes. GDB, wow. If you talk to people in the industry, they're going to say, yeah, it's a piece of crap. And indeed, it has a lot of weaknesses. But it helped a lot and it taught me a lot. I worked with KTrace and KDUMP, which is the kernel hooker as the program will talk to the kernel to make calls like read and close and printf and all that stuff. This sucker intercepts it and spits it out in a format that you can make some logical identification out of. And now I wrote a tool called Disass. Because I wasn't happy with what OBSDUMP spit out, especially for some binaries. I wanted to know more. And I wanted not to have to go through and manually do more. It's not an excellent tool. It helps me out. And in my release of the utility belt, which you guys will find on my blog later on too, you'll find Disass. Lots of fun. So we'll run through the tools just a little bit. Can any of you read this? Sorry. I'll summarize. This is OBSDUMP, the help output. Basically, it allows you to look at the various header files in an executable. Which tells a ton of information. It allows you to disassemble the text or all sections. Anybody done assembly in here? Good. You'll like it better than the rest of you. If you don't know assembly, there are tons of good books out there. I could probably hook you up with some interesting stuff. Reverse engineering of a binary that you don't know. You've really got to hunker down and learn your ASM. OBSDUMP also spits out relocation points. So in a file, you've got everything laid out in a very different fashion than it's going to appear in memory. And some of the stuff that's copied into memory, you want to call it by name. The computer knows it by number. So the relocation points allow you to basically do a DNS lookup on these locations. OBSDUMP-D, you probably can't see that either. You can read it on the PDF that you've got on the CD. This is the very beginning of the disassembly for the bash shell. Again, Readelf's help. You'll see a lot of interesting stuff. I print these out kind of as a placeholder. So if you're reading the PDF later, you'll stop and think, well, let's go play around with that a little bit. Because playing around is the name of the game. If you couldn't read that before, you really can't read this. Again, it is on the PDF. This is a K-trace output of stage 3, actually. I use a K-trace call, give it the process ID of the binary. And it says, okay, we're going to call this. And it returns this. Call this. And it returns this. It's calling select. Anybody done programming? Do you know what select does? Select, if you've got like a file descriptor or something that points at an object, like a file or a device, select will allow you to say, is anything waiting to come in on this file descriptor? Very helpful. It goes down. It hits accept. And if you're not into network programming, there are great books to learn. Accept is the first call for, anybody yell it out? What kind of connection? A TCP connection. You hit accept, you've got a listener, and then you call accept, and it just kind of sits there and waits for somebody to connect. Hey, how's it going? Somebody connects. Accept returns an active file descriptor to a network socket. It's really cool stuff. You can read and write to it almost like you were reading and writing to a file. So I know that that's where it starts the network connection. It goes down, calls a fork, which is a way of spinning off a little child process and running. Calls, oh, it calls read. Wow, go figure. And it gives information on the memory location where that stuff goes. This is a wealth of information. I'm not going to cover it as well as I should. You'll see near the bottom, bacon colon my name colon my password colon something else. That's kdump telling me what I put in there from the network connection. My little client that I wrote spits that in there. Kdump tells me that. It also prints out all the stuff that's written back. Like, down below it, it says tag failure. I screwed up. I didn't know what I was doing. I was just trying stuff. So I made a conscious decision. I'm going to work this until it kills me or until I get it. So I bring up BSD on VMware. Run the stage three binary, which used to be called binary in the previous slides. I renamed it to stage three. Ran it with 6969 because it wants a port number. I wanted it to look just like it would on Ken Shoto's box, right? All right. Then I started Ktrace. Ktrace watches how the program executes. Start a Netcat session. Who here used Netcat? Let me hear it. Netcat is your friend. Very good. Some of you. Let's hear it again. Netcat is your friend. Unless, of course, you're trying to shove Perl into it with unbuffered IO. Yeah. Anyway. So I shove in Netcat to 6969 on the local host. This is my own machine I'm hacking. I give Bacon my name, my password, something else. And then I run Kdump. And you see the output on the previous slide. Then I get into GDB. Very cool stuff. Very scary. GDB stage three. And then I put in the PID. And what you'll see on there is an operating system. A Unix call to grab the PID of stage three. And I analyze Ktrace. Because I was too freaked out of assembly and actual reverse engineering. So it's okay. If you get to a point where you're like, dude, I'm just not comfortable with that. I don't know what I'm doing. That's cool. That's fine. Do something. Keep going. In the Ktrace, wait a minute. I just saw most of that. Okay. This is a continuation of what happened. And so on. Nothing of interest. So basically I'm playing, dude, where's my shell? All over. And I'm traipsing around using GDB. Traipsing around memory space. Trying to find my input. It told me. Ktrace told me where the thing was going. I could have probably found out from many other places a good idea of where to look. But I didn't know. And that's okay. I just, what's at this memory location? Keep going. Oh, my gosh. I ran into a boundary that can't actually spit back anything. I was learning a lot about virtual memory. Virtual memory is basically the computer assigning a huge memory. A huge memory space to an application even though you don't have that much memory. Figuring that you'll run out of memory if you run out of memory. And they want to give you as much leeway as they can. I had no idea that all this stuff was identified in the ELF binary itself. The memory locations. And so I just kept meandering. . OBSDUMP-X would have told me a lot of what I need to know. And so I'm going to share with you just a little bit about what it means. OBSDUMP-X means dump all header information. Not just the section. Not that section. All of it. It's broken into four parts. Whoops. The file header. You've got an ELF binary. So it's an ELF file. It comes with its own little header at the very beginning. That tells about the rest of what you're going to see in the file. It also prints out the program headers. The program headers say we're going to map this part of the binary to this part of virtual memory. Cool. It also lists some dynamic stuff. We require this library. This library before we can run. So if you don't have it, boom, you get an error. And it also spits out section information. Assembly coders. What section, as oddball as it may sound, what section does your code go in? Text. Okay. Yeah. Okay. No. I'm sorry. Your strings don't go in text. Your code goes there. So text is one of many sections. So we're going to talk about some of that. Because in the end, we're not talking about assembly being converted to machine language. That's actually an oxymoron. Assembly is a representation of machine language. It's a one-to-one. There's no compiling going on. The compilers take it from C down to assembler. Then it runs an assembler to convert the assembly into machine. It's a machine language to make an object. And then the linker comes along as if we didn't do enough work. The linker comes along and says, yes, you're blessed. You may start. And starts mapping real addresses based on requirements of other libraries. It's very cool stuff. I just bought at the prodding of my good friend Visigoth from Capture the Flag. Yeah. The Ken Chodo guy. He's awesome. At his prodding, I just bought Loaders and Linkers. Or Linkers and Loaders. Whatever. It's a really good book. What's that? Linkers and Loaders. Exceptional book. Really scary. Had I read this a year ago, I would have been totally over my head. So at the very beginning, we get the file header. The ELF file header, it says, hey, this is an ELF 32 made for the i386 instruction set. Okay. That's cool. So it's not like some Mac that runs. Sorry. Not a MacTel. But an actual Motorola Mac, the old days. It has some of the things that it can do. And a starting address. So after the loader stuff loads from the file into memory, it drops the instruction pointer into this location. Kind of like in Demolition Man. You know, they had him all filled up with that really weird goopy stuff. Naked. Kind of scarring me. And they drop this one little blue thing. God only knows what it is. Boom. Hits. And everything happens. That's the starting address here. The program headers, you'll notice, overlap. There is some, I'm sorry, they encompass each other. You'll notice on the left-hand side, there are different types of program headers. I don't want you guys to be afraid here. This is like part of the visual effect. You've got different types of program headers. The first one is the program header header. Well, basically, that defines where the program header is going to exist. That's fine. The two of most importance are the load header types. These actually will load from the file into virtual memory space. The first one starts off at byte zero in the file. And it maps to 8048000. This is a BSD box. That number will vary. And oftentimes it will look different between platforms. Not very important, but just something you'll know. So that actually maps your binary into virtual memory, even including the ELF header stuff that the OS only cares about. So if you go in GDB and show that memory location and keep going, you'll actually be seeing the bytes from the executable file. The second one starts at 8048000. And offset two. And offset 2000 inside the binary file. Boy, those are really round numbers. You think maybe they pad things so that it works out that way? Uh-huh. That plays into binary manipulation, which this talk won't get into. But if you ever go that far, that's a lot of fun stuff. The others you'll find map into the other loadables. The loadables have certain flags basically saying, I can read, I can write, and I can execute this memory section. So if you want to put in your code, you want to inject some code somewhere in an ELF executable, don't go for the second one in this example, because it only has read and write permissions turned on. I'm going way too deep, aren't I? I'll move on. Anyway. The program headers are awesome and very important. The dynamic section is quite interesting. It lists several disparate things. It's kind of like the miscellaneous area. It says, okay, I need these libraries to run. That's cool. Those are OS libraries. They don't really mean that I have to install anything. It talks about where the initialization is, where the finishing is. Several other things I won't get into, except maybe the GOT, the global offset table, and the PLT, the program linkage table. These are used by your program, because you don't want to rewrite printf. They are used by your program to jump to a local little section of code, which gets transferred to wherever printf was mapped into memory. Cool stuff. This is like a long time of research. Something that you want to get into, though, if you're interested. Now we get into the sections. Now, what was that section again where your code goes? Text. Text is section nine in this binary. There are a lot of other sections. You'll notice the PLT, and you'll notice the... Where is it? You'll notice the GOT, and you'll notice a lot of other stuff. Read-only data, RO data, that can be very helpful when reversing a binary. I won't go into the rest of them, but it says the section of code, or of whatever that's in the file, it lives in the file with this offset, and it needs to be mapped into memory here. Again, by looking at this information, I can tell what virtual memory space looks like. Now remember, when I was a year ago, I didn't know this stuff. I was poking around. I'm trying to share this with you so that if you decide to take this assignment, you won't have to do a lot of the meandering and silly, pointless things that I did. Well, they weren't pointless. We also see the symbol table. This can show everything from the section information and your... even your own written code functions, methods, and where they map to. This is your little look-up service area. So when you want to know what lives where, let's say I want to know where main lives in memory. Boom, right here. I look for main. As long as these symbols aren't stripped, it helps me out. Every binary is different. It's important to realize that if you're really good on one binary, it doesn't mean that they can't make a binary that you would love to hate and would make your eyes bleed. Kenshodo does this. I know last year they had a finger demon where everything was statically compiled. It means these shared libraries were sucked into the overall binary, and then they stripped all the symbols so we didn't know what was what. Real buzzer. So was it a waste of time? Well, obviously not, because I'm here talking. But no, this was not a waste of time. The most difficult thing for me to get over was the fact that I thought I needed to be doing something and having some tangible results for it to be worth my time. But to this day, you'll come in and watch us. I lead the Last Place team for Capture the Flag. We're called Last Place. I'm not hoping to end up there. But come check us out. Things that I learned during that meandering around memory space, they still play into the way that I play the game. And anything else that I do reverse engineering. Again, I'm not going to go over all this. This is for your own visual enjoyment later. When you go back and you play with GDB, these are some of my favorite parts of GDB that help me get around. Like way to print out what's in memory, the way to print out what a register holds in it, and how to set a breakpoint, how to continue after a breakpoint. Because GDB's documentation is really good right? Uh-uh. Also, you can set up memory locations you want to be spit out at you every time you stop. After every instruction, or after a breakpoint. And that can be set up using the display. Just some really good stuff. Get into GDB on your favorite binary. Just plug this stuff in. Do a help on it. Help info. Help display. Help NI. I also like to go through a binary, and as long as it's not too big, I'll actually, my script will grab every call and create a breakpoint for it. This is really good for initial reverse engineering. I just hit continue, and continue, and I get to see what points in memory I'm stopping at for, you know, basically watching the logic. And I'll sit there and I'll look at my dead listing, which is the disassembly. And I'll watch what the program's doing as it runs. I'll also start out with some very basic display settings, which show me EIP in the surrounding area. That's, I'm sorry, ESP in the surrounding area. That's the stack pointer. EBP, which is the base pointer. They both point to the stack. But they give me a good idea of what's going on on the stack memory. It prints out several registers. This is what I use. You can make your own. You can download them as well. So from that point, I went into pseudo-fuzzing mode. I really cringed to call what I was doing fuzzing. It was not anything elite. But I started throwing data at it. Basically, I was running Perl, piping it to Netcat, and seeing if I could break this thing. And I did. But, yeah, later on, it didn't work out so well. Metasploit. I was strapping my Perl code, which is very minimal, a Metasploit exploit, which is Perl. There he was. I'll have to learn Ruby now if I want to use it, I suppose. I took a Perl, or a Metasploit exploit shellcode, shoved it into my Perl program, which then was shoved into Netcat. Pretty kludgy, but it works. Kinda. And here's how it didn't work. It's very important when writing a network exploit to run a sniffer. Why? Any Perl coders here? You can admit it. Perl's great. The very first line here. Dollar sign pipe. Well, depending on... This is a variable. Okay? Dollar sign pipe. Depending on what the value is, your program may or may not use buffered IO. Why is that important? Because if you do multiple line input onto a binary over the network, you may want to give the service a little time in between lines, because otherwise it may not work real well. Buffered IO was saying, okay, I'm only going to wait until you get to this much data before I send anything or until you close it. So I was sending the first line and then waiting a second, sending the second line, and it waited until I sent the second line to send the first line. So you want to run a sniffer while running a remote exploit. I ended up, because I didn't really realize what I was doing, I was still learning Perl at the time. I ended up just rewriting using Perl network code, instead of piping it to Netcat, because I really needed that delay. The binary couldn't handle just shoving stuff down it. This will show up better in your PDF, too. Sorry. This is output from Disass. This is the disassembler that I wrote. Nothing great. It actually just harnesses objdump to grab all the information that it can out of the binary, write up some tables, and spit out basically a more human understanding of what's going on. For example, for those of you who can read this, down to a call, the very first break in the upper section is a call. And it says call to, and on this one it actually says except in the PLT, which is shared library. The first time I did that, I don't know what I had wrong. It didn't tell me what it was writing, or what it was calling. So, Disass spits out, calls to the got table, except. So I'm going to run through, try to just listen to me if you can't see it. Believe it or not, I wasn't expecting this many people. I thought maybe, you know, half of you. So, thanks for coming. So we hit the except. That's the first call. When we come back from except, what do we have? We've got an active socket. One that's been initialized, and we got, you know, this two-way communication, the TCP three-way handshakes taking place, all that good stuff. Little bit farther down, it says, okay, call this child request subroutine. It's just a handler. So we jump into the child request subroutine. That's the third section down, on the right. And child request does the little initialization routine. Every subroutine starts out with, push ESP out of the stack, or I'm sorry, push EBP out of the stack, and then move the stack pointer into the EBP. So what we did is we've created a new frame so that this stack area, it belongs to the subroutine. It's really cool. Very intelligent people made this up. The same very intelligent people, by the way, that decided to grow the stack down, so that when we start putting in stuff in a buffer, we can overwrite stuff, lower on the stack, like the return pointer. So in here, we call memset. Memset just basically clears out the memory space as a stick of zero here, a null. And then we call authenticate. Authenticate just goes through and it takes in the user ID and password that I handed in and checks it against my user ID and password on the Unix system. Pretty cool stuff. There was no vulnerabilities there, though. I'm skipping it. Comes back and it calls to a write, moves down and accesses input buffer. The thing that I want you to pay attention to here is right here. This is like my brainchild. I enjoy this very much because it caused me great excruciating pain before I wrote this. This goes through a subroutine, looks for local memory calls and calls to parameters that are passed in, and it spits them out here. Sorry, it's hexadecimal. This is a signed hex number. The big numbers, the FFF ones, those are negative numbers. The small ones are positive numbers. So everything is based around that base pointer. You know the stack base pointer we're talking about? The base pointer is the delimiter. If you're going against a parameter, you can say the base pointer plus eight, or plus 12, or plus 16. If you're talking about a local variable, the base pointer minus whatever that converts to, and you know what? I don't really care. I do it in my head sometimes. What's most important here is that this tells me that between here, this variable start, and the next variable up, which is below it on the stack, is hexadecimal four zero C. For you guys who don't care about hex right now, just consider that a roughly hex 400, because it's easy to say. And then take a look over here where we do our read. This is a call to a read. So we've come into child request. We've cleared out the memory space. We called authenticate. And it says, yes, you're good, or no, you're bad. And it spits out the results in this write. And then we get a read call to read in the next line. And the parameters, kind of cool, interesting tidbit. On a call, where do you think the parameters are at? Well, they're being pushed on the stack in reverse order from the way they appear in a C program. OK? Let me demonstrate. Call accepts, what is it, three parameters. The first parameter happened to be EBP plus eight. Oh, that's the parameter to this subroutine. OK. The second parameter, that's the file descriptor, by the way, the socket. The second parameter, which you go one up in your disassembly, is a pointer to a memory location. It's a CAN memory location. It's not going to change. 804A200 in this case. And the third parameter, who can tell me what third parameter to a read call is? Network programmers, anyone? Limitation. How big will I allow this read to pull in? The size of the buffer. Thank you. Can't read that probably, but I'll read it to you. Hexadecimal 7FF. Just shy of hexadecimal 800. So we've got a storage location of roughly hex 400 and a read in of approximately maximum of 800. OK. Do the math. Might not jump out at you the first time through, but this is a good indicator that we might have something here. It doesn't happen, the overflow doesn't actually happen here, though. We've read in seven, up to seven FF bytes into this memory location, which we looked up, disass looked up, and came up with a variable called input buffer. Cool. I know what that is. Makes sense. We follow along just a little bit farther, and we see a call to, sscanf. Anybody know what sscanf is? What is it? It reads, it's like a formatted read. What is the sscanf for? String. We're not reading from a keyboard, we're not reading from a file descriptor, we're reading from a string. So what do we do? Our parameters say, well, our input string is 804A200A, I know that, that's the input buffer. Our output is 8049C0A, and we've got some EAX, which actually is just a pointer to a memory location inside the local sub. Oh, wait. Do you think that might be the memory location that's like 400 bytes long? I think so. Let's double check. That one is called FFFF FBE8. Thanks for staying as long as you guys did. I enjoy your company. And this is, oh wait, load effective address, that's the assembly, FFFF, FBE8, before EBP. Well, that's the address pointer of that is loaded into EAX, so EAX is actually looking at that direct point in memory. So we read in this input buffer using SSCANF, looking specifically for the word bacon, which happened, little trivia, a lot of the Kenshodo guys, before they became Kenshodo, actually did a CTF team there called Bacon. The interview that I read said it was because it was the only thing that they all had in common, they liked bacon. So what do we have? Well, we've got a potential buffer overflow here, right? Why? Well, we take a string in that can be, for lack of a better word, 800 bytes long, hex. And we shove it into a buffer that could be 400 bytes long, hex. Well, yeah, but it's SSCANF, we're like formatted. Yeah, but, SSCANF will peel off, what, six bytes? So clearly we've got issues here. This is the buffer overflow. Once overflowed, you keep writing, and you overwrite, first of all, whatever's between that variable and the base pointer. You overwrite the previous frame's base pointer, because that lives right at the base pointer. And then you overwrite EBP plus four. You won't actually see EBP plus four mentioned anywhere in the code. Why? Well, because EBP plus four is the return pointer. It always is. That's just the way that this works. You know this because at the end of a, at the end of a subroutine, if you watch the leave and the ret function, and I recommend that you do this. Holy crap. Okay. I was just giving you a warning. It's time. Wow. We gotta go. Anyway, you overwrite the return pointer, and hopefully the subroutine keeps going. You may have to actually manipulate what you stick in there to make it so that it's sane until it gets to the ret. When it gets to the return, it reads that in, and EIP, the instruction pointer gets redirected to wherever you want it to go. Fun, fun? Very cool. I'm gonna slam through a couple more slides. This is using my favorite GDB display variables. So I'm doing 32 of these little four byte segments starting with ESP. So this is ESP, blah, blah, blah, ESP plus hex 10, hex 20, hex 30, hex 40. Meanwhile, EBP minus 92. Well, why did I do that? Because I know that EBP is now going to be right here. Every time, EBP is right there. Why do I care? Well, because a lot of stuff that's in front of EBP, I care about, because that's local variables, right? That'll show up earlier. A lot of stuff that shows up after, I'm very interested in, like this, which happens to be the return pointer. And when I'm done running the exploit, here's my 90s, not sled, anybody? Hex 90. Here's my shellcode. Actually, sorry, the shellcode started back here somewhere, actually. I overwrote, here's the return pointer. Starting, starting, boom. Well, that's where the return pointer is supposed to be. What I ended up shoving in, made it to the end of the subroutine, they called leave, which moves the base pointer, stack pointer magic, and then return starts execution of my program. Hello? Sex port, 69, 69, and the thrill of conquest. It worked. Ran the exploit, printed out authenticate team 19, my password at the time, it says okay, hey, that's cool. Then I feed in this bacon prefix thing, with a whole bunch of gibberish. I start a netcat, go to 31337 on that system, and I get a shell. ID, ID, PWD, cat the key, and here's stage three's key. Stages four through seven, lots of fun, no time. I did go on to complete them before CTF, it took me a couple weeks, because I was still really newbie. Stick with it. If you're interested, do it. This is not the realm of the gods here, guys. This is the realm of curious, determined people, like you and me. And the more of us, that can do this stuff, the more secure or insecure the world will be. But it'll be you making the decision, not other people. So what's coming, what's gonna happen to me? Well, it's become an addictive habit. I average four to five hours of sleep a night, and have for the last year. I will continue until my fingers and eyes no longer work, because to me this is binary porn. I'm not gonna go through this stuff. Read it. Download the toolkit. It's not exceptional. It helps me out. Hopefully it'll help you out. Maybe it'll help you get started. Cool tools, just like even an un, or a base 64 encoder, decoder. Just a lot of fun tools that I find useful. Format strings. Anybody love to hate format strings? It's got a format string generator. Yeah. I love it. Yeah, let's, I got probably like negative 30 seconds here. There is an outtake. Because about through day four, something like that, I was typing at five in the morning, and I'll tell you what, it's really funny when you wake up typing, and it almost looks like words. This is the result. Here's to complete the transformation. No longer kitty. Thank you very much. . . . . . . . . .