Home > Articles > Security > General Security and Privacy

  • Print
  • + Share This
This chapter is from the book

1.5 Tamperproofing

One of the uses of obfuscation is to add so much confusion to a program that an adversary will give up trying to understand or modify it. But what if Axel is able to break through Doris’ obfuscation defenses, then what? Well, in addition to obfuscating her code, Doris can also tamperproof it. This means that if Axel tries to make modifications to Doris’ program, he will be left with a program with unintended side effects: The cracked program may simply refuse to run, it could crash randomly, it could destroy files on Axel’s computer, or it could phone home and tell Doris about Axel’s attack, and so on.

In general, a tamperproofing algorithm performs two duties. First, it has to detect that the program has been modified. A common strategy is to compute a checksum over the code and compare it to an expected value. An alternative strategy is check that the program is in an acceptable execution state by examining the values of variables.

Once tampering has been detected, the second duty of a tamperproofing algorithm is to execute the tamper response mechanism, for example causing the program to fail. This is actually fairly tricky: You don’t want to alert the attacker to the location of the tamperproofing code since that will make it easier for him to disable it. For example, tamperproofing code like

if (tampering-detected()) abort()

is much too weak because it’s easy for the attacker to trace back from the location where the program failed (the call to abort()) to the location where tampering was detected. Once he has that information, the tamperproofing is easy to disable. A good tamperproofing system separates the tamper detection from the tamper response in both space and time.

1.5.1 Applications of Tamperproofing

Tamperproofing is important in digital rights management systems where any change to the code could allow Axel to enjoy media for free. Here’s a top-level view of a DRM system:

static final long key = 0 xb0b5b0b5 ;
void play ( byte [] media ) {
   // if (! hasPaidMoney (" Bob ")) return ;
   System . out . print ( key );    
   byte [] clear = decrypt (key , media );
   System . out . print ( clear );  
   float [] analog = decode ( clear );
   System . out . print ( analog ); 
   device . write ( analog );
}

Notice how Axel has been able to delete a check (light gray) that prevented him from playing the media if he had no money, and to insert extra code (dark gray) to dump the secret cryptographic key and the decrypted (digital and analog) media. In general, tampering with a program can involve deleting code, inserting new code, or modifying original code. All can be equally devastating.

Another common use of tamperproofing is to protect a license check. Doris inserts a check in the code that stops Axel from running the program after a specific date or after a certain number of executions, or to let no more than a given number of Axel’s employees run the program at any one time. Axel, being an unscrupulous user, locates and disables the license check to give him unlimited use of the program. Doris can obfuscate her program (to make it hard for Axel to find the license code), but she can also tamperproof the license check so that if Axel finds and alters it, the program will no longer function properly:

There are situations where simply failing when tampering is detected isn’t enough; you also need to alert someone that an attack has been attempted. For example, consider a multi-player online computer game where, for performance reasons, the client program caches information (such as local maps) that it won’t let the player see. A player who can hack around such limitations will get an unfair advantage over his competitors. This is a serious problem for the game manufacturer, since players who become disillusioned with the game because of rampant cheating may turn to another one. It’s therefore essential for the game administrators to detect any attempt at tampering so that anyone who tries to cheat can immediately be ejected from the game. The term we use for this problem is remote tamperproofing. The goal is to make sure that a program running on a remote untrusted host is the correct, unadulterated version, and that it is running in a safe environment. “Safe” here can mean that the program is running on the correct hardware (and not under a hacked emulator), that the operating system is at the correct patch-level, that all environment variables have reasonable values, that the process has no debugger attached, and so on. As long as the client code determines that it is running safely and hasn’t been tampered with, it sends back a stream of surreptitious “I’m-OK” signals to the server:

In this figure, the program is using steganographic techniques to embed this secret bitstream in TCP/IP headers.

Even if you don’t intend to cause harm to a cheating game player, monitoring your protected programs for evidence of an ongoing attack can still be useful. We know of at least one major software protection company that includes a phone home facility in their code that allows them to watch, in real time, an attack in progress. Being able to see which strategies the attacker is using, see which strategies are successful, measure how long an attack takes to complete and thus, ultimately, get a feel for which protection algorithms are effective and which are not is definitely useful. However, we know that other software protection companies eschew such eavesdropping because of its problematic privacy issues.

1.5.2 An Example

If you have ever run a signed Java applet or installed a program signed by Microsoft, you’ve already had experience with programs designed to detect tampering. A signed program carries a certificate issued by a known authority that can be used to detect if some part of the program has been changed. Usually such detection is extrinsic to the program itself. For example, if you try to install a signed Microsoft program that has been tampered with, the OS will check that the signature is one that Microsoft trusts and that the program has not been altered since it was signed. Unfortunately, the obvious way of extending such a scheme to allow a program to check itself for tampering is not effective. To see this, have a look at the program in Listing 1.5▸36, which converts temperatures expressed in Fahrenheit into Celsius. The function bad-check-for-tampering protects the program from tampering by comparing a checksum of the program file to a checksum computed when the program was compiled. If they’re not the same, the program simply quits.

Can you think of any difficulties in writing such a program? One problem is that checksum is embedded in the program and as a result affects the checksum itself! To successfully construct such a program requires searching for a value that, when inserted into the program as a checksum, results in the program having that value as a checksum.

A further problem is that in spite of its clever construction, once a function has been identified by the attacker as a tamper-detection function, it’s easy to remove any calls to it.

The function better-check-for-tampering is slightly better. Instead of merely checking for tampering, it incorporates the output of the checksum into the code itself. If the program is altered, the value returned by this function changes, which in turn makes the program subtly incorrect.

In spite of the improvements, better-check-for-tampering remains vulnerable to the same attack as bad-check-for-tampering. Both tamper-checking functions are easy to identify, because programs rarely attempt to read themselves. Once a function is identified as a tamper-checking function, it can be replaced by a simple function that returns the original checksum as a constant. Thereafter, an attacker can go ahead and modify the program arbitrarily.

These weaknesses notwithstanding, checksumming code forms the basis of many tamperproof detection techniques used in practice. You’ll see some of them in Chapter 7 (Software Tamperproofing).

Listing 1.5. A self-checking program in Java.

import java.io.*;
import java.security.*;

public class tamper {

   public static int checksum-self () {
      File file = new File("tamper.class");
      FileInputStream fr = new FileInputStream (file);
      DigestInputStream sha = new DigestInputStream (fr,
                              MessageDigest.getInstance ("SHA"));
      while (fr.read () != -1) {}
      byte[] digest = sha.getMessageDigest().digest ();
      int result = 12;
      for (int i=0; i < digest.length; i++) {
         result = (result + digest[i]) % 16;
      }
   }
   public static boolean bad-check-for-tampering () throws Exception {
      return checksum-self() != 9;
   }
   public static int better-check-for-tampering () throws Exception {
      return checksum-self();
   }
   public static void main (String args[]) throws Exception {
      if (bad-check-for-tampering()) System.exit (-1);
      float celsius=Integer.parseInt (rgs[0]);
      float fahrenheit=better-check-for-tampering() * celsius / 5 + 32;
      System.out.println (celsius + "C = " + fahrenheit + "F");
    }
}
  • + Share This
  • 🔖 Save To Your Account