obviously is gonna be on buffer overflows on the spark you're just treated to a great talk on basically advanced techniques can do I'm going to try and focus on this on doing overflows on other architectures most notably the spark the spark for those are unfamiliar or probably have just heard of them is oh well this is I'm gonna talk about sorry you know order I do a crash course on the spark and spark assembly just because I'm gonna focus a lot on writing the shell code or the payload because that's what differs the most between Intel and and spark and you a lot of the techniques that was already talked about about how to deliver the shell code equally applies here there are some little nuances that will make it different but as a general conceptual overview it's the same the stack is much funkier on the spark and make sure I cover that I'll cover some of the tools that I'm using to develop the shell code and its examples I'll be doing everything on a Solaris box this one right here and Solaris is so nice to come with a wonderful debugger ADB is an absolutely called the absolute debugger is an assembly language level debugger so you can step through look at the registers look at you know binaries you can patch values in memory and do things a lot easier than you can with GDB and that will speak up as everyone is motioning towards me to do then I'll discuss what exactly what happens on an overflow and start discussing shell code and some methods of delivery and I'll be giving some examples too because I like doing that okay the spark Stanford scalable possible scalable processor architecture created by Sun the early 80s was based on the risk design out of UC Berkeley and basically the whole philosophy was take it to make the chip as simple as possible so it's blazing fast and part of what this this is is the 30 bit wide path everything in spark is really pretty because every instruction is 32 bits wide you your shell code is nice and square it's really fun it makes things just typically easier for calculating the size of your shell code and calculating jump addresses and stuff like that it's a pipeline architecture which will yeah I just had to mention because it will get you in some places every clock cycle it basically executes one-and-a-half fish instructions where it basically prepares the second instruction so you have to watch out when you're branching that when you branch jump to another location in code you will execute the statement after the branch so just keep that in mind when you're writing your stuff other things to speed this up is the load store architecture all logical and arithmetic instructions only operate on the registers you can't fetch things some you can't just like increment something in memory because that involve making the chip smarter and slower so and the one thing unique to the spark is this wacky invention called register windows which I will cover in great depth because it's kind of crazy in memory access basically it's relatively simple the only instructions that can access memory or load and store and that whole family of instructions load by byte load by half by a half word so on and so on and all memory access indirect, meaning that you have to write something in the value contained in a register, whereas each register acts like a pointer, basically, as they would in C. This chip was actually written for C compilers, so if you think in C, the spark will be very nice to you. Instructions are one word. Very nice. The registers. RISC chips always have tons of registers, which make things really easy. At each given point in time, you have access to 32 registers. The chip may actually have more registers than that, more general purpose integer registers, but you can only see 32 of them at a time because of the register windows, which I'll talk about. You always have the global registers. You have eight of them that are accessible across every function. You have the output registers, which you load up the arguments to a function to be calling. You have the local registers, which are local to your subroutine. The inputs, which are your caller's output registers. Things to note, the output register 6 is the stack pointer. That points to the bottom of your stack, bottom being the lowest memory address. The input 6 is the frame pointer, which is your caller's stack pointer, and also it points to the top of your... of your stack space. How register windows work is it's a circular stack of 16 registers. The outputs and the local, which are rotated among functions, so you don't have to worry about pushing arguments onto the stack or so on, and to speed up function calls, because those are written for C, and that's what you do all the time. The call is output registers become the input registers in the next function. The call is output registers become the input registers in the next function, and that's what you do all the time. These are all handled by the save and restore instructions. The save and restore instructions allocate your new register set, and they also allocate the stack on the space... or the space on the stack, which we will... we have to get the subroutine call in conventions. Basically, to call a subroutine, very simple, you just place the arguments in the output registers, use the call instruction to actually jump to the location in memory containing the code for the function. The callee uses the save instruction to allocate a register window, and it will also allocate their stack frame, and with that, they calculate the minimum space they need for the stack, in addition to anything they need for local variables, as all allocated in one instruction. Interesting thing to note is that when you are allocating space on the stack for the register window, they're not actually written there. They're only written there when the system runs out of register windows, and when that happens, a trap is called that signals the operating system that it needs to flush some of these registers out to the memory stack, and so basically what you're doing is you're saying, when you need to dump them, dump them here. So you're not actually guaranteed to have them written there, which is kind of difficult because the point of overflowing the buffer is to overwrite the return address, but if the return address is in a register, you have complications. And, you know, the callee does its thing, and at the end it does a ret, which is return to the caller, which just basically jumps to the value stored in the input 7 register plus 8, because the 8 is added because of the branch delay slot that, you know, when it's called, it executes that instruction and the next instruction, so it has to go 8 back. Simple example. We have our main, just we'll call the function foo, and we'll set the upper register 0 to dead beef. This is executed because it is in the branch delay slot. Control transfers over to foo, which saves. The save instruction is interesting because the first argument, oh, one thing to note about Spark assembly is the destination is always on the right. So it was save starting at the original stack pointer, and decrement the stack pointer by 96 bytes, which is the minimum stack frame needed to dump the registers, and, store that value as the new stack pointer, and in between those is when the register window is rotated. So the value of the stack pointer at the first operand is now in the frame pointer register. Then it just loads the value stored at the memory address, stored in register input 0, and puts that value in register local 0, adds 42 to it, storing the result, and register local 1, and similarly stores the result back in dead beef. Then it returns, and returns to transfer the control back, and because the branch delay slot, the restore flips the register window back, and deallocates the stack, so when transfer is controlled back, the caller thinks the world is right again. I want to define traps for you. These are typically called interrupts in other operating systems and architectures. They are transfers of control to supervisor software, meaning it's a request from the application or from other supervisor code, or from the actual hardware for the operating system to get up and do something. These are handled for window overflow and underflow conditions where the operating system has to dump them to the memory stack or restore them. The question is, why do we care? System calls. If you're familiar with Unix kernel, they are all based upon having tons of system calls that will do everything for you. These are all in the manual pages, section 2. Open, close, exec, fork, all these fun things are all there for you. To make a system call, all you do is look up in syscall.h the system call number of the system call you want to execute, throw that in global 1, and execute trap 8. A simple example here. We are going to set the output register to 0, because global 0 is basically the dev null register. It's hard-coded 0. 23 is the index of the setuid system call. Move that to global 1. Do the trap. Notice there is no branch delay slot after a trap. It's only on branches and calls. Now just execute setuid 0, which we'll see why we need to do that. The stack. Like other architectures, the stack goes downward, and it reserves the space for the window in case of overflow or underflow. Basically, in a well-behaved convention obeying functions, all automatic variables are referenced by negative offsets from the frame pointer, because as my little art in the next slide will show you, the first part of the stack in the high memory address is space, if any, for automatic variables, so you just index them that way. Then the bottom of the stack is stuff for the register windows. But you actually really don't need to reference those, because nothing is guaranteed to be there, so why would you want to do that? Here is a struct representation of the minimum stack frame. They do some interesting stuff here. You have eight words allotted for the local, and then you have six for the input registers, and notice these two are also the input registers. We have the frame pointer and the saved program counter, which is where we'll be jumping back to. Basically, you have eight locals, and those next three lines form the eight inputs, which means you can only pass six arguments through the registers to a function. Then we have the structure return address for return and compound, compound values. We decided to throw that in there for fun, so you could store a pointer on the stack instead of putting it in a register. I'm not sure why. Then we have the argument dump area, which is so that the function being called, if it so chooses, can dump its arguments that it got on its input registers onto its stack. Okay. If you need more registers, you can do that and get them all. Then we have the argx area. This is the argument extension. For more than six arguments to a function, this stack, this space just kind of grows as far as needed to place the arguments there. This is allotted with the caller's save instruction, which I put those in there. They load them in. The function will know to reference them as negative to the frame pointer, as yes. That's how that works. We won't really be using that, but here's a nice ASCII art depiction of the stack. The stack goes this way, and I have it going left to right just so you can read it and you can see the string buffers as they are. Locals, inputs, the structure, return address, the instruction pointer. The argument dump area is 24 bytes, and I have the sizes used by them up there. The argument dump area is that one byte. It's also sometimes referred to as the hidden word, which is used to make sure that the stack is double word aligned. The stack and the saved program counter must always be double word aligned, or else your chip will get very angry with you. We're going to make it very angry, but not so angry that it barfs. Then automatic variables we stored here. Right here in my example, I have a string pointer called buff of indeterminate size. It doesn't really matter. Then we have the frame pointer, which is the boundary between our next or our caller's stack frame. There are his locals, his inputs, and my little asterisks. That's his saved program counter. That's our target. That's what we need to hit. It's pretty easy to see that if the buffer grows outside of its boundaries, you just overwrite his registers and basically take him over, which actually presents the interesting thing. You're not overflowing and taking over the function that with the fixed length buffer in it, you are overflowing and taking control from his caller, which is very interesting because sometimes your caller can call the overflowable function, return, call another function, which will overwrite your wonderful stack frame and shellcode, and then basically you're screwed. Of course, you just attended to Greg Hoagland's talk on how to do cool things with the stack and where you can put the code. Something like that should not be a problem. This is what's going to happen when we are overflowing the buffer. I'm just going to trace through over how the register windows rotate the registers and how things change. Obviously, the previous stack frame's saved program counter is overwritten, as is all his other registers. The function returns. His frame pointer becomes the target address, and his input 7 register becomes the target address also. The stack pointer is still valid. The stack pointer will still be the pointer to his stack, which has not been totally foobarred at this point. All his values that he assumed to be safe have just been totally messed up, so he just freaks out, hopefully getting an error condition immediately, and returning. If he does, he tries to jump to the input 7 plus 8. Our target address will be 8, plus 8 bytes, and that is where we take over control. This is your stack on drugs. Basically, these areas on the stack are fine, and in our buff, we just overflow and write our target address off into the horizon. You can basically write it as far as you want, because nothing's going to behave well at this point. Yes? . . Oh, thank you for reminding me. . Basically, we are told that we are not guaranteed that these values will be there, but what happens is, implementations of the Spark architecture, as it's an open architecture, are allowed to have anywhere from 8 to 40 register windows. Luckily, those register windows are always filled in the lowest stages of the kernel, so you can basically assume that every time we do a save or reset restore, they will be saved to the stack and restored from the stack. When the overflowed function does a restore, we'll assume that the registers that it thought it had in the register window were written to the stack and so it restores them from the caller's stack. What it does is we have our target address written all the way through there and it just loads up its registers as it transfers control to the caller, loads up its registers with the target address. I will do some examples and I'll show you what this looks like when I'm stepping through the program and you'll see all the registers are just totally just spammed over. One of the very nice tools that Solaris comes with is just the disassembler. If you've ever looked into basically writing the shell code, writing the assembly code and then changing it to the bytes. It's a pain in the butt. But this makes it rather easy, especially when you just throw a Perl script on top of it and it's a nice little chug and you have a nice little header file that you can use. There are freeware Spark disassemblers available. I just found a page about two hours ago off LinuxAssembly.org has a link to an FBSD link to some Spark assembly examples and on this guy's page he has his own Spark disassembler and Spark assembly. And a couple others that you could use for Linux and or BSD, all running on Spark of course. Excuse me? Is it free? Is it free? Oh, very nice. Okay. Well, if, I'm sure we can find that if you want to give, if you want to give me the URL I can throw it on here for people. Oh, I forgot who already, but someone has a really good free disassembler. GNU. GNU? There's a GNU disassembler? . Oh, wow. I was unaware that they had a disassembler. Wow. I have done my research. Okay. And the other tool that we'll be using on the next slide is this one. It's called GDB. And what I've seen extensively is the absolute debugger. Because this thing, I, correct me if I'm wrong again, I have not seen anything like this for any of the free operating systems. They tend to use GDB for their kernel debuggers and everything else, but I have not seen something that is as assembly language as this one is, as assembly level. Rather funky syntax to get used to if you're coming from the world of nice and pretty hand-holding debuggers. Arguments are address. How many iterations? Two. There's a lot to do in command and modifiers, as you can see. First instruction, it says, starting at the address of main in the object file. The question mark means in the object file. The slash means in the memory image, whether it be a core file or the actual memory of the running process. What I'm saying on the first one is dump 10 instructions, or disassemble 10 instructions starting at main. One of the wonderful idiosyncrasies of this program is everything on this side of the question mark or slash is in hex. Everything on that side is in decimal. But there are modifiers you can use to put them either way, but we should all be very fluid with conversions, even though I'm not. The second example, just display the word stored at code, babe. That's not a real address, but I like it. We can also just query individual registers, basically have a pseudo-redirection instruction that'll say, give me the address of the stack. Assign it to the variable x and it'll print it out for you. Next instruction says, display 24 words starting at the stack pointer. That will give you the full minimum stack frame. And then from there, after that point will be automatic variables, if any. But every function must have at least those, and you can check them out. Here's a more interesting one. In the address of the frame pointer plus 3c, which I can't remember, I'm on the spot so I can't do math, that'll be the saved program counter, write the value, dead beef. And so then you just write the value, step through, and you'll see the program try and jump to it, see the caller try and jump to it when it comes time. The ADB will also do interactive debugging, some simple stuff like this. You don't really, it's not really pertinent, but I threw it on there because I needed space. Wow. This is very difficult to see. This is a contrived session of using ADB to examine what happens when we overflow a program. I wrote a simple program called smash me, which I'll show you in a couple minutes. It basically just does the fatal flaw, does a strcpy or a strcat into a fixed length buffer. And it just takes the argument out of the command line, so I'm just saying run it with this argument. And I said first to set the break, oh, there also is no prompt in ADB, so it's kind of hard to follow along. I said, smash me. Smash me, colon, B, means set a break point at the smash function, which is I have main and I call smash, which has the overflow. And then we run it with that argument, stops at the beginning of smash, we're stepping through, I'll get our stack pointer, and we're going to store the value, go through, we're just stepping through, watching it, it's going to call, I think right there at the bottom of your screen. The bottom of your screen is where it calls strcat. But right now we're going to watch, I can't remember how I did this, oh yes, I call strcat. First I look at our stack pointer and I look at the frame pointer, our caller stack frame, and then I step over that instruction, which we'll call strcat, and we're going to watch what happens after that. The colon, E, means step to the next instruction. But don't follow any jumps or calls. As you can see, the saved program counter is overwritten, as is his entire stack frame. He's not happy. And then I basically just step through to the end, and go right here to where he returns. And so when he returns, the stuff stored on his stack is loaded off the stack into registers, and then... This instruction is flipped over to his caller's local and output registers. And so now we have them all loaded in, back in control of main, they're all loaded in there, and we're going to step through the last instructions of main, where it tries to do a return, right here, and then it says a bus error, because the address 41414141 is not aligned. And you'll get that last way just to see when you've messed up, quit out of that. I'll just, I'll run through that again later with the... Another real-world example. I'm going to start talking now about how to write assembler code that we'll use as mobile code, position-independent code, we can just throw in there, and it will just execute on its own behalf, and take control of the process. Basically, two ways to write this is you can, using your compiler, you can make a asm block, which basically just says, this is straight assembly code, and you just write it in there, compile the program. You run it. And if it gives you a shell, you obviously know it's working. And then, after that, I throw the function into a character array, and then I cast that array to a function pointer, execute the function pointer as the final stress test. Here's my first example of some Spark shell code. This is somewhat brain-dead in some ways, but I'll explain. This representation does contain null bytes in it, so it's useless, basically. But it's ordered in a simple-ish way, to show you just how we're going to write it. I think I'm a bit, I write my shell code at first as if it's a well-behaved function, so I allocate in a new register window, and I just basically, I'm recalling exec, so I'm creating the character array of the function to execute, and I'm creating the arg value, the arg vector. Throw that in there. And I'm just giving it a null for the environment pointer, because, okay. It's a little bit messy, but it's not a problem. One very handy thing about Spark is that it's big Indian, and so you can write strings in a relatively straightforward way, just straight to the stack. One way to do this is, if you're lazy, you, most of the Unixes will come with the octal dump program, and if you just do echo string pipe octal dump slash x, give me hexadecimal output. It'll give you a nice hex. And I just basically said, just chop it into words, and start storing them on the stack, and you have a string. There are, I'm sure there are ways to do the cool little jumping thing that will actually load the address of the string, so you can just write it straight, but that's a little over the top for now. Yeah, and you can basically see I set 59 to the system call number, execute the system call. This is, this can basically be looked at as a well-behaved function to just execute. And I'm just going to somehow, I Hieronymus, I'm going to xeg a shell. Then I chop it down a little more. It doesn't assume it's a well behaved function. I'm lying on that second line, ignore that. Basically I chop out the save and restores, and I just start using the current stack pointer. Because in the situation where the overflow occurs the, assuming the well behaved function assumes that you have valid stack pointers and frame pointers, you can get in situations where your stack pointer will be pointing to right where it's held. right behind your code, and as you're storing memory, you'll be chasing your code as your code executes, and you're overwriting behind it, and you don't want to be there. This code also will not work because it assumes that the frame pointer is valid, but as I discussed before, the frame pointer will be the target address, and so you're stepping on your toes here. This is another example of just chopping things down. You can see I set, here I'm going to explain the string more, I set the two words in two following registers to a stored double word instruction, starting at the address of the frame pointer, minus 16, so it writes the full 8-byte value down, and I basically am constructing in memory the string followed by a null, so that I can use it for both the name of the program to execute, and I build a pointer to that array of character pointers to use as the arg vector. If you've seen Aleph Wan's code in the expression of the stack for fun and profit, he does this also. Very easy and straightforward way to do it. Here is my even better shell code. I'm not saying it's really great, but in writing this, there's an interesting caveat that is not addressed in smashing the stack for fun and profit. Under system v systems, the born shell slash bin sh when passed an effective UID of less than 100 will discard it, so that effective UID is triggered when the program has the suid bit set, which means it keeps your real user ID saying this is who you really are, but effectively your root, and then it calls the shell, and the shell discards the effective UID, and so basically you've found that you've avoided a suid program, and you still have your own privileges, and you're not very pleased. Yes? The second one? It contains a no-bite in this. Oh, thank you. Okay, the set is a synthetic instruction, meaning the assembler basically expands it for you. The set, because everything is 32 bits, how can you write a 32-bit value in the instruction? Because it splits it into two. It first writes the, uses the set-high instruction to write the first, the highest order, 13 bits, to the register, and then does an or with the lower 13 bits, with the lower 8 bits, to complete the whole value. And we'll see when I disassemble the shell code how it's changed over, and I'm just lazy, so I just do the set, because it's easier to see the string there instead of in two words. But yeah, that will, eliminate the no-bite. The no-bite will still be in the set, in the or, but because of the way that the opcode for or is aligned with the bits, it will not be on the correct boundaries to be a, in fact, no-bite. It'll be spread across. Don't have a diagram of that, but you can take my word for it, or call me a liar and chase me out to the parking lot. It's your choice. Let's see, nothing else really change here. Oh, you'll notice that, I do not trust the frame pointer anymore, because I've stepped through with the assembly debugger, and I'm like, wait, why am I doing that? That is just whack. And so everything relative to the stack pointer, I waste four bytes before the stack pointer, because storing straight to the stack pointer introduces a no-bite. And you'll notice, when I'm trying to set a register to zero, I can't use the straightforward instruction by just setting to zero, or moving the global register over, because that introduces a no-bite, so you just do something like, you know, XORs, or there's a thousand different creative ways you can do that, just to feel fun. I'm just going to talk a little bit about the delivery, but not that much, because it has basically been treated better than I could by Greg Hoagland. Same on other architectures, either. You need to do the no-op sled, and then the shellcode, and then write the jump address off into infinity, and let it jump back, which is, has the problem, of if the caller of the overflowable function calls another function, you're not necessarily toast, you're just basically dodging bullets. Or you can just write the jump address to overwrite the saved program counter, then put the no-ops after it, and the code after it, so basically you're jumping backwards in the stack to beyond, to the caller of the caller of the overflowable function, the meta-caller in this case. And basically, you know, because the register will be, the saved program counter will be borked by that point, you don't have to worry about those stack frames, you can, they can just go to hell. Greg Hoagland's talked a lot about this very well, I might add. Okay, some real-world examples, if I can find a place to put this microphone. Okay. Okay. Can everyone see the shell? Okay. Alright, looks good. Um, examples. Okay, first we're going to have our nice little simple smash me example. Here's the source code for that. Very, very simple. Um, smash with the argv1 stircat to 128 byte buffer. Now we run our meta-smash me, which will smash, smash me. Um, one thing you'll basically always see is the calling function will get the value of its stack pointer because it'll, and it'll calculate the offset from its stack pointer so it can try and guess the stack pointer of the function it's trying to overflow because there'll always be a defined number of bytes down the stack, a certain number of function calls down the stack. and so basically what you're going to be doing is you're just going to be creating a very large string, um, in this program what I do is I write, um, I, I pass in the argument of the buffer size that I'm trying to overflow, and so what I do is I write no ops, all the way up to where the shellcode must fit then write the shellcode so it's all within the buffer and then just write tons of return addresses and the return address is calculated as an offset from the stack pointer of the metasmashme process so I just calculate the egg size and it kind of just tells you what it's doing and writes, like the noop I have here is I cannot remember what instruction that is just trust me that it's a basic instruction that does nothing, essentially and just copy the memory into the egg and so the egg represents the entire string I'm trying to pass it with and I call the function so let's see what happens if when we say the offset is zero notice that the shellcode I'm using in this example is 64 bytes so we'll have 64 bytes of noops and this shellcode, so we don't have that big of a window it's not happy so fire up our debugger metasmashme smashme and the core legal instructions for the registers notice how the registers are just basically splatted and so we can just check out our frame pointers, see what they point to they point to themselves again, because basically I did not go back far enough in the stack where I'm just pointing back at my target address, so let's see minus 500, 500 hex, notice that is well beyond it okay so what I'm going to do is put my shellcode actually no, I'll look at look at my noop you'll see that byte there and basically I'm going to search the shellcode through memory for where that thing is and that'll basically calculate the offset for me so I'm going to say we'll start at 500 hex bytes down the stack from the frame pointer do a search for the 32-bit value alright search for that value shows me the first occurrence of it is and now I'm going to do my poor man's hex calculator is that the value we want 980 980 980 980 980 so it's that right there is the value of 980 so I am trying to find out but there is our offset so let's quit out of that and let's put GDB to the test I'm gonna smash me 128 bytes go back we have a shell we basically landed exactly at the first noop thank you but that's some precision that we don't really need basically we know that we have 64 bytes so basically we only have to be within 50 bytes or so or so. So we can just go back and go, you know, try 1,000. No, not happy. 1,050. Bingo. And so the larger the buffer is, basically, the more leeway you have, which we'll go and we'll see an ellipsis example. This is old. This was discovered by Onion, I think, in September 1998 or somewhere like that, and Sun took about a year to post a fix for it. But, so I just took all the patches off my system. I'm feeling kind of vulnerable right now, but it's for the greater good. The details of this bug are, there's an overflow ellipsis in its parsing of the LC messages environment variable, where you can overflow that, and basically, so any Seward program becomes vulnerable to it. So here's my little program right here. I just ask what program to call, how big the buffer is. And what the offset is. And, you know, I'll show you the program in a second. Pretty much the same thing as the last one. Just throws in a new environment. You know, you will have to, you'll have to basically write a program to exploit each one you're going for, typically, just so you can customize it, but it's not that big of a deal. And what we can do is we can then, I'm just going to try, oh, let's go for bin. RSH, and I basically went through with Perl and basically kept giving it, giving larger, larger buffers in LC messages until I got one that died. It was somewhere around a thousand bytes. That's what I'm going to assume the size of the buffer is. So it's offset zero. It dies. Okay. Well, I know now that because it is a thousand bytes of no ops, or a thousand minus 64. I have a very gated buffer. It's a very deep and large window. And so I'm just going to try by offsets of 500. No. No. There we go. And that basically gives me a root shell because in this, the shell code that I'm using, I made sure to call set UID zero before I do that in bin shell, so bin shell is happy and trust me. And it's basically like that. I can use any SUIT program on this. It's on the system at this point, so let's do a find user bin. Okay. Anyone have a favorite? I'll do bin password because that one's nice and easy. But I basically just sat down today and decided which ones I could get. And basically, some of these didn't have the overflow in them because they didn't use the locale support in libc to use it. But the vast majority of them did. So let's start with password. Okay. Oh, wow. Looks like they don't go very far down in the stack and they make it really easy for us. So let's see. What else do I have that's really fun to show you? Okay. Let's go for some really cool shell code that mostly works. I spent the last couple of days on this. Strange, strange bug. It's driving me nuts. But here's an alternate way to develop shell code instead of using the Asim blocks. Just write the assembly file and basically throw it through the assembler, create the object file, and then now you have a main function in a C program that just calls this function, bind shell. And that's just a simple way for me to test it so I can go through here. And mostly because the Asim block just makes Emacs go hairy. And I like Emacs. So. Don't throw anything. Okay. What I'm doing. Oh. Let's see. Where's the source for this originally? First I wrote basically what I want to do in C. Create a socket. Set it up. Bind it. Listen. Set the first connection. Dupe the file descriptors for standard in, standard out, standard error to the socket. And run bin shell. And that's it. I just kind of went through. Translated this into assembly because everything is just a system call. So. I do a trap. Let's see. Right there is the socket call. By 230. Just look through. These, the higher numbered ones will change from system to system so you'll have to look them up on, if you don't have Linux or BSD on there. Just straightforward assembly programming basically. Going through. Go bind. Store it all. Yada, yada, yada. You know, you compile and I just insert in my standard shell code right there. Using the compiler to output assembly code will be very helpful in figuring out how the compiler does stuff. But it is deceptive in a lot of ways because the compiler doesn't like telling you. Or in the various libraries that it's just doing system calls for all these. So you'll go through like six different layered functions. Underscore, underscore, socket, underscore, capital U. That'll finally say, oh, I just do a trap. But just to look through syscall.h and you'll see what it really does. It'll get angry at you. But we tested. I just compiled it and linked the two things together. Oh yeah. That's the bug. For some reason when I run it straight it decides that it will not block and wait for it to accept. It'll just kind of do something. And the thread will just continue on and execute the shell. But when I run it through the debugger and say, what's it called? Bind shell break. And I run it. And I say, yeah, continue. Oh, no. And I just told it to bind. To local host part 2000. Yes. Keep going. It likes to say, I'm about to exec something and things will change. So I'll stop for you. But just ignore that. And basically we have a very, very, very, very, very, very, very, very, very, very, very mutated, very ugly environmented shell right here. It's not found. And you can get enough done from here to do what you need to do. And, obviously, it's running as a NAT because I just ran it for the command line but you just basically through the things I've showed you convert to shell code and throw in the process and you'll have a bind shell. To do so, I have a nice shell. Just to help me out with writing these, I made my disk 2H, and so if I go through to my code, let's see, what I do is I write 3.c, test it out in there, then I disassemble it to a 3 dot, well, I disassemble it to 3.dis, which says diff main 3, little noise at the top, so I just chop those off until I just have the disassembled code, shouldn't hurt you to cut out three lines, I don't want the script to do everything for you, and then just a simple filter, you can do this in Perl, you can do this in whatever you want, but I did it in C because it's fun, 3.dis, pipe to that, and it gives you a nice little header file. It's a nice little header file to include, and this is a quick way to check for null bytes, and just look at your code, hand side by side, and feel warm and fuzzy, but basically with just a couple little tools, you can just tinker around with writing shell code and stuff, and then amazingly you will wake up and say, wait a minute, I'm actually decent at assembly programming now, this is useful, to be the example. I didn't do well in my assembly class until I started doing this stuff, and of course this semester it ended, and now I know everything and can pay attention in class anyway, so grades mean nothing. I don't think I have anything else to show you, and I think I'm out of time. Oh yes, some links to useful things, linuxassembly.org, obviously focuses on Linux and Intel architecture, but they have some great info on there, a little straight from the beaten path, and show you some Spark stuff, some BSD stuff. They have a nice little suite of basically the bin util, or a lot of the smaller utilities written in assembly, so your standard 100k executable is now like 3k, because all they do is call the traps themselves. It's not portable, but it's really small and used for good disks. shellcode.org, I just saw come across, see their bug tracker, volume dev, some mailing list. Today, currently down, we'll have a lot of resources to various shellcodes for various operating systems. Flack55 has a really nice article about writing shellcode on MIPS under IRIX, MIPS also being another of the pioneering RISC chips, very similar to this, it's a very good read also. And this stuff eventually will be on dopesquad.net slash security, whenever I finish it up and put it up there, so you can look there, but if you see a 404, don't have a heart attack.