Anzeige
Anzeige

Más contenido relacionado

Anzeige

Is persistency on serverless even possible?!

  1. Is persistency on serverless even possible?! Pwning AWS Lambdas & GCP Cloud Functions
  2. What we are going to achieve • Persistency on vulnerable Lambda & Cloud Function • Live exfiltration of the data – without role keys • Nearly undetectable method Calc during security conferences is always something big So here it is!
  3. Why this topic
  4. Yuval Avrahami (Unit 42) security research Source: Gaining Persistency on Vulnerable Lambdas - https://unit42.paloaltonetworks.com/gaining-persistency-vulnerable-lambdas/
  5. FaaS usage Source: Flexera State of the Cloud Report 2022 - https://info.flexera.com/CM-REPORT-State-of-the-Cloud
  6. What if there is vulnerability?
  7. What if – RCE?
  8. What if – RCE? • Typosquatting • Dependency confusion • Account takeover • Attacks on package manager itself
  9. Source: https://portswigger.net/daily-swig/malicious-python-library-ctx-removed-from-pypi-repo 25 May 2022 What if – RCE?
  10. Everything is normal
  11. Still normal
  12. But what if?
  13. Data gone!
  14. How the serverless infrastructure works
  15. Cold Start / Cold Boot
  16. Cold Start / Cold Boot • First execution is slower
  17. Cold Start / Cold Boot • First execution is slower • Consecutive calls are faster
  18. Cold Start / Cold Boot • First execution is slower • Consecutive calls are faster • Filesystem persists, but is frozen between calls
  19. Cold Start - how does it works? R e q u e s t t o F u n c t i o n U S E R / S E R V I C E
  20. Cold Start - how does it works? R e q u e s t t o F u n c t i o n „ H e y , w a k e u p ! ” I N V O K E S E R V I C E U S E R / S E R V I C E
  21. Cold Start - how does it works? S e t u p M i c r o V M F I R E C R A C K E R R e q u e s t t o F u n c t i o n „ H e y , w a k e u p ! ” I N V O K E S E R V I C E U S E R / S E R V I C E
  22. Cold Start - how does it works? E x e c u t e f u n c t i o n L A M B D A F I R E C R A C K E R R e q u e s t t o F u n c t i o n „ H e y , w a k e u p ! ” I N V O K E S E R V I C E U S E R / S E R V I C E S e t u p M i c r o V M
  23. Cold Start - how does it works? L A M B D A F I R E C R A C K E R R e q u e s t t o F u n c t i o n „ H e y , w a k e u p ! ” I N V O K E S E R V I C E U S E R / S E R V I C E R e s p o n s e E x e c u t e f u n c t i o n S e t u p M i c r o V M
  24. Consecutive calls L A M B D A F I R E C R A C K E R R e q u e s t t o F u n c t i o n „ I ’ v e g o t r e q u e s t ! ” I N V O K E S E R V I C E U S E R / S E R V I C E R e s p o n s e E x e c u t e f u n c t i o n „ E x e c u t e t h i s ”
  25. Consecutive calls L A M B D A F I R E C R A C K E R „ I ’ v e g o t r e q u e s t ! ” R e q u e s t t o F u n c t i o n I N V O K E S E R V I C E U S E R / S E R V I C E R e s p o n s e „ E x e c u t e t h i s ” E x e c u t e f u n c t i o n
  26. GCP?
  27. GCP? • Nearly the same • Containerization with gVisor (container sandbox)
  28. Control process
  29. AWS - Normal flow
  30. AWS - Normal flow
  31. GCP - Normal flow
  32. GCP - Normal flow
  33. Why persistency is possible in this semi-volatile environment
  34. Why?
  35. Why? • Non-volatile filesystem (at least for few minutes)
  36. Why? • Non-volatile filesystem (at least for few minutes) • Writable filesystem (/tmp and memory)
  37. Why? • Non-volatile filesystem (at least for few minutes) • Writable filesystem (/tmp and memory) • Control process inside the Container / VM
  38. AWS - Malicious flow
  39. AWS - Malicious flow
  40. AWS - Malicious flow
  41. AWS - Malicious flow
  42. GCP?
  43. Graphic design is my passion Monkey-patching!
  44. GCP – Malicious flow
  45. GCP – Malicious flow
  46. GCP – Malicious flow
  47. Exploitation And demo!
  48. Vulnerable function - CVE-2017-18342 PyYAML RCE
  49. https://vimeo.com/user149155597
  50. Switcher – the whole magic
  51. Switcher – read new runtime
  52. Switcher – save the runtime
  53. Switcher – RAM is an option
  54. Switcher – obtain invoke-id
  55. Switcher – run the runtime!
  56. Evil Bootstrap – invoke runtime
  57. Evil Bootstrap – request handling
  58. Evil Bootstrap – request handling this one line
  59. Evil Bootstrap – exfiltrate!
  60. https://vimeo.com/user149155597
  61. Switcher – you know the drill
  62. Switcher – get the user function
  63. Switcher – import functions
  64. Switcher – add to path
  65. Switcher – exec modules
  66. Switcher – exec modules
  67. Switcher – monkey patch!
  68. Evil function
  69. Evil function – add exfiltration
  70. Evil function – sockets!
  71. You could try it too! https://github.com/ Djkusik/ serverless_persistency_poc
  72. From external process?
  73. Mitigations & Detection
  74. AWS GCP Mitigations
  75. • VPC • VPC AWS GCP Mitigations
  76. • VPC • without NAT Gateway • VPC AWS GCP Mitigations
  77. • VPC • without NAT Gateway • VPC • with whole traffic routing, without NAT Gateway AWS GCP Mitigations
  78. • VPC • without NAT Gateway • with NAT Gateway & Security Group not allowing Outbound (implicit deny) • VPC • with whole traffic routing, without NAT Gateway AWS GCP Mitigations
  79. • VPC • without NAT Gateway • with NAT Gateway & Security Group not allowing Outbound (implicit deny) • VPC • with whole traffic routing, without NAT Gateway • with NAT Gateway & Firewall rule deny whole egress (explicit deny required) AWS GCP Mitigations
  80. AWS
  81. AWS
  82. GCP
  83. GCP
  84. It is still an RCE / Command Injection We can find a way to evade these protections
  85. Detection
  86. Detection
  87. Detection Few ideas: • Alerts based on execution time
  88. Detection Few ideas: • Alerts based on execution time • SDLC & CI/CD
  89. Detection Few ideas: • Alerts based on execution time • SDLC & CI/CD • Implementing defensive layers (?)
  90. Detection Few ideas: • Alerts based on execution time • SDLC & CI/CD • Implementing defensive layers (?) • Flow logs (?)
  91. How to research?
  92. How? • AWS Documentation
  93. How? • AWS Documentation • AWS Re:Invented & Blog
  94. How? • AWS Documentation • AWS Re:Invented & Blog • Google it! (or DuckDuckGo it!)
  95. How? • AWS Documentation • AWS Re:Invented & Blog • Google it! (or DuckDuckGo it!) • Deploy local Lambda environment (GitHub)
  96. How? • AWS Documentation • AWS Re:Invented & Blog • Google it! (or DuckDuckGo it!) • Deploy local Lambda environment (GitHub) • Try on real environment ;)
  97. Lambda sHell
  98. Here it is! https://github.com/ Djkusik/Lambda-sHell Based on Yuval’s SPLASH
  99. Paweł Kusiński Senior IT Security Consultant at Securing Practical AWS Security trainer @_pkusik pkusik Thank you! Q&A time

Hinweis der Redaktion

  1. In case of read-only file system, let’s write our new runtime into volatile storage - RAM, as anonymous file
  2. Inspecting stack Memory reading NOT NEEDED Next invocation returns current, if the process did not end
  3. Inspecting stack Memory reading NOT NEEDED Next invocation returns current, if the process did not end
  4. In case where internet connection is required - allowlisting
  5. In case where internet connection is required - allowlisting
  6. In case where internet connection is required - allowlisting
  7. In case where internet connection is required - allowlisting
  8. In case where internet connection is required - allowlisting
  9. In case where internet connection is required - allowlisting
Anzeige