Connecting to the specified address, we get an interface to enter an address and a port for a “remote printer”.
So, let’s start netcat in listening mode
and pass this as the remote printer. We’ll see the service connects to our local netcat session and waits for some input. After entering some gibberish, the service just prints our input and closes.
Let’s have a look at the disassembled code, that handles the communication:
It just receives our input and prints it back via printf. But since it doesn’t pass a format string, it seems to be a simple format string vulnerability.
Quick test:
Ok, our format string shows up in the 7th and 8th parameter.
After printf the service calls close, so we can just overwrite close.
Nicely enough the RemotePrinter service also contains a method, spitting out the flag quite happily, if called.
So all we have to do is to overwrite close (0x08049c80) with this one (0x08048867).
Starting the service in gdb and adjusting the format string led to the following exploit:
After getting this working locally, all there’s left to do is to open up a nc listener passing our payload: