Is Serverless Safe?
~ Hacking AWS Lambda ~
Yutaka Hiroyama
Japan AWS Top Engineer since
2019
Slide 2
Slide 2 text
Who am I
• Yutaka Hiroyama
•iret, Inc.
CISO
Director of Internal Control Promotion Office &
Deputy Division Director of Cloud Integration Division
•AWS Well Architected Lead
AWS Top Engineers - 2019 ~
•Many certifications holder about cloud computing
(AWS e.t.c.), security, development and others.
Slide 3
Slide 3 text
Who is us
Development
Construct
MSP※
Resale
AWS:since 2010
Premium Consulting Partner
Design
App Development
Infrastructure
Slide 4
Slide 4 text
Intro
Slide 5
Slide 5 text
Can you steal another one’s data via this AWS Lambda function?
JNQPSUKTPO
JNQPSUZBNM
EFG)BOEMFS FWFOU
DPOUFYU
EBUBZBNMMPBE FWFOU<%BUB>
TUPSF@EBUB EBUB
SFUVSO\
TUBUVT$PEF
CPEZl0,z
^
JNQPSUKTPO
JNQPSUZBNM
EFG)BOEMFS FWFOU
DPOUFYU
EBUBZBNMMPBE FWFOU<%BUB>
TUPSF@EBUB EBUB
SFUVSO\
TUBUVT$PEF
CPEZl0,z
^
Slide 6
Slide 6 text
Caution!!
https://unit42.paloaltonetworks.com/gaining-persistency-
vulnerable-lambdas/
What Iʼll talk how to attack is under this article.
You should not try this attack for the otherʼs environment !!
Slide 7
Slide 7 text
Hacking
Slide 8
Slide 8 text
Architecture of AWS Lambda
As below is keys of this session.
● A container will be created when cold start happen.
● A bootstrap (runtime) and a code which written by user (handler) exists in the same container.
● A runtime continue to loop procedure that call handler and return the response.
引⽤)
https://aws.amazon.com/jp/blogs/compute/the-serverless-lamp-stack-part-3-replacing-the-web-server/
https://medium.com/build-succeeded/deconstructing-aws-lambda-functions-d1597dd054cd
Slide 9
Slide 9 text
Overview of the technique
The attack can be actualized by replace the bootstrap via the
handler.
It exploit a vulnerability of OS command injection.
The evil bootstrap send received data to specified IP address
just before call handler.
Slide 10
Slide 10 text
Procedure of replacing bootstrap
The attacker can persistence as below.
1. Attacker tampere bootstrap which stole requested data.
2. Attacker create YAML file which contains tampered bootstrap and scripts which can replace
bootstrap process.
3. Attacker send the YAML file.
4. Handler load YAML file.
5. While loading, handler replace current healthy bootstrap process with evil one.
The evil bootstrap send received data to specified IP address just before call handler.
Slide 11
Slide 11 text
Attacking diagram - prepare
Slide 12
Slide 12 text
Attacking diagram - steal data
Replace !
Slide 13
Slide 13 text
Key points
Evil bootstrap has been created based on official one.
The lambda function behave normally.
So, Users and operators are hardly acknowledged the
bootstrap has been replaced.
Slide 14
Slide 14 text
Extract of evil bootstrap
This bootstrap send attached data to
attacker by POST method.
Slide 15
Slide 15 text
Sample code of replacing bootstrap process script
Slide 16
Slide 16 text
Sample of creating evil YAML file script
This script constructs camouflaged YAML file which contains
evil bootstrap and bootstrap process changer.
Slide 17
Slide 17 text
The capture of stolen data
You can see by
Base64 decode
Slide 18
Slide 18 text
Who has responsibility?
Slide 19
Slide 19 text
Shared responsibility model on AWS Lambda
IaaSとサーバーレス
引⽤)
https://docs.aws.amazon.com/whitepapers/latest/security-overview-aws-lambda/the-shared-responsibility-
Slide 20
Slide 20 text
Shared responsibility model on AWS Lambda
IaaSとサーバーレス
Slide 21
Slide 21 text
Analyze
Slide 22
Slide 22 text
About vulnerability
CVE-2017-18342 vulnerability can cause OS command injection. PyYAML library ver 5.1 or less.
CVSS 3 score is 9.8. It’s very dangerous.
引⽤)
https://nvd.nist.gov/vuln/detail/CVE-2017-18342
Protect types
Shift Left (Scan, Separate Network, Encryption)
Shield Right (WAF, IDS/IPS, CWPP, VPC FlowLog, GuardDuty)
Quote)
https://sysdig.com/blog/cnapp-runtime-insights-shift-left-
shield-right/
Slide 26
Slide 26 text
Example of Amazon CodeGuru detection
Detected !!
Slide 27
Slide 27 text
Example of AWS WAF protection
Check “os.execv”
word.
This is the log of AWS WAF, when received the
attack.
Slide 28
Slide 28 text
Important
Both of shift Left and shield right are necessary!
You should prevent not only protect.
Slide 29
Slide 29 text
Wrap-up
Slide 30
Slide 30 text
Is AWS Lambda dangerous?
No!but not safe with no countermeasure
OS command injection is valid on IaaS or On-Prem
environments.
Or rather, it can easily to make it happen, because the
attacker had not to know bootstrap process.
Moreover, AWS Lambda automatically reconstruct
environment by cold start.
Slide 31
Slide 31 text
You should
● You should do vulnerability countermeasures on FaaS
such as AWS Lambda.
● (But the established attack may kill by automatically)
● You had better acknowledge how to work your using
service to protect your system.
● To prevent (Shift left) and to protect / detect (Shield right)
are important. You should both of them.