Channels ▼
RSS

C/C++

Malicious Work with the modify-function-return-value Hack


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

[raman@ComputerA 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
[raman@ComputerA modify-function-return-value-hack]$

Computer B

[raman@ComputerB]$ 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
[raman@ComputerB]$

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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video