Top Banner
60

Automated Patching for Vulnerable Source Code

Aug 08, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Automated Patching for Vulnerable Source Code
Page 2: Automated Patching for Vulnerable Source Code

Automated Patching for Vulnerable Source Code

Vladimir KochetkovApplication Inspector/Compiling Applications

Analysis/Team LeadPositive Technologies

Positive Hack Days V

Page 3: Automated Patching for Vulnerable Source Code

Disclaimer

Page 4: Automated Patching for Vulnerable Source Code

Who are we?

Page 5: Automated Patching for Vulnerable Source Code

Developers of PT Application Inspector!

Page 6: Automated Patching for Vulnerable Source Code

Application Inspector― Strong dogfooding

― Analysis is performed on the limit of ?AST approaches

― Generation of attack vectors

― The Big Red Button Concept

― A proprietary solution

Page 7: Automated Patching for Vulnerable Source Code

Application Inspector― Integration with PT Application Firewall (aka virtual

patches)

Well... still we want more

Page 8: Automated Patching for Vulnerable Source Code

What do we want?

Page 9: Automated Patching for Vulnerable Source Code

To generate patches for the source code!!

Page 10: Automated Patching for Vulnerable Source Code

How to catch the vulnerability?― Know "how it shouldn't be": necessary and

sufficient formal symptoms of vulnerabilities

― Know "how it is": prove the existence of these symptoms in the analyzed code

― Build an attack vector based on the revealed set of symptoms

Page 11: Automated Patching for Vulnerable Source Code

Formal symptoms of injection― Potentially vulnerable operation PVO(text):

operation of direct or indirect "text" interpretation in a formal language

― text = transform(argument), where argument – number of arguments passed to the EP entry point, and transform – the function of intermediate transformations

― There is at least one set of such values of EP elements that can be reached. At these values the syntax tree structure of the "text" value, that reaches PVO, changes.

Page 12: Automated Patching for Vulnerable Source Code

Formalizability of vulnerabilities

Strictly formalizable Poorly formalizable

Injections Access Control

Buffer Overflow Session Management

Heap Overflow CSRFInteger Overflow Concurrency

Memory Management Domain(Logical)

… …

Page 13: Automated Patching for Vulnerable Source Code

What do we have?

Page 14: Automated Patching for Vulnerable Source Code

Symbolic Execution Context Graph!

Page 15: Automated Patching for Vulnerable Source Code

DisclaimerThere is just a review. Further details will be presented at

SIBECRYPT’15Novosibirsk, September 7-12, 2015

Page 16: Automated Patching for Vulnerable Source Code

Symbolic Execution Context Graph!SECG is a graph, an isomorphic CFG, each of its vertices contains information on the context of symbolic execution

The context of symbolic execution - a condition for accessing the current point of execution + a set of conditional states of all objects and variables that can be reached within the current scope

Page 17: Automated Patching for Vulnerable Source Code

Symbolic Execution Context Graph

ε �֜ {}

Page 18: Automated Patching for Vulnerable Source Code

Symbolic Execution Context Graph

