Using Partial Taint Tracking To Protect Against Injection Attacks - - PowerPoint PPT Presentation

using partial taint tracking to
SMART_READER_LITE
LIVE PREVIEW

Using Partial Taint Tracking To Protect Against Injection Attacks - - PowerPoint PPT Presentation

PHP Aspis: Using Partial Taint Tracking To Protect Against Injection Attacks Ioannis Papagiannis , Matteo Migliavacca, Peter Pietzuch Department of Computing, Imperial College London USENIX WebApps 2011 Portland, OR, USA Injection


slide-1
SLIDE 1

PHP Aspis: Using Partial Taint Tracking To Protect Against Injection Attacks

USENIX WebApps 2011 Portland, OR, USA Ioannis Papagiannis, Matteo Migliavacca, Peter Pietzuch Department of Computing, Imperial College London

slide-2
SLIDE 2

2

Injection Vulnerability Example

USENIX WebApps 2011

<?php $name=$GET[„name‟]; $sql = “SELECT * FROM USERS WHERE user=”. $name; mysql_query($sql); ?>

slide-3
SLIDE 3

3

Injection Vulnerability Example

USENIX WebApps 2011

<?php $name=$GET[„name‟]; $sql = “SELECT * FROM USERS WHERE user=”. ; mysql_query($sql); ?> http://…?name=

slide-4
SLIDE 4

4

Sanitisation

USENIX WebApps 2011

<?php $name=$GET[„name‟]; $sql = “SELECT * FROM USERS WHERE user=”. ; mysql_query($sql); ?> http://…?name=Yiannis

slide-5
SLIDE 5

5

Taint Tracking

USENIX WebApps 2011

<?php $name=$GET[„name‟]; $sql = “SELECT * FROM USERS WHERE user=”. $name; mysql_query($sql); ?>

1

2 3 taint data in entry points propagate taint use taint to guide sanitisation

slide-6
SLIDE 6

6

Taint Tracking in PHP

No support

  • 1. Suggested but ignored

[Venema06]

  • 2. Custom research interpreters

[Yip09, Pietraszek06]

USENIX WebApps 2011

taint tracking

“modifications to the Zend engine should be avoided. Changes here result in incompatibilities with the rest

  • f the world, and hardly anyone will ever adapt to

specially patched Zend engines. … Therefore, this method is generally considered bad practice” The PHP Manual

slide-7
SLIDE 7

7

PHP is popular

USENIX WebApps 2011

data provided by langpop.com

slide-8
SLIDE 8

8

PHP Aspis Contributions

Source-to-source transformations Partial Taint Tracking taint tracking!

USENIX WebApps 2011

2 1

slide-9
SLIDE 9

9

PHP Aspis Contributions

Source-to-source transformations Partial Taint Tracking taint tracking!

USENIX WebApps 2011

2 1

slide-10
SLIDE 10

10

Why source transformations?

USENIX WebApps 2011

  • Adopt officially
  • Custom Runtime
  • Source code transformations

On demand Portable

1

slide-11
SLIDE 11

11

Why source transformations?

USENIX WebApps 2011

Challenges:

  • 1. Not everything is an object

(how can you attach taint to strings?)

  • 2. The interpreter cannot be edited

(no metaprogramming)

  • Adopt officially
  • Custom Runtime
  • Source code transformations

On demand Portable

1

slide-12
SLIDE 12

12

What is the performance overhead?

Partial taint tracking: Code is not equally vulnerable

Third-party plugin code Code that handles user data

year WordPress WordPress Plugins 2009 2 13 2010 2 10

CVE WordPress-Platform Injection Vulnerabilities

CVE # Functionality 2009-2851 Display user comments 2009-3891 File upload handler 2010-4257 Trackback handling 2010-4536 Display user comments

CVE WordPress-Core Injection Vulnerabilities

USENIX WebApps 2011

2

slide-13
SLIDE 13

13

  • 2. DESIGN
  • 1. Introduction

USENIX WebApps 2011

  • 3. Implementation
  • 4. Evaluation
slide-14
SLIDE 14

14

PHP Aspis Overview

USENIX WebApps 2011

PHP Aspis Transformed Application Tracking Code

PHP Statements Library Calls Sanitisation Operations

Non Tracking Code

slide-15
SLIDE 15

15

PHP Aspis Overview

USENIX WebApps 2011

PHP Aspis Transformed Application Tracking Code

PHP Statements Library Calls Sanitisation Operations

Non Tracking Code

“Yiannis” Taint

Input HTTP Request

slide-16
SLIDE 16

16

PHP Aspis Overview

USENIX WebApps 2011

PHP Aspis Transformed Application

“Yiannis” Taint

Tracking Code

PHP Statements Library Calls Sanitisation Operations

Non Tracking Code

Input HTTP Request HTML Output SQL Query Eval Statement

slide-17
SLIDE 17

17

PHP Aspis Overview

USENIX WebApps 2011

WordPress

“Yiannis” Taint

