Further Analysis
Now I know what is causing the application to fail on computer B (the different response from the remote server). On computer A (the success case), the remote server is responding back with a SUCCESS
message to the victim application. However, in a failure case, remote server is responding with a STOP
message to the victim application.
What can be done to exploit this?
- Change the behavior of the remote server so that it always returns
SUCCESS
. This is not always possible because the server is under the control of an administrator or someone else having more authority than me. However, it's possible that even the server can be under the hacker's control in this case, attacking the server makes more sense as it then becomes a generic hack. - Change the victim application so that it does not make its decision based on the response string obtained from the server. This is what I will be discussing here.
Running ltrace
with option -i
(causing ltrace
to give EIP
, the instruction pointer, at the time of particular call) on computer B, I got following:
[0x8048801] recvfrom(3, 0xbfb14690, 100, 0, 0xbfb14708) = 30
The value 0x8048801
is the instruction pointer at the time of making a recvfrom
call. This is the code segment in the victim_client
that is changing the flow of code when executing on computer B. This is the target point to attack.
Disassemble the Victim Application
After disassembling (objdump -d victim_client
) the victim application and looking at the address 0x8048801
, I found that this address resides in a function called get_remote_token
. So this is the function that is responsible for talking to the remote server, as can be guessed from its name. Let's see how this function behaves in a success case verus a failure case; that is, on computer A versus computer B. I will use GDB, the GNU debugger tool, to see what this function returns in both cases. This can be done very easily by putting a breakpoint on function get_remote_token()
, and monitoring the value of the eax
register (the standard position where return values are placed by GCC and the compiler toolchain) when this function is about to return.
Computer A
[[email protected] modify-function-return-value-hack]$ gdb ./victim_client -quiet Reading symbols from /home/raman/DR_DOBBS/modify-function-return-value-hack/victim_client...(no debugging symbols found)...done. (gdb) br get_remote_token Breakpoint 1 at 0x804861a (gdb) r Starting program: /home/raman/DR_DOBBS/modify-function-return-value-hack/victim_client Breakpoint 1, 0x0804861a in get_remote_token () Missing separate debuginfos, use: debuginfo-install glibc-2.13.90-9.i686 (gdb) finish Run till exit from #0 0x0804861a in get_remote_token () 0x080488a2 in main () (gdb) p $eax $1 = 0 (gdb) c Continuing. Program initialized success. Executing rest of the program... [Inferior 1 (process 17122) exited normally] (gdb) q [[email protected] modify-function-return-value-hack]$
Computer B
[[email protected]]$ gdb ./victim_client -quiet Reading symbols from /home/raman/ARTICLE/victim_client...(no debugging symbols found)...done. (gdb) br get_remote_token Breakpoint 1 at 0x804861a (gdb) r Starting program: /home/raman/ARTICLE/victim_client Breakpoint 1, 0x0804861a in get_remote_token () Missing separate debuginfos, use: debuginfo-install glibc-2.14.90-24.fc16.6.i686 (gdb) finish Run till exit from #0 0x0804861a in get_remote_token () 0x080488a2 in main () (gdb) p $eax $1 = 1 (gdb) c Continuing. Could not initialize... exiting [Inferior 1 (process 22508) exited with code 01] (gdb) q [[email protected]]$
The difference between the two runs is the return value of get_remote_token()
. In the case of the valid client (computer A), it returns 0; in the case of the invalid client, it returns 1. Can we forcibly change the return value so that it always returns 0? If this can be done, and it does not break the rest of the application's functionality, then we have successfully pulled off a modify-function-return-value hack.