ε �֜ { parm' א { ε �֜ Request.Params["parm1"] } }

Page 19: Automated Patching for Vulnerable Source Code

Symbolic Execution Context Graph

Request.Params["cond1"] == "true" �֜ { parm' א { ε �֜ Request.Params["parm1"] } }

Page 20: Automated Patching for Vulnerable Source Code

Symbolic Execution Context Graph

Request.Params["cond1"] != "true" �֜ { parm' א { Request.Params["cond1"] != "true" �֜ Request.Params["parm1"] } }

Page 21: Automated Patching for Vulnerable Source Code

Symbolic Execution Context Graph

Request.Params["cond1"] != "true" && Request.Params["cond2"] == "true" �֜ { parm' א { Request.Params["cond1"] != "true" �֜ Request.Params["parm1"] } }

Page 22: Automated Patching for Vulnerable Source Code

Symbolic Execution Context Graph

Request.Params["cond1"] != "true" && Request.Params["cond2"] != "true" �֜ { parm' א { Request.Params["cond1"] != "true" �֜ Request.Params["parm1"] } }

Page 23: Automated Patching for Vulnerable Source Code

Symbolic Execution Context Graph

Request.Params["cond1"] != "true" �֜ { parm' א { Request.Params["cond2"] == "true" �֜ Request.Params["parm2"] || Request.Params["cond2"] != "true" �֜ "<div>Harmless value</div>" } }

Page 24: Automated Patching for Vulnerable Source Code

Request.Params["cond1"] != "true" �֜ { parm' א { Request.Params["cond2"] == "true" �֜ Request.Params["parm2"] || Request.Params["cond2"] != "true" �֜ "<div>Harmless value</div>" } }

Symbolic Execution Context Graph

Using the SECG for each PVO we can...

Page 25: Automated Patching for Vulnerable Source Code

Figure out a vulnerability formula!

Page 26: Automated Patching for Vulnerable Source Code

Vulnerability formulaRequest.Params["cond1"] != "true" ⇒

Response.Write( "<a href=\"" + parm ∈ { Request.Params["cond2"] == "true" ⇒ Request.Params["parm2"] ; Request.Params["cond2"] != "true" ⇒ "<div>Harmless value</div>" } + "\">" )

Page 27: Automated Patching for Vulnerable Source Code

Vulnerability formulaRequest.Params["cond1"] != "true" ⇒

Response.Write( "<a href=\"" + parm ∈ { Request.Params["cond2"] == "true" ⇒ Request.Params["parm2"] } + "\">" )

Page 28: Automated Patching for Vulnerable Source Code

Vulnerability formulaRequest.Params["cond1"] != "true"&&

Request.Params["cond2"] == "true" ⇒

Response.Write( "<a href=\"" + Request.Params["parm2"] + "\">" )

Page 29: Automated Patching for Vulnerable Source Code

Vulnerability formulaRequest.Params["cond1"] != "true"&&

Request.Params["cond2"] == "true" ⇒

Response.Write( "<a href=\"" + Request.Params["parm2"] + "\">" )

What value of Request.Params["parm2"] will result in exceeding the limits of the token?

Page 30: Automated Patching for Vulnerable Source Code

The one that is defined by the type of the injection point!

Page 31: Automated Patching for Vulnerable Source Code

<a href=" ">

The type of the injection point is figured out by syntactic heuristics applied to the vulnerable

expression on either side of the point.

Finding the type of the injection point

Page 32: Automated Patching for Vulnerable Source Code

Vulnerability formulaRequest.Params["cond1"] != "true"&&

Request.Params["cond2"] == "true" &&(Request.Params["parm2"] == "\"><script>alert(0)</script>"

|| Request.Params["parm2"] == "\"onmouseover=\"alert(0)") ⇒

Response.Write( "<a href=\"" + Request.Params["parm2"] + "\">" )

Page 33: Automated Patching for Vulnerable Source Code

Vulnerability formulaRequest.Params["cond1"] != "true"&&Request.Params["cond2"] == "true" &&(Request.Params["parm2"] == "\"><script>alert(0)</script>" || Request.Params["parm2"] == "\"onmouseover=\"alert(0)") ⇒

Response.Write( "<a href=\"" + Request.Params["parm2"] + "\">" ) As a result of finding the values unknown in

the context of the vulnerability formula you can get...

-

-

Page 34: Automated Patching for Vulnerable Source Code

A contextual attack vector!

Page 35: Automated Patching for Vulnerable Source Code

The contextual attack vectorVulnerable expression:"<a href=\"" + Request.Params["parm2"] + "\">"

The type of the injection point:HTML: 2-quoted attribute value

Vector variables:Request.Params["parm2"] = "\"><script>alert(0)</script>"

Conditional variables:Request.Params["cond1"] = "__AI_akhivldp"Request.Params["cond2"] = "true"

Page 36: Automated Patching for Vulnerable Source Code

What is missing?

Page 37: Automated Patching for Vulnerable Source Code

SECG gives us anything we need!*

* it also gives us anything we don't need yet

Page 38: Automated Patching for Vulnerable Source Code

The proper patch

― Makes a minimum of changes

― Keeps the semantics of the code

― Solves the problem

― Never makes more problems

Page 39: Automated Patching for Vulnerable Source Code

― Know "how it shouldn't be": necessary and sufficient formal symptoms of vulnerabilities

― Know "how it is": prove the existence of these symptoms in the analyzed code

― eliminate at least one of the required symptoms by changing the code

How to generate a patch?

Page 40: Automated Patching for Vulnerable Source Code

Symptoms of injection that can be eliminated

― Potentially vulnerable operation PVO(text): operation of direct or indirect "text" interpretation in a formal language

― text = transform(argument), where argument – number of arguments passed to the EPentry point, and transform – the function of intermediate transformations

― At least one set of such values of the EP elements exists and is likely to be achieved. At these values the syntax tree structure of the "text" value, that reaches PVO, changes.

Page 42: Automated Patching for Vulnerable Source Code

Attack vector vs patchAttack vector Patch

It suffices to find a single path from the entry point to the PVO and a single set of values of vector variables

It is necessary to find all paths from the entry point to the PVO and all sets of values of vector variables

The type of the injection point can be figured out by using heuristics

The type of the injection point must be figured out strictly along with its semantics

The availability of the application may be compromised

The application should stay available

Page 43: Automated Patching for Vulnerable Source Code

Strong finding the type of the injection point

Step #1: replace each taint source in the vulnerable expression by an unique special character:

<a href='∅'>

Step #2: parse the string with the modified parser of an island language that allows using special characters in the arbitrary token.

Step #3: find in the parsing tree the vertex containing a special character and define the type of the injection point on the basis of the vertex type.

Step #4: According to the type injection point define its semantics.

Page 44: Automated Patching for Vulnerable Source Code

Opening bracket: <

Tag name: a

Attribute definition

Attribute name: href

Assignment sign

2-quoted attr. value: Closing bracket: >

Strong finding the type of the injection point

2-quoted attribute (semantic: URL) value

Page 45: Automated Patching for Vulnerable Source Code

Keeps the semantics of the code- The priority of countermeasures:

1) Typing2) Sanitizing3) Validation

- Consideration of all conditions for executing the PVO as well as values of its arguments during typing and sanitizing

- Applying countermeasures exactly at the source of the vulnerability

Page 46: Automated Patching for Vulnerable Source Code

Typing

Page 47: Automated Patching for Vulnerable Source Code

Typing

2-quoted attribute(semantic: URL) value- typing is possible

Recording a dangerous

value to parm

Page 48: Automated Patching for Vulnerable Source Code

Typing

Page 49: Automated Patching for Vulnerable Source Code

Sanitizing

Page 50: Automated Patching for Vulnerable Source Code

Sanitizing

Text(semantic: TEXT) value- typing is not possible,sanitizing may be applied

Recording a dangerous

value to parm

Page 51: Automated Patching for Vulnerable Source Code

Sanitizing

Page 52: Automated Patching for Vulnerable Source Code

Validation

Page 53: Automated Patching for Vulnerable Source Code

Validation

Typing and sanitizing are not possible, validation is possible

Page 54: Automated Patching for Vulnerable Source Code

Validation

Page 55: Automated Patching for Vulnerable Source Code

Any patches for other attack types?√ Injections

√ Buffer Overflow

√ Heap Overflow

√ Integer Overflow

? Memory Management Attacks

? Access Control Attacks

? Session Fixation

? CSRF

x Race Conditions

x Domain(Logical) Attacks

Page 56: Automated Patching for Vulnerable Source Code

When do we want it?

Page 57: Automated Patching for Vulnerable Source Code

Right now!!!

Page 58: Automated Patching for Vulnerable Source Code

{DEMO}

Page 59: Automated Patching for Vulnerable Source Code

Any questions?

Vladimir Kochetkov

[email protected]@kochetkov_v

Application Inspector/Compiling Applications Analysis/Team LeadPositive Technologies

Page 60: Automated Patching for Vulnerable Source Code