AppSensor CodeMash 2017

121

Click here to load reader

Transcript of AppSensor CodeMash 2017

Page 1: AppSensor CodeMash 2017

Building Self-Defending Applications

With OWASP AppSensor

CodeMash 2017

Page 2: AppSensor CodeMash 2017

housekeeping

• lots of slides

• slides at: http://www.slideshare.net/jtmelton/appsensor-codemash-2017

Page 3: AppSensor CodeMash 2017

me• appsensor dev lead (OWASP)

• dev / security

• why me?

• twitter: @_jtmelton

• email: jtmelton at gmail.com

• github: jtmelton

Page 4: AppSensor CodeMash 2017

you• dev

• security

• ops

• other …

• behavioral security pre-compiler?

Page 5: AppSensor CodeMash 2017

agenda

• thesis

• history (recent)

• motivations / problems

• solution / tech

• future / wrap-up

Page 6: AppSensor CodeMash 2017

thesis:

modern secure applications protect themselves against

attackers

Page 7: AppSensor CodeMash 2017
Page 8: AppSensor CodeMash 2017

(brief) history

Page 9: AppSensor CodeMash 2017

not too long ago dev

• mostly web apps [RoR, PHP, .NET, Java)

• ajax (jquery) use growing

• mobile just getting started

• deployment to VMs

• hadoop picking up

• BI tools

• AWS starting

• cloud hype cycle (NIST defines)

Page 10: AppSensor CodeMash 2017

~now dev• JS everywhere

• functional / rx programming

• cloud everything

• ci/cd

• nosql / CAP light

• containers/orchestration

• big data

• stream processing

• config management

• iot

• beacons [usage, ads, errors, performance]

• actors/csp

• microservices

• cqrs / event sourcing

• mobile

Page 11: AppSensor CodeMash 2017

~now dev• JS everywhere

• functional / rx programming

• cloud everything

• ci/cd

• nosql / CAP light

• containers/orchestration

• big data

• stream processing

• config management

• iot

• beacons [usage, ads, errors, performance]

• actors/csp

• microservices

• cqrs / event sourcing

• mobile

1 .. * of [scale, speed, cloud, lack of environmental access]

Page 12: AppSensor CodeMash 2017
Page 13: AppSensor CodeMash 2017

meanwhile … in security

• 3rd party libs (dep-check)

• bug bounties

• sast / dast evolve (ZAP)

• iast / rasp

• http security headers

• automatic encoding (JXT)

• *-monkey -NetflixOSS

• bdd-security/gauntlt

• ci/cd plugins

• 2fa

• osquery

1 .. * of [scale, speed, cloud, lack of environmental access]

Page 14: AppSensor CodeMash 2017

dev vs. security

• dev is exploiting fundamental architectural and deployment changes to add business value

• security is iterating on existing solutions - and - trying to close gaps (known problems)

Page 15: AppSensor CodeMash 2017

Security is sharpening hand tools

while dev has moved to

power tools

Page 16: AppSensor CodeMash 2017

motivations

Page 17: AppSensor CodeMash 2017

traditional “security”• confidentiality and

integrity important

• availability often ignored by security (informs the whole industry- eg. tooling)

• if availability important, runtime important

X

Page 18: AppSensor CodeMash 2017

Yep, that’s secure!

Page 19: AppSensor CodeMash 2017

your environment

• how many concurrent users do you have right now?

• what are your users doing in the app?

Page 20: AppSensor CodeMash 2017

https://github.com/aphyr/jepsen-talks/blob/master/2015/goto/goto.pdf

Page 21: AppSensor CodeMash 2017

Intuition: • “traditional” security, dev, ops doesn’t know what’s

going on in the app at runtime (holistically)

Page 22: AppSensor CodeMash 2017

Security defects are a subset of all defects

Page 23: AppSensor CodeMash 2017
Page 24: AppSensor CodeMash 2017
Page 25: AppSensor CodeMash 2017

catching defects

• what do dev/qa do for functionality?

• test [unit, integration, system, manual, tools]

• what do attackers do for security?

• test [automated tools, manual]

Page 26: AppSensor CodeMash 2017
Page 27: AppSensor CodeMash 2017
Page 28: AppSensor CodeMash 2017

