building your own waf as a service and forgetting …...implementing response body analysis body is...

56
Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner 1

Upload: others

Post on 05-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Building Your Own WAF as a Service and Forgetting about False

Positives

Juan Berner1

Page 2: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

About me

● Lead security developer @Booking.com

● Twitter: @89berner

● medium.com/@89berner

2Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 3: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

WAF?

● Web Application Firewall

● Mainly used to protect against Application Attacks

● SQLi, RCE, Protocol Violations, Rate Limiting ...

3Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 4: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Deployment mode - Inline

● Pros:○ Traffic inspection○ Ability to block○ Transparent for web servers

● Cons:○ Network placement○ Latency

4Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 5: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Deployment mode - Out of band

● Pros:○ Traffic inspection○ Transparent for web servers○ Simpler network placement

● Cons:○ Can’t block attacks○ PFS

5Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 6: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Deployment mode - Agent

● Pros:○ Easier network placement○ Simple to scale

● Cons:○ More invasive on deployment environment○ Can be less efficient on resource allocation

6Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 7: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Deployment mode - Cloud

● Pros:○ Simple to setup and scale○ Network effect

● Cons:○ Out of your control○ Latency

7Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 8: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Caveats with typical WAF Solutions

● Network placement

● False positive rate

● Lack of control from developers

8Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 9: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

A challenging environment

● No acceptance for false positives

● Reluctance towards commercial appliances

● Blocking could only happen through the Application

● Latency would not be acceptable

9Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 10: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Building the WAF as a Service

● Removes false positives by having an understanding of the application context

● No need for an appliance, just add an API call

● Blocking behaviour is decided by the application

● Ability to avoid latency for regular users

10Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 11: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

How could you build one?

● Open source components already exist

● Creating a log processing pipeline

● Building a WAF API

● Library for logs and calling API

11Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 12: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Study case: Simple web application

● Setup in Google Cloud

● Simple Flask Application

● Code available in github

12Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 13: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Deployment mode?

● Let’s compare

13Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 14: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Out of band mode

14Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 15: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Inline mode

15Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 16: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Every application is different

● Threat model

● FP tolerance

● Risk acceptance

16Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 17: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Finding a middle ground

● Out of band mode removes latency concerns on users

● Inline mode provides security by blocking attacks

● Could we get the best of both worlds?

17Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 18: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Hybrid mode

18Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 19: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Web application

● Can decide which mode to work on○ Inline○ Out of band

● Sends logs with partial request data encrypted

Example: Flask API19

Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 20: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Agent

● Acts as a proxy to Web Application

● Minimal footprint

● Application agnostic

● Gets settings from application

20Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 21: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Agent

21Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 22: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Library

● Simpler to implement

● Will be tied to Application framework

● Inherent risks

● Strategy for this talk

22Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 23: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Historical database

● Historical activity

● Business value

● Patterns of behaviour for FP

23Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 24: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - State store

● Allows to store configuration

● Ideally fast lookup for caching

24Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 25: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Log streaming

● Streaming pipeline

● Web requests are encapsulated and sent through it

25Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Google PusbSub

Page 26: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Log processing

● Replays events not in line against WAF

● Calculates scores through windows of time

26Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Google Dataflow

Page 27: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Log processing

27Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 28: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Log processing

28Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 29: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Log processing

29Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 30: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - WAF service

● Pluggable architecture

● Parallel nature of their components

● Applications can decide how to react

30Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 31: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - WAF service

● Open source components

○ Modsecurity

○ Naxsi

31Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 32: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - WAF service

● Custom modules

○ Apply custom business logic

○ Implement simple services■ Rate limiting■ Rule engine for blocking

○ ML models32

Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 33: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - WAF service

● Proprietary software or appliances

○ Reduced complexity of installation

○ Simple way of evaluation

33Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 34: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

WAF service - Example: Modsecurity

● Could be made api driven through libModSecurity

● Can run on Apache HTTP Server or NGINX

● Results are written as logs

34Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 35: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

WAF service - Modsecurity as an API

● SecRule REMOTE_ADDR "@unconditionalMatch" "phase:4,id:999434,prepend: ...

35Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 36: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

WAF service - Modsecurity as an API

● Implementing response body analysis

● Body is sent to CGI for replay

36Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 37: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

WAF service

37Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 38: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

How to block?

● We decide when to send traffic to the WAF

● Manually or automatically decided

38Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 39: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Traffic routing

● Fingerprint based routing

○ Blocks based on scores

○ IP, client_id, combinations, 0day fingerprints..

○ Added automatically or manually

39Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 40: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Traffic routing

● Net block based routing

○ ISP

○ Hosting providers

○ Tor exit nodes / Proxies

40Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 41: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Traffic routing

● Virtual Patching

○ Always route particular vulnerable endpoints

○ Select for combination of parameters if needed

○ Example: website.com/?vuln_param=

41Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 42: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

FP rate management

● Detection FP vs blocking FP

● Key to allow blocking without impacting users

● Acceptable rate might change per application

42Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 43: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

FP rate management

● Business logic

○ How trustworthy is a user/ip?

○ Key business activity

○ What would be the impact on blocking them

43Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 44: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

FP rate management

● Historical Analysis

○ How normal is this type of request for this endpoint?

○ How does this user compare with others

○ How common are detection FP in this endpoint

44Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 45: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

FP rate management

● Context analysis

○ How many times have they triggered a FP

○ How many requests have they sent

45Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 46: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

FP rate management

● Example: Sleep(

○ message=“I sleep(1 or 2 days)”

■ Might be detected as SQLI

■ Probability of FP is independent from each other

46Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 47: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

FP rate management

● Independant SQLI FP rate: 0.1%

● Our aim, 0.00001% (0.01^5) => Score 5

● Block can happen only for SQLis

● Aimed at attacks that need volume

47Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 48: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Visualisation

● Easily understand activity

● Visibility on attacks

● Performance metrics

Example: ELK48

Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 49: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Visualisation

49Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 50: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Visualisation

50Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 51: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Visualisation

51Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 52: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Components - Visualisation

52Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 53: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Hybrid mode

● Benefits

○ Can reduce latency

○ Flexibility

○ FP rate can be decided

53Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 54: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

Hybrid mode

● Caveats

○ Delayed response time for blocking

○ Complexity

54Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 55: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

55Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner

Page 56: Building Your Own WAF as a Service and Forgetting …...Implementing response body analysis Body is sent to CGI for replay 36 Building Your Own WAF as a Service and Forgetting about

What now?

● Try it!

● https://github.com/89berner/waf-api-talk

● git clone https://github.com/89berner/waf-api-talk && cd waf-api-talk; ./setup $YOUR_GCP_PROJECT

● Questions?

56Building Your Own WAF as a Service and Forgetting about False Positives Juan Berner