Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to...

90
c May 27, 2014 Christian Collberg Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 Christian Collberg University of Arizona www.cs.arizona.edu/ ˜ collberg

Transcript of Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to...

Page 1: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

c© May 27, 2014 Christian Collberg

Software Protection:

How to Crack Programs,and

Defend Against Cracking

Minsk, Belarus, Spring 2014

Christian CollbergUniversity of Arizona

www.cs.arizona.edu/˜collberg

Page 2: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

About me

PhD from

Five years on the faculty at

One year at

Currently Professor at

2 / 45

Page 3: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Professional Interests

Software Protection(tigress.cs.arizona.edu)

Compilers

Programming Languages

Scientific Ethics

Secure Provenance(haathi.cs.arizona.edu).

3 / 45

Page 4: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Personal Interests

Travel (35 countries so far. . . )

Photography:www.cs.arizona.edu/˜collberg/#travel

Foreign Languages

Music:

4 / 45

Page 5: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Education

I teach courses on programminglanguages, compilers, computer security.

5 / 45

Page 6: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Contact me

www.cs.arizona.edu/˜collberg

[email protected]

Office: Room 571

MSU, Sector B!See me if you want to talk about

this coursestudying in the UScomputer security researchtravel, Russia, music, languages . . .. . . anything, really!

6 / 45

Page 7: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

This Course

Page 8: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Overview

1 What is Software Protection?2 When do you need Software

Protection?3 Making programs hard to read

(obfuscation).4 Making programs hard to

modify (anti-tamper).

8 / 45

Page 9: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

When? Where? Why?

1 When?

9 / 45

Page 10: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

When? Where? Why?

1 When? Wednesday 18:00

9 / 45

Page 11: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

When? Where? Why?

1 When? Wednesday 18:002 Where?

9 / 45

Page 12: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

When? Where? Why?

1 When? Wednesday 18:002 Where? Auditorium 612

9 / 45

Page 13: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

When? Where? Why?

1 When? Wednesday 18:002 Where? Auditorium 6123 Why?

9 / 45

Page 14: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

When? Where? Why?

1 When? Wednesday 18:002 Where? Auditorium 6123 Why? It will be super cool!

9 / 45

Page 15: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

When? Where? Why?

1 When? Wednesday 18:002 Where? Auditorium 6123 Why? It will be super cool!4 WWW?

9 / 45

Page 16: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

When? Where? Why?

1 When? Wednesday 18:002 Where? Auditorium 6123 Why? It will be super cool!4 WWW?

www.cs.arizona.edu/˜collberg/

Teaching/bsuir/2014

9 / 45

Page 17: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

What we will learn

How to be crack code (be a bad guy!).

How to be protect code (be a good guy!).

Using software protection tools (Tigress).

10 / 45

Page 18: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

What we will do

I will lecture. . .

In-class exercises. . .“Homework” exercises:

Hack this code!Protect this code from hacking!

11 / 45

Page 19: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Prerequisites

An understanding of C programming.

Some assembly code knowledge is good.

Some Unix, like shell commands, editing(emacs, vi), compiling (gcc), debugging(gdb).

It’s good if you know a little aboutcryptography, compilers, and computersecurity, but not necessary.

12 / 45

Page 20: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Class behavior

Please interrupt with questions!

You can ask a question in Russian (ifsomeone will translate for me!).

Bring a linux/Mac OS laptop to class if youwant, but don’t play games, check email,etc.

13 / 45

Page 21: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Today’s lecture

1 Software Protection Scenarios2 Software Protection Tools3 Overview of Obfuscation4 Overview of Tamperproofing

14 / 45

Page 22: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

MATE Scenarios

Page 23: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Software piracy

AliceP

Alice is a software developer.

16 / 45

Page 24: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Software piracy

Alice Bob

P

P

Alice is a software developer.

Bob buys one copy of Alice’s program.

16 / 45

Page 25: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Software piracy

Alice BobP

P

P

P

Alice is a software developer.

Bob buys one copy of Alice’s program.

Bob illegally sells copies to his friends.16 / 45

Page 26: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

License check tampering

......

abort()if (today()>"Aug 17")

Alice

P

17 / 45

Page 27: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

License check tampering

......

abort()if (today()>"Aug 17")

AliceBob

P

17 / 45

Page 28: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

License check tampering

......

abort()if (today()>"Aug 17")

......

if (false)abort()

AliceBob

P

P

Bob removes license checks to be able torun the program whenever he wants.

17 / 45

Page 29: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

License check tampering

if (today()>"Aug 17")abort()

......

......

if (false)abort()

AliceBob

