the art of identifying vulnerabilities - cascadiafest 2015

53
The Art of Identifying Vulnerabilities CascadiaFest 2015

Upload: evilpacket

Post on 06-Aug-2015

173 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

The Art of Identifying Vulnerabilities

CascadiaFest 2015

Page 2: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

adam_baldwinevilpacket

Page 3: The Art of Identifying Vulnerabilities  - CascadiaFest 2015
Page 4: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

The Art of Identifying Vulnerabilities

CascadiaFest 2015

Page 5: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

What is a vulnerability?

Page 6: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Is it a bug?

Page 7: The Art of Identifying Vulnerabilities  - CascadiaFest 2015
Page 8: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

A PROMISE THAT CAN BE

BROKEN

Page 9: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Systems knowledgeSecurity knowledgeCuriosity

To find vulnerabilities

Page 10: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

SYSTEMS

Page 11: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Vulnerabilities grow in the cracks between

nuances & assumptions

Page 12: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

You must understand the nuances of the systems you create and consume

Page 13: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

https://www.youtube.com/watch?v=8aGhZQkoFbQ

What the heck is the event loop anyway?

Page 14: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

JavaScript Nuanceshttp://dorey.github.io/JavaScript-Equality-Table/

http://nrn.io/view/javascript-common-pitfalls

http://youdontknowjs.com

Page 15: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

JavaScript Nuances

db.passwd == user.passwd

Page 16: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows:

If Type(x) is the same as Type(y), then If Type(x) is Undefined, return true. If Type(x) is Null, return true. If Type(x) is Number, then If x is NaN, return false. If y is NaN, return false. If x is the same Number value as y, return true. If x is +0 and y is −0, return true. If x is −0 and y is +0, return true. Return false. If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions). Otherwise, return false. If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false. Return true if x and y refer to the same object. Otherwise, return false. If x is null and y is undefined, return true. If x is undefined and y is null, return true. If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y). If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y). If Type(x) is either String or Number and Type(y) is Object, return the result of the comparison x == ToPrimitive(y). If Type(x) is Object and Type(y) is either String or Number, return the result of the comparison ToPrimitive(x) == y. Return false. NOTE 1 Given the above definition of equality:

String comparison can be forced by: "" + a == "" + b. Numeric comparison can be forced by: +a == +b. Boolean comparison can be forced by: !a == !b. NOTE 2 The equality operators maintain the following invariants:

A != B is equivalent to !(A == B). A == B is equivalent to B == A, except in the order of evaluation of A and B. NOTE 3 The equality operator is not always transitive. For example, there might be two distinct String objects, each representing the same String value; each String object would be considered equal to the String value by the == operator, but the two String objects would not be equal to each other. For Example:

new String("a") == "a" and "a" == new String("a")are both true. new String("a") == new String("a") is false. NOTE 4 Comparison of Strings uses a simple equality test on sequences of code unit values. There is no attempt to use the more complex, semantically oriented definitions of character or string equality and collating order defined in the Unicode specification. Therefore Strings values that are canonically equal according to the Unicode standard could test as unequal. In effect this algorithm assumes that both Strings are already in normalised form.

The Abstract Equality Comparison Algorithm

ಠ_ಠ

Page 17: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Vulnerabilities are prevalent between one

system & another

Page 18: The Art of Identifying Vulnerabilities  - CascadiaFest 2015
Page 19: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Whose code are you running in production?

Page 20: The Art of Identifying Vulnerabilities  - CascadiaFest 2015
Page 21: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Vulnerabilities multiply in the presence of

complexity

Page 22: The Art of Identifying Vulnerabilities  - CascadiaFest 2015
Page 23: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

SECURITY

Page 24: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Let's put on our security hat

Page 25: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Where to start? Think like an attacker.

Page 26: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

"The trust that happens without conscious decision, like a person sitting in a chair assuming someone hasn't removed one of the legs since they last sat in it."

- Jon Lamendola

Page 27: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

"Thinking like an attacker means that we try to push the boundaries of useful things to see how we can get them to do something that it was not designed for."

- Matt Lowe

Page 28: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

What promises does it make?

Page 29: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

How does it make money?

Page 30: The Art of Identifying Vulnerabilities  - CascadiaFest 2015
Page 31: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

OWASP Top 10

Broken auth & Session Management

Injection

Security Misconfiguration

Insecure Direct Object Reference

Cross-Site Scripting (XSS)

Missing Function Level Access Control

Sensitive Data Exposure

Unvalidated Redirects & Forwards

Using Known Vulnerable Components

Cross-Site Request Forgery

Page 32: The Art of Identifying Vulnerabilities  - CascadiaFest 2015
Page 33: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

nodesecurity.io/advisories

Page 34: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

https://github.com/paragonie/awesome-appsec

Learn from others

Page 35: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

CURIOSITY

Page 36: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

If you don't look, you won't find anything.

Page 37: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Act Ridiculous

Page 38: The Art of Identifying Vulnerabilities  - CascadiaFest 2015
Page 39: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

How can it be used in other ways?

Page 40: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Ask questions, avoid statements

"A User would never..."

Page 41: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

It's about what you don't know not what you know

Page 42: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

DEMO

Page 43: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Understand the Code & Threat Model

Identify Inputs (Sources)

Identify Sinks

Follow the data Source -> Sink

Test & Validate

Repeat

tldr; Process

Page 44: The Art of Identifying Vulnerabilities  - CascadiaFest 2015
Page 45: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Understand the Code• "miliseconds conversion utility" • Simple JS without strict mode • Doesn't use any builtins (core functions) • It's intended to be used in the browser and

server side

Page 46: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

FOLLOW THE DATASOURCE SINK

Page 47: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Identify Inputs (sources)• exports is one function • takes a value • Takes optional options argument

Page 48: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Identify data Sinks• Converted value is returned • regex is a sink that has known attacks

(regular expression denial of service)

1 var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);

Page 49: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

cat index.js | esgraph | dot -Tpng > out.png

Page 50: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

1 var ms = require('./'); 2 var genstr = function (len, chr) { 3 var result = ""; 4 for (i=0; i<=len; i++) { 5 result = result + chr; 6 } 7 8 return result; 9 } 10 11 ms(genstr(process.argv[2], "5") + " minutea");

Test & Validate

Page 51: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Test & ValidateLength Run time (seconds)

10000 0.720

20000 2.491

30000 5.629

40000 12.386

Page 52: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

Be okay with boring, monotonous and unfruitful testing Be persistent

Page 53: The Art of Identifying Vulnerabilities  - CascadiaFest 2015

</presentation>

adam_baldwinevilpacket