WordPress plugin WordPress Core

Input HTTP Request HTML Output SQL Query Eval Statement

slide-18
SLIDE 18

18

PHP Aspis Overview

USENIX WebApps 2011

PHP Aspis Transformed Application

“Yiannis” Taint

Tracking Code

PHP Statements Library Calls Sanitisation Operations

Non Tracking Code

Input HTTP Request HTML Output SQL Query

Taint meta-data

Eval Statement

Vulnerability prevention

1 2

slide-19
SLIDE 19

19

PHP Aspis Overview

USENIX WebApps 2011

PHP Aspis Transformed Application

“Yiannis” Taint

Tracking Code

PHP Statements Library Calls Sanitisation Operations

Non Tracking Code

Input HTTP Request HTML Output SQL Query Eval Statement

Taint meta-data Vulnerability prevention

1 2

slide-20
SLIDE 20

20

Taint Meta-data

Character Level

  • Precise information

USENIX WebApps 2011

1

“SELECT * FROM USERS WHERE user=yiannis”;

untainted tainted

Variable Level

  • Leads to false positives

“SELECT * FROM USERS WHERE user=yiannis”;

tainted

slide-21
SLIDE 21

21

Taint Meta-data

USENIX WebApps 2011

1

More than 1 bit of taint meta-data is required

“SELECT * FROM USERS WHERE user=yiannis”;

untainted

Partial sanitisation (e.g. )

untainted (for SQL Injection)

Character Level

  • Precise information

“SELECT * FROM USERS WHERE user=yiannis”;

untainted tainted

Variable Level

  • Leads to false positives

“SELECT * FROM USERS WHERE user=yiannis”;

tainted

slide-22
SLIDE 22

22

Example

Taint Categories

USENIX WebApps 2011

1

“SELECT * FROM USERS WHERE user=yiannis”;

Taint Category SQL Injection XSS Eval Injection untainted untainted untainted tainted tainted

slide-23
SLIDE 23

23

Example

Taint Categories

USENIX WebApps 2011

1

“SELECT * FROM USERS WHERE user=yiannis”;

Generic way to define:

How an application is supposed to sanitise What to do if it doesn’t Sanitisation Functions htmlentities() htmlspecialchars() Guarded Sinks echo()→AspisAntiXSS() print()→AspisAntiXSS() …

XSS taint category excerpt

Taint Category SQL Injection XSS Eval Injection untainted untainted untainted tainted tainted

slide-24
SLIDE 24

24

PHP Aspis Overview

USENIX WebApps 2011

PHP Aspis Transformed Application

“Yiannis” Taint

Tracking Code

PHP Statements Library Calls Sanitisation Operations

Non Tracking Code

Input HTTP Request HTML Output SQL Query

Taint meta-data Vulnerability prevention

Eval Statement

1 2

slide-25
SLIDE 25

25

PHP Aspis Overview

USENIX WebApps 2011

PHP Aspis Transformed Application

“Yiannis” Taint

Tracking Code

PHP Statements Library Calls Sanitisation Operations

Non Tracking Code

Input HTTP Request HTML Output SQL Query

Taint meta-data Vulnerability prevention

Eval Statement

1 2

slide-26
SLIDE 26

26

Which vulnerabilities can be prevented?

USENIX WebApps 2011

2 Possible Data Flows

to from Tracking Non Tracking Tracking Non Tracking

slide-27
SLIDE 27

27

Tracking code only

USENIX WebApps 2011

2

PHP Aspis Transformed Application Tracking Code Non Tracking Code

Input HTTP Request

“Yiannis” Taint to from Tracking Non Tracking Tracking Non Tracking

slide-28
SLIDE 28

28

Non Tracking code only

USENIX WebApps 2011

2

PHP Aspis Transformed Application Tracking Code Non Tracking Code

Input HTTP Request

“Yiannis” Taint to from Tracking Non Tracking Tracking Non Tracking

slide-29
SLIDE 29

29 USENIX WebApps 2011

2

PHP Aspis Transformed Application Tracking Code Non Tracking Code

Input HTTP Request

“Yiannis” Taint

Non Tracking to Tracking

to from Tracking Non Tracking Tracking Non Tracking

slide-30
SLIDE 30

30 USENIX WebApps 2011

2

PHP Aspis Transformed Application Tracking Code Non Tracking Code

Input HTTP Request

“Yiannis” Taint

Tracking/Non Tracking mixes

to from Tracking Non Tracking Tracking Non Tracking

slide-31
SLIDE 31

31 USENIX WebApps 2011

2

PHP Aspis Transformed Application Tracking Code Non Tracking Code

Input HTTP Request

“Yiannis” Taint

Tracking to Non Tracking

to from Tracking Non Tracking Tracking Non Tracking

slide-32
SLIDE 32

32 USENIX WebApps 2011

2

PHP Aspis Transformed Application Tracking Code Non Tracking Code

Input HTTP Request

“Yiannis” Taint

Tracking to Non Tracking

