13
RE-TRUST Design Alternatives on JVM Paolo Falcarin (Politecnico di Torino - Italy) Trento, December, 19 th 2006 [email protected] http://softeng.polito.it/falcarin Politecnico di Torino Trento 19 ° Dec. 2006 2 Paolo Falcarin Tamper-Detection Tamper-detection goals Detect malicious modifications to program Cause the program to fail if modified Check the executable version itself E.g., compare program with a hash of itself Self-checking relies on code checkers whose position is hidden in the application whose behavior is often obfuscated

RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

1

RE-TRUST Design Alternatives on JVM

Paolo Falcarin(Politecnico di Torino - Italy)

Trento, December, 19th 2006

[email protected]://softeng.polito.it/falcarin

Politecnico di Torino

Trento 19° Dec. 2006 2Paolo Falcarin

Tamper-DetectionTamper-detection goals♦ Detect malicious modifications to program♦ Cause the program to fail if modifiedCheck the executable version itself♦ E.g., compare program with a hash of itselfSelf-checking relies on code checkers ♦ whose position is hidden in the application♦ whose behavior is often obfuscated

Page 2: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

2

Politecnico di Torino

Trento 19° Dec. 2006 3Paolo Falcarin

Issues on self-checking However, no technique can prevent all attacks♦Goal is to increase the cost for the

attackerCurrent self-checking techniques:♦bundled within the application♦can be identified and disabled♦Nobody will notice!!!

Politecnico di Torino

Trento 19° Dec. 2006 4Paolo Falcarin

RE-TRUST approachTwo main benefits:♦remote verification that self-checking

has been performed ♦continuous replacement of self-

checking code2 Prototypes implemented:♦Using Dynamic AOP♦Using JVMTI

Page 3: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

3

Politecnico di Torino

Trento 19° Dec. 2006 5Paolo Falcarin

Prototype(s)

UNTRUSTED

Chat Server

SERVICE

ENTRUSTER

TFlow ServerChat Client

Politecnico di Torino

Trento 19° Dec. 2006 6Paolo Falcarin

Prototype 1: Dynamic Aspect

Dyn AOP runtimeChat

Server

replace

TagMsg

AspectFactory

load

Tag Checker

AspectManagerAspectManager

TrustedFlowChat Client

Code Checker andTag Generator (aspect)

Untrusted

environment

Page 4: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

4

Politecnico di Torino

Trento 19° Dec. 2006 7Paolo Falcarin

Aspect-Oriented Programming

Politecnico di Torino

Trento 19° Dec. 2006 8Paolo Falcarin

Aspect WeavingAspect is “extra-code” that modularizes the implementation of a crosscutting concern The final code is obtained by weaving base code and aspect code♦At compile time with an aspect

compiler♦At run time with a dynamic-AOP JVM

Page 5: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

5

Politecnico di Torino

Trento 19° Dec. 2006 9Paolo Falcarin

Why AOP ?Aspect Oriented Programming (AOP)

Modularizes self-checking codeAspect has a privileged view on the whole codeTrusted Tag generator in dynamic aspect♦ It can be continuously updatedClient code is NOT aspect-aware

Politecnico di Torino

Trento 19° Dec. 2006 10Paolo Falcarin

Dynamic AOP with PROSEPROSE is an extension to standard JVM with dynamic AOP featuresAspects can be remotely added/removed at run-time In PROSE terminology:♦An Aspect is a Java class♦ It contains many Crosscut objects♦A crosscut is a pointcut-advice pair

Page 6: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

6

Politecnico di Torino

Trento 19° Dec. 2006 12Paolo Falcarin

public Crosscut tagGenerator = new MethodCut() {public void METHOD_ARGS(PrintWriter p, String msg) {StringBuffer tag = new StringBuffer(msg);tag.append( crypt( counter, key ));tag = hash(tag); p.println(tag); p.println(counter); p.flush();counter++;} protected PointCutter pointCutter() {PointCutter socket =

Within.method("println").AND(type("PrintWriter"));return Executions.before().AND(socket);

} };

The Tag Generator Crosscut

Politecnico di Torino

Trento 19° Dec. 2006 13Paolo Falcarin

Bytecode checkingUsing BCEL Java library Extract the actual method signature and class name.Keyed-hash of bytecode method is compared with the original oneIf they differ the key is nullified =>The tag generator sends wrong tags=>The server detects tampering

Page 7: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

7

Politecnico di Torino

Trento 19° Dec. 2006 14Paolo Falcarin

public Crosscut bytecodeChecker = new MethodCut() {public void METHOD_ARGS(ANY x, REST pp) {

String className = thisJoinPoint().getThis().getClass().getName();

String method = thisJoinPoint().getSignature();

if (!checkBytecode(className, method)) key=null;

}protected PointCutter pointCutter() {return Executions.before().

AND(Within.packageTypes("it.polito.chat.*"));} };

The Bytecode Checker Crosscut

Politecnico di Torino

Trento 19° Dec. 2006 15Paolo Falcarin