observations

• attackers do bad things

• bad things often easily recognizable (to you … in your business … if you’re looking)

• attacker success often* requires > 1 attempt

* If not, you lose

Page 29: AppSensor CodeMash 2017

Intuition: • security defects exist

• attackers don’t magically know what’s vulnerable *

* Source Code

Page 30: AppSensor CodeMash 2017

Monitoring

Page 31: AppSensor CodeMash 2017

http://worth1000.s3.amazonaws.com/submissions/414000/414200_9830_1024x2000.jpg

Page 32: AppSensor CodeMash 2017

Intuition: • existing (security) “monitoring” is usually

terrible *

* Note: a 2U box will not protect you

Page 33: AppSensor CodeMash 2017

on people

• 18.2 million devs

• 200K security (all, not appsec only)

• ~ 1.1 sec : 100 dev

• 1.75 sec : 100 dev (bsimm)

Page 34: AppSensor CodeMash 2017

Intuition: • there will never be enough “security”

people

Page 35: AppSensor CodeMash 2017

security modern dev• a single mature,

static language

• monolith

• http (really html) endpoints

• polyglot static and dynamic languages

• microservices / soa

• json, thrift, protobuf, grpc, etc. endpoints

• WebAssembly ???

tooling

Page 36: AppSensor CodeMash 2017

@petecheslock

Page 37: AppSensor CodeMash 2017

Intuition: • “traditional” security tooling doesn’t fit

modern dev

… and is unlikely to be able to keep up

Page 38: AppSensor CodeMash 2017

defender’s dilemma

• attacker needs ONE successful attack

• defender * must defend ALL attacks

* you are defenders

Page 39: AppSensor CodeMash 2017

in summary (so far) …• “traditional” security, dev, ops doesn’t know what’s going on

in the app at runtime (holistically)

• security defects exist

• attackers don’t magically know what’s vulnerable

• existing (security) “monitoring” is usually terrible

• there will never be enough “security” people

• “traditional” security tooling doesn’t fit modern dev

… actual defense is _really_ hard

Page 40: AppSensor CodeMash 2017

the pitch

(a humble proposal)

Page 41: AppSensor CodeMash 2017

having to deal with [scale, speed, cloud, lack of

environmental access]..

..this as of now incomplete transition..

..is an huge opportunity for improving security

Page 42: AppSensor CodeMash 2017

