Main navigation | Main content
This page gives hints for some specific vulnerabilities you might exploit in the BCLPR program. We give our primary suggestion for the easiest-to-attack vulnerability first. But if you find that easy, we also mention a couple more places you could attack.
Our suggestion of the easiest vulnerability in this program to attack is a stack buffer overflow in the function print_centered_string. This function is supposed to copy a text string into the middle of an 80-character buffer, but it doesn't correctly handle the case where the string is longer that will fit in the buffer. If you look at where this function is called, it is called with the global variable title as the argument when the server is printing a plain text (not PDF) file. The title is in turn controlled by the -t command-line option. (The function isn't called if no title is given.)
The title supplied on the command line is processed before being used, but the particular processing here happens to make the attack easier rather than harder, because the processing lets you put bytes with any hexadecimal value other than null into the title, by putting a percent sign in front of the two hex digits for the character. (If you wanted just a literal percent sign, you could use %25 because 0x25 is the ASCII code for a percent sign.)
There are is another complication related to null bytes because the overwrite here uses a null-terminated string. The attacker controls the length of the overwrite, but the attacker controlled bytes can't contain a null byte because that would be a terminator. However because the overwrite uses memcpy, it doesn't write a null terminator after the attacker controlled string. In one sample binary we compiled, the normal return address is 0x00000000004028bf, whereas the address of the attack function we want to jump to is 0x000000000040265f. In your binary the addresses will probably be slightly different. Because x86 addresses are little-endian, a partial overwrite will replace bytes starting from the low part of the address. How many bytes should the attacker try to overwrite to turn the first address into the second?
You may have also noticed that this program has a call to a function in the printf family where the format string is under external control, representing a format-string vulnerability. We haven't discussed as much how to attack these, but you might start looking at it if you have time left after your first attack. You might want to start by just providing a format string with a lot of %lx format specifiers to print the contents of the stack in the area where the function is taking its format parameters. A format string attack will be easiest if you can find one of these values that you can also control.