P

PP ′

Bob removes license checks to be able torun the program whenever he wants.

Alice protects her program so that it won’trun after being tampered with.

17 / 45

Page 30: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Malicious reverse engineering

AliceM

P

Alice’s program contains a valuable tradesecret (a clever algorithm or design).

18 / 45

Page 31: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Malicious reverse engineering

Alice BobM

P

Alice’s program contains a valuable tradesecret (a clever algorithm or design).

Bob, a rival developer, copies M into hisown program (code lifting).

18 / 45

Page 32: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Malicious reverse engineering

BobAliceM

P

M

Alice’s program contains a valuable tradesecret (a clever algorithm or design).

Bob, a rival developer, copies M into hisown program (code lifting).

18 / 45

Page 33: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Malicious reverse engineering

Alice BobM

P

MM

Q

Alice’s program contains a valuable tradesecret (a clever algorithm or design).

Bob, a rival developer, copies M into hisown program (code lifting).

18 / 45

Page 34: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Digital rights management (DRM)

Alice

A DRM media player containscryptographic keys that unlock and playencrypted music files.

19 / 45

Page 35: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Digital rights management (DRM)

mediaEncrypted

Alice Bob

A DRM media player containscryptographic keys that unlock and playencrypted music files.

19 / 45

Page 36: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Digital rights management (DRM)

Software Player

media

Crypto keys

EncryptedAlice Bob

A DRM media player containscryptographic keys that unlock and playencrypted music files.

19 / 45

Page 37: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Digital rights management (DRM)

Software Player

Cleartext mediaCrypto keys

Encryptedmedia

Alice Bob

A DRM media player containscryptographic keys that unlock and playencrypted music files.

19 / 45

Page 38: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Digital rights management (DRM)

Software Player

Cleartext mediaCrypto keys

Encryptedmedia

Carol

Alice Bob

A DRM media player containscryptographic keys that unlock and playencrypted music files.

19 / 45

Page 39: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Scenario: Protecting networked

computer games

Alice

P

20 / 45

Page 40: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Scenario: Protecting networked

computer games

BobAlice

P

20 / 45

Page 41: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Scenario: Protecting networked

computer games

Alice Bob

P

P

20 / 45

Page 42: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Scenario: Protecting networked

computer games

Cached data

BobAlice

P

P

20 / 45

Page 43: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Scenario: Protecting networked

computer games

Cached data

BobAlice

P

P

20 / 45

Page 44: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Scenario: Protecting networked

computer games

Cached data

Alice Bob

P

P

20 / 45

Page 45: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Protocol discovery

Call minutes

Alice Bob

P

Alice sells voice-over-IP call minutes.

21 / 45

Page 46: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Protocol discovery

Call minutes

mySkype!

Alice Bob

P P ′

Alice sells voice-over-IP call minutes.

Bob examines the VoIP client to discoverproprietary protocols to build his own rivalclient.

21 / 45

Page 47: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Protecting military software

Alice Bob

The military want to be able to trackclassified software.

22 / 45

Page 48: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Protecting military software

BobAlice

The military want to be able to trackclassified software.In 2001, an EP-3 spy/reconnaissance planelanded on Hainan Island in China after acollision. The crew was unable to destroyall equipment.

22 / 45

Page 49: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Protecting military software

BobAlice

P

The military want to be able to trackclassified software.In 2001, an EP-3 spy/reconnaissance planelanded on Hainan Island in China after acollision. The crew was unable to destroyall equipment.

22 / 45

Page 50: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

The Man-At-The-End Problem

SP

23 / 45

Page 51: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

The Man-At-The-End Problem

SS

P

P

P P

P

23 / 45

Page 52: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

The Man-At-The-End Problem

Emulator

DecompilerDisassembler

DebuggerTracerSlicer

SS

P

P

PP

P

23 / 45

Page 53: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

The Man-At-The-End Problem

TracerSlicer

EmulatorDisassemblerDecompiler

Debugger

SS

P

P

P

P P

23 / 45

Page 54: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

The Man-At-The-End Problem

1. Static/Dynamic Analysis2. Modify3. Test4. Did it work?

SS

P

P

P

PP

23 / 45

Page 55: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

The Man-At-The-End Problem

4. Did it work?

2. Modify1. Static/Dynamic Analysis

3. Test

SS

P

P

PP

P

23 / 45

Page 56: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

The Man-At-The-End Problem

1. Static/dynamic analysis2. Select code3. Select transformation4. Apply transformation5. Done?

SS

P

P

P

P P

23 / 45

Page 57: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

The Man-At-The-End Problem

