Serverless security: attack & defense www.securing.pl #whoami - - PowerPoint PPT Presentation

serverless security attack defense
SMART_READER_LITE
LIVE PREVIEW

Serverless security: attack & defense www.securing.pl #whoami - - PowerPoint PPT Presentation

www.securing.pl Pawel Rzepa Serverless security: attack & defense www.securing.pl #whoami Senior Security Consultant in - Pentesting - Cloud security assessment Blog: https://medium.com/@rzepsky @Rzepsky


slide-1
SLIDE 1

www.securing.pl

Pawel Rzepa

Serverless security: attack & defense

slide-2
SLIDE 2

www.securing.pl

#whoami Senior Security Consultant in

  • Pentesting
  • Cloud security assessment

Blog: https://medium.com/@rzepsky @Rzepsky www.linkedin.com/in/pawel-rzepa

slide-3
SLIDE 3

www.securing.pl

slide-4
SLIDE 4

www.securing.pl

ht https:// //myblog. g.com

WELC ELCOME ME TO TO MY MY BLO LOG

HT HTML, CSS, CSS, JS JS

slide-5
SLIDE 5

www.securing.pl

slide-6
SLIDE 6

www.securing.pl

ht https:// //myblog. g.com

[C [Course] ] How to ma make yo your do dog love yo you?

PAYMEN ENT PROVIDER ER

Ne New pu purch chase we web-ho hook Se Send e-ma mail to to cu customer Gen Gener erate da daily re report rt HT HTML, CSS, CSS, JS JS

slide-7
SLIDE 7

www.securing.pl

Monolithic architecture

Ge Get con

  • nfirmation
  • n of
  • f

pa payment Se Send e-m

  • mail to
  • custom
  • mer

Ge Generate da dail ily repor

  • rt

VS

  • Refactor the website (maybe move to

WordPress + PHP?)

  • You don’t know how big traffic

you’ll have

  • You have to pay for hosting

(based on your assumptions of the traffic)

  • You have to maintain your server

(patch management, latency etc.)

Serverless architecture

slide-8
SLIDE 8

www.securing.pl

FaaS on the example of Lambda

P O S T / c

  • n

f i r m a t i

  • n

H T T P / 1 . 1 event event

PAY AYMEN ENT PROVI VIDER ER

slide-9
SLIDE 9

www.securing.pl

slide-10
SLIDE 10

www.securing.pl

______________________ | | THERE ARE STILL SERVERS IN SERVERLESS |_____________________ | (\__/) || (•ㅅ•) || / づ

slide-11
SLIDE 11

www.securing.pl

ht http: p://w //www.lamb ambdas ashe hell.com/ m/

slide-12
SLIDE 12

www.securing.pl

  • test

Demo https://vimeo.com/426723624

slide-13
SLIDE 13

www.securing.pl

Meet Bob

  • Junior developer
  • He needs to develop a few serverless functions, only for internal usage

My apps aren’t public, so there is no need to put them in security review process

slide-14
SLIDE 14

www.securing.pl

Bob uses Serverless Framework

slide-15
SLIDE 15

www.securing.pl

Bob’s 1st challenge:

Create the PoC app where internal candidates can submit their CVs

slide-16
SLIDE 16

www.securing.pl

  • test

Demo https://vimeo.com/426725013

slide-17
SLIDE 17

www.securing.pl

  • test

OWASP Serverless-Goat

https://github.com/OWASP/Serverless-Goat

slide-18
SLIDE 18

www.securing.pl

  • test
slide-19
SLIDE 19

www.securing.pl

  • test

Don’t use shared function IAM role

slide-20
SLIDE 20

www.securing.pl

  • test

Use per-function IAM role

slide-21
SLIDE 21

www.securing.pl

Azure Functions are deployed as App Service

slide-22
SLIDE 22

www.securing.pl

All functions share the same environment

slide-23
SLIDE 23

www.securing.pl

  • test

Demo https://vimeo.com/462561054

slide-24
SLIDE 24

www.securing.pl

  • test

Demo https://vimeo.com/462561274

slide-25
SLIDE 25

www.securing.pl

slide-26
SLIDE 26

www.securing.pl

  • test

Demo https://vimeo.com/462561651

slide-27
SLIDE 27

www.securing.pl

Waaat?!

slide-28
SLIDE 28

www.securing.pl

Defense

  • Follow least privilege principle!
  • Use per-function IAM role
  • se

serverless ss-i

  • iam