the pitch (#0)

• in addition to a secure SDLC … (ie. > 1 request/attack)

• if you’re not at this stage, work on it first

Page 43: AppSensor CodeMash 2017
Page 44: AppSensor CodeMash 2017

the pitch• figure out what’s happening at runtime

X successAppSensor

• make intrusion detection primitives available in app

• exploit automated response > manual response

• stop attacker before success *

• get self-protecting applications and valuable intel

* define success

Page 45: AppSensor CodeMash 2017

X

X

X

Page 46: AppSensor CodeMash 2017

terminology

• event - suspicious

• attack - malicious (1 .. * events)

• response - take action (1 .. 1 attack)

• detection point - activity category (e.g. cookie modification)

Page 47: AppSensor CodeMash 2017

… On the

shoulders of

giants …

Page 48: AppSensor CodeMash 2017

the tech

Page 49: AppSensor CodeMash 2017

the tech

• the architecture

• getting data in (detection)

• getting data out (visualization)

• current efforts

Page 50: AppSensor CodeMash 2017

Architecture

Page 51: AppSensor CodeMash 2017

Your Application AppSensor

1. Event

2. Attack

3. Response

Page 52: AppSensor CodeMash 2017

Your Application AppSensor

1. Event2. Event

3. Attack

4. Response

Page 53: AppSensor CodeMash 2017

AppSensor

WAF

NIDS

App 1

App 2

App N

Data Viz

SIEM

Analytics

Events / Attacks Event / Attack / Response Notifications

Policy

Responses

Correlation

Page 54: AppSensor CodeMash 2017

AppSensor

NIDS

App 1

App 2

App 3

App 5

Data Viz

SIEM

AnalyticsPolicy

WAF

App 4

WAF & Apps 1, 2 and 4 are correlated

Event Attack

Notification

Response

Page 55: AppSensor CodeMash 2017

AppSensor

IN

OUTPolicy

Reporting Engines

Analysis Engines

ListenersEvent, Attack, Response

StoresHandlerEvents / Attacks

Responses

Page 56: AppSensor CodeMash 2017

Emitters

• ELK

• CEF / Syslog

• Influx / Grafana

• WebSocket

• JMX

• Prometheus

Framework Integration

• Spring Security

Configuration

• XML

Page 57: AppSensor CodeMash 2017

Execution Modes

• REST

• Kafka

• ActiveMQ

• RabbitMQ

• Thrift

• SOAP

• embedded (jvm)

Storage Providers

• JPA2

• ElasticSearch

• Mongo

• Riak

• Influx

• File

• In-memory (testing)

Page 58: AppSensor CodeMash 2017

Adding Detection Points

(getting data in)

Page 59: AppSensor CodeMash 2017

adding detection points

• manually

• appsensor-reverse-proxy

• WAF (e.g. OWASP CRS in ModSecurity)

• OWASP ASIDE (secure IDE plugin/educational)

Page 60: AppSensor CodeMash 2017

manualPOST /account/transfer HTTP/1.1

Host: 127.0.0.1 User-Agent: Mozilla/5.0 (Win…) Accept: text/html,application/xhtml+xml Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://127.0.0.1/account.php Cookie: PHPSESSID=l9…lgt5 Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 30 from_acct=xxx1234&to_acct=xxx9876&amt=20.00

Page 61: AppSensor CodeMash 2017

manualPOST /account/transfer HTTP/1.1

Host: 127.0.0.1 User-Agent: Mozilla/5.0 (Win…) Accept: text/html,application/xhtml+xml Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://127.0.0.1/account.php Cookie: PHPSESSID=l9…lgt5 Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 30 from_acct=xxx1234&to_acct=xxx9876&amt=20.00

Page 62: AppSensor CodeMash 2017

manual@POST public Response transfer( String from, String to, String amount) {

transfer(from, to, amount);

return Response.ok(); }

Page 63: AppSensor CodeMash 2017

manual@POST public Response transfer( String from, String to, String amount) {

if ( currentUser.owns(from) ) { transfer(from, to, amount); }

return Response.ok(); }

Page 64: AppSensor CodeMash 2017

manual@POST public Response transfer( String from, String to, String amount) {

if ( currentUser.owns(from) ) { transfer(from, to, amount); } else { showErrorPage(); // normal error handling }

return Response.ok(); }

Page 65: AppSensor CodeMash 2017

manual@POST public Response transfer( String from, String to, String amount) {

if ( currentUser.owns(from) ) { transfer(from, to, amount); } else {

appsensor.addEvent( new Event(currentUser, "ACE2") ); showErrorPage(); // normal error handling }

return Response.ok(); }

Page 66: AppSensor CodeMash 2017

recommendations

• Aim for key architectural choke points

• AOP can often be helpful

• Exploit custom exception hierarchies

• Look for business logic cases

• Train developers to think this way

Page 67: AppSensor CodeMash 2017

appsensor-reverse-proxy

Page 68: AppSensor CodeMash 2017

appsensor-reverse-proxy

• written in go

• blocks requests

• canned detection points (toggle-able)

• easily extendable

• https://github.com/jtmelton/appsensor-reverse-proxy

Page 69: AppSensor CodeMash 2017

WAF• Send events and/or attacks

• Receive and process responses

• OWASP CRS in ModSecurity has AppSensor rules already

• https://www.trustwave.com/Resources/SpiderLabs-Blog/Implementing-AppSensor-Detection-Points-in-ModSecurity/

Page 70: AppSensor CodeMash 2017

OWASP ASIDE• secure programming IDE plugin (eclipse)

• reminder icon or highlight

• drop down list of applicable sensors

• auto-insertion of ASIDE sensor APIs and code refactoring

• UNCC SIS project (educational component)

• https://www.owasp.org/index.php/OWASP_ASIDE_Project

Page 71: AppSensor CodeMash 2017

OWASP ASIDE

Page 72: AppSensor CodeMash 2017

OWASP ASIDEBasedonESAPIcode(lengthchecked),ASIDEinfersthatthismaybeapointtoinsertanappsensor;whetherasensorisplacedreliesondeveloper’sdecision.

Page 73: AppSensor CodeMash 2017

OWASP ASIDE

ItnotonlycapturesthecontextinformaFon(e.g.thesensoreventisfromusernamefield),butalsorecordsthatthesensoreventisduetoanexceedinglylengthyinput.

Page 74: AppSensor CodeMash 2017

Viewing Data

(getting data out)

Page 75: AppSensor CodeMash 2017

viewing data

• ELK stack (OWASP SoC)

• influxdb / grafana (OWASP SoC)

• appsensor-ui

Page 76: AppSensor CodeMash 2017

ELK

Page 77: AppSensor CodeMash 2017

Influx / Grafana

Page 78: AppSensor CodeMash 2017

appsensor-ui

pictures

Page 79: AppSensor CodeMash 2017
Page 80: AppSensor CodeMash 2017
Page 81: AppSensor CodeMash 2017
Page 82: AppSensor CodeMash 2017
Page 83: AppSensor CodeMash 2017
Page 84: AppSensor CodeMash 2017

Current Efforts

Page 85: AppSensor CodeMash 2017

Rules Engine Goals

• Expand detection capabilities by providing boolean logic and new span primitives

• Reduce false positives by leveraging several suspicious events to discover a malicious event

Page 86: AppSensor CodeMash 2017

Rules Engine

• Multiple sensors grouped into single “Rule” to trigger an attack

• Rule combines sensors with AND/OR/NOT/THEN operators

• Thresholds can be lowered without increasing false-positive rate because there are multiple indicators

• I.e. many SUSPICIOUS factors can define a MALICIOUS factor

Page 87: AppSensor CodeMash 2017

Example - Default Engine

Sensor1 - Multiple failed login attempts (50 attempts / 1 minute)

Rule: Sensor1

Page 88: AppSensor CodeMash 2017

Example - Rules Engine with AND

Sensor1 - Multiple failed login attempts

Sensor2 - Use of blacklisted characters

Sensor3 - Password attempt too long

Sensor4 - Multiple usernames attempted from single IP

Rule: Sensor1 AND Sensor2 AND Sensor3 AND Sensor4

Page 89: AppSensor CodeMash 2017

Example - Rules Engine with OR

Sensor1 - Multiple failed login attempts

Sensor2 - Use of blacklisted characters

Sensor3 - Password attempt too long

Sensor4 - Multiple users attempting to login from single IP

Rule: Sensor1 AND (Sensor2 OR Sensor3 OR Sensor4)

Page 90: AppSensor CodeMash 2017

Example - Rules Engine with THEN

Sensor1 - Use of blacklisted characters

Sensor2 - Large file upload

Sensor3 - Large file download

Sensor1 THEN (Sensor2 OR Sensor3)

Page 91: AppSensor CodeMash 2017

Ultimately Any Combination Will Work

Sensor1 OR Sensor2

THEN

Sensor3 AND (Sensor4 OR Sensor5)

THEN

Sensor6 AND Sensor7 AND Sensor8 AND Sensor9 AND Sensor10

Page 92: AppSensor CodeMash 2017
Page 93: AppSensor CodeMash 2017

Under the Hood

Sensor1 THEN

Sensor2

Page 94: AppSensor CodeMash 2017

Under the Hood

Sensor1 THEN

Sensor2

1. Collect Events

Page 95: AppSensor CodeMash 2017

Sensor1 THEN

Sensor2

1. Collect Events

Under the Hood

Page 96: AppSensor CodeMash 2017

Sensor1 THEN

Sensor2

1. Collect Events

2. First Expression

Under the Hood

Page 97: AppSensor CodeMash 2017

1. Collect Events

Sensor1 THEN

Sensor2

Under the Hood

2. First Expression

Page 98: AppSensor CodeMash 2017

1. Collect Events

Sensor1 THEN

Sensor2

Under the Hood

2. First Expression

Page 99: AppSensor CodeMash 2017

1. Collect Events

Sensor1 THEN

Sensor2

Under the Hood

2. First Expression

Page 100: AppSensor CodeMash 2017

1. Collect Events

Under the Hood

Sensor1 THEN

Sensor2

2. First Expression

3. Second Expression

Page 101: AppSensor CodeMash 2017

Sensor1 THEN

Sensor2

1. Collect Events

Under the Hood

2. First Expression

3. Second Expression

4. Rule Triggered

Thanks David Scrobonia - Landed!

Page 102: AppSensor CodeMash 2017

GSoC 2016 (ML)• An external system using Logstash, Kafka

and Spark that takes in log files, runs machine learning (ML) analysis on the features specified by user and generates a list of rules sorted by an evaluation criteria.

• The aim of this system is to assist users to identify anomalous patterns or behaviors on their system in a readable manner.

Page 103: AppSensor CodeMash 2017

ML Analysis

• Currently implemented algorithms for both simple and complex analysis are k-means clustering, naïve bayes, logistic regression and decision trees.

• You would need to write your own indexer for any new categorical features if the algorithm only accepts numeric features and your own vectorizer for different combinations of multiple features.

• Simple analysis uses one feature (example: HTTP verb, response, lat/long) for clustering and classification

• Complex analysis takes into account multiple features for the ML process.

Page 104: AppSensor CodeMash 2017

ML Future Work• Project is definitely still a work in progress.

• Some changes/improvements to be made:

1. Add support for more common log file formats

2. Add support for other features that can be used in a log file

3. Add visualization to allow users to understand results of complex analysis better

• One major goal of current efforts is a tool you can send web logs in standard formats and receive “suggested rules”

Page 105: AppSensor CodeMash 2017

ML Docs and Video

• All documentation for the GSoC project can be found at: https://github.com/timothy22000/GSoC-MLAnalysisEngine

• https://youtu.be/tsdC_ftjF1g (video demo)

• Thanks Timothy Sum Hon Mun!

Page 106: AppSensor CodeMash 2017

Analysis Engines

Simple thresholds

Large user changes in user base or application

Anomaly Detection

Aggregation of simple thresholds

Basic Trend*Machine Learning

Rules

* not started

Page 107: AppSensor CodeMash 2017

Server Assembler

• Generate your server app!

• Easily select your components and generate a proper app

• Instructions for what config changes to make (db passwords, header names, etc.)

• Currently MOST requested feature

Page 108: AppSensor CodeMash 2017
Page 109: AppSensor CodeMash 2017
Page 110: AppSensor CodeMash 2017

• Thanks Ray LeBlanc - @raybeorn (the work)!

• Thanks Spring Boot (the inspiration and some code)!

Page 111: AppSensor CodeMash 2017
Page 112: AppSensor CodeMash 2017

`

Page 113: AppSensor CodeMash 2017

future plans

Page 114: AppSensor CodeMash 2017

future• complete server assembler (very soon)

• analysis engines (add trend, expand rules and ML)

• expand appsensor-ui

• expand reverse proxy

• framework integration for detection points (spring security exists, add others)

• your idea here ???

Page 115: AppSensor CodeMash 2017

you• help wanted!

• plenty of places to contribute and improve

• friendly, helpful community

• https://github.com/jtmelton/appsensor/issues

• https://www.owasp.org/index.php/OWASP_AppSensor_Project#tab=Road_Map_and_Getting_Involved

Page 116: AppSensor CodeMash 2017

wrap-up

Page 117: AppSensor CodeMash 2017

~related projects

• repsheet (see Aaron - he’s here!)

• ensnare

• fido

• riemann

• apache eagle

• devsecops

• elastalert

• fouroneone

• https://github.com/dschadow/ApplicationIntrusionDetection /

Page 118: AppSensor CodeMash 2017

pick a tool (or 2) …

but use the idea

Page 119: AppSensor CodeMash 2017

contributors• https://www.owasp.org/index.php/

OWASP_AppSensor_Project#tab=Acknowledgements

• https://github.com/jtmelton/appsensor/graphs/contributors

Page 120: AppSensor CodeMash 2017

links

• https://www.owasp.org/index.php/OWASP_AppSensor_Project (download book, dev guide, etc.)

• http://appsensor.org/ (end user / dev docs)

• https://github.com/jtmelton/appsensor

Page 121: AppSensor CodeMash 2017

?

(please fill out the EventsXD survey)