1. Static/dynamic analysis

3. Select transformation

5. Done?

2. Select codeCode

4. Apply transformationTransformations

SS

P

P

PP

P

23 / 45

Page 58: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

The Man-At-The-End Problem

SS

P

P

P P

P

23 / 45

Page 59: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Tigress

24 / 45

Page 60: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

CodeObfuscation

Page 61: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Code obfuscation

To obfuscate a program means to

transform it into a form that is moredifficult for an adversary tounderstand or change than theoriginal code.

26 / 45

Page 62: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Code obfuscation

To obfuscate a program means to

transform it into a form that is moredifficult for an adversary tounderstand or change than theoriginal code.

Vague definition of difficult:

The obfuscated program requiresmore human time, more money, ormore computing power to analyzethan the original program.

26 / 45

Page 63: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Code obfuscation — Example

obfuscated codepublic class C {

static Object get0(Object[] I) {

Integer I7, I6, I4, I3; int t9, t8;

I7=new Integer(9);

for (;;) {

if (((Integer)I[0]).intValue()%((Integer)I[1]).intValue()==0)

{t9=1; t8=0;} else {t9=0; t8=0;}

I4=new Integer(t8);

I6=new Integer(t9);

if ((I4.intValue()ˆI6.intValue())!=0)

return new Integer(((Integer)I[1]).intValue());

else {

if ((((I7.intValue()+ I7.intValue()*I7.intValue())%2!=0)?0:1)!=1)

return new Integer(0);

I3=new Integer(((Integer)I[0]).intValue()%

((Integer)I[1]).intValue());

I[0]=new Integer(((Integer)I[1]).intValue());

I[1]=new Integer(I3.intValue());

}

}

}27 / 45

Page 64: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Code obfuscation — Example original

codepublic class C {

static int gcd(int x, int y) {

int t;

while (true) {

boolean b = x % y == 0;

if (b) return y;

t = x % y; x = y; y = t;

}

}

}

An obfuscation tool turns the original codeinto obfuscated code.We want obfuscating transformations thatmake the program as hard to understand aspossible.

28 / 45

Page 65: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Types of obfuscation

1 Abstraction transformationsDestroy module structure, classes, functions,etc.!

29 / 45

Page 66: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Types of obfuscation

1 Abstraction transformationsDestroy module structure, classes, functions,etc.!

2 Data transformationsReplace data structures with newrepresentations!

29 / 45

Page 67: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Types of obfuscation

1 Abstraction transformationsDestroy module structure, classes, functions,etc.!

2 Data transformationsReplace data structures with newrepresentations!

3 Control transformationsDestroy if-, while-, repeat-, etc.!

29 / 45

Page 68: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Types of obfuscation

1 Abstraction transformationsDestroy module structure, classes, functions,etc.!

2 Data transformationsReplace data structures with newrepresentations!

3 Control transformationsDestroy if-, while-, repeat-, etc.!

4 Dynamic transformationsMake the program change at runtime!

29 / 45

Page 69: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Obfuscation example: original

program

✞ ☎

int main() {

int y = 6;

y = foo(y);

bar(y,42);

}✝ ✆

✞ ☎

int foo(int x) {

return x*7;

}✝ ✆

✞ ☎

void bar(int x, int z) {

if (x==z)

printf("%i\n",x);

}✝ ✆

30 / 45

Page 70: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

After abstraction transformation✞ ☎

int main() {

int y = 6;

y = foobar(y,99,1);

foobar(y,42,2);

}✝ ✆

✞ ☎

int foobar(int x, int z, int s) {

if (s==1)

return x*7;

else if (s==2)

if (x==z)

printf("%i\n",x);

}✝ ✆

It appears as if main calls the samefunction twice!

31 / 45

Page 71: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

After data transformation✞ ☎

int main() {

int y = 12;

y = foobar(y,99,1);

foobar(y,36,2);

}✝ ✆

✞ ☎

int foobar(int x, int z, int s) {

if (s==1)

return (x*37)%51;

else if (s==2)

if (x==z) {

int x2=x*x % 51, x3=x2*x % 51;

int x4=x2*x2 % 51, x8=x4*x4 % 51;

int x11=x8*x3 % 51; printf("%i\n",x11);

}

}✝ ✆

The integers are encrypted with RSA!32 / 45

Page 72: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

After control transformation

✞ ☎

int foobar(int x, int z, int s) {

char* next = &&cell0;

int retVal = 0;

cell0: next = (s==1)?&&cell1:&&cell2; goto *next;

cell1: retVal=(x*37)%51; goto end;

cell2: next = (s==2)?&&cell3:&&end; goto *next;

cell3: next = (x==z)?&&cell4:&&end; goto *next;

cell4: {

int x2=x*x % 51, x3=x2*x % 51;

int x4=x2*x2 % 51, x8=x4*x4 % 51;

int x11=x8*x3 % 51;

printf("%i\n",x11); goto end;

}

end: return retVal;

}✝ ✆33 / 45

Page 73: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Anti-Tamper

Page 74: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

What is code tampering?

Bob wants to modify the program binary sothat it does something different than wewant:

remove functionality (license check)change data (password, cryptographic key)

add functionality (print, save game)

Tamperproofing the code makes it stopworking if Bob changes as little as a byte ofthe binary!

35 / 45

Page 75: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Two phases of tamperproofing

Tamperproofing has to do two things:1 detect tampering2 respond to tampering

36 / 45

Page 76: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Two phases of tamperproofing

Tamperproofing has to do two things:1 detect tampering2 respond to tampering

Essentially:

if (tampering-detected()) abort

but this is too unstealthy!

36 / 45

Page 77: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Two phases of tamperproofing

Detection:1 has the code been changed?2 are variables in an OK state?

37 / 45

Page 78: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Two phases of tamperproofing

Detection:1 has the code been changed?2 are variables in an OK state?

Response:1 refuse to run,2 crash randomly,3 phone home, . . .

37 / 45

Page 79: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Algorithm Chang & Atallah: Checker

network

abort()

...foo(){

check(){

}

if (hash(foo)!=42)

}

38 / 45

Page 80: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Hash functions

✞ ☎

uint32 hash1 (addr_t addr,int words) {

uint32 h = *addr;

int i;

for(i=1; i<words; i++) {

addr++;

h ˆ= *addr;

}

return h;

}✝ ✆

39 / 45

Page 81: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Hash functions

✞ ☎

void important_function () {

...

}

int main () {

int v = hash (important_function,1000);

if (v != 0x4C49F346) {

crash the program

}

important_function(...)

}✝ ✆

40 / 45

Page 82: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Algorithm Chang & Atallah: Checker

network

abort()

...foo(){

check(){

}

if (hash(foo)!=42)

}

41 / 45

Page 83: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Algorithm Chang & Atallah: Checker

network

foo(){...

}

41 / 45

Page 84: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Algorithm Chang & Atallah: Checker

network

}