SandboxJava "sandbox" restricts the operations an application can do.♦ protecting from hostile programs

downloaded from un-trusted serversWe face with the dual problem:♦ The trusted aspects sent by the trusted

server cannot trust the environment they will be deployed in.

♦ Deployed aspect forbids many “dangerous”activities to the running application.

Page 8: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

8

Politecnico di Torino

Trento 19° Dec. 2006 16Paolo Falcarin

public Crosscut shield = new MethodCut() {public void METHOD_ARGS(ANY x, REST pp) {

key=null;}protected PointCutter pointCutter() {PointCutter native = Within.method(NATIVE_MODIFIER);PointCutter fork =

Within.method("exec").AND(type("java.lang.Runtime"));PointCutter loader = Within.subType("java.lang.ClassLoader")).

AND(NOT(Within.type(“java.security.SecureClassLoader”));return Executions.before().AND(native.OR(fork).OR(loader));

}};

The Sandbox Crosscut

Politecnico di Torino

Trento 19° Dec. 2006 17Paolo Falcarin

Prototype 2: JVMTIClient

(e.g. Chat Client)+

Execution monitor

Code Checker(agent)

Tag Generator(agent)

Server (e.g. Chat Server)

+Tag checker

Agentmanagerauth

Msg Tag

update

update

CLIENT SERVER

Page 9: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

9

Politecnico di Torino

Trento 19° Dec. 2006 18Paolo Falcarin

Prototype 2 (JVMTI)Execution interception with JVMTI♦ Run JVM (Java 5) in agent mode♦ An agent plugged-in using the JNI interface♦ It downloads module libraries at run-time

Transparent tag insertion♦ Call to socket write are intercepted ♦ And Data buffer is tagged

Method entry is monitored♦ Method byte-code is continuously verified

With JVMTI also program’s memory can be accessed

Politecnico di Torino

Trento 19° Dec. 2006 19Paolo Falcarin

Tag generationTag is uid:counter:sign:plainmsg♦ Where uid is ip:portCounter-mode block cipher♦ Crypt: Blowfish♦ Hash: sha-1

Crypt

Concat

Hash

counter

key

msg

signature

Page 10: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

10

Politecnico di Torino

Trento 19° Dec. 2006 20Paolo Falcarin

Integrity checkModule contains♦ List of crypto hashes (each method) ♦ Symmetric key

Keyed hash recomputed each time a method is calledHash compared with “good” copy

Politecnico di Torino

Trento 19° Dec. 2006 21Paolo Falcarin

Threats: DisablementDynamic Module allows:♦integrity-checking code better modularized

♦Clearly separated from client−It is inserted at run-time

Disabling checking=>stops tag generation=>tampering detected by TFC=>server can block untrusted client

Page 11: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

11

Politecnico di Torino

Trento 19° Dec. 2006 22Paolo Falcarin

Threats: ReplacementDiscovery of secret key…to create correct tagsReplace aspect to disable checking but sending correct tags:♦Attacker must obtain module code

(coming at run-time)♦Replacement must be applied before

TTG expiresNew module checks previous one

Politecnico di Torino

Trento 19° Dec. 2006 23Paolo Falcarin

Safety features of the JVMUnspecified memory layout: JVM stores Application in different data areas♦ Java stacks (one for each thread)♦ A method area where bytecodes are stored♦ A heap, where objects created are stored When the JVM loads a class file, it decides where to store the bytecodes.An attacker cannot predict where the class’ data will be storedThe way in which a JVM lays out its inner data depends on JVM implementation

Page 12: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

12

Politecnico di Torino

Trento 19° Dec. 2006 24Paolo Falcarin

Threats: debuggersDynamic AOP relies on debugger Prototype2 relies on JVMTIIn both cases attackers cannot run client in debug mode♦ Is this enough to thwart them?Attacker should be smart to discover the checker behavior♦Difficult access to mobile code ♦Automating this attack before a new

module arrives is not trivial

Politecnico di Torino

Trento 19° Dec. 2006 25Paolo Falcarin

Open issues: platformAll software-based techniques rely on an un-trusted external platform:♦ the JVM, the O.S., the hardware.This is a problem for ALL integrity-checking techniquesOur Prototype could (?) check authenticity of:♦underlying VM♦O.S. & HW configuration

Page 13: RE-TRUST Design Alternatives on JVMre-trust.dit.unitn.it/files/20061219Doc/falcarin_polito.pdf · Aspect-Oriented Programming Politecnico di Torino Paolo Falcarin Trento 19° Dec

13

Politecnico di Torino

Trento 19° Dec. 2006 26Paolo Falcarin

ConclusionsThe aspect/agent checker is:♦Not bundled within application♦ Its strategy is not visible through

static code analysis♦Easily configurable♦Can check previously installed ones♦Could check the platform itself

Politecnico di Torino

Trento 19° Dec. 2006 27Paolo Falcarin

Possible EnhancementsModule obfuscationModule factoryServer authenticationNetwork protocol designMeasuresO.S. configuration checkingIntegration with HWHiding key with White-box Cryptography