taj: effective taint analysis of web applications

29
TAJ: Effective Taint Analysis of Web Applications Yinzhi Cao Reference: http ://www.cs.tau.ac.il/~ omertrip/pldi09/TAJ.ppt www.cs.cmu.edu/~ soonhok/talks/20110301.pdf

Upload: tolla

Post on 05-Jan-2016

43 views

Category:

Documents


2 download

DESCRIPTION

TAJ: Effective Taint Analysis of Web Applications. Yinzhi Cao. Reference: http ://www.cs.tau.ac.il/~ omertrip/pldi09/TAJ.ppt www.cs.cmu.edu/~ soonhok/talks/20110301.pdf. Motivating Example *. Taint Flow #1. * Inspired by Refl1 in SecuriBench Micro. Motivating Example *. Taint Flow #2. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: TAJ: Effective Taint Analysis of Web Applications

TAJ: Effective Taint Analysis of Web Applications

Yinzhi Cao

Reference: http://www.cs.tau.ac.il/~omertrip/pldi09/TAJ.pptwww.cs.cmu.edu/~soonhok/talks/20110301.pdf

Page 2: TAJ: Effective Taint Analysis of Web Applications

2

Motivating Example*

* Inspired by Refl1 inSecuriBench Micro

Taint Flow #1

Page 3: TAJ: Effective Taint Analysis of Web Applications

3

Motivating Example*

Sanitizer

* Inspired by Refl1 inSecuriBench Micro

Taint Flow #2

Page 4: TAJ: Effective Taint Analysis of Web Applications

4

Motivating Example*

* Inspired by Refl1 inSecuriBench Micro

Non-tainted

Taint Flow #3

Page 5: TAJ: Effective Taint Analysis of Web Applications

5

Motivating Example*

* Inspired by Refl1 inSecuriBench Micro

Reflection

Page 6: TAJ: Effective Taint Analysis of Web Applications

Several Concepts

• Slicing• Thin Slicing• Hybrid Thin Slicing• Taint Analysis• Thin Slicing + Taint Analysis

Page 7: TAJ: Effective Taint Analysis of Web Applications

Slicing

• Boring Definition: The slice of a program with respect to program point p and variable x consists of a reduced program that computes the same sequence of values for x at p. That is, at point p the behavior of the reduced program with respect to variable x is indistinguishable from that of the original program.

Page 8: TAJ: Effective Taint Analysis of Web Applications

An Example

1. x = new A();2. z = x;3. y = new B();4. a = new C();5. w = x;6. w.f = y;7. if (w == z) {8. a.g = y9. v = z.f; 10. }

1. x = new A();2. z = x;3. y = new B();5. w = x;6. w.f = y;7. if (w == z) {9. v = z.f; 10. }

Slicing for v at 9

Page 9: TAJ: Effective Taint Analysis of Web Applications

Thin Slicing

• Only producer statements are preserved.• Producer statements - A statement t is a

producer for a seed s iff (1) s = t or (2) t writes a value to a location directly used by some other producer

• Other statements: explainer statement

Page 10: TAJ: Effective Taint Analysis of Web Applications

1. x = new A();2. z = x;3. y = new B();4. w = x;5. w.f = y;6. if (w == z) {7. v = z.f; 8. }

3. y = new B();5. w.f = y;7. v = z.f;

Thin Slicing seed 7

Page 11: TAJ: Effective Taint Analysis of Web Applications

Dependence Graph

Page 12: TAJ: Effective Taint Analysis of Web Applications

Two Types of Existing Thin Slicing

• Context- and Flow- Insensitive Thin Slicing (Fast but inaccurate in most cases)

• Context- and Flow- Sensitive Thin Slicing (Slow but accurate in most cases)

Page 13: TAJ: Effective Taint Analysis of Web Applications

So in TAJ,

• Hybrid Thin Slicing(1) Flow-insensitive and Context-sensitive for the

heap(2) Flow- and Context-sensitive for local variablesFast and accurate

Page 14: TAJ: Effective Taint Analysis of Web Applications

Taint Analysis

Page 15: TAJ: Effective Taint Analysis of Web Applications

Hybrid Thin Slicing + Taint Analysis

Page 16: TAJ: Effective Taint Analysis of Web Applications
Page 17: TAJ: Effective Taint Analysis of Web Applications

• Note that this is forwards thin slicing instead of backwards thin slicing.

Page 18: TAJ: Effective Taint Analysis of Web Applications

Several Tricks Played

• Taint Carriers• Handling Exceptions• Code Reduction• Eliminating Redundant Flows• Refection APIs• Native Methods

Page 19: TAJ: Effective Taint Analysis of Web Applications

Taint Carrier

• private static class Internal {• private String s;• public Internal(String s) {• this.s = s;• }• public String toString() {• return s;• }• }• Internal i1 = new Internal(s1); // s1 is tainted• writer.println(i1)

Page 20: TAJ: Effective Taint Analysis of Web Applications

• Create a pointer analysis• So there is an edge between i1 and s

• private static class Internal {• private String s;• public Internal(String s) {• this.s = s;• }• public String toString() {• return s;• }• }• Internal i1 = new Internal(s1); // s1 is tainted• writer.println(i1)

Page 21: TAJ: Effective Taint Analysis of Web Applications

Handling Exceptions

protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException { try { ... } catch (Exception e) { resp.getWriter().println(e); }}

Page 22: TAJ: Effective Taint Analysis of Web Applications

• Problem: Exception.getMessage is the source but it is called implicitly at Exception.toString

• Solution: Mark the combination println(e); as source.

Page 23: TAJ: Effective Taint Analysis of Web Applications

Code Reduction

• Predict behavior of some common libraries and skip tracking.

For example, URLEncoder.encode is a sanitizer.

Page 24: TAJ: Effective Taint Analysis of Web Applications

24PLDI 2009

Eliminating Redundant Flows

• Flows are equivalent iff– Parts under application code

coincide– Sinks corresponding to same

issues type

• Dramatically improves user experience (on JBoard, x25 less reports)

• Sound, minimal with respect to remediation

n2n2

n9n9n8

n8

n4n4n3

n3

n1n1

n11n11

n7n7n6

n6n5n5

n10n10

Application

Library

Sinks with same issue type

Page 25: TAJ: Effective Taint Analysis of Web Applications

Others

• Reflection: Try to infer it if it is constant.• Native Methods: Hand-coded models.

Page 26: TAJ: Effective Taint Analysis of Web Applications

Results

• Speed:– Hybrid thin slicing is 2.65X slower than context

insensitive slicing (CI)– Hybrid thin slicing is 29X faster than context

sensitive slicing (CS)• Accuracy:– Accuracy score: the ratio between the number of

true positives and the number of true and false positives combined

– Hybrid: 0.35, CS: 0.54, CI: 0.22

Page 27: TAJ: Effective Taint Analysis of Web Applications

Pixy

• A flow-sensitive and context-sensitive data flow analysis for PHP.

Page 28: TAJ: Effective Taint Analysis of Web Applications

Vulnerability One

Page 29: TAJ: Effective Taint Analysis of Web Applications

Vulnerability Two