serverless security attack defense
play

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


  1. www.securing.pl Pawel Rzepa Serverless security: attack & defense

  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

  3. www.securing.pl

  4. www.securing.pl ht https:// //myblog. g.com WELC ELCOME ME TO TO MY MY BLO LOG HT HTML, CSS, CSS, JS JS

  5. www.securing.pl

  6. www.securing.pl New pu Ne purch chase PAYMEN ENT web-ho we hook https:// ht //myblog. g.com PROVIDER ER [Course] [C ] How to ma make yo your do dog love yo you? Se Send e-ma mail to to cu customer HT HTML, CSS, CSS, JS JS Gen Gener erate da daily re report rt

  7. www.securing.pl Monolithic architecture Serverless architecture • Refactor the website (maybe move to WordPress + PHP?) Get con Ge onfirmation on of of pa payment • You don’t know how big traffic VS you’ll have • You have to pay for hosting Se Send e-m -mail to o (based on your assumptions of the custom omer traffic) • You have to maintain your server (patch management, latency etc.) Ge Generate da dail ily repor ort

  8. FaaS on the example of Lambda www.securing.pl PAY AYMEN ENT P O S T / c o PROVI VIDER ER n f i r m a t i o n H T T P event / 1 . 1 event

  9. www.securing.pl

  10. ______________________ www.securing.pl | | THERE ARE STILL SERVERS IN SERVERLESS |_____________________ | (\__/) || (• ㅅ •) || / づ

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

  12. www.securing.pl • test Demo https://vimeo.com/426723624

  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

  14. www.securing.pl Bob uses Serverless Framework

  15. www.securing.pl Bob’s 1 st challenge: Create the PoC app where internal candidates can submit their CVs

  16. www.securing.pl • test Demo https://vimeo.com/426725013

  17. www.securing.pl • test OWASP Serverless-Goat https://github.com/OWASP/Serverless-Goat

  18. www.securing.pl • test

  19. www.securing.pl Don’t use shared function IAM role • test

  20. www.securing.pl Use per-function IAM role • test

  21. Azure Functions are deployed as App Service www.securing.pl

  22. All functions share the same environment www.securing.pl

  23. www.securing.pl • test Demo https://vimeo.com/462561054

  24. www.securing.pl • test Demo https://vimeo.com/462561274

  25. www.securing.pl

  26. www.securing.pl • test Demo https://vimeo.com/462561651

  27. www.securing.pl Waaat?!

  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

  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.

  30. www.securing.pl • test And above all: TEST YOUR CODE!!!

  31. www.securing.pl Bob’s 2 nd 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 ', ownerIdentity: [Object], arn: 'arn:aws:s3:::serverless-security-demo' }, object : { key: ' test-new.png ', size: 20, eTag: '3de8f8b0dc94b8c2230fab9ec0ba0506', sequencer: '005E88ACC4D5810265' }

  32. www.securing.pl

  33. www.securing.pl tu

  34. www.securing.pl Bob writes a proof-of-concept

  35. www.securing.pl tu

  36. www.securing.pl

  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

  38. www.securing.pl dependency poisoning in real life… tu

  39. www.securing.pl In 2018 NPM EventStream package was found malicious…

  40. www.securing.pl

  41. www.securing.pl • test

  42. www.securing.pl Ad Added the mali alicious us pac ackag kage: flatmap-stream@0.1.1 • 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…. : y r o t s l l u F q m v m l U 2 / y l . t i b / / : s p t t h

  43. www.securing.pl • test Demo https://vimeo.com/426724437

  44. www.securing.pl Defense • Monitor dependencies (Snyk/Black Duck/OWASP Dependency-Track) • Scan for known vulnerabilities ( `$ npm audit fix` )

  45. www.securing.pl Bob’s 3 rd challenge: Only some extensions should be scanned

  46. www.securing.pl • test

  47. www.securing.pl Regular expression Denial of Service (ReDoS) • test

  48. www.securing.pl • test Demo https://vimeo.com/426724608

  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

  50. www.securing.pl ht http: p:// //re redos-ch check cker.su surge.sh sh

  51. www.securing.pl Defense • Adjust Lambda concurrent execution limit and throttling • Track anomalies in logs • Set up a billing alarm

  52. www.securing.pl Bob’s 4 th challenge: The Lambda function should create a new entry in DynamoDB

  53. Why you shouldn’t store secrets in environment variables www.securing.pl • test

  54. www.securing.pl • test

  55. www.securing.pl Example of default bucket policy created by Serverless Framework • test

  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" } (...)

  57. www.securing.pl Defense • Encrypt secrets, e.g. using KMS • Store secrets in Secret Manager or SSM Parameter Store and easily reference them: db_pass: ${ssm:/path/to/db_pass~true} • In Azure use Key Vault • In GCP use Secret Manager

  58. www.securing.pl www.securing.pl LAST BUT NOT LEAST

  59. www.securing.pl • test

  60. www.securing.pl Remember, finding dangling HTTP-triggered FaaS is as simple as enumerating subdomains!!! • test https://[random]. execute-api .[ region ]. amazonaws.com/ [API endpoint name] http(s)://[App Service name]. azurewebsites.net/api/ [function name] https://[region]-[App Engine name]. cloudfunctions.net/ [function name]

  61. www.securing.pl • test Regularly audit your cloud infrastructure and sed resources!!! remove al all not u not use

  62. www.securing.pl Gaining an access to the cloud is just a beginning… • test https://bit.ly/30YhL8D

  63. pawel.rzepa@securing.pl 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/ ! ! ! u o y k n a h T

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend