1 00:00:11,540 --> 00:00:16,000 obviously is gonna be on buffer overflows on the spark you're just treated to a great talk 2 00:00:16,000 --> 00:00:21,520 on basically advanced techniques can do I'm going to try and focus on this on doing overflows on 3 00:00:21,520 --> 00:00:28,280 other architectures most notably the spark the spark for those are unfamiliar or probably have 4 00:00:28,280 --> 00:00:35,780 just heard of them is oh well this is I'm gonna talk about sorry you know order I do a crash 5 00:00:35,780 --> 00:00:41,820 course on the spark and spark assembly just because I'm gonna focus a lot on writing the 6 00:00:41,820 --> 00:00:47,720 shell code or the payload because that's what differs the most between Intel and and spark 7 00:00:47,720 --> 00:00:53,880 and you a lot of the techniques that was already talked about about how to deliver the shell code 8 00:00:53,880 --> 00:00:58,220 equally applies here there are some little nuances that will make it different 9 00:00:58,280 --> 00:01:05,920 but as a general conceptual overview it's the same the stack is much funkier on the spark and 10 00:01:06,560 --> 00:01:11,120 make sure I cover that I'll cover some of the tools that I'm using to develop the shell code 11 00:01:11,120 --> 00:01:18,060 and its examples I'll be doing everything on a Solaris box this one right here and Solaris is 12 00:01:18,060 --> 00:01:22,700 so nice to come with a wonderful debugger ADB is an absolutely called the absolute debugger is an 13 00:01:22,700 --> 00:01:27,620 assembly language level debugger so you can step through look at the registers look at you know 14 00:01:28,300 --> 00:01:34,880 binaries you can patch values in memory and do things a lot easier than you can with GDB and that 15 00:01:34,880 --> 00:01:41,160 will speak up as everyone is motioning towards me to do then I'll discuss what exactly what happens 16 00:01:41,160 --> 00:01:46,740 on an overflow and start discussing shell code and some methods of delivery and I'll be giving 17 00:01:46,740 --> 00:01:52,920 some examples too because I like doing that okay the spark Stanford scalable possible 18 00:01:52,920 --> 00:01:58,200 scalable processor architecture created by Sun the early 80s was based on the risk design 19 00:01:58,280 --> 00:02:02,820 out of UC Berkeley and basically the whole philosophy was take it to make the chip as 20 00:02:02,820 --> 00:02:08,680 simple as possible so it's blazing fast and part of what this this is is the 30 bit wide path 21 00:02:08,680 --> 00:02:13,960 everything in spark is really pretty because every instruction is 32 bits wide you your shell code 22 00:02:13,960 --> 00:02:20,920 is nice and square it's really fun it makes things just typically easier for calculating the 23 00:02:20,920 --> 00:02:25,100 size of your shell code and calculating jump addresses and stuff like that it's a pipeline 24 00:02:25,100 --> 00:02:28,220 architecture which will yeah I just had to mention 25 00:02:28,280 --> 00:02:34,320 because it will get you in some places every clock cycle it basically executes one-and-a-half 26 00:02:34,320 --> 00:02:38,160 fish instructions where it basically prepares the second instruction so you have to watch out when 27 00:02:38,160 --> 00:02:43,300 you're branching that when you branch jump to another location in code you will execute the 28 00:02:43,300 --> 00:02:50,020 statement after the branch so just keep that in mind when you're writing your stuff other things 29 00:02:50,020 --> 00:02:55,640 to speed this up is the load store architecture all logical and arithmetic instructions only 30 00:02:55,640 --> 00:02:58,180 operate on the registers you can't fetch things some you 31 00:02:58,280 --> 00:03:01,860 can't just like increment something in memory because that involve making the chip smarter and 32 00:03:01,860 --> 00:03:08,160 slower so and the one thing unique to the spark is this wacky invention called register windows 33 00:03:08,160 --> 00:03:16,260 which I will cover in great depth because it's kind of crazy in memory access basically it's 34 00:03:16,260 --> 00:03:20,600 relatively simple the only instructions that can access memory or load and store and that whole 35 00:03:20,600 --> 00:03:27,720 family of instructions load by byte load by half by a half word so on and so on and all memory access 36 00:03:28,280 --> 00:03:31,960 indirect, meaning that you have to write something 37 00:03:31,960 --> 00:03:36,140 in the value contained in a register, whereas each register 38 00:03:36,140 --> 00:03:38,820 acts like a pointer, basically, as they would in C. 39 00:03:40,880 --> 00:03:44,080 This chip was actually written for C 40 00:03:44,080 --> 00:03:48,160 compilers, so if you think in C, the spark will be 41 00:03:48,160 --> 00:03:48,800 very nice to you. 42 00:03:51,220 --> 00:03:56,180 Instructions are one word. Very nice. The registers. RISC chips always 43 00:03:56,180 --> 00:03:59,780 have tons of registers, which make things really easy. 44 00:04:01,300 --> 00:04:03,900 At each given point in time, you have access to 32 45 00:04:03,900 --> 00:04:08,000 registers. The chip may actually have more registers than that, more general 46 00:04:08,000 --> 00:04:12,040 purpose integer registers, but you can only see 32 of them at a time because of 47 00:04:12,040 --> 00:04:15,940 the register windows, which I'll talk about. You always have the global registers. 48 00:04:16,120 --> 00:04:19,700 You have eight of them that are accessible across every function. 49 00:04:20,280 --> 00:04:23,840 You have the output registers, which you load up the arguments to 50 00:04:23,840 --> 00:04:25,060 a function to be calling. 51 00:04:25,060 --> 00:04:28,640 You have the local registers, which are local to your subroutine. 52 00:04:28,780 --> 00:04:32,740 The inputs, which are your caller's output registers. 53 00:04:33,940 --> 00:04:36,900 Things to note, the output register 54 00:04:36,900 --> 00:04:39,760 6 is the stack pointer. That points to 55 00:04:40,600 --> 00:04:44,780 the bottom of your stack, bottom being the lowest memory address. 56 00:04:45,040 --> 00:04:48,660 The input 6 is the frame pointer, which is your 57 00:04:48,660 --> 00:04:52,980 caller's stack pointer, and also it points to the top 58 00:04:52,980 --> 00:04:54,260 of your... 59 00:04:55,060 --> 00:04:56,240 of your stack space. 60 00:04:58,280 --> 00:05:04,040 How register windows work is it's a circular stack of 16 registers. 61 00:05:04,380 --> 00:05:09,860 The outputs and the local, which are rotated among functions, so you 62 00:05:09,860 --> 00:05:13,260 don't have to worry about pushing arguments onto the stack or so on, 63 00:05:13,300 --> 00:05:17,060 and to speed up function calls, because those are written for C, and 64 00:05:17,060 --> 00:05:18,740 that's what you do all the time. 65 00:05:20,080 --> 00:05:23,020 The call is output registers become the input registers in the next function. 66 00:05:24,180 --> 00:05:25,040 The call is output registers become the input registers in the next function, and that's what you do all the time. 67 00:05:25,060 --> 00:05:27,300 These are all handled by the save and restore instructions. 68 00:05:27,740 --> 00:05:30,560 The save and restore instructions allocate your new register set, 69 00:05:30,700 --> 00:05:33,280 and they also allocate the stack on the space... 70 00:05:33,280 --> 00:05:36,580 or the space on the stack, which we will... 71 00:05:36,580 --> 00:05:38,800 we have to get the subroutine call in conventions. 72 00:05:40,200 --> 00:05:42,360 Basically, to call a subroutine, very simple, 73 00:05:42,500 --> 00:05:44,580 you just place the arguments in the output registers, 74 00:05:44,840 --> 00:05:47,900 use the call instruction to actually jump to the 75 00:05:47,900 --> 00:05:50,160 location in memory containing the code for the function. 76 00:05:50,420 --> 00:05:54,960 The callee uses the save instruction to allocate a register window, 77 00:05:54,960 --> 00:05:58,100 and it will also allocate their stack frame, 78 00:05:58,280 --> 00:06:03,580 and with that, they calculate the minimum space they need for the stack, 79 00:06:04,380 --> 00:06:06,900 in addition to anything they need for local variables, 80 00:06:07,060 --> 00:06:08,660 as all allocated in one instruction. 81 00:06:10,020 --> 00:06:12,240 Interesting thing to note is that 82 00:06:12,900 --> 00:06:15,360 when you are allocating space on the stack for the register window, 83 00:06:15,620 --> 00:06:17,020 they're not actually written there. 84 00:06:17,340 --> 00:06:21,820 They're only written there when the system runs out of register windows, 85 00:06:22,020 --> 00:06:24,480 and when that happens, a trap is called that 86 00:06:24,960 --> 00:06:27,160 signals the operating system that it needs to flush 87 00:06:28,200 --> 00:06:30,900 some of these registers out to the memory stack, 88 00:06:31,140 --> 00:06:32,560 and so basically what you're doing is you're saying, 89 00:06:32,680 --> 00:06:34,300 when you need to dump them, dump them here. 90 00:06:34,960 --> 00:06:37,660 So you're not actually guaranteed to have them written there, 91 00:06:38,860 --> 00:06:40,440 which is kind of difficult because 92 00:06:40,840 --> 00:06:43,780 the point of overflowing the buffer is to overwrite the return address, 93 00:06:44,040 --> 00:06:45,640 but if the return address is in a register, 94 00:06:46,900 --> 00:06:47,780 you have complications. 95 00:06:50,200 --> 00:06:51,980 And, you know, the callee does its thing, 96 00:06:52,080 --> 00:06:54,280 and at the end it does a ret, 97 00:06:54,280 --> 00:06:56,480 which is return to the caller, 98 00:06:56,660 --> 00:06:59,780 which just basically jumps to the value stored 99 00:06:59,780 --> 00:07:04,200 in the input 7 register plus 8, 100 00:07:04,300 --> 00:07:07,640 because the 8 is added because of the branch delay slot 101 00:07:07,640 --> 00:07:09,120 that, you know, when it's called, 102 00:07:09,160 --> 00:07:10,980 it executes that instruction and the next instruction, 103 00:07:11,140 --> 00:07:12,520 so it has to go 8 back. 104 00:07:15,000 --> 00:07:15,840 Simple example. 105 00:07:16,500 --> 00:07:20,780 We have our main, just we'll call the function foo, 106 00:07:20,860 --> 00:07:23,680 and we'll set the upper register 0 107 00:07:23,680 --> 00:07:24,400 to dead beef. 108 00:07:25,280 --> 00:07:27,720 This is executed because it is in the branch delay slot. 109 00:07:28,100 --> 00:07:30,380 Control transfers over to foo, 110 00:07:31,060 --> 00:07:31,940 which saves. 111 00:07:32,200 --> 00:07:33,780 The save instruction is interesting because 112 00:07:33,780 --> 00:07:35,640 the first argument, 113 00:07:35,860 --> 00:07:37,400 oh, one thing to note about Spark assembly 114 00:07:37,400 --> 00:07:40,760 is the destination is always on the right. 115 00:07:41,100 --> 00:07:45,480 So it was save starting at the original stack pointer, 116 00:07:45,640 --> 00:07:48,580 and decrement the stack pointer by 96 bytes, 117 00:07:48,760 --> 00:07:50,780 which is the minimum stack frame needed 118 00:07:50,780 --> 00:07:51,740 to dump the registers, 119 00:07:51,920 --> 00:07:52,640 and, 120 00:07:52,640 --> 00:07:55,940 store that value as the new stack pointer, 121 00:07:56,120 --> 00:07:58,800 and in between those is when the register window is rotated. 122 00:07:59,780 --> 00:08:03,240 So the value of the stack pointer at the first operand 123 00:08:03,240 --> 00:08:05,740 is now in the frame pointer register. 124 00:08:08,640 --> 00:08:13,800 Then it just loads the value stored at the memory address, 125 00:08:13,960 --> 00:08:16,500 stored in register input 0, 126 00:08:16,720 --> 00:08:19,320 and puts that value in register local 0, 127 00:08:19,520 --> 00:08:21,660 adds 42 to it, storing the result, 128 00:08:21,660 --> 00:08:22,860 and register local 1, 129 00:08:23,460 --> 00:08:26,900 and similarly stores the result back in dead beef. 130 00:08:27,740 --> 00:08:28,780 Then it returns, 131 00:08:28,900 --> 00:08:31,000 and returns to transfer the control back, 132 00:08:31,160 --> 00:08:32,180 and because the branch delay slot, 133 00:08:32,420 --> 00:08:34,740 the restore flips the register window back, 134 00:08:34,920 --> 00:08:36,400 and deallocates the stack, 135 00:08:36,560 --> 00:08:38,100 so when transfer is controlled back, 136 00:08:38,380 --> 00:08:41,100 the caller thinks the world is right again. 137 00:08:42,440 --> 00:08:44,180 I want to define traps for you. 138 00:08:44,640 --> 00:08:46,400 These are typically called interrupts 139 00:08:46,400 --> 00:08:49,140 in other operating systems and architectures. 140 00:08:49,480 --> 00:08:50,880 They are transfers of control 141 00:08:50,880 --> 00:08:51,720 to supervisor software, 142 00:08:52,040 --> 00:08:54,920 meaning it's a request from the application 143 00:08:54,920 --> 00:08:56,560 or from other supervisor code, 144 00:08:56,740 --> 00:08:58,440 or from the actual hardware 145 00:08:58,440 --> 00:09:01,160 for the operating system to get up and do something. 146 00:09:03,680 --> 00:09:10,160 These are handled for window overflow and underflow conditions 147 00:09:10,160 --> 00:09:12,540 where the operating system has to dump them 148 00:09:12,540 --> 00:09:14,240 to the memory stack or restore them. 149 00:09:14,560 --> 00:09:16,400 The question is, why do we care? 150 00:09:17,440 --> 00:09:18,260 System calls. 151 00:09:19,140 --> 00:09:20,720 If you're familiar with Unix kernel, 152 00:09:20,880 --> 00:09:23,900 they are all based upon having tons of system calls 153 00:09:23,900 --> 00:09:24,960 that will do everything for you. 154 00:09:26,700 --> 00:09:30,660 These are all in the manual pages, section 2. 155 00:09:30,940 --> 00:09:32,880 Open, close, exec, fork, 156 00:09:33,000 --> 00:09:35,240 all these fun things are all there for you. 157 00:09:35,420 --> 00:09:36,580 To make a system call, 158 00:09:36,740 --> 00:09:39,600 all you do is look up in syscall.h 159 00:09:39,600 --> 00:09:42,480 the system call number of the system call you want to execute, 160 00:09:42,740 --> 00:09:44,080 throw that in global 1, 161 00:09:44,220 --> 00:09:45,960 and execute trap 8. 162 00:09:46,780 --> 00:09:48,020 A simple example here. 163 00:09:49,740 --> 00:09:53,840 We are going to set the output register to 0, 164 00:09:53,940 --> 00:09:56,440 because global 0 is basically the dev null register. 165 00:09:56,540 --> 00:09:57,360 It's hard-coded 0. 166 00:09:58,440 --> 00:10:01,340 23 is the index of the setuid system call. 167 00:10:01,480 --> 00:10:02,700 Move that to global 1. 168 00:10:02,800 --> 00:10:03,540 Do the trap. 169 00:10:05,520 --> 00:10:09,520 Notice there is no branch delay slot after a trap. 170 00:10:10,540 --> 00:10:12,000 It's only on branches and calls. 171 00:10:13,320 --> 00:10:15,000 Now just execute setuid 0, 172 00:10:15,900 --> 00:10:17,320 which we'll see why we need to do that. 173 00:10:18,940 --> 00:10:19,900 The stack. 174 00:10:21,800 --> 00:10:23,140 Like other architectures, 175 00:10:23,180 --> 00:10:23,900 the stack goes downward, 176 00:10:24,040 --> 00:10:26,680 and it reserves the space for the window 177 00:10:26,680 --> 00:10:27,860 in case of overflow or underflow. 178 00:10:30,280 --> 00:10:34,480 Basically, in a well-behaved convention obeying functions, 179 00:10:35,880 --> 00:10:39,880 all automatic variables are referenced by negative offsets 180 00:10:39,880 --> 00:10:41,040 from the frame pointer, 181 00:10:41,180 --> 00:10:44,580 because as my little art in the next slide will show you, 182 00:10:45,420 --> 00:10:47,760 the first part of the stack in the high memory address 183 00:10:48,020 --> 00:10:51,780 is space, if any, for automatic variables, 184 00:10:51,920 --> 00:10:52,920 so you just index them that way. 185 00:10:53,680 --> 00:10:57,580 Then the bottom of the stack is stuff for the register windows. 186 00:10:57,720 --> 00:10:59,760 But you actually really don't need to reference those, 187 00:10:59,960 --> 00:11:02,540 because nothing is guaranteed to be there, 188 00:11:02,640 --> 00:11:03,600 so why would you want to do that? 189 00:11:05,560 --> 00:11:09,780 Here is a struct representation of the minimum stack frame. 190 00:11:10,660 --> 00:11:12,020 They do some interesting stuff here. 191 00:11:12,920 --> 00:11:17,640 You have eight words allotted for the local, 192 00:11:18,780 --> 00:11:21,160 and then you have six for the input registers, 193 00:11:21,360 --> 00:11:24,380 and notice these two are also the input registers. 194 00:11:24,480 --> 00:11:30,340 We have the frame pointer and the saved program counter, 195 00:11:30,480 --> 00:11:32,040 which is where we'll be jumping back to. 196 00:11:32,180 --> 00:11:33,520 Basically, you have eight locals, 197 00:11:33,600 --> 00:11:36,160 and those next three lines form the eight inputs, 198 00:11:37,120 --> 00:11:40,700 which means you can only pass six arguments 199 00:11:40,700 --> 00:11:43,520 through the registers to a function. 200 00:11:45,320 --> 00:11:47,120 Then we have the structure return address 201 00:11:47,120 --> 00:11:48,000 for return and compound, 202 00:11:48,020 --> 00:11:48,580 compound values. 203 00:11:49,400 --> 00:11:51,240 We decided to throw that in there for fun, 204 00:11:52,460 --> 00:11:54,260 so you could store a pointer on the stack 205 00:11:54,260 --> 00:11:55,220 instead of putting it in a register. 206 00:11:55,360 --> 00:11:55,820 I'm not sure why. 207 00:11:56,500 --> 00:11:59,040 Then we have the argument dump area, 208 00:11:59,280 --> 00:12:02,520 which is so that the function being called, 209 00:12:03,060 --> 00:12:04,280 if it so chooses, 210 00:12:04,520 --> 00:12:08,820 can dump its arguments that it got on its input registers 211 00:12:08,820 --> 00:12:09,720 onto its stack. 212 00:12:10,760 --> 00:12:11,160 Okay. 213 00:12:12,340 --> 00:12:13,480 If you need more registers, 214 00:12:13,680 --> 00:12:14,720 you can do that and get them all. 215 00:12:15,080 --> 00:12:16,420 Then we have the argx area. 216 00:12:16,420 --> 00:12:18,560 This is the argument extension. 217 00:12:19,240 --> 00:12:22,360 For more than six arguments to a function, 218 00:12:22,560 --> 00:12:25,260 this stack, this space just kind of grows 219 00:12:25,260 --> 00:12:30,100 as far as needed to place the arguments there. 220 00:12:30,440 --> 00:12:34,380 This is allotted with the caller's save instruction, 221 00:12:35,600 --> 00:12:36,780 which I put those in there. 222 00:12:36,880 --> 00:12:37,740 They load them in. 223 00:12:37,820 --> 00:12:39,560 The function will know to reference them 224 00:12:40,100 --> 00:12:42,260 as negative to the frame pointer, 225 00:12:43,140 --> 00:12:44,220 as yes. 226 00:12:47,400 --> 00:12:48,260 That's how that works. 227 00:12:48,340 --> 00:12:49,740 We won't really be using that, 228 00:12:49,820 --> 00:12:51,860 but here's a nice ASCII art depiction of the stack. 229 00:12:52,680 --> 00:12:53,780 The stack goes this way, 230 00:12:54,280 --> 00:12:55,660 and I have it going left to right 231 00:12:55,660 --> 00:12:57,260 just so you can read it 232 00:12:57,260 --> 00:12:59,080 and you can see the string buffers as they are. 233 00:13:00,140 --> 00:13:01,340 Locals, inputs, the structure, 234 00:13:02,140 --> 00:13:04,140 return address, the instruction pointer. 235 00:13:04,420 --> 00:13:06,420 The argument dump area is 24 bytes, 236 00:13:06,500 --> 00:13:09,340 and I have the sizes used by them up there. 237 00:13:11,440 --> 00:13:13,760 The argument dump area is that one byte. 238 00:13:13,820 --> 00:13:16,060 It's also sometimes referred to as the hidden word, 239 00:13:16,420 --> 00:13:17,460 which is used to make sure 240 00:13:17,460 --> 00:13:21,080 that the stack is double word aligned. 241 00:13:21,360 --> 00:13:23,860 The stack and the saved program counter 242 00:13:23,860 --> 00:13:25,060 must always be double word aligned, 243 00:13:25,340 --> 00:13:27,260 or else your chip will get very angry with you. 244 00:13:28,800 --> 00:13:29,860 We're going to make it very angry, 245 00:13:29,920 --> 00:13:31,180 but not so angry that it barfs. 246 00:13:32,000 --> 00:13:33,680 Then automatic variables we stored here. 247 00:13:33,900 --> 00:13:35,040 Right here in my example, 248 00:13:35,140 --> 00:13:37,740 I have a string pointer called buff 249 00:13:37,740 --> 00:13:38,780 of indeterminate size. 250 00:13:39,020 --> 00:13:39,540 It doesn't really matter. 251 00:13:40,600 --> 00:13:42,420 Then we have the frame pointer, 252 00:13:42,540 --> 00:13:44,520 which is the boundary between our next 253 00:13:44,520 --> 00:13:46,300 or our caller's stack frame. 254 00:13:46,420 --> 00:13:48,340 There are his locals, his inputs, 255 00:13:48,560 --> 00:13:50,000 and my little asterisks. 256 00:13:50,280 --> 00:13:51,720 That's his saved program counter. 257 00:13:52,560 --> 00:13:53,320 That's our target. 258 00:13:53,420 --> 00:13:54,220 That's what we need to hit. 259 00:13:55,120 --> 00:13:56,360 It's pretty easy to see that 260 00:13:56,360 --> 00:13:58,940 if the buffer grows outside of its boundaries, 261 00:13:59,220 --> 00:14:00,640 you just overwrite his registers 262 00:14:02,780 --> 00:14:04,660 and basically take him over, 263 00:14:06,260 --> 00:14:07,960 which actually presents the interesting thing. 264 00:14:08,080 --> 00:14:08,980 You're not overflowing 265 00:14:11,740 --> 00:14:13,460 and taking over the function 266 00:14:13,460 --> 00:14:16,300 that with the fixed length buffer 267 00:14:16,420 --> 00:14:18,840 in it, you are overflowing 268 00:14:18,840 --> 00:14:20,680 and taking control from his caller, 269 00:14:20,860 --> 00:14:22,660 which is very interesting 270 00:14:22,660 --> 00:14:24,040 because sometimes your caller 271 00:14:24,040 --> 00:14:25,380 can call the overflowable function, 272 00:14:25,600 --> 00:14:27,540 return, call another function, 273 00:14:27,640 --> 00:14:29,720 which will overwrite your wonderful 274 00:14:29,720 --> 00:14:31,120 stack frame and shellcode, 275 00:14:31,280 --> 00:14:34,040 and then basically you're screwed. 276 00:14:34,340 --> 00:14:36,300 Of course, you just attended 277 00:14:36,300 --> 00:14:37,280 to Greg Hoagland's talk 278 00:14:37,280 --> 00:14:39,320 on how to do cool things with the stack 279 00:14:39,320 --> 00:14:40,200 and where you can put the code. 280 00:14:40,960 --> 00:14:43,020 Something like that should not be a problem. 281 00:14:44,760 --> 00:14:45,940 This is what's going to happen 282 00:14:45,940 --> 00:14:49,080 when we are overflowing the buffer. 283 00:14:49,280 --> 00:14:50,480 I'm just going to trace through 284 00:14:50,480 --> 00:14:52,620 over how the register windows 285 00:14:52,620 --> 00:14:53,800 rotate the registers 286 00:14:53,800 --> 00:14:54,820 and how things change. 287 00:14:55,740 --> 00:14:57,320 Obviously, the previous stack frame's 288 00:14:57,320 --> 00:14:59,000 saved program counter is overwritten, 289 00:14:59,100 --> 00:15:01,140 as is all his other registers. 290 00:15:02,360 --> 00:15:03,360 The function returns. 291 00:15:05,980 --> 00:15:09,180 His frame pointer becomes the target address, 292 00:15:09,420 --> 00:15:12,280 and his input 7 register 293 00:15:12,280 --> 00:15:13,920 becomes the target address also. 294 00:15:13,920 --> 00:15:16,240 The stack pointer is still valid. 295 00:15:16,420 --> 00:15:17,200 The stack pointer will still be 296 00:15:17,200 --> 00:15:19,380 the pointer to his stack, 297 00:15:19,600 --> 00:15:21,140 which has not been totally 298 00:15:21,140 --> 00:15:22,460 foobarred at this point. 299 00:15:24,220 --> 00:15:27,940 All his values that he assumed to be safe 300 00:15:27,940 --> 00:15:29,460 have just been totally messed up, 301 00:15:29,560 --> 00:15:31,300 so he just freaks out, 302 00:15:32,220 --> 00:15:34,060 hopefully getting an error condition immediately, 303 00:15:36,140 --> 00:15:37,100 and returning. 304 00:15:38,140 --> 00:15:40,360 If he does, he tries to jump 305 00:15:40,360 --> 00:15:42,280 to the input 7 plus 8. 306 00:15:42,660 --> 00:15:43,900 Our target address will be 8, 307 00:15:43,920 --> 00:15:44,400 plus 8 bytes, 308 00:15:44,560 --> 00:15:46,760 and that is where we take over control. 309 00:15:49,640 --> 00:15:51,120 This is your stack on drugs. 310 00:15:53,380 --> 00:15:57,100 Basically, these areas on the stack are fine, 311 00:15:57,280 --> 00:15:58,320 and in our buff, 312 00:15:58,460 --> 00:16:00,760 we just overflow and write our target address 313 00:16:01,420 --> 00:16:02,440 off into the horizon. 314 00:16:02,940 --> 00:16:04,740 You can basically write it as far as you want, 315 00:16:04,840 --> 00:16:08,640 because nothing's going to behave well at this point. 316 00:16:08,860 --> 00:16:09,260 Yes? 317 00:16:10,020 --> 00:16:10,420 . 318 00:16:13,500 --> 00:16:13,900 . 319 00:16:15,900 --> 00:16:17,420 Oh, thank you for reminding me. 320 00:16:17,820 --> 00:16:18,040 . 321 00:16:19,400 --> 00:16:21,440 Basically, we are told that we are not guaranteed 322 00:16:21,980 --> 00:16:23,680 that these values will be there, 323 00:16:23,860 --> 00:16:25,320 but what happens is, 324 00:16:28,400 --> 00:16:29,760 implementations of the Spark architecture, 325 00:16:30,620 --> 00:16:31,800 as it's an open architecture, 326 00:16:32,040 --> 00:16:35,020 are allowed to have anywhere from 8 to 40 register windows. 327 00:16:35,680 --> 00:16:37,600 Luckily, those register windows are 328 00:16:37,600 --> 00:16:40,100 always filled in the lowest stages of the kernel, 329 00:16:40,220 --> 00:16:42,600 so you can basically assume 330 00:16:42,600 --> 00:16:43,900 that every time we do a save or reset 331 00:16:43,920 --> 00:16:48,120 restore, they will be saved to the stack and restored from the stack. 332 00:16:48,480 --> 00:16:57,220 When the overflowed function does a restore, we'll assume that the registers that it thought 333 00:16:57,220 --> 00:17:03,700 it had in the register window were written to the stack and so it restores them from 334 00:17:03,700 --> 00:17:05,860 the caller's stack. 335 00:17:07,680 --> 00:17:12,920 What it does is we have our target address written all the way through there and it just 336 00:17:12,920 --> 00:17:17,460 loads up its registers as it transfers control to the caller, loads up its registers with 337 00:17:17,460 --> 00:17:18,060 the target address. 338 00:17:19,400 --> 00:17:22,660 I will do some examples and I'll show you what this looks like when I'm stepping through 339 00:17:22,660 --> 00:17:27,280 the program and you'll see all the registers are just totally just spammed over. 340 00:17:28,920 --> 00:17:33,280 One of the very nice tools that Solaris comes with is just the disassembler. 341 00:17:35,240 --> 00:17:40,340 If you've ever looked into basically writing the shell code, writing the assembly code 342 00:17:40,340 --> 00:17:41,820 and then changing it to the bytes. 343 00:17:42,540 --> 00:17:43,440 It's a pain in the butt. 344 00:17:43,680 --> 00:17:47,140 But this makes it rather easy, especially when you just throw a Perl script on top of 345 00:17:47,140 --> 00:17:51,600 it and it's a nice little chug and you have a nice little header file that you can use. 346 00:17:53,260 --> 00:17:56,020 There are freeware Spark disassemblers available. 347 00:17:57,720 --> 00:18:04,780 I just found a page about two hours ago off LinuxAssembly.org has a link to an FBSD link 348 00:18:04,780 --> 00:18:10,940 to some Spark assembly examples and on this guy's page he has his own Spark disassembler 349 00:18:10,940 --> 00:18:11,700 and Spark assembly. 350 00:18:11,820 --> 00:18:18,340 And a couple others that you could use for Linux and or BSD, all running on Spark of 351 00:18:18,340 --> 00:18:18,560 course. 352 00:18:19,940 --> 00:18:20,300 Excuse me? 353 00:18:26,500 --> 00:18:27,160 Is it free? 354 00:18:27,440 --> 00:18:28,020 Is it free? 355 00:18:28,340 --> 00:18:29,440 Oh, very nice. 356 00:18:32,740 --> 00:18:33,100 Okay. 357 00:18:34,840 --> 00:18:39,240 Well, if, I'm sure we can find that if you want to give, if you want to give me the URL 358 00:18:39,240 --> 00:18:40,900 I can throw it on here for people. 359 00:18:42,540 --> 00:18:48,400 Oh, I forgot who already, but someone has a really good free disassembler. 360 00:18:48,840 --> 00:18:49,320 GNU. 361 00:18:50,860 --> 00:18:51,340 GNU? 362 00:18:51,660 --> 00:18:52,960 There's a GNU disassembler? 363 00:18:53,740 --> 00:18:54,220 . 364 00:18:59,000 --> 00:18:59,700 Oh, wow. 365 00:18:59,840 --> 00:19:01,900 I was unaware that they had a disassembler. 366 00:19:02,160 --> 00:19:02,640 Wow. 367 00:19:03,040 --> 00:19:04,220 I have done my research. 368 00:19:04,400 --> 00:19:04,880 Okay. 369 00:19:09,120 --> 00:19:10,880 And the other tool that we'll be using on the next slide is this one. 370 00:19:10,880 --> 00:19:11,180 It's called GDB. 371 00:19:11,180 --> 00:19:12,640 And what I've seen extensively is the absolute debugger. 372 00:19:13,300 --> 00:19:17,960 Because this thing, I, correct me if I'm wrong again, I have not seen anything like this 373 00:19:17,960 --> 00:19:20,260 for any of the free operating systems. 374 00:19:20,640 --> 00:19:26,100 They tend to use GDB for their kernel debuggers and everything else, but I have not seen 375 00:19:26,700 --> 00:19:29,980 something that is as assembly language as this one is, as assembly level. 376 00:19:31,760 --> 00:19:36,360 Rather funky syntax to get used to if you're coming from the world of nice and pretty hand-holding 377 00:19:36,360 --> 00:19:36,740 debuggers. 378 00:19:38,360 --> 00:19:39,320 Arguments are address. 379 00:19:39,580 --> 00:19:40,520 How many iterations? 380 00:19:40,660 --> 00:19:40,860 Two. 381 00:19:40,860 --> 00:19:42,680 There's a lot to do in command and modifiers, as you can see. 382 00:19:43,080 --> 00:19:49,220 First instruction, it says, starting at the address of main in the object file. 383 00:19:49,340 --> 00:19:50,900 The question mark means in the object file. 384 00:19:51,120 --> 00:19:56,100 The slash means in the memory image, whether it be a core file or the actual memory of 385 00:19:56,100 --> 00:19:56,600 the running process. 386 00:19:57,960 --> 00:20:05,340 What I'm saying on the first one is dump 10 instructions, or disassemble 10 instructions 387 00:20:05,340 --> 00:20:06,180 starting at main. 388 00:20:07,080 --> 00:20:10,840 One of the wonderful idiosyncrasies of this program is everything on this side of the 389 00:20:10,840 --> 00:20:13,000 question mark or slash is in hex. 390 00:20:13,200 --> 00:20:14,980 Everything on that side is in decimal. 391 00:20:16,680 --> 00:20:21,960 But there are modifiers you can use to put them either way, but we should all be very 392 00:20:21,960 --> 00:20:23,580 fluid with conversions, even though I'm not. 393 00:20:25,080 --> 00:20:29,040 The second example, just display the word stored at code, babe. 394 00:20:29,300 --> 00:20:31,620 That's not a real address, but I like it. 395 00:20:32,800 --> 00:20:38,300 We can also just query individual registers, basically have a pseudo-redirection instruction 396 00:20:38,300 --> 00:20:40,720 that'll say, give me the address of the stack. 397 00:20:41,400 --> 00:20:43,540 Assign it to the variable x and it'll print it out for you. 398 00:20:44,420 --> 00:20:48,460 Next instruction says, display 24 words starting at the stack pointer. 399 00:20:48,640 --> 00:20:52,500 That will give you the full minimum stack frame. 400 00:20:53,120 --> 00:20:56,360 And then from there, after that point will be automatic variables, if any. 401 00:20:56,520 --> 00:20:59,700 But every function must have at least those, and you can check them out. 402 00:21:00,760 --> 00:21:01,720 Here's a more interesting one. 403 00:21:03,300 --> 00:21:10,100 In the address of the frame pointer plus 3c, which I can't remember, I'm on the spot so 404 00:21:10,100 --> 00:21:16,840 I can't do math, that'll be the saved program counter, write the value, dead beef. 405 00:21:17,340 --> 00:21:21,260 And so then you just write the value, step through, and you'll see the program try and 406 00:21:21,260 --> 00:21:24,140 jump to it, see the caller try and jump to it when it comes time. 407 00:21:27,360 --> 00:21:31,160 The ADB will also do interactive debugging, some simple stuff like this. 408 00:21:31,200 --> 00:21:34,720 You don't really, it's not really pertinent, but I threw it on there because I needed space. 409 00:21:36,060 --> 00:21:36,460 Wow. 410 00:21:37,260 --> 00:21:39,020 This is very difficult to see. 411 00:21:40,100 --> 00:21:45,400 This is a contrived session of using ADB to examine what happens when we overflow a 412 00:21:45,400 --> 00:21:45,640 program. 413 00:21:46,060 --> 00:21:49,300 I wrote a simple program called smash me, which I'll show you in a couple minutes. 414 00:21:49,940 --> 00:21:56,040 It basically just does the fatal flaw, does a strcpy or a strcat into a fixed length buffer. 415 00:21:57,080 --> 00:22:00,560 And it just takes the argument out of the command line, so I'm just saying run it with 416 00:22:01,060 --> 00:22:01,560 this argument. 417 00:22:02,700 --> 00:22:07,200 And I said first to set the break, oh, there also is no prompt in ADB, so it's kind of 418 00:22:07,200 --> 00:22:07,900 hard to follow along. 419 00:22:08,100 --> 00:22:09,940 I said, smash me. 420 00:22:09,940 --> 00:22:14,700 Smash me, colon, B, means set a break point at the smash function, which is I have main 421 00:22:14,700 --> 00:22:17,040 and I call smash, which has the overflow. 422 00:22:18,000 --> 00:22:24,760 And then we run it with that argument, stops at the beginning of smash, we're stepping 423 00:22:24,760 --> 00:22:32,960 through, I'll get our stack pointer, and we're going to store the value, go through, 424 00:22:33,080 --> 00:22:38,660 we're just stepping through, watching it, it's going to call, I think right there at 425 00:22:38,660 --> 00:22:39,380 the bottom of your screen. 426 00:22:39,380 --> 00:22:42,600 The bottom of your screen is where it calls strcat. 427 00:22:43,920 --> 00:22:49,600 But right now we're going to watch, I can't remember how I did this, oh yes, I call strcat. 428 00:22:50,620 --> 00:22:55,580 First I look at our stack pointer and I look at the frame pointer, our caller stack frame, 429 00:22:56,240 --> 00:23:04,220 and then I step over that instruction, which we'll call strcat, and we're going to watch 430 00:23:04,220 --> 00:23:05,140 what happens after that. 431 00:23:06,680 --> 00:23:09,180 The colon, E, means step to the next instruction. 432 00:23:09,180 --> 00:23:12,040 But don't follow any jumps or calls. 433 00:23:14,120 --> 00:23:21,020 As you can see, the saved program counter is overwritten, as is his entire stack frame. 434 00:23:21,580 --> 00:23:22,780 He's not happy. 435 00:23:24,600 --> 00:23:30,080 And then I basically just step through to the end, and go right here to where he returns. 436 00:23:30,580 --> 00:23:37,300 And so when he returns, the stuff stored on his stack is loaded off the stack into registers, 437 00:23:37,420 --> 00:23:37,980 and then... 438 00:23:39,180 --> 00:23:45,200 This instruction is flipped over to his caller's local and output registers. 439 00:23:45,940 --> 00:23:50,300 And so now we have them all loaded in, back in control of main, they're all loaded in 440 00:23:50,300 --> 00:23:54,220 there, and we're going to step through the last instructions of main, where it tries 441 00:23:54,220 --> 00:23:59,800 to do a return, right here, and then it says a bus error, because the address 41414141 442 00:23:59,800 --> 00:24:00,700 is not aligned. 443 00:24:00,960 --> 00:24:05,860 And you'll get that last way just to see when you've messed up, quit out of that. 444 00:24:06,920 --> 00:24:09,160 I'll just, I'll run through that again later with the... 445 00:24:09,180 --> 00:24:11,080 Another real-world example. 446 00:24:13,080 --> 00:24:17,860 I'm going to start talking now about how to write assembler code that we'll use as mobile 447 00:24:17,860 --> 00:24:22,700 code, position-independent code, we can just throw in there, and it will just execute 448 00:24:22,700 --> 00:24:24,720 on its own behalf, and take control of the process. 449 00:24:26,460 --> 00:24:32,260 Basically, two ways to write this is you can, using your compiler, you can make a asm block, 450 00:24:32,860 --> 00:24:36,160 which basically just says, this is straight assembly code, and you just write it in there, 451 00:24:36,240 --> 00:24:36,960 compile the program. 452 00:24:37,200 --> 00:24:37,920 You run it. 453 00:24:37,920 --> 00:24:41,520 And if it gives you a shell, you obviously know it's working. 454 00:24:43,100 --> 00:24:48,480 And then, after that, I throw the function into a character array, and then I cast that 455 00:24:48,480 --> 00:24:52,840 array to a function pointer, execute the function pointer as the final stress test. 456 00:24:53,980 --> 00:24:56,160 Here's my first example of some Spark shell code. 457 00:24:56,740 --> 00:24:59,720 This is somewhat brain-dead in some ways, but I'll explain. 458 00:25:02,360 --> 00:25:07,100 This representation does contain null bytes in it, so it's useless, basically. 459 00:25:07,100 --> 00:25:12,160 But it's ordered in a simple-ish way, to show you just how we're going to write it. 460 00:25:13,560 --> 00:25:18,000 I think I'm a bit, I write my shell code at first as if it's a well-behaved function, 461 00:25:18,600 --> 00:25:25,340 so I allocate in a new register window, and I just basically, I'm recalling exec, so 462 00:25:25,340 --> 00:25:30,140 I'm creating the character array of the function to execute, and I'm creating the arg value, 463 00:25:30,280 --> 00:25:30,940 the arg vector. 464 00:25:31,500 --> 00:25:32,400 Throw that in there. 465 00:25:33,040 --> 00:25:37,020 And I'm just giving it a null for the environment pointer, because, okay. 466 00:25:37,100 --> 00:25:38,720 It's a little bit messy, but it's not a problem. 467 00:25:39,500 --> 00:25:46,480 One very handy thing about Spark is that it's big Indian, and so you can write strings 468 00:25:46,480 --> 00:25:48,960 in a relatively straightforward way, just straight to the stack. 469 00:25:52,780 --> 00:25:58,880 One way to do this is, if you're lazy, you, most of the Unixes will come with the octal 470 00:25:58,880 --> 00:26:04,820 dump program, and if you just do echo string pipe octal dump slash x, give me hexadecimal 471 00:26:04,820 --> 00:26:05,060 output. 472 00:26:05,500 --> 00:26:06,620 It'll give you a nice hex. 473 00:26:07,100 --> 00:26:10,600 And I just basically said, just chop it into words, and start storing them on the stack, 474 00:26:10,760 --> 00:26:11,460 and you have a string. 475 00:26:13,020 --> 00:26:17,820 There are, I'm sure there are ways to do the cool little jumping thing that will actually 476 00:26:17,820 --> 00:26:22,280 load the address of the string, so you can just write it straight, but that's a little 477 00:26:22,760 --> 00:26:23,560 over the top for now. 478 00:26:26,280 --> 00:26:31,700 Yeah, and you can basically see I set 59 to the system call number, execute the system 479 00:26:31,700 --> 00:26:31,960 call. 480 00:26:32,400 --> 00:26:37,080 This is, this can basically be looked at as a well-behaved function to just execute. 481 00:26:37,100 --> 00:26:38,360 And I'm just going to somehow, I Hieronymus, I'm going to xeg a shell. 482 00:26:40,000 --> 00:26:41,940 Then I chop it down a little more. 483 00:26:44,080 --> 00:26:46,200 It doesn't assume it's a well behaved function. 484 00:26:46,420 --> 00:26:48,300 I'm lying on that second line, ignore that. 485 00:26:49,020 --> 00:26:54,200 Basically I chop out the save and restores, and I just start using the current stack pointer. 486 00:26:54,460 --> 00:27:00,160 Because in the situation where the overflow occurs the, assuming the well behaved function 487 00:27:00,160 --> 00:27:04,240 assumes that you have valid stack pointers and frame pointers, you can get in situations 488 00:27:04,240 --> 00:27:07,080 where your stack pointer will be pointing to right where it's held. 489 00:27:07,080 --> 00:27:08,800 right behind your code, and 490 00:27:08,800 --> 00:27:10,580 as you're storing memory, you'll be 491 00:27:11,120 --> 00:27:12,940 chasing your code as your code 492 00:27:12,940 --> 00:27:14,680 executes, and you're overwriting behind it, 493 00:27:14,720 --> 00:27:16,300 and you don't want to be there. 494 00:27:19,080 --> 00:27:21,160 This code also will not 495 00:27:21,160 --> 00:27:22,960 work because it assumes that the 496 00:27:22,960 --> 00:27:25,060 frame pointer is valid, but as I discussed 497 00:27:25,060 --> 00:27:27,140 before, the frame pointer will be 498 00:27:27,140 --> 00:27:29,040 the target address, and so you're 499 00:27:29,040 --> 00:27:30,020 stepping on your toes here. 500 00:27:30,740 --> 00:27:32,900 This is another example of just chopping things down. 501 00:27:34,620 --> 00:27:35,800 You can see I 502 00:27:35,800 --> 00:27:38,900 set, here I'm going to explain the 503 00:27:38,900 --> 00:27:40,820 string more, I set the two words in two 504 00:27:40,820 --> 00:27:41,280 following 505 00:27:43,040 --> 00:27:44,960 registers to a stored double word 506 00:27:44,960 --> 00:27:46,440 instruction, starting at the 507 00:27:46,940 --> 00:27:48,980 address of the frame pointer, minus 16, so 508 00:27:48,980 --> 00:27:50,880 it writes the full 8-byte 509 00:27:50,880 --> 00:27:52,800 value down, and 510 00:27:52,800 --> 00:27:54,260 I basically am constructing in memory 511 00:27:55,640 --> 00:27:56,600 the string 512 00:27:56,600 --> 00:27:57,640 followed by 513 00:27:59,520 --> 00:28:00,480 a null, 514 00:28:00,660 --> 00:28:02,440 so that I can use it for both the 515 00:28:03,200 --> 00:28:04,380 name of the program to execute, 516 00:28:04,380 --> 00:28:06,160 and I build a pointer to that 517 00:28:07,100 --> 00:28:08,520 array of character pointers 518 00:28:09,400 --> 00:28:10,660 to use as the arg vector. 519 00:28:11,620 --> 00:28:12,600 If you've seen 520 00:28:12,600 --> 00:28:14,260 Aleph Wan's code in the 521 00:28:14,960 --> 00:28:16,320 expression of the stack for fun and profit, 522 00:28:16,950 --> 00:28:17,740 he does this also. 523 00:28:18,520 --> 00:28:20,360 Very easy and straightforward way to do it. 524 00:28:22,840 --> 00:28:24,840 Here is my even better shell code. 525 00:28:25,020 --> 00:28:26,520 I'm not saying it's really great, but 526 00:28:26,980 --> 00:28:28,840 in writing this, there's an interesting caveat 527 00:28:28,840 --> 00:28:30,900 that is not addressed in 528 00:28:30,900 --> 00:28:32,380 smashing the stack for fun and profit. 529 00:28:34,380 --> 00:28:35,700 Under system v systems, 530 00:28:36,980 --> 00:28:37,520 the 531 00:28:38,580 --> 00:28:40,100 born shell slash bin sh 532 00:28:40,100 --> 00:28:42,320 when passed an effective 533 00:28:42,320 --> 00:28:44,020 UID of less than 100 534 00:28:44,020 --> 00:28:46,360 will discard it, so 535 00:28:46,360 --> 00:28:48,300 that effective UID 536 00:28:48,300 --> 00:28:50,540 is triggered when the program 537 00:28:50,540 --> 00:28:52,440 has the suid bit set, which means 538 00:28:52,440 --> 00:28:54,360 it keeps your real user ID 539 00:28:54,360 --> 00:28:56,640 saying this is who you really are, but effectively 540 00:28:56,640 --> 00:28:58,500 your root, and then it calls the 541 00:28:58,500 --> 00:29:00,540 shell, and the shell discards 542 00:29:00,540 --> 00:29:02,440 the effective UID, and so basically 543 00:29:02,440 --> 00:29:04,080 you've found that you've 544 00:29:04,380 --> 00:29:06,260 avoided a suid program, and you still 545 00:29:06,260 --> 00:29:07,680 have your own privileges, and you're 546 00:29:07,680 --> 00:29:08,900 not very pleased. 547 00:29:09,220 --> 00:29:09,680 Yes? 548 00:29:16,380 --> 00:29:18,320 The second one? 549 00:29:18,960 --> 00:29:20,340 It contains a no-bite 550 00:29:20,340 --> 00:29:22,200 in this. Oh, thank you. 551 00:29:22,420 --> 00:29:24,260 Okay, the set is a synthetic instruction, 552 00:29:24,900 --> 00:29:26,060 meaning the assembler basically 553 00:29:26,060 --> 00:29:27,040 expands it for you. 554 00:29:27,680 --> 00:29:30,540 The set, because everything is 32 bits, 555 00:29:30,640 --> 00:29:32,320 how can you write a 32-bit 556 00:29:32,320 --> 00:29:33,780 value in the instruction? 557 00:29:34,380 --> 00:29:35,320 Because it splits it into two. 558 00:29:35,760 --> 00:29:38,380 It first writes the, uses the set-high 559 00:29:38,380 --> 00:29:40,360 instruction to write the first, the highest 560 00:29:40,360 --> 00:29:42,460 order, 13 bits, to the 561 00:29:42,460 --> 00:29:44,460 register, and then does an 562 00:29:44,460 --> 00:29:46,460 or with the lower 13 bits, with the lower 563 00:29:46,460 --> 00:29:48,380 8 bits, to complete the whole 564 00:29:48,380 --> 00:29:50,420 value. And we'll see when I disassemble the shell 565 00:29:50,420 --> 00:29:51,360 code how it's 566 00:29:52,380 --> 00:29:54,240 changed over, and I'm just lazy, 567 00:29:54,360 --> 00:29:55,800 so I just do the set, because 568 00:29:56,420 --> 00:29:58,380 it's easier to see the string there instead of 569 00:29:58,960 --> 00:29:59,940 in two words. 570 00:30:00,980 --> 00:30:01,740 But yeah, that 571 00:30:01,740 --> 00:30:02,280 will, 572 00:30:05,200 --> 00:30:06,900 eliminate the no-bite. The no-bite will still be 573 00:30:06,900 --> 00:30:08,780 in the set, in the or, 574 00:30:09,520 --> 00:30:10,940 but because of the way that 575 00:30:11,580 --> 00:30:12,960 the opcode for or is 576 00:30:12,960 --> 00:30:14,840 aligned with the bits, it will 577 00:30:14,840 --> 00:30:16,760 not be on the correct boundaries to be 578 00:30:16,760 --> 00:30:18,480 a, in fact, no-bite. 579 00:30:18,680 --> 00:30:19,600 It'll be spread across. 580 00:30:20,800 --> 00:30:22,240 Don't have a diagram of that, but 581 00:30:22,860 --> 00:30:24,920 you can take my word for it, or call me a liar 582 00:30:24,920 --> 00:30:26,880 and chase me out to the parking lot. 583 00:30:27,040 --> 00:30:27,620 It's your choice. 584 00:30:29,840 --> 00:30:30,900 Let's see, nothing else 585 00:30:31,360 --> 00:30:32,680 really change here. 586 00:30:33,240 --> 00:30:34,240 Oh, you'll notice that, 587 00:30:34,380 --> 00:30:36,120 I do not trust the frame pointer anymore, 588 00:30:37,280 --> 00:30:38,080 because I've 589 00:30:38,080 --> 00:30:40,180 stepped through with the assembly debugger, and I'm like, wait, 590 00:30:40,300 --> 00:30:41,740 why am I doing that? That is just whack. 591 00:30:42,280 --> 00:30:44,440 And so everything relative to the stack 592 00:30:44,440 --> 00:30:46,160 pointer, I waste 593 00:30:46,160 --> 00:30:47,960 four bytes before the stack pointer, because 594 00:30:47,960 --> 00:30:50,080 storing straight to the stack pointer introduces 595 00:30:50,080 --> 00:30:51,760 a no-bite. And you'll notice, 596 00:30:53,040 --> 00:30:54,380 when I'm trying to set a register 597 00:30:54,380 --> 00:30:56,360 to zero, I can't use the straightforward instruction 598 00:30:56,360 --> 00:30:57,780 by just setting to zero, 599 00:30:57,900 --> 00:30:59,920 or moving the global register over, 600 00:31:00,740 --> 00:31:02,240 because that introduces a no-bite, so 601 00:31:02,240 --> 00:31:04,340 you just do something like, you know, XORs, 602 00:31:04,380 --> 00:31:04,460 or 603 00:31:06,240 --> 00:31:08,080 there's a thousand different creative ways 604 00:31:08,080 --> 00:31:09,460 you can do that, just to feel fun. 605 00:31:12,880 --> 00:31:14,220 I'm just going to talk a little bit about the 606 00:31:14,220 --> 00:31:16,240 delivery, but not that much, 607 00:31:16,300 --> 00:31:17,860 because it has basically been treated 608 00:31:17,860 --> 00:31:19,480 better than I could by Greg Hoagland. 609 00:31:21,300 --> 00:31:22,520 Same on other architectures, 610 00:31:22,520 --> 00:31:24,200 either. You need to do the no-op sled, 611 00:31:24,560 --> 00:31:25,740 and then the shellcode, 612 00:31:26,260 --> 00:31:26,860 and then 613 00:31:28,400 --> 00:31:30,060 write the jump address off into infinity, 614 00:31:30,200 --> 00:31:31,220 and let it jump back, 615 00:31:32,640 --> 00:31:33,300 which is, 616 00:31:33,340 --> 00:31:34,220 has the problem, 617 00:31:34,380 --> 00:31:36,440 of if the caller of the overflowable 618 00:31:36,440 --> 00:31:37,960 function calls another function, 619 00:31:38,180 --> 00:31:40,220 you're not necessarily toast, you're just 620 00:31:40,220 --> 00:31:41,580 basically dodging bullets. 621 00:31:43,060 --> 00:31:44,320 Or you can just write the 622 00:31:44,320 --> 00:31:46,300 jump address to overwrite 623 00:31:46,300 --> 00:31:48,360 the saved program counter, 624 00:31:48,500 --> 00:31:50,140 then put the no-ops after it, 625 00:31:50,160 --> 00:31:52,200 and the code after it, so basically you're jumping backwards 626 00:31:52,200 --> 00:31:54,200 in the stack to beyond, to the 627 00:31:54,200 --> 00:31:55,480 caller of the caller of 628 00:31:56,860 --> 00:31:58,000 the overflowable function, 629 00:31:58,160 --> 00:31:59,280 the meta-caller in this case. 630 00:32:00,600 --> 00:32:01,040 And 631 00:32:02,100 --> 00:32:03,960 basically, you know, because the register will be, 632 00:32:04,380 --> 00:32:06,660 the saved program counter will be borked by that point, 633 00:32:07,080 --> 00:32:08,560 you don't have to worry about those stack frames, 634 00:32:08,780 --> 00:32:10,360 you can, they can just go to hell. 635 00:32:11,660 --> 00:32:13,040 Greg Hoagland's talked a lot about this 636 00:32:14,600 --> 00:32:15,580 very well, I might add. 637 00:32:16,400 --> 00:32:17,820 Okay, some real-world examples, 638 00:32:18,000 --> 00:32:19,520 if I can find a place to put this microphone. 639 00:32:26,820 --> 00:32:27,140 Okay. 640 00:32:53,640 --> 00:32:54,100 Okay. 641 00:32:58,860 --> 00:33:00,600 Can everyone see the shell? Okay. 642 00:33:01,480 --> 00:33:02,640 Alright, looks good. 643 00:33:02,940 --> 00:33:03,400 Um, 644 00:33:04,380 --> 00:33:04,600 examples. 645 00:33:06,600 --> 00:33:07,940 Okay, first we're going to have our 646 00:33:07,940 --> 00:33:09,500 nice little simple smash me example. 647 00:33:10,740 --> 00:33:12,240 Here's the source code for that. 648 00:33:13,120 --> 00:33:14,600 Very, very simple. 649 00:33:14,860 --> 00:33:16,220 Um, smash with the argv1 650 00:33:17,060 --> 00:33:18,560 stircat to 128 651 00:33:18,560 --> 00:33:19,560 byte buffer. 652 00:33:20,000 --> 00:33:22,460 Now we run our meta-smash me, which will 653 00:33:22,460 --> 00:33:23,520 smash, smash me. 654 00:33:25,200 --> 00:33:26,160 Um, one 655 00:33:26,160 --> 00:33:28,460 thing you'll basically always 656 00:33:28,460 --> 00:33:30,280 see is the calling function will 657 00:33:30,280 --> 00:33:32,680 get the value of its stack pointer 658 00:33:32,680 --> 00:33:34,280 because it'll, and 659 00:33:34,380 --> 00:33:36,080 it'll calculate the offset from its stack pointer 660 00:33:36,080 --> 00:33:37,580 so it can try and guess the stack pointer 661 00:33:38,080 --> 00:33:39,780 of the function it's trying to overflow 662 00:33:39,780 --> 00:33:42,720 because there'll always be a defined number of bytes 663 00:33:42,720 --> 00:33:43,640 down the stack, 664 00:33:43,820 --> 00:33:45,880 a certain number of function calls down the stack. 665 00:33:48,220 --> 00:33:49,900 and so basically what you're going to be doing is 666 00:33:49,900 --> 00:33:50,980 you're just going to be creating 667 00:33:51,540 --> 00:33:52,540 a very large string, 668 00:33:53,120 --> 00:33:53,340 um, 669 00:33:53,840 --> 00:33:56,000 in this program what I do is I write, 670 00:33:56,600 --> 00:33:57,040 um, 671 00:33:57,260 --> 00:33:59,940 I, I pass in the argument of the buffer size 672 00:33:59,940 --> 00:34:01,000 that I'm trying to overflow, 673 00:34:01,280 --> 00:34:02,580 and so what I do is I write 674 00:34:02,580 --> 00:34:03,680 no ops, 675 00:34:03,680 --> 00:34:05,700 all the way up to where the shellcode must fit 676 00:34:05,700 --> 00:34:07,940 then write the shellcode so it's all within the buffer 677 00:34:07,940 --> 00:34:09,620 and then just 678 00:34:09,620 --> 00:34:11,420 write tons of return addresses 679 00:34:11,420 --> 00:34:13,540 and the return address is calculated 680 00:34:13,540 --> 00:34:15,620 as an offset from the stack pointer 681 00:34:15,620 --> 00:34:18,140 of the metasmashme 682 00:34:18,140 --> 00:34:18,320 process 683 00:34:20,180 --> 00:34:21,640 so I just calculate the egg size 684 00:34:21,640 --> 00:34:25,300 and it kind of just tells you what it's doing 685 00:34:26,920 --> 00:34:27,400 and 686 00:34:27,400 --> 00:34:29,700 writes, like the noop I have here 687 00:34:30,380 --> 00:34:30,860 is 688 00:34:30,860 --> 00:34:33,480 I cannot remember what instruction that is 689 00:34:33,480 --> 00:34:35,260 just trust me that it's a basic instruction 690 00:34:35,260 --> 00:34:37,260 that does nothing, essentially 691 00:34:37,260 --> 00:34:41,720 and just copy the memory 692 00:34:41,720 --> 00:34:43,620 into the egg 693 00:34:43,620 --> 00:34:45,720 and so the egg represents the entire string 694 00:34:45,720 --> 00:34:46,540 I'm trying to pass it with 695 00:34:47,120 --> 00:34:48,180 and I call the function 696 00:34:48,180 --> 00:34:51,100 so let's see what happens if 697 00:34:51,100 --> 00:34:52,820 when we say the offset is zero 698 00:34:54,060 --> 00:34:55,640 notice that the shellcode 699 00:34:55,640 --> 00:34:57,840 I'm using in this example is 64 bytes 700 00:34:57,840 --> 00:34:59,780 so we'll have 64 bytes of noops 701 00:35:00,740 --> 00:35:01,220 and 702 00:35:01,220 --> 00:35:03,180 this shellcode, so we don't have 703 00:35:03,180 --> 00:35:04,200 that big of a window 704 00:35:06,720 --> 00:35:07,540 it's not happy 705 00:35:08,180 --> 00:35:09,400 so fire up our debugger 706 00:35:10,640 --> 00:35:11,080 metasmashme 707 00:35:13,280 --> 00:35:13,720 smashme 708 00:35:13,720 --> 00:35:14,360 and the core 709 00:35:15,160 --> 00:35:16,680 legal instructions for the registers 710 00:35:17,780 --> 00:35:19,840 notice how the registers are just basically splatted 711 00:35:20,420 --> 00:35:21,780 and so we can just 712 00:35:23,980 --> 00:35:26,180 check out our frame pointers, see what they point to 713 00:35:26,180 --> 00:35:31,220 they point to themselves again, because basically I did not go back far enough in the stack 714 00:35:31,220 --> 00:35:31,720 where I'm just 715 00:35:31,720 --> 00:35:32,700 pointing back at my 716 00:35:33,180 --> 00:35:34,560 target address, so let's see 717 00:35:35,180 --> 00:35:37,380 minus 500, 500 hex, notice 718 00:35:37,380 --> 00:35:39,820 that is well beyond it 719 00:35:39,820 --> 00:35:40,980 okay so what I'm going to do 720 00:35:41,820 --> 00:35:42,320 is 721 00:35:53,100 --> 00:35:54,660 put my shellcode 722 00:35:54,660 --> 00:35:55,820 actually no, I'll look at 723 00:35:57,540 --> 00:35:58,980 look at my noop 724 00:35:59,350 --> 00:36:00,440 you'll see that byte there 725 00:36:01,060 --> 00:36:03,160 and basically I'm going to search the shellcode 726 00:36:03,180 --> 00:36:03,500 through memory 727 00:36:04,260 --> 00:36:05,980 for where that thing is 728 00:36:05,980 --> 00:36:08,520 and that'll basically calculate the offset for me 729 00:36:09,020 --> 00:36:10,360 so I'm going to say we'll start at 730 00:36:11,140 --> 00:36:12,760 500 hex bytes 731 00:36:13,480 --> 00:36:15,320 down the stack from the frame pointer 732 00:36:15,320 --> 00:36:18,540 do a search for the 32-bit value 733 00:36:21,400 --> 00:36:21,920 alright 734 00:36:28,300 --> 00:36:29,800 search for that value 735 00:36:30,600 --> 00:36:32,360 shows me the first occurrence of it is 736 00:36:32,360 --> 00:36:33,140 and 737 00:36:34,900 --> 00:36:36,800 now I'm going to do my 738 00:36:38,200 --> 00:36:39,860 poor man's 739 00:36:39,860 --> 00:36:40,860 hex calculator 740 00:36:48,320 --> 00:36:51,140 is that the value we want 741 00:36:51,140 --> 00:36:53,020 980 742 00:36:53,020 --> 00:36:53,400 980 743 00:36:53,400 --> 00:36:54,420 980 744 00:36:55,480 --> 00:36:56,440 980 745 00:36:57,560 --> 00:36:58,520 980 746 00:36:59,820 --> 00:37:01,300 so it's 747 00:37:01,300 --> 00:37:02,340 that right there is the value of 980 748 00:37:02,340 --> 00:37:02,420 so I am trying to find out 749 00:37:02,420 --> 00:37:02,960 but there is our offset 750 00:37:03,780 --> 00:37:04,300 so 751 00:37:05,200 --> 00:37:06,780 let's quit out of that and let's 752 00:37:06,780 --> 00:37:08,540 put GDB to the test 753 00:37:08,540 --> 00:37:11,000 I'm gonna smash me 128 bytes 754 00:37:11,000 --> 00:37:12,340 go back 755 00:37:14,420 --> 00:37:15,420 we have a shell 756 00:37:15,420 --> 00:37:17,760 we basically landed exactly at the first noop 757 00:37:18,720 --> 00:37:19,760 thank you 758 00:37:24,680 --> 00:37:27,320 but that's some precision that we don't really need 759 00:37:27,920 --> 00:37:32,320 basically we know that we have 64 bytes so basically we only have to be within 50 bytes or so 760 00:37:32,340 --> 00:37:39,720 or so. So we can just go back and go, you know, try 1,000. No, not happy. 1,050. Bingo. 761 00:37:40,320 --> 00:37:46,320 And so the larger the buffer is, basically, the more leeway you have, which we'll go and 762 00:37:46,320 --> 00:37:53,180 we'll see an ellipsis example. This is old. This was discovered by Onion, I think, in 763 00:37:53,180 --> 00:37:59,280 September 1998 or somewhere like that, and Sun took about a year to post a fix for it. 764 00:37:59,280 --> 00:38:03,840 But, so I just took all the patches off my system. I'm feeling kind of vulnerable right 765 00:38:03,840 --> 00:38:12,340 now, but it's for the greater good. The details of this bug are, there's an overflow ellipsis 766 00:38:12,340 --> 00:38:18,180 in its parsing of the LC messages environment variable, where you can overflow that, and 767 00:38:18,180 --> 00:38:24,220 basically, so any Seward program becomes vulnerable to it. So here's my little program right here. 768 00:38:24,340 --> 00:38:27,420 I just ask what program to call, how big the buffer is. 769 00:38:29,280 --> 00:38:33,280 And what the offset is. And, you know, I'll show you the program in a second. 770 00:38:35,320 --> 00:38:42,660 Pretty much the same thing as the last one. Just throws in a new environment. You know, 771 00:38:42,740 --> 00:38:51,060 you will have to, you'll have to basically write a program to exploit each one you're 772 00:38:51,060 --> 00:38:54,020 going for, typically, just so you can customize it, but it's not that big of a deal. 773 00:38:54,460 --> 00:38:58,520 And what we can do is we can then, I'm just going to try, oh, let's go for bin. 774 00:39:00,580 --> 00:39:06,660 RSH, and I basically went through with Perl and basically kept giving it, giving larger, 775 00:39:09,100 --> 00:39:12,760 larger buffers in LC messages until I got one that died. It was somewhere around a thousand 776 00:39:12,760 --> 00:39:16,060 bytes. That's what I'm going to assume the size of the buffer is. So it's offset zero. 777 00:39:18,120 --> 00:39:25,480 It dies. Okay. Well, I know now that because it is a thousand bytes of no ops, or a thousand 778 00:39:25,480 --> 00:39:25,980 minus 64. 779 00:39:27,120 --> 00:39:29,260 I have a very gated buffer. 780 00:39:29,280 --> 00:39:32,800 It's a very deep and large window. And so I'm just going to try by offsets of 500. 781 00:39:33,660 --> 00:39:34,060 No. 782 00:39:38,000 --> 00:39:38,400 No. 783 00:39:40,740 --> 00:39:41,400 There we go. 784 00:39:43,300 --> 00:39:48,440 And that basically gives me a root shell because in this, the shell code that I'm using, I 785 00:39:48,440 --> 00:39:53,840 made sure to call set UID zero before I do that in bin shell, so bin shell is happy and 786 00:39:53,840 --> 00:39:54,320 trust me. 787 00:39:56,200 --> 00:39:57,420 And it's basically like that. 788 00:39:57,480 --> 00:39:59,260 I can use any SUIT program on this. 789 00:39:59,280 --> 00:40:03,460 It's on the system at this point, so let's do a find user bin. 790 00:40:07,640 --> 00:40:08,080 Okay. 791 00:40:08,240 --> 00:40:09,120 Anyone have a favorite? 792 00:40:11,380 --> 00:40:14,320 I'll do bin password because that one's nice and easy. 793 00:40:14,820 --> 00:40:18,220 But I basically just sat down today and decided which ones I could get. 794 00:40:18,500 --> 00:40:22,060 And basically, some of these didn't have the overflow in them because they didn't use the 795 00:40:22,060 --> 00:40:23,980 locale support in libc to use it. 796 00:40:24,060 --> 00:40:25,380 But the vast majority of them did. 797 00:40:25,520 --> 00:40:27,760 So let's start with password. 798 00:40:28,480 --> 00:40:28,920 Okay. 799 00:40:30,400 --> 00:40:31,020 Oh, wow. 800 00:40:33,560 --> 00:40:36,440 Looks like they don't go very far down in the stack and they make it really easy for 801 00:40:36,440 --> 00:40:36,580 us. 802 00:40:39,560 --> 00:40:40,380 So let's see. 803 00:40:40,440 --> 00:40:42,700 What else do I have that's really fun to show you? 804 00:40:43,620 --> 00:40:43,980 Okay. 805 00:40:45,840 --> 00:40:49,240 Let's go for some really cool shell code that mostly works. 806 00:40:52,120 --> 00:40:53,820 I spent the last couple of days on this. 807 00:40:55,100 --> 00:40:56,220 Strange, strange bug. 808 00:40:56,400 --> 00:40:57,000 It's driving me nuts. 809 00:40:59,320 --> 00:41:03,000 But here's an alternate way to develop shell code instead of using the Asim blocks. 810 00:41:03,700 --> 00:41:09,220 Just write the assembly file and basically throw it through the assembler, create the 811 00:41:09,220 --> 00:41:13,740 object file, and then now you have a main function in a C program that just calls this 812 00:41:13,740 --> 00:41:14,820 function, bind shell. 813 00:41:15,640 --> 00:41:19,900 And that's just a simple way for me to test it so I can go through here. 814 00:41:20,020 --> 00:41:23,100 And mostly because the Asim block just makes Emacs go hairy. 815 00:41:23,300 --> 00:41:24,980 And I like Emacs. 816 00:41:25,120 --> 00:41:25,340 So. 817 00:41:26,200 --> 00:41:27,000 Don't throw anything. 818 00:41:28,540 --> 00:41:28,940 Okay. 819 00:41:29,020 --> 00:41:29,360 What I'm doing. 820 00:41:29,480 --> 00:41:29,640 Oh. 821 00:41:29,700 --> 00:41:30,160 Let's see. 822 00:41:30,220 --> 00:41:31,320 Where's the source for this originally? 823 00:41:39,680 --> 00:41:43,300 First I wrote basically what I want to do in C. Create a socket. 824 00:41:43,680 --> 00:41:44,440 Set it up. 825 00:41:44,500 --> 00:41:44,880 Bind it. 826 00:41:44,960 --> 00:41:45,300 Listen. 827 00:41:45,520 --> 00:41:46,460 Set the first connection. 828 00:41:47,480 --> 00:41:50,960 Dupe the file descriptors for standard in, standard out, standard error to the socket. 829 00:41:51,120 --> 00:41:52,140 And run bin shell. 830 00:41:54,520 --> 00:41:55,320 And that's it. 831 00:41:55,340 --> 00:41:56,300 I just kind of went through. 832 00:42:00,600 --> 00:42:03,960 Translated this into assembly because everything is just a system call. 833 00:42:04,640 --> 00:42:05,000 So. 834 00:42:05,640 --> 00:42:06,660 I do a trap. 835 00:42:06,840 --> 00:42:07,320 Let's see. 836 00:42:07,440 --> 00:42:09,420 Right there is the socket call. 837 00:42:09,940 --> 00:42:10,720 By 230. 838 00:42:10,960 --> 00:42:11,400 Just look through. 839 00:42:11,580 --> 00:42:15,240 These, the higher numbered ones will change from system to system so you'll have to look 840 00:42:15,240 --> 00:42:17,660 them up on, if you don't have Linux or BSD on there. 841 00:42:19,000 --> 00:42:21,140 Just straightforward assembly programming basically. 842 00:42:21,420 --> 00:42:22,220 Going through. 843 00:42:23,620 --> 00:42:24,360 Go bind. 844 00:42:27,060 --> 00:42:28,180 Store it all. 845 00:42:28,360 --> 00:42:29,140 Yada, yada, yada. 846 00:42:30,200 --> 00:42:34,160 You know, you compile and I just insert in my standard shell code right there. 847 00:42:35,080 --> 00:42:39,000 Using the compiler to output assembly code will be very helpful in figuring out how the 848 00:42:39,000 --> 00:42:39,760 compiler does stuff. 849 00:42:39,980 --> 00:42:44,360 But it is deceptive in a lot of ways because the compiler doesn't like telling you. 850 00:42:44,580 --> 00:42:48,100 Or in the various libraries that it's just doing system calls for all these. 851 00:42:48,240 --> 00:42:50,500 So you'll go through like six different layered functions. 852 00:42:50,800 --> 00:42:53,140 Underscore, underscore, socket, underscore, capital U. 853 00:42:53,140 --> 00:42:55,800 That'll finally say, oh, I just do a trap. 854 00:42:57,040 --> 00:43:00,780 But just to look through syscall.h and you'll see what it really does. 855 00:43:01,360 --> 00:43:02,380 It'll get angry at you. 856 00:43:03,440 --> 00:43:04,640 But we tested. 857 00:43:04,880 --> 00:43:07,560 I just compiled it and linked the two things together. 858 00:43:08,520 --> 00:43:09,440 Oh yeah. 859 00:43:09,640 --> 00:43:10,360 That's the bug. 860 00:43:10,500 --> 00:43:15,480 For some reason when I run it straight it decides that it will not block and wait for 861 00:43:15,480 --> 00:43:15,960 it to accept. 862 00:43:16,240 --> 00:43:18,360 It'll just kind of do something. 863 00:43:18,560 --> 00:43:21,880 And the thread will just continue on and execute the shell. 864 00:43:21,880 --> 00:43:27,020 But when I run it through the debugger and say, what's it called? 865 00:43:27,480 --> 00:43:28,880 Bind shell break. 866 00:43:29,580 --> 00:43:30,180 And I run it. 867 00:43:31,180 --> 00:43:32,240 And I say, yeah, continue. 868 00:43:32,540 --> 00:43:32,840 Oh, no. 869 00:43:34,520 --> 00:43:38,920 And I just told it to bind. 870 00:43:39,020 --> 00:43:40,360 To local host part 2000. 871 00:43:43,320 --> 00:43:43,680 Yes. 872 00:43:43,860 --> 00:43:44,460 Keep going. 873 00:43:44,660 --> 00:43:47,440 It likes to say, I'm about to exec something and things will change. 874 00:43:47,540 --> 00:43:48,700 So I'll stop for you. 875 00:43:48,840 --> 00:43:50,220 But just ignore that. 876 00:43:50,480 --> 00:43:51,860 And basically we have a very, very, very, very, very, very, very, very, very, very, 877 00:43:51,860 --> 00:43:54,720 very mutated, very ugly environmented shell right here. 878 00:43:55,560 --> 00:43:56,580 It's not found. 879 00:43:56,920 --> 00:44:02,900 And you can get enough done from here to do what you need to do. 880 00:44:03,300 --> 00:44:11,200 And, obviously, it's running as a NAT because I just ran it for the command line but you 881 00:44:11,200 --> 00:44:17,060 just basically through the things I've showed you convert to shell code and throw in the 882 00:44:17,060 --> 00:44:19,080 process and you'll have a bind shell. 883 00:44:20,120 --> 00:44:21,840 To do so, I have a nice shell. 884 00:44:28,900 --> 00:44:34,480 Just to help me out with writing these, I made my disk 2H, and so if I go through to 885 00:44:34,480 --> 00:44:44,180 my code, let's see, what I do is I write 3.c, test it out in there, then I disassemble it 886 00:44:44,180 --> 00:44:52,280 to a 3 dot, well, I disassemble it to 3.dis, which says diff main 3, little noise at the 887 00:44:52,280 --> 00:44:56,560 top, so I just chop those off until I just have the disassembled code, shouldn't hurt 888 00:44:56,560 --> 00:45:01,940 you to cut out three lines, I don't want the script to do everything for you, and then 889 00:45:01,940 --> 00:45:06,400 just a simple filter, you can do this in Perl, you can do this in whatever you want, but 890 00:45:06,400 --> 00:45:13,940 I did it in C because it's fun, 3.dis, pipe to that, and it gives you a nice little header 891 00:45:13,940 --> 00:45:14,100 file. 892 00:45:14,180 --> 00:45:18,960 It's a nice little header file to include, and this is a quick way to check for null 893 00:45:18,960 --> 00:45:27,540 bytes, and just look at your code, hand side by side, and feel warm and fuzzy, but basically 894 00:45:27,540 --> 00:45:33,240 with just a couple little tools, you can just tinker around with writing shell code and 895 00:45:33,240 --> 00:45:38,340 stuff, and then amazingly you will wake up and say, wait a minute, I'm actually decent 896 00:45:38,340 --> 00:45:43,920 at assembly programming now, this is useful, to be the example. 897 00:45:44,180 --> 00:45:47,660 I didn't do well in my assembly class until I started doing this stuff, and of course 898 00:45:47,660 --> 00:45:51,760 this semester it ended, and now I know everything and can pay attention in class anyway, so 899 00:45:53,220 --> 00:45:54,220 grades mean nothing. 900 00:45:55,960 --> 00:45:58,740 I don't think I have anything else to show you, and I think I'm out of time. 901 00:46:04,720 --> 00:46:13,400 Oh yes, some links to useful things, linuxassembly.org, obviously focuses on Linux and Intel architecture, 902 00:46:14,180 --> 00:46:18,500 but they have some great info on there, a little straight from the beaten path, and 903 00:46:18,500 --> 00:46:20,160 show you some Spark stuff, some BSD stuff. 904 00:46:21,280 --> 00:46:25,240 They have a nice little suite of basically the bin util, or a lot of the smaller utilities 905 00:46:25,240 --> 00:46:31,720 written in assembly, so your standard 100k executable is now like 3k, because all they 906 00:46:31,720 --> 00:46:33,360 do is call the traps themselves. 907 00:46:33,780 --> 00:46:37,200 It's not portable, but it's really small and used for good disks. 908 00:46:38,780 --> 00:46:43,460 shellcode.org, I just saw come across, see their bug tracker, volume dev, some mailing 909 00:46:43,460 --> 00:46:43,680 list. 910 00:46:43,680 --> 00:46:49,400 Today, currently down, we'll have a lot of resources to various shellcodes for various 911 00:46:49,400 --> 00:46:50,260 operating systems. 912 00:46:52,100 --> 00:46:58,680 Flack55 has a really nice article about writing shellcode on MIPS under IRIX, MIPS also being 913 00:46:58,680 --> 00:47:05,320 another of the pioneering RISC chips, very similar to this, it's a very good read also. 914 00:47:06,140 --> 00:47:13,160 And this stuff eventually will be on dopesquad.net slash security, whenever I finish it up and 915 00:47:13,160 --> 00:47:18,880 put it up there, so you can look there, but if you see a 404, don't have a heart attack.