26.07.2018 Views

hacking-the-art-of-exploitation

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

methods. If ei<strong>the</strong>r <strong>of</strong> <strong>the</strong>se passwords is used, <strong>the</strong> function returns 1, which<br />

grants access. You should be able to figure most <strong>of</strong> that out just by looking at<br />

<strong>the</strong> source code before compiling it. Use <strong>the</strong> -g option when you do compile<br />

it, though, since we will be debugging this later.<br />

reader@<strong>hacking</strong>:~/booksrc $ gcc -g -o auth_overflow auth_overflow.c<br />

reader@<strong>hacking</strong>:~/booksrc $ ./auth_overflow<br />

Usage: ./auth_overflow <br />

reader@<strong>hacking</strong>:~/booksrc $ ./auth_overflow test<br />

Access Denied.<br />

reader@<strong>hacking</strong>:~/booksrc $ ./auth_overflow brillig<br />

-=-=-=-=-=-=-=-=-=-=-=-=-=-<br />

Access Granted.<br />

-=-=-=-=-=-=-=-=-=-=-=-=-=reader@<strong>hacking</strong>:~/booksrc<br />

$ ./auth_overflow outgrabe<br />

-=-=-=-=-=-=-=-=-=-=-=-=-=-<br />

Access Granted.<br />

-=-=-=-=-=-=-=-=-=-=-=-=-=reader@<strong>hacking</strong>:~/booksrc<br />

$<br />

So far, everything works as <strong>the</strong> source code says it should. This is to be<br />

expected from something as deterministic as a computer program. But an<br />

overflow can lead to unexpected and even contradictory behavior, allowing<br />

access without a proper password.<br />

reader@<strong>hacking</strong>:~/booksrc $ ./auth_overflow AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA<br />

-=-=-=-=-=-=-=-=-=-=-=-=-=-<br />

Access Granted.<br />

-=-=-=-=-=-=-=-=-=-=-=-=-=reader@<strong>hacking</strong>:~/booksrc<br />

$<br />

You may have already figured out what happened, but let’s look at this<br />

with a debugger to see <strong>the</strong> specifics <strong>of</strong> it.<br />

reader@<strong>hacking</strong>:~/booksrc $ gdb -q ./auth_overflow<br />

Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".<br />

(gdb) list 1<br />

1 #include <br />

2 #include <br />

3 #include <br />

4<br />

5 int check_au<strong>the</strong>ntication(char *password) {<br />

6 int auth_flag = 0;<br />

7 char password_buffer[16];<br />

8<br />

9 strcpy(password_buffer, password);<br />

10<br />

(gdb)<br />

Exploitation 123

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!