am-ro roles-pe per-fu function (ht https:/ ://bit. bit.ly/2 /2MzjdYh)

  • Harden your API Gateway
  • Use API Gateway Request Validation
  • se

serverless ss-re reqval alidat ator-pl plugin (ht https: s://b //bit.ly/2 /2Xq Xqay0k)

  • Consider using WAF
slide-29
SLIDE 29

www.securing.pl

In GCP by default all Cloud Functions in a Google Cloud project share the same runtime service account (with Editor role :0 ) – create unique service account to each function In Azure apply RBAC to assign limited permissions to resource

  • group. You can use Shared Access Signature tokens to get limited

access to other resources.

slide-30
SLIDE 30

www.securing.pl

  • test

And above all: TEST YOUR CODE!!!

slide-31
SLIDE 31

www.securing.pl

Bob’s 2nd challenge:

Files uploaded to the particular S3 bucket should be automatically renamed with some prefix

test-new.png event

s3: { s3SchemaVersion: '1.0', configurationId: 'f67747b9-c02c-4e54-8e49-2dba5060d555', bucket: { name: 'serverless-security-demo',

  • wnerIdentity: [Object],

arn: 'arn:aws:s3:::serverless-security-demo' },

  • bject: {

key: 'test-new.png', size: 20, eTag: '3de8f8b0dc94b8c2230fab9ec0ba0506', sequencer: '005E88ACC4D5810265' }

slide-32
SLIDE 32

www.securing.pl

slide-33
SLIDE 33

www.securing.pl

tu

slide-34
SLIDE 34

www.securing.pl

Bob writes a proof-of-concept

slide-35
SLIDE 35

www.securing.pl

tu

slide-36
SLIDE 36

www.securing.pl

slide-37
SLIDE 37

www.securing.pl

How to defend?

  • You can limit the outgoing traffic by using a VPC-enabled Lambda in

Private Subnet

  • Outbound traffic can be controlled by Security Groups (default VPC SGs

allow all outbound traffic)

  • If your Lambda need an access to any of your

resources, then use VPC endpoint policies to control the access Private subnet

slide-38
SLIDE 38

www.securing.pl

tu

dependency poisoning in real life…

slide-39
SLIDE 39

www.securing.pl

In 2018 NPM EventStream package was found malicious…

slide-40
SLIDE 40

www.securing.pl

slide-41
SLIDE 41

www.securing.pl

  • test
slide-42
SLIDE 42

www.securing.pl

  • test
  • The malicious code was decrypted only for the copay-dash package
  • a popular Bitcoin platform which includes event-stream as a

dependency

  • The goal of the malicious script was to steal Bitcoin wallets
  • It worked pretty well, but one method used by malicious package

became deprecated…. F u l l s t

  • r

y : h t t p s : / / b i t . l y / 2 U l m v m q

Ad Added the mali alicious us pac ackag kage: flatmap-stream@0.1.1

slide-43
SLIDE 43

www.securing.pl

  • test

Demo https://vimeo.com/426724437

slide-44
SLIDE 44

www.securing.pl

Defense

  • Monitor dependencies (Snyk/Black Duck/OWASP

Dependency-Track)

  • Scan for known vulnerabilities (`$ npm audit fix`)
slide-45
SLIDE 45

www.securing.pl

Bob’s 3rd challenge:

Only some extensions should be scanned

slide-46
SLIDE 46

www.securing.pl

  • test
slide-47
SLIDE 47

www.securing.pl

  • test

Regular expression Denial of Service (ReDoS)

slide-48
SLIDE 48

www.securing.pl

  • test

Demo https://vimeo.com/426724608

slide-49
SLIDE 49

www.securing.pl

Denial of Wallet

  • Default timeout in Serverless Framework is 6 seconds and maximum

timeout in AWS Lambda is 15 minutes

  • Price for 100 ms (1024 MB memory allocated): $0.0000016667
  • Sending 100 K requests, each billed for 900000ms: ~1500 USD

No big differences between

slide-50
SLIDE 50

www.securing.pl

ht http: p:// //re redos-ch check cker.su surge.sh sh

slide-51
SLIDE 51

www.securing.pl

Defense

  • Adjust Lambda concurrent execution limit and throttling
  • Track anomalies in logs
  • Set up a billing alarm
slide-52
SLIDE 52

www.securing.pl

Bob’s 4th challenge:

The Lambda function should create a new entry in DynamoDB

slide-53
SLIDE 53

www.securing.pl

  • test

Why you shouldn’t store secrets in environment variables

slide-54
SLIDE 54

www.securing.pl

  • test
slide-55
SLIDE 55

www.securing.pl

  • test

Example of default bucket policy created by Serverless Framework

slide-56
SLIDE 56

www.securing.pl

  • test

$ cat compiled-cloudformation-template.json (...) "Environment": { "Variables": { "HOST_DB": "1.2.3.4", ”DB_PORT": "3306", "USER": "db_user", "PASS": ” \(8cW:$W ", "DB": "test_db" } (...)

slide-57
SLIDE 57

www.securing.pl

Defense

  • Encrypt secrets, e.g. using KMS
  • Store secrets in Secret Manager or SSM Parameter Store and easily

reference them:

  • In Azure use Key Vault
  • In GCP use Secret Manager

db_pass: ${ssm:/path/to/db_pass~true}

slide-58
SLIDE 58

www.securing.pl www.securing.pl

LAST BUT NOT LEAST

slide-59
SLIDE 59

www.securing.pl

  • test
slide-60
SLIDE 60

www.securing.pl

  • test

Remember, finding dangling HTTP-triggered FaaS is as simple as enumerating subdomains!!!

https://[region]-[App Engine name].cloudfunctions.net/[function name] https://[random].execute-api.[region].amazonaws.com/[API endpoint name] http(s)://[App Service name].azurewebsites.net/api/[function name]

slide-61
SLIDE 61

www.securing.pl

  • test

Regularly audit your cloud infrastructure and remove al all not u not use sed resources!!!

slide-62
SLIDE 62

www.securing.pl

  • test

Gaining an access to the cloud is just a beginning… https://bit.ly/30YhL8D

slide-63
SLIDE 63

www.securing.pl

Let’s stay in touch!!!

  • Are you interested in taking a cloud security assessment?
  • Would you like to send me some feedback regarding this presentation?
  • Please contact me on paw

pawel.rz .rzepa@ pa@securi ring.pl .pl

  • or on Twitter: @Rz

Rzepsk sky

  • or on LinkedIn: ht

https:/ ://www.l www.lin inkedin in.c .com/i /in/p n/pawel-rz rzepa pa-5326965b 5326965b/

T h a n k y

  • u

! ! !

pawel.rzepa@securing.pl