foo(){ foo(){...

}...

41 / 45

Page 85: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Algorithm Chang & Atallah: Checker

network

}

foo(){...

}

foo(){

foo(){...

}cp

...

check(){

}

}

if (hash(foo)!=42)

...foo(){

41 / 45

Page 86: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Algorithm Chang & Atallah: Checker

network

if (hash(...)!=42)

foo(){...

}

foo(){...

}cp

}

check(){if (hash(foo)!=42)

...foo(){

check(){

}cp

foo(){...

}

}41 / 45

Page 87: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Repairing Hacked Functions✞ ☎

void copy_of_important_function () {

...

}

void important_function () {

...

}

int main () {

int v = hash (important_function,1000);

if (v != 0x4C49F346) {

memcpy(important_function,

copy_of_important_function,

1000)

}

important_function(...)

}✝ ✆

42 / 45

Page 88: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Checker network

decrypt

play

getkey

decode

main

r1 c1

c0

c2r2

r3

c3

code — code blocksci — checkersri — repairers

43 / 45

Page 89: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Skype’s hash function

✞ ☎

uint32 hash7() {

addr_t addr=(addr_t)((uint32)addrˆ(uint32)addr);

addr = (addr_t)((uint32)addr + 0x688E5C);

uint32 hash = 0x320E83 ˆ 0x1C4C4;

int bound = hash + 0xFFCC5AFD;

do {

uint32 data=*((addr_t)((uint32)addr + 0x10));

goto b1; asm volatile(".byte 0x19"); b1:

hash = hash ⊕ data; addr -= 1; bound--;

} while (bound!=0);

goto b2; asm volatile(".byte 0x73"); b2:

goto b3; asm volatile(".word 0xC8528417,..."); b3:

hash-=0x4C49F346; return hash;

}✝ ✆

44 / 45

Page 90: Software Protection: How to Crack Programs,collberg/Teaching/mgu/... · Software Protection: How to Crack Programs, and Defend Against Cracking Minsk, Belarus, Spring 2014 ... Please

Next week’s lecture

1 Software Hacking Techniques2 Bring a Linux/MacOS laptop, if

you have. Make sure gcc and

gdb have been installed.3 Look at Exercise 1 files on the

website.

45 / 45