to from Tracking Non Tracking Tracking Non Tracking

slide-33
SLIDE 33

33

Summary: Prevented Vulnerabilities

USENIX WebApps 2011

2

Vulnerabilities Prevented

Tracking-code only Tracking to non tracking

Vulnerabilities Not Prevented

Non Tracking-code only Non Tracking to Tracking Tracking/Non Tracking mixes

to From Tracking Non Tracking Tracking Non Tracking to from Tracking Non Tracking Tracking Non Tracking

slide-34
SLIDE 34

34

  • 3. IMPLE

LEMEN MENTAT ATION ON

1. Introduction 2. Design

USENIX WebApps 2011

  • 4. Evaluation
slide-35
SLIDE 35

35

Storing Taint Meta-Data

USENIX WebApps 2011

Original value Aspis-protected value “Hello” array ( “Hello”, TaintCats ) 12 array ( 12, TaintCats )

Store taint in place

Interoperation with non-tracking code

Use arrays

2-10x faster than object initialisation Scalar assignment semantics

slide-36
SLIDE 36

36

Taint Tracking Transformations

USENIX WebApps 2011

Statements & Expressions must

  • 1. operate with Aspis-protected values
  • 2. propagate taint correctly
  • 3. return Aspis-protected values

Original expression Transformed Expression $s.$t concat($s,$t) if ($v) {} if ($v[0]) {} $j = $i++ $j = postincr($i)

slide-37
SLIDE 37

37

PHP Function Library

USENIX WebApps 2011

Library functions do not work with Aspis-protected values

use interceptors! Default Interceptor strip input taint add empty output taint good as the default fclose(), fopen() Custom Interceptors guess the taint of the output substr() reimplement the function sort()

More custom interceptors, less false negatives

  • Default: drop taint, not abort the call
  • Support existing applications without developer intervention
slide-38
SLIDE 38

38

The rest…

USENIX WebApps 2011

Taint representation Expressions Statements PHP Library Function Calls Taint initialisation Tracking/Non Tracking Calls Calls to sanitisation functions Calls to sinks Variable variables Variable function calls Include Statements Dynamic code generation

slide-39
SLIDE 39

39

  • 4. EVAL

ALUAT ATION

1. Introduction 2. Design 3. Implementation

USENIX WebApps 2011

slide-40
SLIDE 40

40

Goals

Is PHP Aspis effective in preventing injection attacks? What is the performance overhead?

USENIX WebApps 2011

2 1

slide-41
SLIDE 41

41

Goals

Is PHP Aspis effective in preventing injection attacks? What is the performance overhead?

USENIX WebApps 2011

2 1

slide-42
SLIDE 42

42

Evaluation methodology

USENIX WebApps 2011

WordPress

“Yiannis” Taint

Plugin Tracking Code WordPress Core

Non Tracking Code

Use all reported WordPress plugins to the CVE since 1/1/2010 Replay the provided attack vectors where possible

CVE attack vector Tainted?

1

Tainted?

slide-43
SLIDE 43

43

WordPress Plugins Results

USENIX WebApps 2011

1

Total plugins with injection vulnerabilities: 15 Tested plugins: 14

  • 1 plugin was not publicly available

Vulnerabilities prevented: 12

  • 10 XSS cases
  • 2 SQL Injection cases

Vulnerabilities not prevented: 2 (false negatives)

  • Stored XSS attacks
  • PHP Aspis does not track taint in the database

No observed false positives

slide-44
SLIDE 44

44

PHP Aspis Overhead

USENIX WebApps 2011

2

0.2 0.4 0.6 0.8 1 1.2 1.4 DBGen 50 100 150 200 250 300 350 400 450 500 PrimeGen 50 100 150 200 250 300 350 400 450 WordPress Off On Partial

Page Generation (ms) Issues DB queries Generates prime numbers Blogging platform

slide-45
SLIDE 45

45

Conclusion

Partial taint tracking

  • Can be applied by source code transformations
  • Is suitable for applications that support plugins
  • Is effective for real world plugin vulnerabilities

PHP Aspis design favours false negatives

  • False negatives are a consequence of partial taint tracking
  • False positives break existing applications

“Reasonable” performance overhead

  • Suitable for deployments where security is more important than

performance

  • Partial taint tracking for the WordPress case: 2.2x slowdown

USENIX WebApps 2011

slide-46
SLIDE 46

46

The End

Ioannis Papagiannis DoC, Imperial College London $git clone git://github.com/jpapayan/aspis.git

ip108@doc.ic.ac.uk

USENIX WebApps 2011

slide-47
SLIDE 47

47

References

USENIX WebApps 2011

[1] Venema, W. Runtime taint support proposal. In PHP Internals mailing list (2006) [2] Yip, A. Wang X., et all. Improving application security with data flow assertions. In SOSP 2009 [3] Pietraszek, T and Berghe, C. Defending against injection attacks through context sensitive string evaluation. In Recent Advances in Intrusion Detection (2006)